Refactor to replace some sketchy code with code actually in use.
--HG--
rename : src/sixtypical/objects.py => src/sixtypical/model.py
Chris Pressey
6 years ago
0 | 0 |
syntax: glob
|
1 | 1 |
|
2 | |
*.o
|
3 | |
*.hi
|
4 | 2 |
*.pyc
|
39 | 39 |
* explicitly-addressed memory locations.
|
40 | 40 |
* generate 6502 code (either Ophis assembler or machine code `PRG` files.)
|
41 | 41 |
* `while` loops.
|
|
42 |
* `repeat` loops.
|
42 | 43 |
* a little demo that actually compiles and runs on a C64 emulator.
|
43 | 44 |
|
44 | 45 |
For 0.4 and/or beyond:
|
2 | 2 |
import sys
|
3 | 3 |
|
4 | 4 |
from sixtypical.ast import Program, Defn, Routine, Block, Instr
|
5 | |
from sixtypical.parser import ConstantRef, LocationRef
|
|
5 |
from sixtypical.model import ConstantRef, LocationRef
|
6 | 6 |
|
7 | 7 |
|
8 | 8 |
UNINITIALIZED = 'UNINITIALIZED'
|
0 | 0 |
# encoding: UTF-8
|
1 | 1 |
|
2 | 2 |
from sixtypical.ast import Program, Defn, Routine, Block, Instr
|
3 | |
from sixtypical.parser import ConstantRef, LocationRef
|
|
3 |
from sixtypical.model import ConstantRef, LocationRef
|
4 | 4 |
|
5 | 5 |
|
6 | 6 |
# TODO: should not inherit from dict
|
|
0 |
"""Data/storage model for SixtyPical."""
|
|
1 |
|
|
2 |
class LocationRef(object):
|
|
3 |
def __init__(self, name):
|
|
4 |
self.name = name
|
|
5 |
|
|
6 |
def __repr__(self):
|
|
7 |
return 'LocationRef(%r)' % self.name
|
|
8 |
|
|
9 |
|
|
10 |
class ConstantRef(object):
|
|
11 |
def __init__(self, value):
|
|
12 |
self.value = value
|
|
13 |
|
|
14 |
def __repr__(self):
|
|
15 |
return 'ConstantRef(%r)' % self.value
|
|
16 |
|
|
17 |
|
|
18 |
# TODO type=byte
|
|
19 |
|
|
20 |
REG_A = LocationRef('a')
|
|
21 |
REG_X = LocationRef('x')
|
|
22 |
REG_Y = LocationRef('y')
|
|
23 |
|
|
24 |
# TODO type=bit
|
|
25 |
|
|
26 |
FLAG_Z = LocationRef('z')
|
|
27 |
FLAG_C = LocationRef('c')
|
|
28 |
FLAG_N = LocationRef('n')
|
|
29 |
FLAG_V = LocationRef('v')
|
0 | |
|
1 | |
|
2 | |
class Type(object):
|
3 | |
pass
|
4 | |
|
5 | |
class BitType(Type):
|
6 | |
pass
|
7 | |
|
8 | |
class ByteType(Type):
|
9 | |
pass
|
10 | |
|
11 | |
class MemoryLocation(object):
|
12 | |
def __init__(self, name, type_=ByteType, readonly=False):
|
13 | |
self.name = name
|
14 | |
self.type_ = type_
|
15 | |
self.readonly = readonly
|
16 | |
|
17 | |
|
18 | |
regA = MemoryLocation('a')
|
19 | |
regX = MemoryLocation('x')
|
20 | |
regY = MemoryLocation('y')
|
21 | |
|
22 | |
regC = MemoryLocation('c', type=BitType)
|
23 | |
regZ = MemoryLocation('z', type=BitType)
|
24 | |
regN = MemoryLocation('n', type=BitType)
|
25 | |
regV = MemoryLocation('v', type=BitType)
|
26 | |
|
27 | |
|
28 | |
class Context(dict):
|
29 | |
# maps MemoryLoction -> properties: uninitialized, initialized, written
|
30 | |
pass
|
2 | 2 |
import re
|
3 | 3 |
|
4 | 4 |
from sixtypical.ast import Program, Defn, Routine, Block, Instr
|
|
5 |
from sixtypical.model import LocationRef, ConstantRef
|
5 | 6 |
|
6 | 7 |
|
7 | 8 |
class Scanner(object):
|
|
66 | 67 |
return True
|
67 | 68 |
else:
|
68 | 69 |
return False
|
69 | |
|
70 | |
|
71 | |
# - - - -
|
72 | |
|
73 | |
|
74 | |
class LocationRef(object):
|
75 | |
def __init__(self, name):
|
76 | |
self.name = name
|
77 | |
|
78 | |
def __repr__(self):
|
79 | |
return 'LocationRef(%r)' % self.name
|
80 | |
|
81 | |
|
82 | |
class ConstantRef(object):
|
83 | |
def __init__(self, value):
|
84 | |
self.value = value
|
85 | |
|
86 | |
def __repr__(self):
|
87 | |
return 'ConstantRef(%r)' % self.value
|
88 | |
|
89 | |
|
90 | |
# - - - -
|
91 | 70 |
|
92 | 71 |
|
93 | 72 |
class Parser(object):
|