git @ Cat's Eye Technologies SixtyPical / dd4c50f
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
8 changed file(s) with 34 addition(s) and 59 deletion(s). Raw diff Collapse all Expand all
0 *.o
1 *.hi
20 *.pyc
00 syntax: glob
11
2 *.o
3 *.hi
42 *.pyc
3939 * explicitly-addressed memory locations.
4040 * generate 6502 code (either Ophis assembler or machine code `PRG` files.)
4141 * `while` loops.
42 * `repeat` loops.
4243 * a little demo that actually compiles and runs on a C64 emulator.
4344
4445 For 0.4 and/or beyond:
22 import sys
33
44 from sixtypical.ast import Program, Defn, Routine, Block, Instr
5 from sixtypical.parser import ConstantRef, LocationRef
5 from sixtypical.model import ConstantRef, LocationRef
66
77
88 UNINITIALIZED = 'UNINITIALIZED'
00 # encoding: UTF-8
11
22 from sixtypical.ast import Program, Defn, Routine, Block, Instr
3 from sixtypical.parser import ConstantRef, LocationRef
3 from sixtypical.model import ConstantRef, LocationRef
44
55
66 # 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
-31
src/sixtypical/objects.py less more
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
22 import re
33
44 from sixtypical.ast import Program, Defn, Routine, Block, Instr
5 from sixtypical.model import LocationRef, ConstantRef
56
67
78 class Scanner(object):
6667 return True
6768 else:
6869 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 # - - - -
9170
9271
9372 class Parser(object):