git @ Cat's Eye Technologies SixtyPical / c0243ee
Wire up the compiler and wring out obvious bugs. Chris Pressey 6 years ago
4 changed file(s) with 16 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
1919 from sixtypical.parser import Parser
2020 from sixtypical.evaluator import eval_program
2121 from sixtypical.analyzer import analyze_program
22 from sixtypical.emitter import Emitter
23 from sixtypical.compiler import compile_program
2224
2325
2426 if __name__ == '__main__':
5557 sys.exit(1)
5658 print 'ok'
5759
60 if options.compile:
61 emitter = Emitter(41952)
62 compile_program(program, emitter)
63 emitter.serialize(sys.stdout)
64
5865 if options.execute:
5966 context = eval_program(program)
6067 print str(context)
77 from sixtypical.gen6502 import Generator
88
99
10 def compile_program(program):
10 def compile_program(program, emitter):
1111 assert isinstance(program, Program)
12 generator = Generator(49152)
12 generator = Generator(emitter)
1313 routines = {r.name: r for r in program.routines}
1414 for routine in program.routines:
1515 compile_routine(routine, generator, routines)
4141 if isinstance(src, ConstantRef):
4242 # LDA #...
4343 pass
44 elif:
44 else:
4545 # LDA abs
4646 pass
4747 elif dest == REG_X:
48 pass
4849 elif dest == REG_Y:
50 pass
4951 else:
5052 raise KeyError
5153 elif opcode == 'st':
5254 if src == REG_A:
5355 # assert isinstance(dest, MemoryRef)
5456 # generate STA
57 pass
5558 else:
5659 raise KeyError
5760 elif opcode == 'add':
5656
5757 def make_label(self, name=None):
5858 if name is None:
59 name = 'label' + self.name_counter
59 name = 'label' + str(self.name_counter)
6060 self.name_counter += 1
6161 return Label(name, addr=self.addr)
6262
33
44
55 class Generator(object):
6 def __init__(self, addr):
7 self.emitter = Emitter(addr)
6 def __init__(self, emitter):
7 self.emitter = emitter
88
99 ### ld ###
1010