Skip to content

Commit

Permalink
3390
Browse files Browse the repository at this point in the history
  • Loading branch information
akkartik committed Sep 17, 2016
1 parent 760f683 commit a0331a9
Show file tree
Hide file tree
Showing 33 changed files with 240 additions and 240 deletions.
2 changes: 1 addition & 1 deletion 042name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def main [

:(scenario transform_names_supports_static_arrays)
def main [
x:array:num:3 <- create-array
x:@:num:3 <- create-array
y:num <- copy 3
]
+name: assign x 1
Expand Down
32 changes: 16 additions & 16 deletions 043space.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
# if default-space is 10, and if an array of 5 locals lies from location 12 to 16 (inclusive),
# then local 0 is really location 12, local 1 is really location 13, and so on.
def main [
# pretend address:array:location; in practice we'll use new
# pretend address:@:location; in practice we'll use new
10:num <- copy 0 # refcount
11:num <- copy 5 # length
default-space:&:array:location <- copy 10/unsafe
default-space:&:@:location <- copy 10/unsafe
1:num <- copy 23
]
+mem: storing 23 in location 13
Expand All @@ -18,11 +18,11 @@ def main [
def main [
# pretend pointer from outside (2000 reserved for refcount)
2001:num <- copy 34
# pretend address:array:location; in practice we'll use new
# pretend address:@:location; in practice we'll use new
1000:num <- copy 0 # refcount
1001:num <- copy 5 # length
# actual start of this recipe
default-space:&:array:location <- copy 1000/unsafe
default-space:&:@:location <- copy 1000/unsafe
1:&:num <- copy 2000/unsafe # even local variables always contain raw addresses
8:num/raw <- copy *1:&:num
]
Expand Down Expand Up @@ -84,7 +84,7 @@ int address(int offset, int base) {
:(after "Begin Preprocess write_memory(x, data)")
if (x.name == "default-space") {
if (!scalar(data) || !is_space(x))
raise << maybe(current_recipe_name()) << "'default-space' should be of type address:array:location, but is " << to_string(x.type) << '\n' << end();
raise << maybe(current_recipe_name()) << "'default-space' should be of type address:@:location, but is " << to_string(x.type) << '\n' << end();
current_call().default_space = data.at(0);
return;
}
Expand All @@ -95,8 +95,8 @@ bool is_space(const reagent& r) {

:(scenario get_default_space)
def main [
default-space:&:array:location <- copy 10/unsafe
1:&:array:location/raw <- copy default-space:&:array:location
default-space:&:@:location <- copy 10/unsafe
1:&:@:location/raw <- copy default-space:&:@:location
]
+mem: storing 10 in location 1

Expand All @@ -114,11 +114,11 @@ def main [
# pretend pointer to container from outside (2000 reserved for refcount)
2001:num <- copy 34
2002:num <- copy 35
# pretend address:array:location; in practice we'll use new
# pretend address:@:location; in practice we'll use new
1000:num <- copy 0 # refcount
1001:num <- copy 5 # length
# actual start of this recipe
default-space:&:array:location <- copy 1000/unsafe
default-space:&:@:location <- copy 1000/unsafe
1:&:point <- copy 2000/unsafe
9:num/raw <- get *1:&:point, 1:offset
]
Expand All @@ -135,13 +135,13 @@ def main [
2001:num <- copy 2 # length
2002:num <- copy 34
2003:num <- copy 35
# pretend address:array:location; in practice we'll use new
# pretend address:@:location; in practice we'll use new
1000:num <- copy 0 # refcount
1001:num <- copy 5 # length
# actual start of this recipe
default-space:&:array:location <- copy 1000/unsafe
1:&:array:num <- copy 2000/unsafe
9:num/raw <- index *1:&:array:num, 1
default-space:&:@:location <- copy 1000/unsafe
1:&:@:num <- copy 2000/unsafe
9:num/raw <- index *1:&:@:num, 1
]
+mem: storing 35 in location 9

Expand All @@ -168,7 +168,7 @@ if (s == "number-of-locals") return true;

:(before "End Rewrite Instruction(curr, recipe result)")
// rewrite `new-default-space` to
// `default-space:&:array:location <- new location:type, number-of-locals:literal`
// `default-space:&:@:location <- new location:type, number-of-locals:literal`
// where N is Name[recipe][""]
if (curr.name == "new-default-space") {
rewrite_default_space_instruction(curr);
Expand Down Expand Up @@ -199,7 +199,7 @@ def main [
def foo [
local-scope
x:num <- copy 34
return default-space:&:array:location
return default-space:&:@:location
]
# both calls to foo should have received the same default-space
+mem: storing 1 in location 3
Expand Down Expand Up @@ -304,7 +304,7 @@ void rewrite_default_space_instruction(instruction& curr) {
curr.ingredients.push_back(reagent("number-of-locals:literal"));
if (!curr.products.empty())
raise << "new-default-space can't take any results\n" << end();
curr.products.push_back(reagent("default-space:&:array:location"));
curr.products.push_back(reagent("default-space:&:@:location"));
}

:(scenario local_scope_frees_up_addresses_inside_containers)
Expand Down
8 changes: 4 additions & 4 deletions 044space_surround.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
:(scenario surrounding_space)
# location 1 in space 1 refers to the space surrounding the default space, here 20.
def main [
# pretend address:array:location; in practice we'll use new
# pretend address:@:location; in practice we'll use new
10:num <- copy 0 # refcount
11:num <- copy 5 # length
# pretend address:array:location; in practice we'll use new
# pretend address:@:location; in practice we'll use new
20:num <- copy 0 # refcount
21:num <- copy 5 # length
# actual start of this recipe
default-space:&:array:location <- copy 10/unsafe
0:&:array:location/names:dummy <- copy 20/unsafe # later layers will explain the /names: property
default-space:&:@:location <- copy 10/unsafe
0:&:@:location/names:dummy <- copy 20/unsafe # later layers will explain the /names: property
1:num <- copy 32
1:num/space:1 <- copy 33
]
Expand Down
28 changes: 14 additions & 14 deletions 045closure_name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

:(scenario closure)
def main [
default-space:&:array:location <- new location:type, 30
1:&:array:location/names:new-counter <- new-counter
2:num/raw <- increment-counter 1:&:array:location/names:new-counter
3:num/raw <- increment-counter 1:&:array:location/names:new-counter
default-space:&:@:location <- new location:type, 30
1:&:@:location/names:new-counter <- new-counter
2:num/raw <- increment-counter 1:&:@:location/names:new-counter
3:num/raw <- increment-counter 1:&:@:location/names:new-counter
]
def new-counter [
default-space:&:array:location <- new location:type, 30
default-space:&:@:location <- new location:type, 30
x:num <- copy 23
y:num <- copy 3 # variable that will be incremented
return default-space:&:array:location
return default-space:&:@:location
]
def increment-counter [
default-space:&:array:location <- new location:type, 30
0:&:array:location/names:new-counter <- next-ingredient # outer space must be created by 'new-counter' above
default-space:&:@:location <- new location:type, 30
0:&:@:location/names:new-counter <- next-ingredient # outer space must be created by 'new-counter' above
y:num/space:1 <- add y:num/space:1, 1 # increment
y:num <- copy 234 # dummy
return y:num/space:1
Expand Down Expand Up @@ -46,7 +46,7 @@ void collect_surrounding_spaces(const recipe_ordinal r) {
if (is_literal(inst.products.at(j))) continue;
if (inst.products.at(j).name != "0") continue;
if (!is_space(inst.products.at(j))) {
raise << "slot 0 should always have type address:array:location, but is '" << to_string(inst.products.at(j)) << "'\n" << end();
raise << "slot 0 should always have type address:@:location, but is '" << to_string(inst.products.at(j)) << "'\n" << end();
continue;
}
string_tree* s = property(inst.products.at(j), "names");
Expand Down Expand Up @@ -153,16 +153,16 @@ def new-scope [
new-default-space
x:&:num <- new number:type
*x:&:num <- copy 34
return default-space:&:array:location
return default-space:&:@:location
]
def use-scope [
local-scope
outer:&:array:location <- next-ingredient
0:&:array:location/names:new-scope <- copy outer:&:array:location
outer:&:@:location <- next-ingredient
0:&:@:location/names:new-scope <- copy outer:&:@:location
return *x:&:num/space:1
]
def main [
1:&:array:location/raw <- new-scope
2:num/raw <- use-scope 1:&:array:location/raw
1:&:@:location/raw <- new-scope
2:num/raw <- use-scope 1:&:@:location/raw
]
+mem: storing 34 in location 2
12 changes: 6 additions & 6 deletions 046global.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

:(scenario global_space)
def main [
# pretend address:array:location; in practice we'll use new
# pretend address:@:location; in practice we'll use new
10:num <- copy 0 # refcount
11:num <- copy 5 # length
# pretend address:array:location; in practice we'll use new
# pretend address:@:location; in practice we'll use new
20:num <- copy 0 # refcount
21:num <- copy 5 # length
# actual start of this recipe
global-space:&:array:location <- copy 20/unsafe
default-space:&:array:location <- copy 10/unsafe
global-space:&:@:location <- copy 20/unsafe
default-space:&:@:location <- copy 10/unsafe
1:num <- copy 23
1:num/space:global <- copy 24
]
Expand All @@ -43,7 +43,7 @@ global_space = 0;
:(after "Begin Preprocess write_memory(x, data)")
if (x.name == "global-space") {
if (!scalar(data) || !is_space(x))
raise << maybe(current_recipe_name()) << "'global-space' should be of type address:array:location, but tried to write '" << to_string(x.type) << "'\n" << end();
raise << maybe(current_recipe_name()) << "'global-space' should be of type address:@:location, but tried to write '" << to_string(x.type) << "'\n" << end();
if (Current_routine->global_space)
raise << "routine already has a global-space; you can't over-write your globals" << end();
Current_routine->global_space = data.at(0);
Expand All @@ -63,7 +63,7 @@ if (x.name == "global-space") {

:(scenario global_space_with_names)
def main [
global-space:&:array:location <- new location:type, 10
global-space:&:@:location <- new location:type, 10
x:num <- copy 23
1:num/space:global <- copy 24
]
Expand Down
4 changes: 2 additions & 2 deletions 047check_type_by_name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def main [
:(scenario array_type_without_size_fails)
% Hide_errors = true;
def main [
x:array:num <- merge 2, 12, 13
x:@:num <- merge 2, 12, 13
]
+error: main can't determine the size of array variable 'x'. Either allocate it separately and make the type of 'x' an address, or specify the length of the array in the type of 'x'.
Expand All @@ -119,7 +119,7 @@ def foo [ # dummy
]
def main [
local-scope
0:&:array:location/names:foo <- copy 0 # specify surrounding space
0:&:@:location/names:foo <- copy 0 # specify surrounding space
x:bool <- copy 1/true
x:num/space:1 <- copy 34
x/space:1 <- copy 35
Expand Down
2 changes: 1 addition & 1 deletion 053recipe_header.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ if (result.has_header) {
//: Support type abbreviations in headers.

:(scenario type_abbreviations_in_recipe_headers)
type string = address:array:char
type string = address:@:char
def main [
local-scope
a:string <- foo
Expand Down
2 changes: 1 addition & 1 deletion 054static_dispatch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def foo a:bool -> b:num [
+error: main: failed to find a matching call for 'y:num <- foo x'

:(scenario override_methods_with_type_abbreviations)
type string = address:array:char
type string = address:@:char
def main [
local-scope
s:text <- new [abc]
Expand Down
4 changes: 2 additions & 2 deletions 055shape_shifting_container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ container bar:_a:_b [
]
def main [
1:text <- new [abc]
2:bar:num:array:char <- merge 34/x, 1:text/y
2:bar:num:@:char <- merge 34/x, 1:text/y
]
$error: 0

Expand Down Expand Up @@ -449,7 +449,7 @@ void test_replace_middle_type_ingredient_with_multiple2() {

void test_replace_middle_type_ingredient_with_multiple3() {
run("container foo_table:_key:_value [\n"
" data:&:array:foo_table_row:_key:_value\n"
" data:&:@:foo_table_row:_key:_value\n"
"]\n"
"\n"
"container foo_table_row:_key:_value [\n"
Expand Down
8 changes: 4 additions & 4 deletions 056shape_shifting_recipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -905,17 +905,17 @@ def foo x:&:_elem -> y:num [
# version with headers padded with lots of unrelated concrete types
def main [
1:num <- copy 23
2:&:array:num <- copy 0
3:num <- foo 2:&:array:num, 1:num
2:&:@:num <- copy 0
3:num <- foo 2:&:@:num, 1:num
]
# variant with concrete type
def foo dummy:&:array:num, x:num -> y:num, dummy:&:array:num [
def foo dummy:&:@:num, x:num -> y:num, dummy:&:@:num [
local-scope
load-ingredients
return 34
]
# shape-shifting variant
def foo dummy:&:array:num, x:_elem -> y:num, dummy:&:array:num [
def foo dummy:&:@:num, x:_elem -> y:num, dummy:&:@:num [
local-scope
load-ingredients
return 35
Expand Down
Loading

0 comments on commit a0331a9

Please sign in to comment.