git @ Cat's Eye Technologies SixtyPical / ce8e839
First cut at a --run option for sixtypical, replacing loadngo.sh. Chris Pressey 2 years ago
1 changed file(s) with 39 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
1010 import codecs
1111 import json
1212 from pprint import pprint
13 from subprocess import check_call
1314 import sys
15 from tempfile import NamedTemporaryFile
1416 import traceback
1517
1618 from sixtypical.parser import Parser, SymbolTable, merge_programs
6365 compilation_roster = fa.serialize()
6466 dump(compilation_roster)
6567
66 if options.analyze_only or options.output is None:
68 if options.analyze_only or (options.output is None and not options.run):
6769 return
6870
6971 start_addr = None
7375 else:
7476 start_addr = int(options.origin, 10)
7577
76 with open(options.output, 'wb') as fh:
77 outputter = outputter_class_for(options.output_format)(fh, start_addr=start_addr)
78 outputter.write_prelude()
79 compiler = Compiler(symtab, outputter.emitter)
80 compiler.compile_program(program, compilation_roster=compilation_roster)
81 outputter.write_postlude()
82 if options.debug:
83 pprint(outputter.emitter)
84 else:
85 outputter.emitter.serialize_to(fh)
78 if options.run:
79 fh = NamedTemporaryFile(delete=False)
80 output_filename = fh.name
81 else:
82 fh = open(options.output, 'wb')
83 output_filename = options.output
84
85 outputter = outputter_class_for(options.output_format)(fh, start_addr=start_addr)
86 outputter.write_prelude()
87 compiler = Compiler(symtab, outputter.emitter)
88 compiler.compile_program(program, compilation_roster=compilation_roster)
89 outputter.write_postlude()
90 if options.debug:
91 pprint(outputter.emitter)
92 else:
93 outputter.emitter.serialize_to(fh)
94
95 fh.close()
96
97 if options.run:
98 emu = {
99 'c64-basic-prg': "x64 -config vicerc",
100 'vic20-basic-prg': "xvic -config vicerc",
101 'atari2600-cart': "stella"
102 }.get(options.output_format)
103 if not emu:
104 raise ValueError("No emulator configured for selected --output-format '{}'".format(options.output_format))
105
106 command = "{} {}".format(emu, output_filename)
107 check_call(command, shell=True)
86108
87109
88110 if __name__ == '__main__':
142164 help="Display debugging information when analyzing and compiling."
143165 )
144166 argparser.add_argument(
167 "--run",
168 action="store_true",
169 help="Engage 'load-and-go' operation: write the output to a temporary filename, "
170 "infer an emulator from the given --output-format, and boot the emulator."
171 )
172 argparser.add_argument(
145173 "--traceback",
146174 action="store_true",
147175 help="When an error occurs, display a full Python traceback."