mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-02-16 15:30:26 +00:00
Wire up the compiler and wring out obvious bugs.
This commit is contained in:
parent
ba55065060
commit
c0243ee6ba
@ -20,6 +20,8 @@ import traceback
|
||||
from sixtypical.parser import Parser
|
||||
from sixtypical.evaluator import eval_program
|
||||
from sixtypical.analyzer import analyze_program
|
||||
from sixtypical.emitter import Emitter
|
||||
from sixtypical.compiler import compile_program
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@ -56,6 +58,11 @@ if __name__ == '__main__':
|
||||
sys.exit(1)
|
||||
print 'ok'
|
||||
|
||||
if options.compile:
|
||||
emitter = Emitter(41952)
|
||||
compile_program(program, emitter)
|
||||
emitter.serialize(sys.stdout)
|
||||
|
||||
if options.execute:
|
||||
context = eval_program(program)
|
||||
print str(context)
|
||||
|
@ -8,9 +8,9 @@ from sixtypical.model import (
|
||||
from sixtypical.gen6502 import Generator
|
||||
|
||||
|
||||
def compile_program(program):
|
||||
def compile_program(program, emitter):
|
||||
assert isinstance(program, Program)
|
||||
generator = Generator(49152)
|
||||
generator = Generator(emitter)
|
||||
routines = {r.name: r for r in program.routines}
|
||||
for routine in program.routines:
|
||||
compile_routine(routine, generator, routines)
|
||||
@ -42,17 +42,20 @@ def compile_instr(instr, generator, routines):
|
||||
if isinstance(src, ConstantRef):
|
||||
# LDA #...
|
||||
pass
|
||||
elif:
|
||||
else:
|
||||
# LDA abs
|
||||
pass
|
||||
elif dest == REG_X:
|
||||
pass
|
||||
elif dest == REG_Y:
|
||||
pass
|
||||
else:
|
||||
raise KeyError
|
||||
elif opcode == 'st':
|
||||
if src == REG_A:
|
||||
# assert isinstance(dest, MemoryRef)
|
||||
# generate STA
|
||||
pass
|
||||
else:
|
||||
raise KeyError
|
||||
elif opcode == 'add':
|
||||
|
@ -57,7 +57,7 @@ class Emitter(object):
|
||||
|
||||
def make_label(self, name=None):
|
||||
if name is None:
|
||||
name = 'label' + self.name_counter
|
||||
name = 'label' + str(self.name_counter)
|
||||
self.name_counter += 1
|
||||
return Label(name, addr=self.addr)
|
||||
|
||||
|
@ -4,8 +4,8 @@ from sixtypical.emitter import Emitter, Word, Label
|
||||
|
||||
|
||||
class Generator(object):
|
||||
def __init__(self, addr):
|
||||
self.emitter = Emitter(addr)
|
||||
def __init__(self, emitter):
|
||||
self.emitter = emitter
|
||||
|
||||
### ld ###
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user