Replace --run option with terser --run-on option.
Chris Pressey
3 years ago
21 | 21 | * Refactored internal data structures that represent |
22 | 22 | references and types to be immutable `namedtuple`s. |
23 | 23 | * Added `--dump-exit-contexts` option to `sixtypical`. |
24 | * Added a new `--run` option to `sixtypical`, which replaces | |
25 | the old `loadngo.sh` script. | |
24 | * Added a new `--run-on=<emu>` option to `sixtypical`, which | |
25 | replaces the old `loadngo.sh` script. | |
26 | 26 | |
27 | 27 | 0.18 |
28 | 28 | ---- |
3 | 3 | _Version 0.19. Work-in-progress, everything is subject to change._ |
4 | 4 | |
5 | 5 | **SixtyPical** is a [low-level](#low-level) programming language |
6 | supporting a [sophisticated static analysis](#sophisticated-static-analysis). | |
6 | supporting a sophisticated [static analysis](#static-analysis). | |
7 | 7 | Its reference compiler can generate [efficient code](#efficient-code) for |
8 | 8 | several 6502-based [target platforms](#target-platforms) while catching many |
9 | 9 | common mistakes at compile-time, reducing the time spent in debugging. |
17 | 17 | |
18 | 18 | sixtypical |
19 | 19 | |
20 | If you have the [VICE][] emulator installed, you can run | |
20 | If you have the [VICE][] emulator suite installed, you can run | |
21 | 21 | |
22 | sixtypical --output-format=c64-basic-prg --run eg/c64/hearts.60p | |
22 | sixtypical --run-on=x64 eg/c64/hearts.60p | |
23 | 23 | |
24 | 24 | and it will compile the [hearts.60p source code](eg/c64/hearts.60p) and |
25 | 25 | automatically start it in the `x64` emulator, and you should see: |
26 | 26 | |
27 | 27 |  |
28 | 28 | |
29 | You can try `sixtypical --run` on other sources in the `eg` directory | |
29 | You can try `sixtypical --run-on` on other sources in the `eg` directory | |
30 | 30 | tree, which contains more extensive examples, including an entire |
31 | 31 | game(-like program); see [eg/README.md](eg/README.md) for a listing. |
32 | 32 | |
62 | 62 | While a programmer will find these constructs convenient, their |
63 | 63 | inclusion in the language is primarily to make programs easier to analyze. |
64 | 64 | |
65 | ### Sophisticated static analysis | |
65 | ### Static analysis | |
66 | 66 | |
67 | 67 | The language defines an [effect system][], and the reference |
68 | 68 | compiler [abstractly interprets][] the input program to check that |
65 | 65 | compilation_roster = fa.serialize() |
66 | 66 | dump(compilation_roster) |
67 | 67 | |
68 | if options.analyze_only or (options.output is None and not options.run): | |
68 | if options.analyze_only or (options.output is None and not options.run_on): | |
69 | 69 | return |
70 | 70 | |
71 | 71 | start_addr = None |
75 | 75 | else: |
76 | 76 | start_addr = int(options.origin, 10) |
77 | 77 | |
78 | if options.run: | |
78 | if options.run_on: | |
79 | 79 | fh = NamedTemporaryFile(delete=False) |
80 | 80 | output_filename = fh.name |
81 | Outputter = outputter_class_for({ | |
82 | 'x64': 'c64-basic-prg', | |
83 | 'xvic': 'vic20-basic-prg', | |
84 | 'stella': 'atari2600-cart', | |
85 | }.get(options.run_on)) | |
81 | 86 | else: |
82 | 87 | fh = open(options.output, 'wb') |
83 | 88 | output_filename = options.output |
84 | ||
85 | outputter = outputter_class_for(options.output_format)(fh, start_addr=start_addr) | |
89 | Outputter = outputter_class_for(options.output_format) | |
90 | ||
91 | outputter = Outputter(fh, start_addr=start_addr) | |
86 | 92 | outputter.write_prelude() |
87 | 93 | compiler = Compiler(symtab, outputter.emitter) |
88 | 94 | compiler.compile_program(program, compilation_roster=compilation_roster) |
94 | 100 | |
95 | 101 | fh.close() |
96 | 102 | |
97 | if options.run: | |
103 | if options.run_on: | |
98 | 104 | emu = { |
99 | 'c64-basic-prg': "x64 -config vicerc", | |
100 | 'vic20-basic-prg': "xvic -config vicerc", | |
101 | 'atari2600-cart': "stella" | |
102 | }.get(options.output_format) | |
105 | 'x64': "x64 -config vicerc", | |
106 | 'xvic': "xvic -config vicerc", | |
107 | 'stella': "stella" | |
108 | }.get(options.run_on) | |
103 | 109 | if not emu: |
104 | raise ValueError("No emulator configured for selected --output-format '{}'".format(options.output_format)) | |
110 | raise ValueError("No emulator configured for selected --run-on '{}'".format(options.output_format)) | |
105 | 111 | |
106 | 112 | command = "{} {}".format(emu, output_filename) |
107 | 113 | check_call(command, shell=True) |
164 | 170 | help="Display debugging information when analyzing and compiling." |
165 | 171 | ) |
166 | 172 | 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." | |
173 | "--run-on", type=str, default=None, | |
174 | help="If given, engage 'load-and-go' operation with the given emulator: write " | |
175 | "the output to a temporary filename, using an appropriate --output-format " | |
176 | "and boot the emulator with it. Options are: x64, xvic, stella." | |
171 | 177 | ) |
172 | 178 | argparser.add_argument( |
173 | 179 | "--traceback", |
10 | 10 | programs use "standard" support modules, so those should be included |
11 | 11 | first too. For example: |
12 | 12 | |
13 | sixtypical --output-format=c64-basic-prg --run support/c64.60p support/stdlib.60p vector-table.60p | |
13 | sixtypical --run-on=x64 support/c64.60p support/stdlib.60p vector-table.60p | |
14 | 14 | |
15 | 15 | `chrout` is a routine with outputs the value of the accumulator |
16 | 16 | as an ASCII character, disturbing none of the other registers, |