Skip to content

Commit

Permalink
Merge pull request #28 from jblebrun/symtables
Browse files Browse the repository at this point in the history
Emit symbol tables
  • Loading branch information
jblebrun committed Oct 17, 2020
2 parents 8b81433 + 3699ec4 commit e9e8920
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
14 changes: 13 additions & 1 deletion octopy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
6 changes: 4 additions & 2 deletions octopy/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion octopy/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion test/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/testdata/macrocalls.8o
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
:macro cs r {
:calc offset { 12 * CALLS + 1 }
r := CALLS
}

Expand Down

0 comments on commit e9e8920

Please sign in to comment.