diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-10-28 13:08:26 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-10-28 13:19:41 -0700 |
commit | 1fa530589eee7b668d936e77c1c430f18907a481 (patch) | |
tree | 95a506363d74231d1e85b402549b0ca6a466391e /021check_instruction.cc | |
parent | 48086e1044a8c000eb7977621cde0813f7bb70cf (diff) | |
download | mu-1fa530589eee7b668d936e77c1c430f18907a481.tar.gz |
2299 - check types of ingredients in calls
Still very incomplete: a) we perform the check at runtime b) tests for edit and sandbox apps no longer work; we can't fix them until we get type parameters in both containers and recipes (because list and list operations need to become generic).
Diffstat (limited to '021check_instruction.cc')
-rw-r--r-- | 021check_instruction.cc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/021check_instruction.cc b/021check_instruction.cc index 2fdaad60..f3dd89d8 100644 --- a/021check_instruction.cc +++ b/021check_instruction.cc @@ -88,10 +88,27 @@ bool types_match(reagent lhs, reagent rhs) { // (trees perform the same check recursively on each subtree) bool types_match(type_tree* lhs, type_tree* rhs) { if (!lhs) return true; + if (!rhs || rhs->value == 0) { + if (lhs->value == Type_ordinal["array"]) return false; + if (lhs->value == Type_ordinal["address"]) return false; + return size_of(rhs) == size_of(lhs); + } if (lhs->value != rhs->value) return false; return types_match(lhs->left, rhs->left) && types_match(lhs->right, rhs->right); } +// hacky version that allows 0 addresses +bool types_match(const reagent lhs, const type_tree* rhs, const vector<double>& data) { + if (is_dummy(lhs)) return true; + if (!rhs || rhs->value == 0) { + if (lhs.type->value == Type_ordinal["array"]) return false; + if (lhs.type->value == Type_ordinal["address"]) return scalar(data) && data.at(0) == 0; + return size_of(rhs) == size_of(lhs); + } + if (lhs.type->value != rhs->value) return false; + return types_match(lhs.type->left, rhs->left) && types_match(lhs.type->right, rhs->right); +} + bool is_raw(const reagent& r) { return has_property(r, "raw"); } |