From b142a7620246d57b461e5863b9d1092a917a2fc3 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 16 May 2015 13:17:36 -0700 Subject: 1383 - warn on unknown type This bit me in the last commit for the first time. Layer 010vm.cc is starting to look weird. It has references to stuff that gets implemented much later, like containers and exclusive containers. Its helpers are getting an increasing amount of logic. And it has no tests. I'm still inclined to think it's useful to have major data structures in one place, even if they aren't used for a bit. But those helpers should perhaps move out somehow or get some tests in the same layer. --- 010vm.cc | 5 ++++- 020run.cc | 8 ++++++++ 038scheduler.cc | 4 ++++ 047jump_label.cc | 3 +++ 060string.mu | 3 ++- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/010vm.cc b/010vm.cc index 9b1641bd..c5e13543 100644 --- a/010vm.cc +++ b/010vm.cc @@ -183,7 +183,10 @@ reagent::reagent(string s) :value(0), initialized(false) { // structures for the first row of properties name = properties.at(0).first; for (index_t i = 0; i < properties.at(0).second.size(); ++i) { - types.push_back(Type_number[properties.at(0).second.at(i)]); + string type = properties.at(0).second.at(i); + if (Type_number.find(type) == Type_number.end()) + raise << "unknown type: " << type << '\n'; + types.push_back(Type_number[type]); } if (name == "_" && types.empty()) { types.push_back(0); diff --git a/020run.cc b/020run.cc index b93b7c98..32981fa6 100644 --- a/020run.cc +++ b/020run.cc @@ -239,3 +239,11 @@ recipe main [ _ <- copy 0:literal ] +run: instruction main/0 + +:(scenario run_warns_on_unknown_types) +% Hide_warnings = true; +recipe main [ + # integer is not a type + 1:integer <- copy 0:literal +] ++warn: unknown type: integer diff --git a/038scheduler.cc b/038scheduler.cc index 3d425d50..101d1960 100644 --- a/038scheduler.cc +++ b/038scheduler.cc @@ -123,6 +123,10 @@ Next_routine_id = 1; id = Next_routine_id; Next_routine_id++; +//: it needs a new type: 'recipe' +:(before "End Mu Types Initialization") +Type_number["recipe"] = 0; + //: routines save the routine that spawned them :(before "End routine Fields") // todo: really should be routine_id, but that's less efficient. diff --git a/047jump_label.cc b/047jump_label.cc index dd65c432..3158233b 100644 --- a/047jump_label.cc +++ b/047jump_label.cc @@ -10,6 +10,9 @@ recipe main [ ] -mem: storing 0 in location 1 +:(before "End Mu Types Initialization") +Type_number["label"] = 0; + :(after "int main") Transform.push_back(transform_labels); diff --git a/060string.mu b/060string.mu index d6921c8a..55dc0840 100644 --- a/060string.mu +++ b/060string.mu @@ -403,7 +403,7 @@ recipe interpolate [ { # while i < template.length tem-done?:boolean <- greater-or-equal i:number, tem-len:number - break-if tem-done?:boolean, 2:blocks + break-if tem-done?:boolean, +done:label # while template[i] != '_' in:character <- index template:address:array:character/deref, i:number underscore?:boolean <- equal in:character, 95:literal # '_' @@ -437,6 +437,7 @@ recipe interpolate [ i:number <- add i:number, 1:literal loop # interpolate next arg } + +done # done with holes; copy rest of template directly into result { # while i < template.length -- cgit 1.4.1-2-gfad0