1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-22 01:32:13 +00:00

First cut at a --run option for sixtypical, replacing loadngo.sh.

This commit is contained in:
Chris Pressey 2019-04-11 16:53:43 +01:00
parent 04a9438898
commit ce8e83908b

View File

@ -11,7 +11,9 @@ from argparse import ArgumentParser
import codecs
import json
from pprint import pprint
from subprocess import check_call
import sys
from tempfile import NamedTemporaryFile
import traceback
from sixtypical.parser import Parser, SymbolTable, merge_programs
@ -64,7 +66,7 @@ def process_input_files(filenames, options):
compilation_roster = fa.serialize()
dump(compilation_roster)
if options.analyze_only or options.output is None:
if options.analyze_only or (options.output is None and not options.run):
return
start_addr = None
@ -74,16 +76,36 @@ def process_input_files(filenames, options):
else:
start_addr = int(options.origin, 10)
with open(options.output, 'wb') as fh:
outputter = outputter_class_for(options.output_format)(fh, start_addr=start_addr)
outputter.write_prelude()
compiler = Compiler(symtab, outputter.emitter)
compiler.compile_program(program, compilation_roster=compilation_roster)
outputter.write_postlude()
if options.debug:
pprint(outputter.emitter)
else:
outputter.emitter.serialize_to(fh)
if options.run:
fh = NamedTemporaryFile(delete=False)
output_filename = fh.name
else:
fh = open(options.output, 'wb')
output_filename = options.output
outputter = outputter_class_for(options.output_format)(fh, start_addr=start_addr)
outputter.write_prelude()
compiler = Compiler(symtab, outputter.emitter)
compiler.compile_program(program, compilation_roster=compilation_roster)
outputter.write_postlude()
if options.debug:
pprint(outputter.emitter)
else:
outputter.emitter.serialize_to(fh)
fh.close()
if options.run:
emu = {
'c64-basic-prg': "x64 -config vicerc",
'vic20-basic-prg': "xvic -config vicerc",
'atari2600-cart': "stella"
}.get(options.output_format)
if not emu:
raise ValueError("No emulator configured for selected --output-format '{}'".format(options.output_format))
command = "{} {}".format(emu, output_filename)
check_call(command, shell=True)
if __name__ == '__main__':
@ -142,6 +164,12 @@ if __name__ == '__main__':
action="store_true",
help="Display debugging information when analyzing and compiling."
)
argparser.add_argument(
"--run",
action="store_true",
help="Engage 'load-and-go' operation: write the output to a temporary filename, "
"infer an emulator from the given --output-format, and boot the emulator."
)
argparser.add_argument(
"--traceback",
action="store_true",