From 97eb971b7574b3f283d7111a567a301faec9912d Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 27 Dec 2016 22:20:43 -0800 Subject: 3725 More improvements to cross-linking example programs. Include their own functions as well in the tags for each program, even as you share the core .mu files everywhere. --- html/042name.cc.html | 167 ++++++++++++++++++++++++++++----------------------- 1 file changed, 93 insertions(+), 74 deletions(-) (limited to 'html/042name.cc.html') diff --git a/html/042name.cc.html b/html/042name.cc.html index 23a3ba8f..915412f1 100644 --- a/html/042name.cc.html +++ b/html/042name.cc.html @@ -292,81 +292,100 @@ if ('onhashchange' in window) { 229 //:: Support element names for containers in 'get' and 'get-location' and 'put'. 230 //: (get-location is implemented later) 231 -232 :(scenario transform_names_transforms_container_elements) -233 def main [ -234 p:&:point <- copy 0 -235 a:num <- get *p:&:point, y:offset -236 b:num <- get *p:&:point, x:offset -237 ] -238 +name: element y of type point is at offset 1 -239 +name: element x of type point is at offset 0 +232 :(before "End update GET offset_value in Check") +233 else { +234 if (!offset.initialized) { +235 raise << maybe(get(Recipe, r).name) << "uninitialized offset '" << offset.name << "' in '" << to_original_string(inst) << "'\n" << end(); +236 break; +237 } +238 offset_value = offset.value; +239 } 240 -241 :(before "End transform_names(inst) Special-cases") -242 // replace element names of containers with offsets -243 if (inst.name == "get" || inst.name == "get-location" || inst.name == "put") { -244 //: avoid raising any errors here; later layers will support overloading new -245 //: instructions with the same names (static dispatch), which could lead to -246 //: spurious errors -247 if (SIZE(inst.ingredients) < 2) -248 break; // error raised elsewhere -249 if (!is_literal(inst.ingredients.at(1))) -250 break; // error raised elsewhere -251 if (inst.ingredients.at(1).name.find_first_not_of("0123456789") != string::npos) { -252 // since first non-address in base type must be a container, we don't have to canonize -253 type_ordinal base_type = skip_addresses(inst.ingredients.at(0).type); -254 if (base_type == -1) -255 break; // error raised elsewhere -256 if (contains_key(Type, base_type)) { // otherwise we'll raise an error elsewhere -257 inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name, get(Recipe, r).name)); -258 trace(9993, "name") << "element " << inst.ingredients.at(1).name << " of type " << get(Type, base_type).name << " is at offset " << no_scientific(inst.ingredients.at(1).value) << end(); -259 } -260 } -261 } -262 -263 //: this test is actually illegal so can't call run -264 :(scenarios transform) -265 :(scenario transform_names_handles_containers) -266 def main [ -267 a:point <- copy 0/unsafe -268 b:num <- copy 0/unsafe -269 ] -270 +name: assign a 1 -271 +name: assign b 3 -272 -273 //:: Support variant names for exclusive containers in 'maybe-convert'. -274 -275 :(scenarios run) -276 :(scenario transform_names_handles_exclusive_containers) -277 def main [ -278 12:num <- copy 1 -279 13:num <- copy 35 -280 14:num <- copy 36 -281 20:point, 22:bool <- maybe-convert 12:number-or-point/unsafe, p:variant -282 ] -283 +name: variant p of type number-or-point has tag 1 -284 +mem: storing 1 in location 22 -285 +mem: storing 35 in location 20 -286 +mem: storing 36 in location 21 -287 -288 :(before "End transform_names(inst) Special-cases") -289 // convert variant names of exclusive containers -290 if (inst.name == "maybe-convert") { -291 if (SIZE(inst.ingredients) != 2) { -292 raise << maybe(get(Recipe, r).name) << "exactly 2 ingredients expected in '" << inst.original_string << "'\n" << end(); -293 break; -294 } -295 assert(is_literal(inst.ingredients.at(1))); -296 if (inst.ingredients.at(1).name.find_first_not_of("0123456789") != string::npos) { -297 // since first non-address in base type must be an exclusive container, we don't have to canonize -298 type_ordinal base_type = skip_addresses(inst.ingredients.at(0).type); -299 if (base_type == -1) -300 raise << maybe(get(Recipe, r).name) << "expected an exclusive-container in '" << inst.original_string << "'\n" << end(); -301 if (contains_key(Type, base_type)) { // otherwise we'll raise an error elsewhere -302 inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name, get(Recipe, r).name)); -303 trace(9993, "name") << "variant " << inst.ingredients.at(1).name << " of type " << get(Type, base_type).name << " has tag " << no_scientific(inst.ingredients.at(1).value) << end(); -304 } -305 } -306 } +241 :(scenario transform_names_transforms_container_elements) +242 def main [ +243 p:&:point <- copy 0 +244 a:num <- get *p:&:point, y:offset +245 b:num <- get *p:&:point, x:offset +246 ] +247 +name: element y of type point is at offset 1 +248 +name: element x of type point is at offset 0 +249 +250 :(before "End transform_names(inst) Special-cases") +251 // replace element names of containers with offsets +252 if (inst.name == "get" || inst.name == "get-location" || inst.name == "put") { +253 //: avoid raising any errors here; later layers will support overloading new +254 //: instructions with the same names (static dispatch), which could lead to +255 //: spurious errors +256 if (SIZE(inst.ingredients) < 2) +257 break; // error raised elsewhere +258 if (!is_literal(inst.ingredients.at(1))) +259 break; // error raised elsewhere +260 if (inst.ingredients.at(1).name.find_first_not_of("0123456789") != string::npos) { +261 // since first non-address in base type must be a container, we don't have to canonize +262 type_ordinal base_type = skip_addresses(inst.ingredients.at(0).type); +263 if (contains_key(Type, base_type)) { // otherwise we'll raise an error elsewhere +264 inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name, get(Recipe, r).name)); +265 trace(9993, "name") << "element " << inst.ingredients.at(1).name << " of type " << get(Type, base_type).name << " is at offset " << no_scientific(inst.ingredients.at(1).value) << end(); +266 } +267 } +268 } +269 +270 :(scenario missing_type_in_get) +271 % Hide_errors = true; +272 def main [ +273 get a, x:offset +274 ] +275 +error: main: missing type for 'a' in 'get a, x:offset' +276 +277 //: this test is actually illegal so can't call run +278 :(scenarios transform) +279 :(scenario transform_names_handles_containers) +280 def main [ +281 a:point <- copy 0/unsafe +282 b:num <- copy 0/unsafe +283 ] +284 +name: assign a 1 +285 +name: assign b 3 +286 +287 //:: Support variant names for exclusive containers in 'maybe-convert'. +288 +289 :(scenarios run) +290 :(scenario transform_names_handles_exclusive_containers) +291 def main [ +292 12:num <- copy 1 +293 13:num <- copy 35 +294 14:num <- copy 36 +295 20:point, 22:bool <- maybe-convert 12:number-or-point/unsafe, p:variant +296 ] +297 +name: variant p of type number-or-point has tag 1 +298 +mem: storing 1 in location 22 +299 +mem: storing 35 in location 20 +300 +mem: storing 36 in location 21 +301 +302 :(before "End transform_names(inst) Special-cases") +303 // convert variant names of exclusive containers +304 if (inst.name == "maybe-convert") { +305 if (SIZE(inst.ingredients) != 2) { +306 raise << maybe(get(Recipe, r).name) << "exactly 2 ingredients expected in '" << inst.original_string << "'\n" << end(); +307 break; +308 } +309 assert(is_literal(inst.ingredients.at(1))); +310 if (inst.ingredients.at(1).name.find_first_not_of("0123456789") != string::npos) { +311 // since first non-address in base type must be an exclusive container, we don't have to canonize +312 type_ordinal base_type = skip_addresses(inst.ingredients.at(0).type); +313 if (contains_key(Type, base_type)) { // otherwise we'll raise an error elsewhere +314 inst.ingredients.at(1).set_value(find_element_name(base_type, inst.ingredients.at(1).name, get(Recipe, r).name)); +315 trace(9993, "name") << "variant " << inst.ingredients.at(1).name << " of type " << get(Type, base_type).name << " has tag " << no_scientific(inst.ingredients.at(1).value) << end(); +316 } +317 } +318 } +319 +320 :(scenario missing_type_in_maybe_convert) +321 % Hide_errors = true; +322 def main [ +323 maybe-convert a, x:variant +324 ] +325 +error: main: missing type for 'a' in 'maybe-convert a, x:variant' -- cgit 1.4.1-2-gfad0