diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-11-27 22:23:54 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-11-27 22:23:54 -0800 |
commit | c561f6a91926cb3c9c22f483b94ca40a01e6a9c0 (patch) | |
tree | 25382bf6e061f5b643ca297683ee5b11384dc089 /057static_dispatch.cc | |
parent | dfdbcbab4299bbb4fc2725abf7fa26ac592e296e (diff) | |
download | mu-c561f6a91926cb3c9c22f483b94ca40a01e6a9c0.tar.gz |
2487
Ok, now I'm a little happier about our type checking. Type checking lies in three layers: layer 21: checking types, usually at run-time in the VM or just before layer 57: checking type names layer 59: checking type names It's taken me the process of writing this commit to convince myself that all three layers check mappings for literal values in a consistent manner. Layer 21 uses sizes, and layers 57/59 have whitelists, but either way the goal is that number != character != boolean unless mediated through a literal.
Diffstat (limited to '057static_dispatch.cc')
-rw-r--r-- | 057static_dispatch.cc | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/057static_dispatch.cc b/057static_dispatch.cc index 114d7c7c..223e6ec9 100644 --- a/057static_dispatch.cc +++ b/057static_dispatch.cc @@ -76,11 +76,24 @@ bool all_reagents_match(const recipe& r1, const recipe& r2) { return true; } -bool exact_match(type_tree* a, type_tree* b) { - if (a == b) return true; +:(before "End Globals") +set<string> Literal_type_names; +:(before "End One-time Setup") +Literal_type_names.insert("number"); +Literal_type_names.insert("character"); +:(code) +bool deeply_equal_types(const string_tree* a, const string_tree* b) { + if (!a) return !b; + if (!b) return !a; + if (a->value == "literal" && b->value == "literal") + return true; + if (a->value == "literal") + return Literal_type_names.find(b->value) != Literal_type_names.end(); + if (b->value == "literal") + return Literal_type_names.find(a->value) != Literal_type_names.end(); return a->value == b->value - && exact_match(a->left, b->left) - && exact_match(a->right, b->right); + && deeply_equal_types(a->left, b->left) + && deeply_equal_types(a->right, b->right); } string next_unused_recipe_name(const string& recipe_name) { |