diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-11-15 01:02:53 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-11-15 01:02:53 -0800 |
commit | 687dd3f5da63bee9dd310bc4ac2844ece43e3fba (patch) | |
tree | 3e57d03f17a59c97a9ba10b15ee87084eced66e1 | |
parent | ef96f57ce264c8e0bd98f6e8622d1c1e2eceafb2 (diff) | |
download | mu-687dd3f5da63bee9dd310bc4ac2844ece43e3fba.tar.gz |
2442
Fix the drawback in the previous commit: if an ingredient is just a literal 0 we'll skip its type-checking and hope to map type ingredients elsewhere.
-rw-r--r-- | 021check_instruction.cc | 11 | ||||
-rw-r--r-- | 059shape_shifting_recipe.cc | 18 | ||||
-rw-r--r-- | 073list.mu | 3 | ||||
-rw-r--r-- | 075duplex_list.mu | 36 | ||||
-rw-r--r-- | edit/001-editor.mu | 3 | ||||
-rw-r--r-- | edit/005-sandbox.mu | 3 |
6 files changed, 37 insertions, 37 deletions
diff --git a/021check_instruction.cc b/021check_instruction.cc index fc1f0a1f..15d14afc 100644 --- a/021check_instruction.cc +++ b/021check_instruction.cc @@ -79,17 +79,16 @@ bool types_match(reagent lhs, reagent rhs) { // to sidestep type-checking, use /raw in the source. // this is unsafe, and will be highlighted in red inside vim. just for some tests. if (is_raw(rhs)) return true; - // allow writing 0 to any address - if (rhs.name == "0" && is_mu_address(lhs)) return true; - if (is_literal(rhs)) return valid_type_for_literal(lhs) && size_of(rhs) == size_of(lhs); + if (is_literal(rhs)) return valid_type_for_literal(lhs, rhs) && size_of(rhs) == size_of(lhs); if (!lhs.type) return !rhs.type; return types_match(lhs.type, rhs.type); } -bool valid_type_for_literal(const reagent& r) { - if (is_mu_array(r)) return false; - if (is_mu_address(r)) return false; +bool valid_type_for_literal(const reagent& lhs, const reagent& literal_rhs) { + if (is_mu_array(lhs)) return false; // End valid_type_for_literal Special-cases + // allow writing 0 to any address + if (is_mu_address(lhs)) return literal_rhs.name == "0"; return true; } diff --git a/059shape_shifting_recipe.cc b/059shape_shifting_recipe.cc index feffd410..7b2d547d 100644 --- a/059shape_shifting_recipe.cc +++ b/059shape_shifting_recipe.cc @@ -37,7 +37,7 @@ if (Current_routine->calls.front().running_step_index == 0 //: Make sure we don't match up literals with type ingredients without //: specialization. :(before "End valid_type_for_literal Special-cases") -if (contains_type_ingredient_name(r)) return false; +if (contains_type_ingredient_name(lhs)) return false; //: We'll be creating recipes without loading them from anywhere by //: *specializing* existing recipes, so make sure we don't clear any of those @@ -213,6 +213,7 @@ void compute_type_ingredient_mappings(const recipe& exemplar, const instruction& reagent ingredient = inst.ingredients.at(i); assert(ingredient.properties.at(0).second); canonize_type(ingredient); + if (is_mu_address(exemplar_reagent) && ingredient.name == "0") continue; // assume it matches accumulate_type_ingredients(exemplar_reagent, ingredient, mappings, exemplar, inst, caller_recipe, error); } limit = min(SIZE(inst.products), SIZE(exemplar.products)); @@ -507,3 +508,18 @@ recipe foo x:_elem -> y:_elem [ y <- add x, 1 ] +mem: storing 4 in location 1 + +:(scenario specialize_with_literal_3) +% Hide_errors = true; +recipe main [ + local-scope + # permit '0' to map to address to shape-shifting type-ingredient + 1:address:character/raw <- foo 0 +] +recipe foo x:address:_elem -> y:address:_elem [ + local-scope + load-ingredients + y <- copy x +] ++mem: storing 0 in location 1 +$error: 0 diff --git a/073list.mu b/073list.mu index 7d8c2297..db840647 100644 --- a/073list.mu +++ b/073list.mu @@ -34,8 +34,7 @@ recipe rest in:address:list:_elem -> result:address:list:_elem [ scenario list-handling [ run [ - 1:address:list:number <- copy 0 - 1:address:list:number <- push 3, 1:address:list:number + 1:address:list:number <- push 3, 0 1:address:list:number <- push 4, 1:address:list:number 1:address:list:number <- push 5, 1:address:list:number 2:number <- first 1:address:list:number diff --git a/075duplex_list.mu b/075duplex_list.mu index 168c0b88..15f07f1c 100644 --- a/075duplex_list.mu +++ b/075duplex_list.mu @@ -46,8 +46,7 @@ scenario duplex-list-handling [ # reserve locations 0, 1 and 2 to check for missing null check 1:number <- copy 34 2:number <- copy 35 - 3:address:duplex-list:character <- copy 0 - 3:address:duplex-list:character <- push-duplex 3, 3:address:duplex-list:character + 3:address:duplex-list:character <- push-duplex 3, 0 3:address:duplex-list:character <- push-duplex 4, 3:address:duplex-list:character 3:address:duplex-list:character <- push-duplex 5, 3:address:duplex-list:character 4:address:duplex-list:character <- copy 3:address:duplex-list:character @@ -110,8 +109,7 @@ recipe insert-duplex x:_elem, in:address:duplex-list:_elem -> new-node:address:d scenario inserting-into-duplex-list [ run [ - 1:address:duplex-list:character <- copy 0 # 1 points to head of list - 1:address:duplex-list:character <- push-duplex 3, 1:address:duplex-list:character + 1:address:duplex-list:character <- push-duplex 3, 0 1:address:duplex-list:character <- push-duplex 4, 1:address:duplex-list:character 1:address:duplex-list:character <- push-duplex 5, 1:address:duplex-list:character 2:address:duplex-list:character <- next-duplex 1:address:duplex-list:character # 2 points inside list @@ -147,8 +145,7 @@ scenario inserting-into-duplex-list [ scenario inserting-at-end-of-duplex-list [ run [ - 1:address:duplex-list:character <- copy 0 # 1 points to head of list - 1:address:duplex-list:character <- push-duplex 3, 1:address:duplex-list:character + 1:address:duplex-list:character <- push-duplex 3, 0 1:address:duplex-list:character <- push-duplex 4, 1:address:duplex-list:character 1:address:duplex-list:character <- push-duplex 5, 1:address:duplex-list:character 2:address:duplex-list:character <- next-duplex 1:address:duplex-list:character # 2 points inside list @@ -185,8 +182,7 @@ scenario inserting-at-end-of-duplex-list [ scenario inserting-after-start-of-duplex-list [ run [ - 1:address:duplex-list:character <- copy 0 # 1 points to head of list - 1:address:duplex-list:character <- push-duplex 3, 1:address:duplex-list:character + 1:address:duplex-list:character <- push-duplex 3, 0 1:address:duplex-list:character <- push-duplex 4, 1:address:duplex-list:character 1:address:duplex-list:character <- push-duplex 5, 1:address:duplex-list:character 2:address:duplex-list:character <- insert-duplex 6, 1:address:duplex-list:character @@ -256,8 +252,7 @@ recipe remove-duplex in:address:duplex-list:_elem -> next-node:address:duplex-li scenario removing-from-duplex-list [ run [ - 1:address:duplex-list:character <- copy 0 # 1 points to head of list - 1:address:duplex-list:character <- push-duplex 3, 1:address:duplex-list:character + 1:address:duplex-list:character <- push-duplex 3, 0 1:address:duplex-list:character <- push-duplex 4, 1:address:duplex-list:character 1:address:duplex-list:character <- push-duplex 5, 1:address:duplex-list:character 2:address:duplex-list:character <- next-duplex 1:address:duplex-list:character # 2 points at second element @@ -285,8 +280,7 @@ scenario removing-from-duplex-list [ scenario removing-from-start-of-duplex-list [ run [ - 1:address:duplex-list:character <- copy 0 # 1 points to head of list - 1:address:duplex-list:character <- push-duplex 3, 1:address:duplex-list:character + 1:address:duplex-list:character <- push-duplex 3, 0 1:address:duplex-list:character <- push-duplex 4, 1:address:duplex-list:character 1:address:duplex-list:character <- push-duplex 5, 1:address:duplex-list:character # removing from head? return value matters. @@ -312,8 +306,7 @@ scenario removing-from-start-of-duplex-list [ scenario removing-from-end-of-duplex-list [ run [ - 1:address:duplex-list:character <- copy 0 # 1 points to head of list - 1:address:duplex-list:character <- push-duplex 3, 1:address:duplex-list:character + 1:address:duplex-list:character <- push-duplex 3, 0 1:address:duplex-list:character <- push-duplex 4, 1:address:duplex-list:character 1:address:duplex-list:character <- push-duplex 5, 1:address:duplex-list:character # delete last element @@ -343,8 +336,7 @@ scenario removing-from-end-of-duplex-list [ scenario removing-from-singleton-list [ run [ - 1:address:duplex-list:character <- copy 0 # 1 points to singleton list - 1:address:duplex-list:character <- push-duplex 3, 1:address:duplex-list:character + 1:address:duplex-list:character <- push-duplex 3, 0 2:address:duplex-list:character <- remove-duplex 1:address:duplex-list:character 3:address:duplex-list:character <- get *1:address:duplex-list:character, next:offset 4:address:duplex-list:character <- get *1:address:duplex-list:character, prev:offset @@ -381,8 +373,7 @@ recipe remove-duplex-between start:address:duplex-list:_elem, end:address:duplex scenario remove-range [ # construct a duplex list with six elements [13, 14, 15, 16, 17, 18] - 1:address:duplex-list:character <- copy 0 - 1:address:duplex-list:character <- push-duplex 18, 1:address:duplex-list:character + 1:address:duplex-list:character <- push-duplex 18, 0 1:address:duplex-list:character <- push-duplex 17, 1:address:duplex-list:character 1:address:duplex-list:character <- push-duplex 16, 1:address:duplex-list:character 1:address:duplex-list:character <- push-duplex 15, 1:address:duplex-list:character @@ -393,8 +384,7 @@ scenario remove-range [ # first pointer: to the third element 2:address:duplex-list:character <- next-duplex 1:address:duplex-list:character 2:address:duplex-list:character <- next-duplex 2:address:duplex-list:character - 3:address:duplex-list:character <- copy 0 - 2:address:duplex-list:character <- remove-duplex-between 2:address:duplex-list:character, 3:address:duplex-list:character/null + 2:address:duplex-list:character <- remove-duplex-between 2:address:duplex-list:character, 0 # now check the list 4:character <- get *1:address:duplex-list:character, value:offset 5:address:duplex-list:character <- next-duplex 1:address:duplex-list:character @@ -413,8 +403,7 @@ scenario remove-range [ scenario remove-range-to-end [ # construct a duplex list with six elements [13, 14, 15, 16, 17, 18] - 1:address:duplex-list:character <- copy 0 - 1:address:duplex-list:character <- push-duplex 18, 1:address:duplex-list:character + 1:address:duplex-list:character <- push-duplex 18, 0 1:address:duplex-list:character <- push-duplex 17, 1:address:duplex-list:character 1:address:duplex-list:character <- push-duplex 16, 1:address:duplex-list:character 1:address:duplex-list:character <- push-duplex 15, 1:address:duplex-list:character @@ -448,8 +437,7 @@ scenario remove-range-to-end [ scenario remove-range-empty [ # construct a duplex list with six elements [13, 14, 15, 16, 17, 18] - 1:address:duplex-list:character <- copy 0 # 1 points to singleton list - 1:address:duplex-list:character <- push-duplex 14, 1:address:duplex-list:character + 1:address:duplex-list:character <- push-duplex 14, 0 1:address:duplex-list:character <- push-duplex 13, 1:address:duplex-list:character run [ # delete 16 onwards diff --git a/edit/001-editor.mu b/edit/001-editor.mu index 97953274..4b8da7a8 100644 --- a/edit/001-editor.mu +++ b/edit/001-editor.mu @@ -64,8 +64,7 @@ recipe new-editor s:address:array:character, screen:address:screen, left:number, x <- get-address *result, cursor-column:offset *x <- copy left init:address:address:duplex-list:character <- get-address *result, data:offset - *init <- copy 0 - *init <- push-duplex 167/§, *init + *init <- push-duplex 167/§, 0/tail top-of-screen:address:address:duplex-list:character <- get-address *result, top-of-screen:offset *top-of-screen <- copy *init y:address:address:duplex-list:character <- get-address *result, before-cursor:offset diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu index 53e42701..358d148c 100644 --- a/edit/005-sandbox.mu +++ b/edit/005-sandbox.mu @@ -151,8 +151,7 @@ recipe run-sandboxes env:address:programming-environment-data, screen:address:sc *dest <- copy new-sandbox # clear sandbox editor init:address:address:duplex-list:character <- get-address *current-sandbox, data:offset - *init <- copy 0 - *init <- push-duplex 167/§, *init + *init <- push-duplex 167/§, 0/tail top-of-screen:address:address:duplex-list:character <- get-address *current-sandbox, top-of-screen:offset *top-of-screen <- copy *init } |