Long-overdue reorganization to support general 'dilated' reagents up
front. This also allows me to move tests that are really about unrelated
layers out of layers dealing with parsing.
This commit is contained in:
Kartik K. Agaram 2016-05-17 18:25:26 -07:00
parent 38f72faa18
commit 882989243a
15 changed files with 25 additions and 32 deletions

View File

@ -16,7 +16,6 @@ def main [
]
# successfully parsed
:(scenarios run)
:(scenario dilated_reagent_with_comment)
def main [
{1: number, foo: bar} <- copy 34 # test comment

View File

@ -3,6 +3,7 @@
// come in handy later for expressing complex types, like "a dictionary from
// (address to array of charaters) to (list of numbers)".
:(scenarios load)
:(scenario dilated_reagent_with_nested_brackets)
def main [
{1: number, foo: (bar (baz quux))} <- copy 34
@ -68,32 +69,3 @@ container foo [
container bar [
]
+parse: product: {1: ("foo" ("address" "array" "character") ("bar" "number"))}
:(scenario dilated_reagent_in_static_array)
def main [
{1: (array (address number) 3)} <- create-array
5:address:number <- new number:type
{1: (array (address number) 3)} <- put-index {1: (array (address number) 3)}, 0, 5:address:number
*5:address:number <- copy 34
6:number <- copy *5:address:number
]
+run: creating array of size 4
+mem: storing 34 in location 6
//: an exception is 'new', which takes a type tree as its ingredient *value*
:(scenario dilated_reagent_with_new)
def main [
x:address:address:number <- new {(address number): type}
]
+new: size of ("address" "number") is 1
:(before "End Post-processing(expected_product) When Checking 'new'")
{
string_tree* tmp_type_names = parse_string_tree(expected_product.type->name);
delete expected_product.type;
expected_product.type = new_type_tree(tmp_type_names);
delete tmp_type_names;
}
:(before "End Post-processing(type_name) When Converting 'new'")
type_name = parse_string_tree(type_name);

View File

@ -132,6 +132,12 @@ def main [
]
+mem: storing 0 in location 3
:(scenario dilated_reagent_with_new)
def main [
1:address:address:number <- new {(address number): type}
]
+new: size of ("address" "number") is 1
//: 'new' takes a weird 'type' as its first ingredient; don't error on it
:(before "End Mu Types Initialization")
put(Type_ordinal, "type", 0);
@ -180,7 +186,12 @@ bool product_of_new_is_valid(const instruction& inst) {
drop_from_type(product, "array");
}
reagent/*copy*/ expected_product("x:"+inst.ingredients.at(0).name);
// End Post-processing(expected_product) When Checking 'new'
{
string_tree* tmp_type_names = parse_string_tree(expected_product.type->name);
delete expected_product.type;
expected_product.type = new_type_tree(tmp_type_names);
delete tmp_type_names;
}
return types_strictly_match(product, expected_product);
}
@ -224,7 +235,7 @@ void transform_new_to_allocate(const recipe_ordinal r) {
if (inst.name == "new") {
inst.operation = ALLOCATE;
string_tree* type_name = new string_tree(inst.ingredients.at(0).name);
// End Post-processing(type_name) When Converting 'new'
type_name = parse_string_tree(type_name);
type_tree* type = new_type_tree(type_name);
inst.ingredients.at(0).set_value(size_of(type));
trace(9992, "new") << "size of " << to_string(type_name) << " is " << inst.ingredients.at(0).value << end();

View File

@ -319,6 +319,17 @@ def main [
]
+mem: storing 34 in location 3
:(scenario dilated_reagent_in_static_array)
def main [
{1: (array (address number) 3)} <- create-array
5:address:number <- new number:type
{1: (array (address number) 3)} <- put-index {1: (array (address number) 3)}, 0, 5:address:number
*5:address:number <- copy 34
6:number <- copy *5:address:number
]
+run: creating array of size 4
+mem: storing 34 in location 6
:(before "Update PUT_INDEX base in Check")
if (!canonize_type(base)) break;
:(before "Update PUT_INDEX index in Check")