1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-25 23:49:17 +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 codecs
import json import json
from pprint import pprint from pprint import pprint
from subprocess import check_call
import sys import sys
from tempfile import NamedTemporaryFile
import traceback import traceback
from sixtypical.parser import Parser, SymbolTable, merge_programs from sixtypical.parser import Parser, SymbolTable, merge_programs
@ -64,7 +66,7 @@ def process_input_files(filenames, options):
compilation_roster = fa.serialize() compilation_roster = fa.serialize()
dump(compilation_roster) 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 return
start_addr = None start_addr = None
@ -74,7 +76,13 @@ def process_input_files(filenames, options):
else: else:
start_addr = int(options.origin, 10) start_addr = int(options.origin, 10)
with open(options.output, 'wb') as 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 = outputter_class_for(options.output_format)(fh, start_addr=start_addr)
outputter.write_prelude() outputter.write_prelude()
compiler = Compiler(symtab, outputter.emitter) compiler = Compiler(symtab, outputter.emitter)
@ -85,6 +93,20 @@ def process_input_files(filenames, options):
else: else:
outputter.emitter.serialize_to(fh) 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__': if __name__ == '__main__':
argparser = ArgumentParser() argparser = ArgumentParser()
@ -142,6 +164,12 @@ if __name__ == '__main__':
action="store_true", action="store_true",
help="Display debugging information when analyzing and compiling." 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( argparser.add_argument(
"--traceback", "--traceback",
action="store_true", action="store_true",