diff options
-rw-r--r-- | 020_check_type_by_instruction.cc (renamed from 048_check_type_by_instruction.cc) | 38 | ||||
-rw-r--r-- | 021run.cc (renamed from 020run.cc) | 6 | ||||
-rw-r--r-- | 022arithmetic.cc (renamed from 021arithmetic.cc) | 0 | ||||
-rw-r--r-- | 023boolean.cc (renamed from 022boolean.cc) | 0 | ||||
-rw-r--r-- | 024jump.cc (renamed from 023jump.cc) | 0 | ||||
-rw-r--r-- | 025compare.cc (renamed from 024compare.cc) | 0 | ||||
-rw-r--r-- | 032array.cc | 28 | ||||
-rw-r--r-- | 048_check_type_by_name.cc (renamed from 049_check_type_by_name.cc) | 0 |
8 files changed, 39 insertions, 33 deletions
diff --git a/048_check_type_by_instruction.cc b/020_check_type_by_instruction.cc index dab8916b..d1eb9694 100644 --- a/048_check_type_by_instruction.cc +++ b/020_check_type_by_instruction.cc @@ -57,3 +57,41 @@ recipe main [ 1:number, 2:array:number <- copy 34, 35 ] +warn: main: can't copy 35 to array 2:array:number + +:(code) +bool is_mu_array(reagent r) { + if (is_literal(r)) return false; + while (has_property(r, "lookup")) { + if (r.types.empty()) { + raise << "can't lookup non-address: " << r.original_string << '\n' << end(); + return false; + } + if (r.types.at(0) != Type_ordinal["address"]) { + raise << "can't lookup non-address: " << r.original_string << '\n' << end(); + return false; + } + r.types.erase(r.types.begin()); + drop_one_lookup(r); + } + return !r.types.empty() && r.types.at(0) == Type_ordinal["array"]; +} + +void drop_one_lookup(reagent& r) { + for (vector<pair<string, vector<string> > >::iterator p = r.properties.begin(); p != r.properties.end(); ++p) { + if (p->first == "lookup") { + r.properties.erase(p); + return; + } + } + assert(false); +} + +bool is_literal(const reagent& r) { + return SIZE(r.types) == 1 && r.types.at(0) == 0; +} + +// helper for tests +void run(string form) { + vector<recipe_ordinal> tmp = load(form); + transform_all(); +} diff --git a/020run.cc b/021run.cc index 116d44a7..514e1204 100644 --- a/020run.cc +++ b/021run.cc @@ -299,11 +299,7 @@ bool is_dummy(const reagent& x) { return x.name == "_"; } -bool is_literal(const reagent& r) { - return SIZE(r.types) == 1 && r.types.at(0) == 0; -} - -:(code) +:(replace{} "void run(string form)") // helper for tests void run(string form) { vector<recipe_ordinal> tmp = load(form); diff --git a/021arithmetic.cc b/022arithmetic.cc index 107f0853..107f0853 100644 --- a/021arithmetic.cc +++ b/022arithmetic.cc diff --git a/022boolean.cc b/023boolean.cc index ead678cf..ead678cf 100644 --- a/022boolean.cc +++ b/023boolean.cc diff --git a/023jump.cc b/024jump.cc index 925906de..925906de 100644 --- a/023jump.cc +++ b/024jump.cc diff --git a/024compare.cc b/025compare.cc index 619caa03..619caa03 100644 --- a/024compare.cc +++ b/025compare.cc diff --git a/032array.cc b/032array.cc index 7ad84367..1b8d5900 100644 --- a/032array.cc +++ b/032array.cc @@ -332,31 +332,3 @@ case LENGTH: { recipe_ordinal r = current_instruction().operation; if (r == CREATE_ARRAY || r == INDEX || r == INDEX_ADDRESS || r == LENGTH) return false; - -:(code) -bool is_mu_array(reagent r) { - if (is_literal(r)) return false; - while (has_property(r, "lookup")) { - if (r.types.empty()) { - raise << "can't lookup non-address: " << r.original_string << '\n' << end(); - return false; - } - if (r.types.at(0) != Type_ordinal["address"]) { - raise << "can't lookup non-address: " << r.original_string << '\n' << end(); - return false; - } - r.types.erase(r.types.begin()); - drop_one_lookup(r); - } - return !r.types.empty() && r.types.at(0) == Type_ordinal["array"]; -} - -void drop_one_lookup(reagent& r) { - for (vector<pair<string, vector<string> > >::iterator p = r.properties.begin(); p != r.properties.end(); ++p) { - if (p->first == "lookup") { - r.properties.erase(p); - return; - } - } - assert(false); -} diff --git a/049_check_type_by_name.cc b/048_check_type_by_name.cc index 8510d02c..8510d02c 100644 --- a/049_check_type_by_name.cc +++ b/048_check_type_by_name.cc |