diff options
author | Kartik Agaram <vc@akkartik.com> | 2019-07-27 16:01:55 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2019-07-27 17:47:59 -0700 |
commit | 6e1eeeebfb453fa7c871869c19375ce60fbd7413 (patch) | |
tree | 539c4a3fdf1756ae79770d5c4aaf6366f1d1525e /archive/2.vm/013update_operation.cc | |
parent | 8846a7f85cc04b77b2fe8a67b6d317723437b00c (diff) | |
download | mu-6e1eeeebfb453fa7c871869c19375ce60fbd7413.tar.gz |
5485 - promote SubX to top-level
Diffstat (limited to 'archive/2.vm/013update_operation.cc')
-rw-r--r-- | archive/2.vm/013update_operation.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/archive/2.vm/013update_operation.cc b/archive/2.vm/013update_operation.cc new file mode 100644 index 00000000..ffe3dbb9 --- /dev/null +++ b/archive/2.vm/013update_operation.cc @@ -0,0 +1,40 @@ +//: Once all code is loaded, save operation ids of instructions and check that +//: nothing's undefined. + +:(before "End Instruction Modifying Transforms") +Transform.push_back(update_instruction_operations); // idempotent + +:(code) +void update_instruction_operations(const recipe_ordinal r) { + trace(101, "transform") << "--- compute instruction operations for recipe " << get(Recipe, r).name << end(); + recipe& caller = get(Recipe, r); +//? cerr << "--- compute instruction operations for recipe " << caller.name << '\n'; + for (int index = 0; index < SIZE(caller.steps); ++index) { + instruction& inst = caller.steps.at(index); + if (inst.is_label) continue; + if (!contains_key(Recipe_ordinal, inst.name)) { + raise << maybe(caller.name) << "instruction '" << inst.name << "' has no recipe in '" << to_original_string(inst) << "'\n" << end(); + continue; + } + inst.operation = get(Recipe_ordinal, inst.name); + // End Instruction Operation Checks + } +} + +// hook to suppress inserting recipe name into errors +string maybe(string recipe_name) { + // End maybe(recipe_name) Special-cases + return recipe_name + ": "; +} + +void test_missing_arrow() { + Hide_errors = true; + transform( + "def main [\n" + " 1:number , copy 0\n" // typo: ',' instead of '<-' + "]\n" + ); + CHECK_TRACE_CONTENTS( + "error: main: instruction '1:number' has no recipe in '1:number copy, 0'\n" + ); +} |