diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-06-15 22:12:03 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-06-15 22:12:03 -0700 |
commit | 0edd9b9fc60440213e4df926ea511419ee291f1e (patch) | |
tree | 84b22f7afdeb9110ad7105c5fc070dacff178502 /024jump.cc | |
parent | 3f34ac9369978b396d00a4fd02c9fb06b8eea621 (diff) | |
download | mu-0edd9b9fc60440213e4df926ea511419ee291f1e.tar.gz |
4257 - abortive attempt at safe fat pointers
I've been working on this slowly over several weeks, but it's too hard to support 0 as the null value for addresses. I constantly have to add exceptions for scalar value corresponding to an address type (now occupying 2 locations). The final straw is the test for 'reload': x:num <- reload text 'reload' returns an address. But there's no way to know that for arbitrary instructions. New plan: let's put this off for a bit and first create support for literals. Then use 'null' instead of '0' for addresses everywhere. Then it'll be easy to just change what 'null' means.
Diffstat (limited to '024jump.cc')
-rw-r--r-- | 024jump.cc | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/024jump.cc b/024jump.cc index 37011290..b7011c09 100644 --- a/024jump.cc +++ b/024jump.cc @@ -72,7 +72,7 @@ case JUMP_IF: { raise << maybe(get(Recipe, r).name) << "'" << to_original_string(inst) << "' should get exactly two ingredients\n" << end(); break; } - if (!is_mu_scalar(inst.ingredients.at(0))) { + if (!is_mu_address(inst.ingredients.at(0)) && !is_mu_scalar(inst.ingredients.at(0))) { raise << maybe(get(Recipe, r).name) << "'" << to_original_string(inst) << "' requires a boolean for its first ingredient, but '" << inst.ingredients.at(0).name << "' has type '" << names_to_string_without_quotes(inst.ingredients.at(0).type) << "'\n" << end(); break; } @@ -90,7 +90,7 @@ case JUMP_IF: { :(before "End Primitive Recipe Implementations") case JUMP_IF: { assert(current_instruction().ingredients.at(1).initialized); - if (!ingredients.at(0).at(0)) { + if (!scalar_ingredient(ingredients, 0)) { trace(9998, "run") << "jump-if fell through" << end(); break; } @@ -109,7 +109,7 @@ def main [ ] +run: jump-if {999: "literal"}, {1: "offset"} +run: jumping to instruction 2 --run: {1: "number"} <- copy {1: "literal"} +-run: {123: "number"} <- copy {1: "literal"} -mem: storing 1 in location 123 :(scenario jump_if_fallthrough) @@ -122,6 +122,17 @@ def main [ +run: {123: "number"} <- copy {1: "literal"} +mem: storing 1 in location 123 +:(scenario jump_if_on_address) +def main [ + 10:&:num <- copy 999/unsafe + jump-if 10:&:number, 1:offset + 123:num <- copy 1 +] ++run: jump-if {10: ("address" "number")}, {1: "offset"} ++run: jumping to instruction 3 +-run: {123: "number"} <- copy {1: "literal"} +-mem: storing 1 in location 123 + :(before "End Primitive Recipe Declarations") JUMP_UNLESS, :(before "End Primitive Recipe Numbers") @@ -132,7 +143,7 @@ case JUMP_UNLESS: { raise << maybe(get(Recipe, r).name) << "'" << to_original_string(inst) << "' should get exactly two ingredients\n" << end(); break; } - if (!is_mu_scalar(inst.ingredients.at(0))) { + if (!is_mu_address(inst.ingredients.at(0)) && !is_mu_scalar(inst.ingredients.at(0))) { raise << maybe(get(Recipe, r).name) << "'" << to_original_string(inst) << "' requires a boolean for its first ingredient, but '" << inst.ingredients.at(0).name << "' has type '" << names_to_string_without_quotes(inst.ingredients.at(0).type) << "'\n" << end(); break; } @@ -150,7 +161,7 @@ case JUMP_UNLESS: { :(before "End Primitive Recipe Implementations") case JUMP_UNLESS: { assert(current_instruction().ingredients.at(1).initialized); - if (ingredients.at(0).at(0)) { + if (scalar_ingredient(ingredients, 0)) { trace(9998, "run") << "jump-unless fell through" << end(); break; } |