Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit symbol tables #28

Merged
merged 1 commit into from
Oct 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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