diff --git a/octopy/__main__.py b/octopy/__main__.py index fbb146d..0b74801 100644 --- a/octopy/__main__.py +++ b/octopy/__main__.py @@ -16,4 +16,16 @@ else: outname = sys.argv[1].split(".")[0] + ".ch8" fout = open(outname, 'w') - fout.buffer.write(program) + fout.buffer.write(program.program) + + if len(sys.argv) > 3: + outname = sys.argv[3] + else: + outname = sys.argv[1].split(".")[0] + ".sym" + + fout = open(outname, 'w') + for name, pc in program.labels.items(): + fout.write("{} = 0x0{:3X}\n".format(name, pc+0x200)) + for name, pc in program.consts.items(): + if name not in program.labels: + fout.write("{} = {}\n".format(name, pc)) diff --git a/octopy/assemble.py b/octopy/assemble.py index 5635964..5fda578 100644 --- a/octopy/assemble.py +++ b/octopy/assemble.py @@ -19,12 +19,14 @@ def print_error(err): def assemble(f): program = Program() + tokenizer = Tokenizer(f) try: - parser = Parser(Tokenizer(f), program) + parser = Parser(tokenizer, program) parser.parse() program.resolve() except ParseError as error: print_error(error) - return program.program + program.consts = tokenizer.consts + return program diff --git a/octopy/tokenizer.py b/octopy/tokenizer.py index 1475b38..ab0290a 100644 --- a/octopy/tokenizer.py +++ b/octopy/tokenizer.py @@ -80,7 +80,7 @@ def expect(self, matcher, msg): def expect_ident(self): if not validIdent.match(self.current_token.text): - self.error("Expected an identifier") + self.error("Expected an identifier: {}".format(self.current_token.text)) return self.current_token def next_ident(self): diff --git a/test/programs.py b/test/programs.py index fa483ab..4b2eb88 100644 --- a/test/programs.py +++ b/test/programs.py @@ -48,7 +48,9 @@ def run_program_test(self, name): # Compile the program srcfile = filehere("{}.8o".format(name)) with open(srcfile) as src: - program = assemble(src) + assembly = assemble(src) + + program = assembly.program # Generate the comparisons for each 16 byte group pc = 0 diff --git a/test/testdata/macrocalls.8o b/test/testdata/macrocalls.8o index 7bf5f0c..d4ad37f 100644 --- a/test/testdata/macrocalls.8o +++ b/test/testdata/macrocalls.8o @@ -1,4 +1,5 @@ :macro cs r { + :calc offset { 12 * CALLS + 1 } r := CALLS }