git.haldean.org cvm / 0880ff1
VM can now call functions without arguments. Return values are supported. Will Brown 9 years ago
3 changed file(s) with 21 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
00 from parse.c import parse
1 from util import print_tree
1 from util import print_tree, print_instructions
22 from translate import translate
33 from link import link
44 from binary import write_binary, parse_instructions
2323
2424 instructions = link(*translate(tree))
2525 if args.write_assembly:
26 for c in instructions:
27 print(c)
26 print_instructions(instructions)
2827
2928 with open(args.output, 'w') as binout:
3029 write_binary(instructions, binout)
2727 print(' ' * tablvl + str(root))
2828 else:
2929 print(' ' * tablvl + 'None')
30
31 def print_instructions(instrs):
32 for instr in instrs:
33 instr_str = instr[0].upper()
34 for arg in instr[1:]:
35 instr_str += ' %d' % arg
36 print(instr_str)
0 LDCONST 5
1 CALL 7
2 PRINT
3 PRINT
4 PRINT
5 PRINT
6 HALT
7 LDCONST '\n'
8 LDCONST 's'
9 LDCONST 'e'
10 LDCONST 'y'
11 RETURN