2241 - back to type-checking get-address

Now duplex-list is fully non-generic and only works with characters. But
we'll fix that in a bit..
This commit is contained in:
Kartik K. Agaram 2015-10-05 16:43:21 -07:00
parent 22a2524048
commit fb5470bc5a
5 changed files with 32 additions and 10 deletions

View File

@ -267,13 +267,25 @@ case GET_ADDRESS: {
raise << maybe(Recipe[r].name) << "second ingredient of 'get' should have type 'offset', but got " << inst.ingredients.at(1).original_string << '\n' << end();
break;
}
long long int offset_value = 0;
if (is_integer(offset.name)) { // later layers permit non-integer offsets
long long int offset_value = to_integer(offset.name);
offset_value = to_integer(offset.name);
if (offset_value < 0 || offset_value >= SIZE(Type[base_type].elements)) {
raise << maybe(Recipe[r].name) << "invalid offset " << offset_value << " for " << Type[base_type].name << '\n' << end();
break;
}
}
else {
offset_value = offset.value;
}
reagent product = inst.products.at(0);
canonize_type(product);
reagent element;
element.types = Type[base_type].elements.at(offset_value);
element.types.insert(element.types.begin(), Type_ordinal["address"]);
if (!types_match(product, element)) {
raise << maybe(Recipe[r].name) << "'get-address' " << offset.original_string << " (" << offset_value << ") on " << Type[base_type].name << " can't be saved in " << product.original_string << "; type should be " << dump_types(element) << '\n' << end();
}
break;
}
:(before "End Primitive Recipe Implementations")
@ -318,6 +330,16 @@ recipe main [
]
+warn: main: invalid offset -1 for point-number
:(scenario get_address_product_type_mismatch)
% Hide_warnings = true;
recipe main [
12:number <- copy 34
13:number <- copy 35
14:number <- copy 36
15:number <- get-address 12:point-number/raw, 1:offset
]
+warn: main: 'get-address' 1:offset (1) on point-number can't be saved in 15:number; type should be address:number
//:: Allow containers to be defined in mu code.
:(scenarios load)

View File

@ -152,7 +152,7 @@ recipe main [
1:number <- copy 2
2:number <- copy 34
3:number <- copy 35
4:number <- get-address 1:address:point/lookup, 0:offset
4:address:number <- get-address 1:address:point/lookup, 0:offset
]
+mem: storing 2 in location 4

View File

@ -6,13 +6,13 @@ container duplex-list [
prev:address:duplex-list
]
# result:address:duplex-list <- push-duplex x:location, in:address:duplex-list
# result:address:duplex-list <- push-duplex x:character , in:address:duplex-list
recipe push-duplex [
local-scope
x:location <- next-ingredient
x:character <- next-ingredient
in:address:duplex-list <- next-ingredient
result:address:duplex-list <- new duplex-list:type
val:address:location <- get-address *result, value:offset
val:address:character <- get-address *result, value:offset
*val <- copy x
next:address:address:duplex-list <- get-address *result, next:offset
*next <- copy in
@ -91,14 +91,14 @@ scenario duplex-list-handling [
]
]
# l:address:duplex-list <- insert-duplex x:location, in:address:duplex-list
# l:address:duplex-list <- insert-duplex x:character, in:address:duplex-list
# Inserts 'x' after 'in'. Returns some pointer into the list.
recipe insert-duplex [
local-scope
x:location <- next-ingredient
x:character <- next-ingredient
in:address:duplex-list <- next-ingredient
new-node:address:duplex-list <- new duplex-list:type
val:address:location <- get-address *new-node, value:offset
val:address:character <- get-address *new-node, value:offset
*val <- copy x
next-node:address:duplex-list <- get *in, next:offset
# in.next = new-node

View File

@ -28,7 +28,7 @@ container console [
recipe new-fake-console [
local-scope
result:address:console <- new console:type
buf:address:address:array:character <- get-address *result, data:offset
buf:address:address:array:event <- get-address *result, data:offset
*buf <- next-ingredient
idx:address:number <- get-address *result, index:offset
*idx <- copy 0

View File

@ -52,7 +52,7 @@ case ASSUME_CONSOLE: {
istringstream in("[" + current_instruction().ingredients.at(0).name + "]");
recipe r = slurp_body(in);
long long int num_events = count_events(r);
// initialize the events
// initialize the events like in new-fake-console
long long int size = num_events*size_of_event() + /*space for length*/1;
ensure_space(size);
long long int event_data_address = Current_routine->alloc;