This commit is contained in:
Kartik K. Agaram 2016-09-17 10:28:25 -07:00
parent e24799ead4
commit 7a84094adb
30 changed files with 858 additions and 858 deletions

View File

@ -8,7 +8,7 @@
:(scenario scenario_block)
scenario foo [
run [
1:number <- copy 13
1:num <- copy 13
]
memory-should-contain [
1 <- 13
@ -19,13 +19,13 @@ scenario foo [
:(scenario scenario_multiple_blocks)
scenario foo [
run [
1:number <- copy 13
1:num <- copy 13
]
memory-should-contain [
1 <- 13
]
run [
2:number <- copy 13
2:num <- copy 13
]
memory-should-contain [
1 <- 13
@ -37,7 +37,7 @@ scenario foo [
:(scenario scenario_check_memory_and_trace)
scenario foo [
run [
1:number <- copy 13
1:num <- copy 13
trace 1, [a], [a b c]
]
memory-should-contain [
@ -94,7 +94,7 @@ scenario parse_scenario(istream& in) {
:(scenario read_scenario_with_bracket_in_comment)
scenario foo [
# ']' in comment
1:number <- copy 0
1:num <- copy 0
]
+run: {1: "number"} <- copy {0: "literal"}
@ -224,7 +224,7 @@ void test_maybe_make_raw() {
vector<recipe_ordinal> tmp = load(
"def scenario_foo [\n"
" local-scope\n"
" __maybe_make_raw_test__:number <- copy 34\n"
" __maybe_make_raw_test__:num <- copy 34\n"
"]\n");
mark_autogenerated(tmp.at(0));
bind_special_scenario_names(tmp.at(0));
@ -240,10 +240,10 @@ void test_maybe_make_raw() {
% Hide_errors = true;
% Disable_redefine_checks = true;
def scenario-foo [
1:number <- copy 34
1:num <- copy 34
]
def scenario-foo [
1:number <- copy 35
1:num <- copy 35
]
+error: redefining recipe scenario-foo
@ -258,7 +258,7 @@ def scenario-foo [
:(scenario run)
def main [
run [
1:number <- copy 13
1:num <- copy 13
]
]
+mem: storing 13 in location 1
@ -295,10 +295,10 @@ if (starts_with(caller.name, "run_"))
:(scenario run_multiple)
def main [
run [
1:number <- copy 13
1:num <- copy 13
]
run [
2:number <- copy 13
2:num <- copy 13
]
]
+mem: storing 13 in location 1
@ -449,10 +449,10 @@ def main [
% Scenario_testing_scenario = true;
% Hide_errors = true;
def main [
1:number <- copy 3
2:number <- copy 97 # 'a'
3:number <- copy 98 # 'b'
4:number <- copy 99 # 'c'
1:num <- copy 3
2:num <- copy 97 # 'a'
3:num <- copy 98 # 'b'
4:num <- copy 99 # 'c'
memory-should-contain [
1:array:character <- [ab]
]
@ -461,10 +461,10 @@ def main [
:(scenario memory_check_string)
def main [
1:number <- copy 3
2:number <- copy 97 # 'a'
3:number <- copy 98 # 'b'
4:number <- copy 99 # 'c'
1:num <- copy 3
2:num <- copy 97 # 'a'
3:num <- copy 98 # 'b'
4:num <- copy 99 # 'c'
memory-should-contain [
1:array:character <- [abc]
]

View File

@ -2,7 +2,7 @@
scenario first_scenario_in_mu [
run [
10:number <- add 2, 2
10:num <- add 2, 2
]
memory-should-contain [
10 <- 4
@ -12,7 +12,7 @@ scenario first_scenario_in_mu [
scenario scenario_with_comment_in_mu [
run [
# comment
10:number <- add 2, 2
10:num <- add 2, 2
]
memory-should-contain [
10 <- 4
@ -23,7 +23,7 @@ scenario scenario_with_multiple_comments_in_mu [
run [
# comment1
# comment2
10:number <- add 2, 2
10:num <- add 2, 2
]
memory-should-contain [
10 <- 4
@ -32,7 +32,7 @@ scenario scenario_with_multiple_comments_in_mu [
scenario check_text_in_memory [
run [
10:number <- copy 3
10:num <- copy 3
11:char <- copy 97 # 'a'
12:char <- copy 98 # 'b'
13:char <- copy 99 # 'c'
@ -44,7 +44,7 @@ scenario check_text_in_memory [
scenario check_trace [
run [
10:number <- add 2, 2
10:num <- add 2, 2
]
trace-should-contain [
mem: storing 4 in location 10
@ -53,7 +53,7 @@ scenario check_trace [
scenario check_trace_negative [
run [
10:number <- add 2, 2
10:num <- add 2, 2
]
trace-should-not-contain [
mem: storing 3 in location 10

View File

@ -8,12 +8,12 @@
:(scenario tangle_before)
def main [
1:number <- copy 0
1:num <- copy 0
<label1>
3:number <- copy 0
3:num <- copy 0
]
before <label1> [
2:number <- copy 0
2:num <- copy 0
]
+mem: storing 0 in location 1
+mem: storing 0 in location 2
@ -159,15 +159,15 @@ void check_insert_fragments() {
:(scenario tangle_before_and_after)
def main [
1:number <- copy 0
1:num <- copy 0
<label1>
4:number <- copy 0
4:num <- copy 0
]
before <label1> [
2:number <- copy 0
2:num <- copy 0
]
after <label1> [
3:number <- copy 0
3:num <- copy 0
]
+mem: storing 0 in location 1
+mem: storing 0 in location 2
@ -180,33 +180,33 @@ $mem: 4
:(scenario tangle_ignores_jump_target)
% Hide_errors = true;
def main [
1:number <- copy 0
1:num <- copy 0
+label1
4:number <- copy 0
4:num <- copy 0
]
before +label1 [
2:number <- copy 0
2:num <- copy 0
]
+error: can't tangle before label +label1
:(scenario tangle_keeps_labels_separate)
def main [
1:number <- copy 0
1:num <- copy 0
<label1>
<label2>
6:number <- copy 0
6:num <- copy 0
]
before <label1> [
2:number <- copy 0
2:num <- copy 0
]
after <label1> [
3:number <- copy 0
3:num <- copy 0
]
before <label2> [
4:number <- copy 0
4:num <- copy 0
]
after <label2> [
5:number <- copy 0
5:num <- copy 0
]
+mem: storing 0 in location 1
+mem: storing 0 in location 2
@ -222,21 +222,21 @@ $mem: 6
:(scenario tangle_stacks_multiple_fragments)
def main [
1:number <- copy 0
1:num <- copy 0
<label1>
6:number <- copy 0
6:num <- copy 0
]
before <label1> [
2:number <- copy 0
2:num <- copy 0
]
after <label1> [
3:number <- copy 0
3:num <- copy 0
]
before <label1> [
4:number <- copy 0
4:num <- copy 0
]
after <label1> [
5:number <- copy 0
5:num <- copy 0
]
+mem: storing 0 in location 1
# 'before' fragments stack in order
@ -252,17 +252,17 @@ $mem: 6
:(scenario tangle_supports_fragments_with_multiple_instructions)
def main [
1:number <- copy 0
1:num <- copy 0
<label1>
6:number <- copy 0
6:num <- copy 0
]
before <label1> [
2:number <- copy 0
3:number <- copy 0
2:num <- copy 0
3:num <- copy 0
]
after <label1> [
4:number <- copy 0
5:number <- copy 0
4:num <- copy 0
5:num <- copy 0
]
+mem: storing 0 in location 1
+mem: storing 0 in location 2
@ -276,21 +276,21 @@ $mem: 6
:(scenario tangle_tangles_into_all_labels_with_same_name)
def main [
1:number <- copy 10
1:num <- copy 10
<label1>
4:number <- copy 10
4:num <- copy 10
recipe2
]
def recipe2 [
1:number <- copy 11
1:num <- copy 11
<label1>
4:number <- copy 11
4:num <- copy 11
]
before <label1> [
2:number <- copy 12
2:num <- copy 12
]
after <label1> [
3:number <- copy 12
3:num <- copy 12
]
+mem: storing 10 in location 1
+mem: storing 12 in location 2
@ -308,16 +308,16 @@ $mem: 8
:(scenario tangle_tangles_into_all_labels_with_same_name_2)
def main [
1:number <- copy 10
1:num <- copy 10
<label1>
<label1>
4:number <- copy 10
4:num <- copy 10
]
before <label1> [
2:number <- copy 12
2:num <- copy 12
]
after <label1> [
3:number <- copy 12
3:num <- copy 12
]
+mem: storing 10 in location 1
+mem: storing 12 in location 2
@ -332,16 +332,16 @@ $mem: 6
:(scenario tangle_tangles_into_all_labels_with_same_name_3)
def main [
1:number <- copy 10
1:num <- copy 10
<label1>
<foo>
4:number <- copy 10
4:num <- copy 10
]
before <label1> [
2:number <- copy 12
2:num <- copy 12
]
after <label1> [
3:number <- copy 12
3:num <- copy 12
]
after <foo> [
<label1>
@ -359,15 +359,15 @@ $mem: 6
:(scenario tangle_handles_jump_target_inside_fragment)
def main [
1:number <- copy 10
1:num <- copy 10
<label1>
4:number <- copy 10
4:num <- copy 10
]
before <label1> [
jump +label2:label
2:number <- copy 12
2:num <- copy 12
+label2
3:number <- copy 12
3:num <- copy 12
]
+mem: storing 10 in location 1
# label1
@ -380,16 +380,16 @@ $mem: 3
:(scenario tangle_renames_jump_target)
def main [
1:number <- copy 10
1:num <- copy 10
<label1>
+label2
4:number <- copy 10
4:num <- copy 10
]
before <label1> [
jump +label2:label
2:number <- copy 12
2:num <- copy 12
+label2 # renamed
3:number <- copy 12
3:num <- copy 12
]
+mem: storing 10 in location 1
# label1
@ -402,15 +402,15 @@ $mem: 3
:(scenario tangle_jump_to_base_recipe)
def main [
1:number <- copy 10
1:num <- copy 10
<label1>
+label2
4:number <- copy 10
4:num <- copy 10
]
before <label1> [
jump +label2:label
2:number <- copy 12
3:number <- copy 12
2:num <- copy 12
3:num <- copy 12
]
+mem: storing 10 in location 1
# label1
@ -431,14 +431,14 @@ void test_new_fragment_after_tangle() {
" <label>\n"
"]\n"
"after <label> [\n"
" 1:number/raw <- copy 34\n"
" 1:num/raw <- copy 34\n"
"]\n");
transform_all();
CHECK_TRACE_DOESNT_CONTAIN_ERROR();
Hide_errors = true;
// try to tangle into recipe foo after transform
load("before <label> [\n"
" 2:number/raw <- copy 35\n"
" 2:num/raw <- copy 35\n"
"]\n");
CHECK_TRACE_CONTAINS_ERROR();
}

View File

@ -3,12 +3,12 @@
:(scenario recipe_with_header)
def main [
1:number/raw <- add2 3, 5
1:num/raw <- add2 3, 5
]
def add2 x:number, y:number -> z:number [
def add2 x:num, y:num -> z:num [
local-scope
load-ingredients
z:number <- add x, y
z:num <- add x, y
return z
]
+mem: storing 8 in location 1
@ -51,12 +51,12 @@ void load_recipe_header(istream& in, recipe& result) {
:(scenario recipe_handles_stray_comma)
def main [
1:number/raw <- add2 3, 5
1:num/raw <- add2 3, 5
]
def add2 x:number, y:number -> z:number, [
def add2 x:num, y:num -> z:num, [
local-scope
load-ingredients
z:number <- add x, y
z:num <- add x, y
return z
]
+mem: storing 8 in location 1
@ -66,16 +66,16 @@ def main [
foo
]
def foo, [
1:number/raw <- add 2, 2
1:num/raw <- add 2, 2
]
def bar [
1:number/raw <- add 2, 3
1:num/raw <- add 2, 3
]
+mem: storing 4 in location 1
:(scenario recipe_handles_wrong_arrow)
% Hide_errors = true;
def foo a:number <- b:number [
def foo a:num <- b:num [
]
+error: recipe foo should say '->' and not '<-'
@ -119,7 +119,7 @@ for (int i = 0; i < SIZE(x.products); ++i)
:(scenario recipe_without_ingredients_or_products_has_header)
def test [
1:number <- copy 34
1:num <- copy 34
]
+parse: recipe test has a header
@ -218,21 +218,21 @@ case NEXT_INGREDIENT_WITHOUT_TYPECHECKING: {
:(scenario show_clear_error_on_bad_call)
% Hide_errors = true;
def main [
1:number <- foo 34
1:num <- foo 34
]
def foo x:point -> y:number [
def foo x:point -> y:num [
local-scope
load-ingredients
return 35
]
+error: main: ingredient 0 has the wrong type at '1:number <- foo 34'
+error: main: ingredient 0 has the wrong type at '1:num <- foo 34'
:(scenario show_clear_error_on_bad_call_2)
% Hide_errors = true;
def main [
1:point <- foo 34
]
def foo x:number -> y:number [
def foo x:num -> y:num [
local-scope
load-ingredients
return x
@ -269,10 +269,10 @@ void check_calls_against_header(const recipe_ordinal r) {
:(scenarios transform)
:(scenario recipe_headers_are_checked)
% Hide_errors = true;
def add2 x:number, y:number -> z:number [
def add2 x:num, y:num -> z:num [
local-scope
load-ingredients
z:address:number <- copy 0/unsafe
z:address:num <- copy 0/unsafe
return z
]
+error: add2: replied with the wrong type at 'return z'
@ -301,17 +301,17 @@ void check_reply_instructions_against_header(const recipe_ordinal r) {
:(scenario recipe_headers_are_checked_2)
% Hide_errors = true;
def add2 x:number, y:number [
def add2 x:num, y:num [
local-scope
load-ingredients
z:address:number <- copy 0/unsafe
z:address:num <- copy 0/unsafe
return z
]
+error: add2: replied with the wrong number of products at 'return z'
:(scenario recipe_headers_check_for_duplicate_names)
% Hide_errors = true;
def add2 x:number, x:number -> z:number [
def add2 x:num, x:num -> z:num [
local-scope
load-ingredients
return z
@ -342,9 +342,9 @@ void check_header_ingredients(const recipe_ordinal r) {
:(scenarios run)
:(scenario deduce_instruction_types_from_recipe_header)
def main [
1:number/raw <- add2 3, 5
1:num/raw <- add2 3, 5
]
def add2 x:number, y:number -> z:number [
def add2 x:num, y:num -> z:num [
local-scope
load-ingredients
z <- add x, y # no type for z
@ -399,9 +399,9 @@ void deduce_types_from_header(const recipe_ordinal r) {
:(scenario return_based_on_header)
def main [
1:number/raw <- add2 3, 5
1:num/raw <- add2 3, 5
]
def add2 x:number, y:number -> z:number [
def add2 x:num, y:num -> z:num [
local-scope
load-ingredients
z <- add x, y
@ -450,9 +450,9 @@ void add_header_products(instruction& inst, const recipe& caller_recipe) {
:(scenario explicit_reply_ignores_header)
def main [
1:number/raw, 2:number/raw <- add2 3, 5
1:num/raw, 2:num/raw <- add2 3, 5
]
def add2 a:number, b:number -> y:number, z:number [
def add2 a:num, b:num -> y:num, z:num [
local-scope
load-ingredients
y <- add a, b
@ -464,9 +464,9 @@ def add2 a:number, b:number -> y:number, z:number [
:(scenario return_on_fallthrough_based_on_header)
def main [
1:number/raw <- add2 3, 5
1:num/raw <- add2 3, 5
]
def add2 x:number, y:number -> z:number [
def add2 x:num, y:num -> z:num [
local-scope
load-ingredients
z <- add x, y
@ -476,23 +476,23 @@ def add2 x:number, y:number -> z:number [
:(scenario return_on_fallthrough_already_exists)
def main [
1:number/raw <- add2 3, 5
1:num/raw <- add2 3, 5
]
def add2 x:number, y:number -> z:number [
def add2 x:num, y:num -> z:num [
local-scope
load-ingredients
z <- add x, y # no type for z
return z
]
+transform: instruction: return {z: ()}
-transform: instruction: reply z:number
-transform: instruction: reply z:num
+mem: storing 8 in location 1
:(scenario return_after_conditional_reply_based_on_header)
def main [
1:number/raw <- add2 3, 5
1:num/raw <- add2 3, 5
]
def add2 x:number, y:number -> z:number [
def add2 x:num, y:num -> z:num [
local-scope
load-ingredients
z <- add x, y # no type for z
@ -503,15 +503,15 @@ def add2 x:number, y:number -> z:number [
:(scenario recipe_headers_perform_same_ingredient_check)
% Hide_errors = true;
def main [
1:number <- copy 34
2:number <- copy 34
3:number <- add2 1:number, 2:number
1:num <- copy 34
2:num <- copy 34
3:num <- add2 1:num, 2:num
]
def add2 x:number, y:number -> x:number [
def add2 x:num, y:num -> x:num [
local-scope
load-ingredients
]
+error: main: '3:number <- add2 1:number, 2:number' should write to '1:number' rather than '3:number'
+error: main: '3:num <- add2 1:num, 2:num' should write to '1:num' rather than '3:num'
:(before "End Includes")
using std::min;

View File

@ -4,12 +4,12 @@
:(scenario static_dispatch)
def main [
7:number/raw <- test 3
7:num/raw <- test 3
]
def test a:number -> z:number [
def test a:num -> z:num [
z <- copy 1
]
def test a:number, b:number -> z:number [
def test a:num, b:num -> z:num [
z <- copy 2
]
+mem: storing 1 in location 7
@ -119,12 +119,12 @@ string next_unused_recipe_name(const string& recipe_name) {
:(scenario static_dispatch_picks_most_similar_variant)
def main [
7:number/raw <- test 3, 4, 5
7:num/raw <- test 3, 4, 5
]
def test a:number -> z:number [
def test a:num -> z:num [
z <- copy 1
]
def test a:number, b:number -> z:number [
def test a:num, b:num -> z:num [
z <- copy 2
]
+mem: storing 2 in location 7
@ -386,17 +386,17 @@ bool next_stash(const call& c, instruction* stash_inst) {
:(scenario static_dispatch_disabled_in_recipe_without_variants)
def main [
1:number <- test 3
1:num <- test 3
]
def test [
2:number <- next-ingredient # ensure no header
2:num <- next-ingredient # ensure no header
return 34
]
+mem: storing 34 in location 1
:(scenario static_dispatch_disabled_on_headerless_definition)
% Hide_errors = true;
def test a:number -> z:number [
def test a:num -> z:num [
z <- copy 1
]
def test [
@ -409,22 +409,22 @@ def test [
def test [
return 34
]
def test a:number -> z:number [
def test a:num -> z:num [
z <- copy 1
]
+error: redefining recipe test
:(scenario static_dispatch_on_primitive_names)
def main [
1:number <- copy 34
2:number <- copy 34
3:bool <- equal 1:number, 2:number
1:num <- copy 34
2:num <- copy 34
3:bool <- equal 1:num, 2:num
4:bool <- copy 0/false
5:bool <- copy 0/false
6:bool <- equal 4:bool, 5:bool
]
# temporarily hardcode number equality to always fail
def equal x:number, y:number -> z:bool [
def equal x:num, y:num -> z:bool [
local-scope
load-ingredients
z <- copy 0/false
@ -438,12 +438,12 @@ def equal x:number, y:number -> z:bool [
def main [
_ <- test 3, 4
]
def test a:number -> z:point [
def test a:num -> z:point [
local-scope
load-ingredients
z <- merge a, 0
]
def test a:number, b:number -> z:point [
def test a:num, b:num -> z:point [
local-scope
load-ingredients
z <- merge a, b
@ -456,12 +456,12 @@ def main [
test x
]
container foo [
x:number
x:num
]
def test a:address:foo -> z:number [
def test a:address:foo -> z:num [
local-scope
load-ingredients
z:number <- get *a, x:offset
z:num <- get *a, x:offset
]
$error: 0
@ -470,24 +470,24 @@ def main [
x:address:foo <- new foo:type
test x
]
def test a:address:foo -> z:number [
def test a:address:foo -> z:num [
local-scope
load-ingredients
z:number <- get *a, x:offset
z:num <- get *a, x:offset
]
container foo [
x:number
x:num
]
$error: 0
:(scenario static_dispatch_prefers_literals_to_be_numbers_rather_than_addresses)
def main [
1:number <- foo 0
1:num <- foo 0
]
def foo x:address:number -> y:number [
def foo x:address:num -> y:num [
return 34
]
def foo x:number -> y:number [
def foo x:num -> y:num [
return 35
]
+mem: storing 35 in location 1
@ -497,25 +497,25 @@ def foo x:number -> y:number [
def main [
local-scope
x:char <- copy 10/newline
1:number/raw <- foo x
1:num/raw <- foo x
]
def foo x:number -> y:number [
def foo x:num -> y:num [
load-ingredients
return 34
]
+error: main: ingredient 0 has the wrong type at '1:number/raw <- foo x'
+error: main: ingredient 0 has the wrong type at '1:num/raw <- foo x'
-mem: storing 34 in location 1
:(scenario static_dispatch_dispatches_literal_to_boolean_before_character)
def main [
1:number/raw <- foo 0 # valid literal for boolean
1:num/raw <- foo 0 # valid literal for boolean
]
def foo x:char -> y:number [
def foo x:char -> y:num [
local-scope
load-ingredients
return 34
]
def foo x:bool -> y:number [
def foo x:bool -> y:num [
local-scope
load-ingredients
return 35
@ -525,14 +525,14 @@ def foo x:bool -> y:number [
:(scenario static_dispatch_dispatches_literal_to_character_when_out_of_boolean_range)
def main [
1:number/raw <- foo 97 # not a valid literal for boolean
1:num/raw <- foo 97 # not a valid literal for boolean
]
def foo x:char -> y:number [
def foo x:char -> y:num [
local-scope
load-ingredients
return 34
]
def foo x:bool -> y:number [
def foo x:bool -> y:num [
local-scope
load-ingredients
return 35
@ -542,14 +542,14 @@ def foo x:bool -> y:number [
:(scenario static_dispatch_dispatches_literal_to_number_if_at_all_possible)
def main [
1:number/raw <- foo 97
1:num/raw <- foo 97
]
def foo x:char -> y:number [
def foo x:char -> y:num [
local-scope
load-ingredients
return 34
]
def foo x:number -> y:number [
def foo x:num -> y:num [
local-scope
load-ingredients
return 35
@ -574,20 +574,20 @@ string header_label(const recipe& caller) {
:(scenario reload_variant_retains_other_variants)
def main [
1:number <- copy 34
2:number <- foo 1:number
1:num <- copy 34
2:num <- foo 1:num
]
def foo x:number -> y:number [
def foo x:num -> y:num [
local-scope
load-ingredients
return 34
]
def foo x:address:number -> y:number [
def foo x:address:num -> y:num [
local-scope
load-ingredients
return 35
]
def! foo x:address:number -> y:number [
def! foo x:address:num -> y:num [
local-scope
load-ingredients
return 36
@ -598,33 +598,33 @@ $error: 0
:(scenario dispatch_errors_come_after_unknown_name_errors)
% Hide_errors = true;
def main [
y:number <- foo x
y:num <- foo x
]
def foo a:number -> b:number [
def foo a:num -> b:num [
local-scope
load-ingredients
return 34
]
def foo a:bool -> b:number [
def foo a:bool -> b:num [
local-scope
load-ingredients
return 35
]
+error: main: missing type for 'x' in 'y:number <- foo x'
+error: main: failed to find a matching call for 'y:number <- foo x'
+error: main: missing type for 'x' in 'y:num <- foo x'
+error: main: failed to find a matching call for 'y:num <- foo x'
:(scenario override_methods_with_type_abbreviations)
type string = address:array:char
def main [
local-scope
s:text <- new [abc]
1:number/raw <- foo s
1:num/raw <- foo s
]
def foo a:text -> result:number [
def foo a:text -> result:num [
return 34
]
# identical to previous variant once you take type abbreviation into account
def! foo a:string -> result:number [
def! foo a:string -> result:num [
return 35
]
+mem: storing 35 in location 1

View File

@ -23,10 +23,10 @@ if (!base_type->atom) base_type = base_type->left;
:(scenario size_of_shape_shifting_container)
container foo:_t [
x:_t
y:number
y:num
]
def main [
1:foo:number <- merge 12, 13
1:foo:num <- merge 12, 13
3:foo:point <- merge 14, 15, 16
]
+mem: storing 12 in location 1
@ -42,7 +42,7 @@ container foo:_a:_b [
y:_b
]
def main [
1:foo:number:bool <- merge 34, 1/true
1:foo:num:bool <- merge 34, 1/true
]
$error: 0
@ -69,7 +69,7 @@ container bar:_a:_b [
]
def main [
1:text <- new [abc]
2:bar:number:array:char <- merge 34/x, 1:text/y
2:bar:num:array:char <- merge 34/x, 1:text/y
]
$error: 0
@ -95,7 +95,7 @@ container foo:_b [
:(scenario type_ingredient_must_start_with_underscore)
% Hide_errors = true;
container foo:t [
x:number
x:num
]
+error: foo: type ingredient 't' must begin with an underscore
@ -202,10 +202,10 @@ if (type->value >= START_TYPE_INGREDIENTS
:(scenario size_of_shape_shifting_exclusive_container)
exclusive-container foo:_t [
x:_t
y:number
y:num
]
def main [
1:foo:number <- merge 0/x, 34
1:foo:num <- merge 0/x, 34
3:foo:point <- merge 0/x, 15, 16
6:foo:point <- merge 1/y, 23
]
@ -226,18 +226,18 @@ def main [
:(scenario get_on_shape_shifting_container)
container foo:_t [
x:_t
y:number
y:num
]
def main [
1:foo:point <- merge 14, 15, 16
2:number <- get 1:foo:point, y:offset
2:num <- get 1:foo:point, y:offset
]
+mem: storing 16 in location 2
:(scenario get_on_shape_shifting_container_2)
container foo:_t [
x:_t
y:number
y:num
]
def main [
1:foo:point <- merge 14, 15, 16
@ -249,7 +249,7 @@ def main [
:(scenario get_on_shape_shifting_container_3)
container foo:_t [
x:_t
y:number
y:num
]
def main [
1:foo:address:point <- merge 34/unsafe, 48
@ -260,15 +260,15 @@ def main [
:(scenario get_on_shape_shifting_container_inside_container)
container foo:_t [
x:_t
y:number
y:num
]
container bar [
x:foo:point
y:number
y:num
]
def main [
1:bar <- merge 14, 15, 16, 17
2:number <- get 1:bar, 1:offset
2:num <- get 1:bar, 1:offset
]
+mem: storing 17 in location 2
@ -367,7 +367,7 @@ bool final_type_ingredient(int type_ingredient_index, const type_info& container
void test_replace_type_ingredients_entire() {
run("container foo:_elem [\n"
" x:_elem\n"
" y:number\n"
" y:num\n"
"]\n");
reagent callsite("x:foo:point");
reagent element = element_type(callsite.type, 0);
@ -403,7 +403,7 @@ void test_replace_type_ingredients_head_middle() {
" x:_elem\n"
"]\n"
"container bar:_elem [\n"
" x:foo:_elem:number\n"
" x:foo:_elem:num\n"
"]\n");
reagent callsite("x:bar:address");
reagent element = element_type(callsite.type, 0);
@ -473,11 +473,11 @@ bool has_nth_type(const type_tree* base, int n) {
% Hide_errors = true;
container foo:_t [
x:_t
y:number
y:num
]
def main [
10:foo:point <- merge 14, 15, 16
1:number <- get 10:foo, 1:offset
1:num <- get 10:foo, 1:offset
]
+error: illegal type "foo" seems to be missing a type ingredient or three
@ -502,7 +502,7 @@ if (info.kind == EXCLUSIVE_CONTAINER) {
:(before "End Unit Tests")
void test_container_sizes_shape_shifting_container() {
run("container foo:_t [\n"
" x:number\n"
" x:num\n"
" y:_t\n"
"]\n");
reagent r("x:foo:point");
@ -512,20 +512,20 @@ void test_container_sizes_shape_shifting_container() {
void test_container_sizes_shape_shifting_exclusive_container() {
run("exclusive-container foo:_t [\n"
" x:number\n"
" x:num\n"
" y:_t\n"
"]\n");
reagent r("x:foo:point");
compute_container_sizes(r);
CHECK_EQ(r.metadata.size, 3);
reagent r2("x:foo:number");
reagent r2("x:foo:num");
compute_container_sizes(r2);
CHECK_EQ(r2.metadata.size, 2);
}
void test_container_sizes_compound_type_ingredient() {
run("container foo:_t [\n"
" x:number\n"
" x:num\n"
" y:_t\n"
"]\n");
reagent r("x:foo:address:point");
@ -539,10 +539,10 @@ void test_container_sizes_compound_type_ingredient() {
void test_container_sizes_recursive_shape_shifting_container() {
run("container foo:_t [\n"
" x:number\n"
" x:num\n"
" y:address:foo:_t\n"
"]\n");
reagent r2("x:foo:number");
reagent r2("x:foo:num");
compute_container_sizes(r2);
CHECK_EQ(r2.metadata.size, 2);
}
@ -562,10 +562,10 @@ if (info.kind == EXCLUSIVE_CONTAINER) {
:(before "End Unit Tests")
void test_container_address_offsets_in_shape_shifting_container() {
run("container foo:_t [\n"
" x:number\n"
" x:num\n"
" y:_t\n"
"]\n");
reagent r("x:foo:address:number");
reagent r("x:foo:address:num");
compute_container_sizes(r);
compute_container_address_offsets(r);
CHECK_EQ(SIZE(r.metadata.address), 1);
@ -579,14 +579,14 @@ void test_container_address_offsets_in_shape_shifting_container() {
void test_container_address_offsets_in_nested_shape_shifting_container() {
run("container foo:_t [\n"
" x:number\n"
" x:num\n"
" y:_t\n"
"]\n"
"container bar:_t [\n"
" x:_t\n"
" y:foo:_t\n"
"]\n");
reagent r("x:bar:address:number");
reagent r("x:bar:address:num");
CLEAR_TRACE;
compute_container_sizes(r);
compute_container_address_offsets(r);
@ -606,12 +606,12 @@ void test_container_address_offsets_in_nested_shape_shifting_container() {
:(scenario merge_check_shape_shifting_container_containing_exclusive_container)
container foo:_elem [
x:number
x:num
y:_elem
]
exclusive-container bar [
x:number
y:number
x:num
y:num
]
def main [
1:foo:bar <- merge 23, 1/y, 34
@ -624,12 +624,12 @@ $error: 0
:(scenario merge_check_shape_shifting_container_containing_exclusive_container_2)
% Hide_errors = true;
container foo:_elem [
x:number
x:num
y:_elem
]
exclusive-container bar [
x:number
y:number
x:num
y:num
]
def main [
1:foo:bar <- merge 23, 1/y, 34, 35
@ -638,12 +638,12 @@ def main [
:(scenario merge_check_shape_shifting_exclusive_container_containing_container)
exclusive-container foo:_elem [
x:number
x:num
y:_elem
]
container bar [
x:number
y:number
x:num
y:num
]
def main [
1:foo:bar <- merge 1/y, 23, 34
@ -655,12 +655,12 @@ $error: 0
:(scenario merge_check_shape_shifting_exclusive_container_containing_container_2)
exclusive-container foo:_elem [
x:number
x:num
y:_elem
]
container bar [
x:number
y:number
x:num
y:num
]
def main [
1:foo:bar <- merge 0/x, 23
@ -670,12 +670,12 @@ $error: 0
:(scenario merge_check_shape_shifting_exclusive_container_containing_container_3)
% Hide_errors = true;
exclusive-container foo:_elem [
x:number
x:num
y:_elem
]
container bar [
x:number
y:number
x:num
y:num
]
def main [
1:foo:bar <- merge 1/y, 23

View File

@ -6,7 +6,7 @@ def main [
11:point <- foo 10:point
]
# non-matching variant
def foo a:number -> result:number [
def foo a:num -> result:num [
local-scope
load-ingredients
result <- copy 34
@ -510,7 +510,7 @@ def main [
11:point <- foo 10:point
]
# non-matching shape-shifting variant
def foo a:_t, b:_t -> result:number [
def foo a:_t, b:_t -> result:num [
local-scope
load-ingredients
result <- copy 34
@ -537,7 +537,7 @@ def bar a:foo:_t -> result:_t [
]
container foo:_t [
x:_t
y:number
y:num
]
+mem: storing 14 in location 20
+mem: storing 15 in location 21
@ -566,12 +566,12 @@ def main [
def bar a:foo:_t -> result:_t [
local-scope
load-ingredients
x:number <- copy 1
x:num <- copy 1
result <- get a, x:offset # shouldn't collide with other variable
]
container foo:_t [
x:_t
y:number
y:num
]
+mem: storing 14 in location 20
+mem: storing 15 in location 21
@ -592,9 +592,9 @@ def main [
]
container foo:_t [
x:_t
y:number
y:num
]
def bar x:number -> result:address:foo:_t [
def bar x:num -> result:address:foo:_t [
local-scope
load-ingredients
# new refers to _t in its ingredient *value*
@ -609,7 +609,7 @@ def main [
1:address:foo:point <- bar 3
11:foo:point <- copy *1:address:foo:point
]
def bar x:number -> result:address:foo:_t [
def bar x:num -> result:address:foo:_t [
local-scope
load-ingredients
# new refers to _t in its ingredient *value*
@ -618,7 +618,7 @@ def bar x:number -> result:address:foo:_t [
# container defined after use
container foo:_t [
x:_t
y:number
y:num
]
+mem: storing 0 in location 11
+mem: storing 0 in location 12
@ -642,7 +642,7 @@ void test_shape_shifting_new_ingredient_does_not_pollute_global_namespace() {
transform("def barz x:_elem [\n"
" local-scope\n"
" load-ingredients\n"
" y:address:number <- new _elem:type\n"
" y:address:num <- new _elem:type\n"
"]\n"
"def fooz [\n"
" local-scope\n"
@ -652,7 +652,7 @@ void test_shape_shifting_new_ingredient_does_not_pollute_global_namespace() {
// type-ingredient
run("container foo:_elem [\n"
" x:_elem\n"
" y:number\n"
" y:num\n"
"]\n");
// then it should work as usual
reagent callsite("x:foo:point");
@ -679,14 +679,14 @@ def bar a:_t -> result:_t [
:(scenario shape_shifting_recipe_error)
% Hide_errors = true;
def main [
a:number <- copy 3
b:address:number <- foo a
a:num <- copy 3
b:address:num <- foo a
]
def foo a:_t -> b:_t [
load-ingredients
b <- copy a
]
+error: main: no call found for 'b:address:number <- foo a'
+error: main: no call found for 'b:address:num <- foo a'
:(scenario specialize_inside_recipe_without_header)
def main [
@ -694,8 +694,8 @@ def main [
]
def foo [
local-scope
x:number <- next-ingredient # ensure no header
1:number/raw <- bar x # call a shape-shifting recipe
x:num <- next-ingredient # ensure no header
1:num/raw <- bar x # call a shape-shifting recipe
]
def bar x:_elem -> y:_elem [
local-scope
@ -708,7 +708,7 @@ def bar x:_elem -> y:_elem [
def main [
local-scope
# permit literal to map to number
1:number/raw <- foo 3
1:num/raw <- foo 3
]
def foo x:_elem -> y:_elem [
local-scope
@ -765,25 +765,25 @@ def main [
def foo x:_elem, y:_elem [
local-scope
load-ingredients
1:number/raw <- add x, y
1:num/raw <- add x, y
]
+mem: storing 7 in location 1
:(scenario multiple_shape_shifting_variants)
# try to call two different shape-shifting recipes with the same name
def main [
e1:d1:number <- merge 3
e2:d2:number <- merge 4, 5
1:number/raw <- foo e1
2:number/raw <- foo e2
e1:d1:num <- merge 3
e2:d2:num <- merge 4, 5
1:num/raw <- foo e1
2:num/raw <- foo e2
]
# the two shape-shifting definitions
def foo a:d1:_elem -> b:number [
def foo a:d1:_elem -> b:num [
local-scope
load-ingredients
return 34
]
def foo a:d2:_elem -> b:number [
def foo a:d2:_elem -> b:num [
local-scope
load-ingredients
return 35
@ -793,7 +793,7 @@ container d1:_elem [
x:_elem
]
container d2:_elem [
x:number
x:num
y:_elem
]
+mem: storing 34 in location 1
@ -802,17 +802,17 @@ container d2:_elem [
:(scenario multiple_shape_shifting_variants_2)
# static dispatch between shape-shifting variants, _including pointer lookups_
def main [
e1:d1:number <- merge 3
e2:address:d2:number <- new {(d2 number): type}
1:number/raw <- foo e1
2:number/raw <- foo *e2 # different from previous scenario
e1:d1:num <- merge 3
e2:address:d2:num <- new {(d2 number): type}
1:num/raw <- foo e1
2:num/raw <- foo *e2 # different from previous scenario
]
def foo a:d1:_elem -> b:number [
def foo a:d1:_elem -> b:num [
local-scope
load-ingredients
return 34
]
def foo a:d2:_elem -> b:number [
def foo a:d2:_elem -> b:num [
local-scope
load-ingredients
return 35
@ -821,7 +821,7 @@ container d1:_elem [
x:_elem
]
container d2:_elem [
x:number
x:num
y:_elem
]
+mem: storing 34 in location 1
@ -830,10 +830,10 @@ container d2:_elem [
:(scenario missing_type_in_shape_shifting_recipe)
% Hide_errors = true;
def main [
a:d1:number <- merge 3
a:d1:num <- merge 3
foo a
]
def foo a:d1:_elem -> b:number [
def foo a:d1:_elem -> b:num [
local-scope
load-ingredients
copy e # no such variable
@ -849,10 +849,10 @@ container d1:_elem [
:(scenario missing_type_in_shape_shifting_recipe_2)
% Hide_errors = true;
def main [
a:d1:number <- merge 3
a:d1:num <- merge 3
foo a
]
def foo a:d1:_elem -> b:number [
def foo a:d1:_elem -> b:num [
local-scope
load-ingredients
get e, x:offset # unknown variable in a 'get', which does some extra checking
@ -868,15 +868,15 @@ container d1:_elem [
:(scenarios transform)
:(scenario specialize_recursive_shape_shifting_recipe)
def main [
1:number <- copy 34
2:number <- foo 1:number
1:num <- copy 34
2:num <- foo 1:num
]
def foo x:_elem -> y:number [
def foo x:_elem -> y:num [
local-scope
load-ingredients
{
break
y:number <- foo x
y:num <- foo x
}
return y
]
@ -886,15 +886,15 @@ def foo x:_elem -> y:number [
:(scenarios run)
:(scenario specialize_most_similar_variant)
def main [
1:address:number <- new number:type
2:number <- foo 1:address:number
1:address:num <- new number:type
2:num <- foo 1:address:num
]
def foo x:_elem -> y:number [
def foo x:_elem -> y:num [
local-scope
load-ingredients
return 34
]
def foo x:address:_elem -> y:number [
def foo x:address:_elem -> y:num [
local-scope
load-ingredients
return 35
@ -904,18 +904,18 @@ def foo x:address:_elem -> y:number [
:(scenario specialize_most_similar_variant_2)
# version with headers padded with lots of unrelated concrete types
def main [
1:number <- copy 23
2:address:array:number <- copy 0
3:number <- foo 2:address:array:number, 1:number
1:num <- copy 23
2:address:array:num <- copy 0
3:num <- foo 2:address:array:num, 1:num
]
# variant with concrete type
def foo dummy:address:array:number, x:number -> y:number, dummy:address:array:number [
def foo dummy:address:array:num, x:num -> y:num, dummy:address:array:num [
local-scope
load-ingredients
return 34
]
# shape-shifting variant
def foo dummy:address:array:number, x:_elem -> y:number, dummy:address:array:number [
def foo dummy:address:array:num, x:_elem -> y:num, dummy:address:array:num [
local-scope
load-ingredients
return 35
@ -929,24 +929,24 @@ def main [
foo 1:text
]
def foo x:text [
2:number <- copy 34
2:num <- copy 34
]
def foo x:address:_elem [
2:number <- copy 35
2:num <- copy 35
]
# make sure the more precise version was used
+mem: storing 34 in location 2
:(scenario specialize_literal_as_number)
def main [
1:number <- foo 23
1:num <- foo 23
]
def foo x:_elem -> y:number [
def foo x:_elem -> y:num [
local-scope
load-ingredients
return 34
]
def foo x:char -> y:number [
def foo x:char -> y:num [
local-scope
load-ingredients
return 35
@ -956,16 +956,16 @@ def foo x:char -> y:number [
:(scenario specialize_literal_as_number_2)
# version calling with literal
def main [
1:number <- foo 0
1:num <- foo 0
]
# variant with concrete type
def foo x:number -> y:number [
def foo x:num -> y:num [
local-scope
load-ingredients
return 34
]
# shape-shifting variant
def foo x:address:_elem -> y:number [
def foo x:address:_elem -> y:num [
local-scope
load-ingredients
return 35
@ -975,16 +975,16 @@ def foo x:address:_elem -> y:number [
:(scenario specialize_literal_as_address)
def main [
1:number <- foo 0
1:num <- foo 0
]
# variant with concrete address type
def foo x:address:number -> y:number [
def foo x:address:num -> y:num [
local-scope
load-ingredients
return 34
]
# shape-shifting variant
def foo x:address:_elem -> y:number [
def foo x:address:_elem -> y:num [
local-scope
load-ingredients
return 35
@ -999,14 +999,14 @@ def foo a:_elem [
]
# define a container with field 'z'
container foo2 [
z:number
z:num
]
def main [
local-scope
x:foo2 <- merge 34
y:number <- get x, z:offse # typo in 'offset'
y:num <- get x, z:offse # typo in 'offset'
# define a variable with the same name 'z'
z:number <- copy 34
z:num <- copy 34
# trigger specialization of the shape-shifting recipe
foo z
]
@ -1019,14 +1019,14 @@ def foo a:_elem [
]
# define a container with field 'z'
container foo2 [
z:number
z:num
]
def main [
local-scope
x:foo2 <- merge 34
y:number <- get x, z:offse # typo in 'offset'
y:num <- get x, z:offse # typo in 'offset'
# define a variable with the same name 'z'
z:address:number <- copy 34
z:address:num <- copy 34
# trigger specialization of the shape-shifting recipe
foo *z
]

View File

@ -34,11 +34,11 @@ $error: 0
:(scenario can_modify_ingredients_that_are_also_products_3)
def main [
local-scope
p:address:array:number <- new number:type, 3
p:address:array:num <- new number:type, 3
p <- foo p
]
# mutable address
def foo p:address:array:number -> p:address:array:number [
def foo p:address:array:num -> p:address:array:num [
local-scope
load-ingredients
*p <- put-index *p, 0, 34
@ -49,9 +49,9 @@ $error: 0
def main [
local-scope
p:address:d1 <- new d1:type
q:number <- foo p
q:num <- foo p
]
def foo p:address:d1 -> q:number [
def foo p:address:d1 -> q:num [
local-scope
load-ingredients
x:address:d1 <- new d1:type
@ -59,8 +59,8 @@ def foo p:address:d1 -> q:number [
reply 36
]
container d1 [
p:number
q:number
p:num
q:num
]
$error: 0
@ -68,11 +68,11 @@ $error: 0
% Hide_errors = true;
def main [
local-scope
x:address:number <- new number:type
x:address:num <- new number:type
foo x
]
# immutable address to primitive
def foo x:address:number [
def foo x:address:num [
local-scope
load-ingredients
*x <- copy 34
@ -102,10 +102,10 @@ def foo x:point-number [
:(scenario can_modify_immutable_pointers)
def main [
local-scope
x:address:number <- new number:type
x:address:num <- new number:type
foo x
]
def foo x:address:number [
def foo x:address:num [
local-scope
load-ingredients
# modify the address, not the payload
@ -117,10 +117,10 @@ $error: 0
% Hide_errors = true;
def main [
local-scope
x:address:number <- new number:type
x:address:num <- new number:type
foo x
]
def foo x:address:number [
def foo x:address:num [
local-scope
load-ingredients
# modify address; ok
@ -183,7 +183,7 @@ $error: 0
:(scenario cannot_modify_address_inside_immutable_ingredients)
% Hide_errors = true;
container foo [
x:address:array:number # contains an address
x:address:array:num # contains an address
]
def main [
# don't run anything
@ -191,14 +191,14 @@ def main [
def foo a:address:foo [
local-scope
load-ingredients
x:address:array:number <- get *a, x:offset # just a regular get of the container
x:address:array:num <- get *a, x:offset # just a regular get of the container
*x <- put-index *x, 0, 34 # but then a put-index on the result
]
+error: foo: cannot modify 'x' in instruction '*x <- put-index *x, 0, 34' because that would modify a which is an ingredient of recipe foo but not also a product
:(scenario cannot_modify_address_inside_immutable_ingredients_2)
container foo [
x:address:array:number # contains an address
x:address:array:num # contains an address
]
def main [
# don't run anything
@ -208,7 +208,7 @@ def foo a:address:foo [
load-ingredients
b:foo <- merge 0
# modify b, completely unrelated to immutable ingredient a
x:address:array:number <- get b, x:offset
x:address:array:num <- get b, x:offset
*x <- put-index *x, 0, 34
]
$error: 0
@ -216,32 +216,32 @@ $error: 0
:(scenario cannot_modify_address_inside_immutable_ingredients_3)
% Hide_errors = true;
container foo [
x:number
x:num
]
def main [
# don't run anything
]
def foo a:address:array:address:number [
def foo a:address:array:address:num [
local-scope
load-ingredients
x:address:number <- index *a, 0 # just a regular index of the array
x:address:num <- index *a, 0 # just a regular index of the array
*x <- copy 34 # but then modify the result
]
+error: foo: cannot modify 'x' in instruction '*x <- copy 34' because that would modify a which is an ingredient of recipe foo but not also a product
:(scenario cannot_modify_address_inside_immutable_ingredients_4)
container foo [
x:address:array:number # contains an address
x:address:array:num # contains an address
]
def main [
# don't run anything
]
def foo a:address:array:address:number [
def foo a:address:array:address:num [
local-scope
load-ingredients
b:address:array:address:number <- new {(address number): type}, 3
b:address:array:address:num <- new {(address number): type}, 3
# modify b, completely unrelated to immutable ingredient a
x:address:number <- index *b, 0
x:address:num <- index *b, 0
*x <- copy 34
]
$error: 0
@ -269,11 +269,11 @@ $error: 0
:(scenario treat_optional_ingredients_as_mutable)
def main [
k:address:number <- new number:type
k:address:num <- new number:type
test k
]
# recipe taking an immutable address ingredient
def test k:address:number [
def test k:address:num [
local-scope
load-ingredients
foo k
@ -282,7 +282,7 @@ def test k:address:number [
def foo -> [
local-scope
load-ingredients
k:address:number, found?:bool <- next-ingredient
k:address:num, found?:bool <- next-ingredient
# we don't further check k for immutability, but assume it's mutable
]
$error: 0
@ -310,20 +310,20 @@ def bar [
:(scenario check_space_of_reagents_in_immutability_checks)
def main [
a:address:array:location <- new-closure
b:address:number <- new number:type
run-closure b:address:number, a:address:array:location
b:address:num <- new number:type
run-closure b:address:num, a:address:array:location
]
def new-closure [
new-default-space
x:address:number <- new number:type
x:address:num <- new number:type
return default-space
]
def run-closure x:address:number, s:address:array:location [
def run-closure x:address:num, s:address:array:location [
local-scope
load-ingredients
0:address:array:location/names:new-closure <- copy s
# different space; always mutable
*x:address:number/space:1 <- copy 34
*x:address:num/space:1 <- copy 34
]
$error: 0
@ -406,7 +406,7 @@ set<int> scan_contained_in_product_indices(const instruction& inst, set<int>& in
:(scenario immutability_infects_contained_in_variables)
% Hide_errors = true;
container test-list [
value:number
value:num
next:address:test-list
]
def main [
@ -526,7 +526,7 @@ set<int> ingredient_indices(const instruction& inst, const set<reagent>& ingredi
:(scenarios transform)
:(scenario can_modify_contained_in_addresses)
container test-list [
value:number
value:num
next:address:test-list
]
def main [

View File

@ -25,7 +25,7 @@ scenario to-text-line-early-warning-for-static-dispatch [
]
scenario array-to-text-line-early-warning-for-static-dispatch [
n:address:array:number <- new number:type, 3
n:address:array:num <- new number:type, 3
x:text <- array-to-text-line n
# just ensure there were no errors
]

View File

@ -2,9 +2,9 @@
:(scenario passing_literals_to_recipes)
def main [
1:number/raw <- foo [abc]
1:num/raw <- foo [abc]
]
def foo x:text -> n:number [
def foo x:text -> n:num [
local-scope
load-ingredients
n <- length *x

View File

@ -3,8 +3,8 @@
def equal a:text, b:text -> result:boolean [
local-scope
load-ingredients
a-len:number <- length *a
b-len:number <- length *b
a-len:num <- length *a
b-len:num <- length *b
# compare lengths
{
trace 99, [text-equal], [comparing lengths]
@ -14,7 +14,7 @@ def equal a:text, b:text -> result:boolean [
}
# compare each corresponding character
trace 99, [text-equal], [comparing characters]
i:number <- copy 0
i:num <- copy 0
{
done?:boolean <- greater-or-equal i, a-len
break-if done?
@ -98,11 +98,11 @@ scenario text-equal-common-lengths-but-distinct [
# A new type to help incrementally construct texts.
container buffer [
length:number
length:num
data:text
]
def new-buffer capacity:number -> result:address:buffer [
def new-buffer capacity:num -> result:address:buffer [
local-scope
load-ingredients
result <- new buffer:type
@ -122,12 +122,12 @@ def grow-buffer buf:address:buffer -> buf:address:buffer [
load-ingredients
# double buffer size
olddata:text <- get *buf, data:offset
oldlen:number <- length *olddata
newlen:number <- multiply oldlen, 2
oldlen:num <- length *olddata
newlen:num <- multiply oldlen, 2
newdata:text <- new character:type, newlen
*buf <- put *buf, data:offset, newdata
# copy old contents
i:number <- copy 0
i:num <- copy 0
{
done?:boolean <- greater-or-equal i, oldlen
break-if done?
@ -141,9 +141,9 @@ def grow-buffer buf:address:buffer -> buf:address:buffer [
def buffer-full? in:address:buffer -> result:boolean [
local-scope
load-ingredients
len:number <- get *in, length:offset
len:num <- get *in, length:offset
s:text <- get *in, data:offset
capacity:number <- length *s
capacity:num <- length *s
result <- greater-or-equal len, capacity
]
@ -152,8 +152,8 @@ def append buf:address:buffer, x:_elem -> buf:address:buffer [
local-scope
load-ingredients
text:text <- to-text x
len:number <- length *text
i:number <- copy 0
len:num <- length *text
i:num <- copy 0
{
done?:boolean <- greater-or-equal i, len
break-if done?
@ -167,7 +167,7 @@ def append buf:address:buffer, x:_elem -> buf:address:buffer [
def append buf:address:buffer, c:char -> buf:address:buffer [
local-scope
load-ingredients
len:number <- get *buf, length:offset
len:num <- get *buf, length:offset
{
# backspace? just drop last character if it exists and return
backspace?:boolean <- equal c, 8/backspace
@ -193,8 +193,8 @@ def append buf:address:buffer, c:char -> buf:address:buffer [
def append buf:address:buffer, t:text -> buf:address:buffer [
local-scope
load-ingredients
len:number <- length *t
i:number <- copy 0
len:num <- length *t
i:num <- copy 0
{
done?:boolean <- greater-or-equal i, len
break-if done?
@ -224,7 +224,7 @@ scenario buffer-append-works [
x <- append x, c
s3:text <- get *x, data:offset
20:boolean/raw <- equal s1, s3
21:number/raw <- get *x, length:offset
21:num/raw <- get *x, length:offset
30:array:char/raw <- copy *s3
]
memory-should-contain [
@ -284,11 +284,11 @@ def buffer-to-array in:address:buffer -> result:text [
break-if in
return 0
}
len:number <- get *in, length:offset
len:num <- get *in, length:offset
s:text <- get *in, data:offset
# we can't just return s because it is usually the wrong length
result <- new character:type, len
i:number <- copy 0
i:num <- copy 0
{
done?:boolean <- greater-or-equal i, len
break-if done?
@ -392,11 +392,11 @@ scenario replace-character-in-text [
]
]
def replace s:text, oldc:char, newc:char, from:number/optional -> s:text [
def replace s:text, oldc:char, newc:char, from:num/optional -> s:text [
local-scope
load-ingredients
len:number <- length *s
i:number <- find-next s, oldc, from
len:num <- length *s
i:num <- find-next s, oldc, from
done?:boolean <- greater-or-equal i, len
return-if done?, s/same-as-ingredient:0
*s <- put-index *s, i, newc
@ -457,14 +457,14 @@ def interpolate template:text -> result:text [
local-scope
load-ingredients # consume just the template
# compute result-len, space to allocate for result
tem-len:number <- length *template
result-len:number <- copy tem-len
tem-len:num <- length *template
result-len:num <- copy tem-len
{
# while ingredients remain
a:text, arg-received?:boolean <- next-ingredient
break-unless arg-received?
# result-len = result-len + arg.length - 1 (for the 'underscore' being replaced)
a-len:number <- length *a
a-len:num <- length *a
result-len <- add result-len, a-len
result-len <- subtract result-len, 1
loop
@ -473,8 +473,8 @@ def interpolate template:text -> result:text [
_ <- next-ingredient # skip template
result <- new character:type, result-len
# repeatedly copy sections of template and 'holes' into result
result-idx:number <- copy 0
i:number <- copy 0
result-idx:num <- copy 0
i:num <- copy 0
{
# while arg received
a:text, arg-received?:boolean <- next-ingredient
@ -495,7 +495,7 @@ def interpolate template:text -> result:text [
loop
}
# copy 'a' into result
j:number <- copy 0
j:num <- copy 0
{
# while j < a.length
arg-done?:boolean <- greater-or-equal j, a-len
@ -630,9 +630,9 @@ def space? c:char -> result:boolean [
def trim s:text -> result:text [
local-scope
load-ingredients
len:number <- length *s
len:num <- length *s
# left trim: compute start
start:number <- copy 0
start:num <- copy 0
{
{
at-end?:boolean <- greater-or-equal start, len
@ -647,7 +647,7 @@ def trim s:text -> result:text [
loop
}
# right trim: compute end
end:number <- subtract len, 1
end:num <- subtract len, 1
{
not-at-start?:boolean <- greater-than end, start
assert not-at-start?, [end ran up against start]
@ -658,11 +658,11 @@ def trim s:text -> result:text [
loop
}
# result = new character[end+1 - start]
new-len:number <- subtract end, start, -1
new-len:num <- subtract end, start, -1
result:text <- new character:type, new-len
# copy the untrimmed parts between start and end
i:number <- copy start
j:number <- copy 0
i:num <- copy start
j:num <- copy 0
{
# while i <= end
done?:boolean <- greater-than i, end
@ -737,10 +737,10 @@ scenario trim-newline-tab [
]
]
def find-next text:text, pattern:char, idx:number -> next-index:number [
def find-next text:text, pattern:char, idx:num -> next-index:num [
local-scope
load-ingredients
len:number <- length *text
len:num <- length *text
{
eof?:boolean <- greater-or-equal idx, len
break-if eof?
@ -757,7 +757,7 @@ scenario text-find-next [
run [
local-scope
x:text <- new [a/b]
10:number/raw <- find-next x, 47/slash, 0/start-index
10:num/raw <- find-next x, 47/slash, 0/start-index
]
memory-should-contain [
10 <- 1
@ -768,7 +768,7 @@ scenario text-find-next-empty [
run [
local-scope
x:text <- new []
10:number/raw <- find-next x, 47/slash, 0/start-index
10:num/raw <- find-next x, 47/slash, 0/start-index
]
memory-should-contain [
10 <- 0
@ -779,7 +779,7 @@ scenario text-find-next-initial [
run [
local-scope
x:text <- new [/abc]
10:number/raw <- find-next x, 47/slash, 0/start-index
10:num/raw <- find-next x, 47/slash, 0/start-index
]
memory-should-contain [
10 <- 0 # prefix match
@ -790,7 +790,7 @@ scenario text-find-next-final [
run [
local-scope
x:text <- new [abc/]
10:number/raw <- find-next x, 47/slash, 0/start-index
10:num/raw <- find-next x, 47/slash, 0/start-index
]
memory-should-contain [
10 <- 3 # suffix match
@ -801,7 +801,7 @@ scenario text-find-next-missing [
run [
local-scope
x:text <- new [abcd]
10:number/raw <- find-next x, 47/slash, 0/start-index
10:num/raw <- find-next x, 47/slash, 0/start-index
]
memory-should-contain [
10 <- 4 # no match
@ -812,7 +812,7 @@ scenario text-find-next-invalid-index [
run [
local-scope
x:text <- new [abc]
10:number/raw <- find-next x, 47/slash, 4/start-index
10:num/raw <- find-next x, 47/slash, 4/start-index
]
memory-should-contain [
10 <- 4 # no change
@ -823,7 +823,7 @@ scenario text-find-next-first [
run [
local-scope
x:text <- new [ab/c/]
10:number/raw <- find-next x, 47/slash, 0/start-index
10:num/raw <- find-next x, 47/slash, 0/start-index
]
memory-should-contain [
10 <- 2 # first '/' of multiple
@ -834,7 +834,7 @@ scenario text-find-next-second [
run [
local-scope
x:text <- new [ab/c/]
10:number/raw <- find-next x, 47/slash, 3/start-index
10:num/raw <- find-next x, 47/slash, 3/start-index
]
memory-should-contain [
10 <- 4 # second '/' of multiple
@ -843,12 +843,12 @@ scenario text-find-next-second [
# search for a pattern of multiple characters
# fairly dumb algorithm
def find-next text:text, pattern:text, idx:number -> next-index:number [
def find-next text:text, pattern:text, idx:num -> next-index:num [
local-scope
load-ingredients
first:char <- index *pattern, 0
# repeatedly check for match at current idx
len:number <- length *text
len:num <- length *text
{
# does some unnecessary work checking even when there isn't enough of text left
done?:boolean <- greater-or-equal idx, len
@ -868,7 +868,7 @@ scenario find-next-text-1 [
local-scope
x:text <- new [abc]
y:text <- new [bc]
10:number/raw <- find-next x, y, 0
10:num/raw <- find-next x, y, 0
]
memory-should-contain [
10 <- 1
@ -880,7 +880,7 @@ scenario find-next-text-2 [
local-scope
x:text <- new [abcd]
y:text <- new [bc]
10:number/raw <- find-next x, y, 1
10:num/raw <- find-next x, y, 1
]
memory-should-contain [
10 <- 1
@ -892,7 +892,7 @@ scenario find-next-no-match [
local-scope
x:text <- new [abc]
y:text <- new [bd]
10:number/raw <- find-next x, y, 0
10:num/raw <- find-next x, y, 0
]
memory-should-contain [
10 <- 3 # not found
@ -904,7 +904,7 @@ scenario find-next-suffix-match [
local-scope
x:text <- new [abcd]
y:text <- new [cd]
10:number/raw <- find-next x, y, 0
10:num/raw <- find-next x, y, 0
]
memory-should-contain [
10 <- 2
@ -916,7 +916,7 @@ scenario find-next-suffix-match-2 [
local-scope
x:text <- new [abcd]
y:text <- new [cde]
10:number/raw <- find-next x, y, 0
10:num/raw <- find-next x, y, 0
]
memory-should-contain [
10 <- 4 # not found
@ -924,20 +924,20 @@ scenario find-next-suffix-match-2 [
]
# checks if pattern matches at index 'idx'
def match-at text:text, pattern:text, idx:number -> result:boolean [
def match-at text:text, pattern:text, idx:num -> result:boolean [
local-scope
load-ingredients
pattern-len:number <- length *pattern
pattern-len:num <- length *pattern
# check that there's space left for the pattern
{
x:number <- length *text
x:num <- length *text
x <- subtract x, pattern-len
enough-room?:boolean <- lesser-or-equal idx, x
break-if enough-room?
return 0/not-found
}
# check each character of pattern
pattern-idx:number <- copy 0
pattern-idx:num <- copy 0
{
done?:boolean <- greater-or-equal pattern-idx, pattern-len
break-if done?
@ -1065,7 +1065,7 @@ def split s:text, delim:char -> result:address:array:text [
local-scope
load-ingredients
# empty text? return empty array
len:number <- length *s
len:num <- length *s
{
empty?:boolean <- equal len, 0
break-unless empty?
@ -1073,8 +1073,8 @@ def split s:text, delim:char -> result:address:array:text [
return
}
# count #pieces we need room for
count:number <- copy 1 # n delimiters = n+1 pieces
idx:number <- copy 0
count:num <- copy 1 # n delimiters = n+1 pieces
idx:num <- copy 0
{
idx <- find-next s, delim, idx
done?:boolean <- greater-or-equal idx, len
@ -1086,13 +1086,13 @@ def split s:text, delim:char -> result:address:array:text [
# allocate space
result <- new {(address array character): type}, count
# repeatedly copy slices start..end until delimiter into result[curr-result]
curr-result:number <- copy 0
start:number <- copy 0
curr-result:num <- copy 0
start:num <- copy 0
{
# while next delim exists
done?:boolean <- greater-or-equal start, len
break-if done?
end:number <- find-next s, delim, start
end:num <- find-next s, delim, start
# copy start..end into result[curr-result]
dest:text <- copy-range s, start, end
*result <- put-index *result, curr-result, dest
@ -1108,7 +1108,7 @@ scenario text-split-1 [
local-scope
x:text <- new [a/b]
y:address:array:text <- split x, 47/slash
10:number/raw <- length *y
10:num/raw <- length *y
a:text <- index *y, 0
b:text <- index *y, 1
20:array:char/raw <- copy *a
@ -1126,7 +1126,7 @@ scenario text-split-2 [
local-scope
x:text <- new [a/b/c]
y:address:array:text <- split x, 47/slash
10:number/raw <- length *y
10:num/raw <- length *y
a:text <- index *y, 0
b:text <- index *y, 1
c:text <- index *y, 2
@ -1147,7 +1147,7 @@ scenario text-split-missing [
local-scope
x:text <- new [abc]
y:address:array:text <- split x, 47/slash
10:number/raw <- length *y
10:num/raw <- length *y
a:text <- index *y, 0
20:array:char/raw <- copy *a
]
@ -1162,7 +1162,7 @@ scenario text-split-empty [
local-scope
x:text <- new []
y:address:array:text <- split x, 47/slash
10:number/raw <- length *y
10:num/raw <- length *y
]
memory-should-contain [
10 <- 0 # empty result
@ -1174,7 +1174,7 @@ scenario text-split-empty-piece [
local-scope
x:text <- new [a/b//c]
y:address:array:text <- split x:text, 47/slash
10:number/raw <- length *y
10:num/raw <- length *y
a:text <- index *y, 0
b:text <- index *y, 1
c:text <- index *y, 2
@ -1197,7 +1197,7 @@ def split-first text:text, delim:char -> x:text, y:text [
local-scope
load-ingredients
# empty text? return empty texts
len:number <- length *text
len:num <- length *text
{
empty?:boolean <- equal len, 0
break-unless empty?
@ -1205,7 +1205,7 @@ def split-first text:text, delim:char -> x:text, y:text [
y:text <- new []
return
}
idx:number <- find-next text, delim, 0
idx:num <- find-next text, delim, 0
x:text <- copy-range text, 0, idx
idx <- add idx, 1
y:text <- copy-range text, idx, len
@ -1225,18 +1225,18 @@ scenario text-split-first [
]
]
def copy-range buf:text, start:number, end:number -> result:text [
def copy-range buf:text, start:num, end:num -> result:text [
local-scope
load-ingredients
# if end is out of bounds, trim it
len:number <- length *buf
end:number <- min len, end
len:num <- length *buf
end:num <- min len, end
# allocate space for result
len <- subtract end, start
result:text <- new character:type, len
# copy start..end into result[curr-result]
src-idx:number <- copy start
dest-idx:number <- copy 0
src-idx:num <- copy start
dest-idx:num <- copy 0
{
done?:boolean <- greater-or-equal src-idx, end
break-if done?

View File

@ -4,7 +4,7 @@
:(scenario rewrite_stashes_to_text)
def main [
local-scope
n:number <- copy 34
n:num <- copy 34
stash n
]
+transform: {stash_2_0: ("address" "array" "character")} <- to-text-line {n: "number"}
@ -13,7 +13,7 @@ def main [
:(scenario rewrite_traces_to_text)
def main [
local-scope
n:number <- copy 34
n:num <- copy 34
trace 2, [app], n
]
+transform: {trace_2_2: ("address" "array" "character")} <- to-text-line {n: "number"}
@ -25,7 +25,7 @@ def main [
:(scenario rewrite_stashes_of_arrays)
def main [
local-scope
n:address:array:number <- new number:type, 3
n:address:array:num <- new number:type, 3
stash *n
]
+transform: {stash_2_0: ("address" "array" "character")} <- array-to-text-line {n: ("address" "array" "number")}
@ -34,14 +34,14 @@ def main [
:(scenario ignore_stashes_of_static_arrays)
def main [
local-scope
n:array:number:3 <- create-array
n:array:num:3 <- create-array
stash n
]
+transform: stash {n: ("array" "number" "3")}
:(scenario rewrite_stashes_of_recipe_header_products)
container foo [
x:number
x:num
]
def bar -> x:foo [
local-scope
@ -148,7 +148,7 @@ bool is_static_array(const reagent& x) {
:(scenario append_other_types_to_text)
def main [
local-scope
n:number <- copy 11
n:num <- copy 11
c:character <- copy 111/o
a:text <- append [abc], 10, n, c
expected:text <- new [abc1011o]
@ -161,8 +161,8 @@ def main [
:(scenario rewrite_stash_continues_to_fall_back_to_default_implementation)
# type without a to-text implementation
container foo [
x:number
y:number
x:num
y:num
]
def main [
local-scope

View File

@ -15,7 +15,7 @@ scenario array-from-args [
# create an array out of a list of scalar args
def new-array -> result:text [
local-scope
capacity:number <- copy 0
capacity:num <- copy 0
{
# while read curr-value
curr-value:char, exists?:boolean <- next-ingredient
@ -25,7 +25,7 @@ def new-array -> result:text [
}
result <- new character:type, capacity
rewind-ingredients
i:number <- copy 0
i:num <- copy 0
{
# while read curr-value
done?:boolean <- greater-or-equal i, capacity

View File

@ -30,15 +30,15 @@ def rest in:address:list:_elem -> result:address:list:_elem/contained-in:in [
scenario list-handling [
run [
local-scope
x:address:list:number <- push 3, 0
x:address:list:num <- push 3, 0
x <- push 4, x
x <- push 5, x
10:number/raw <- first x
10:num/raw <- first x
x <- rest x
11:number/raw <- first x
11:num/raw <- first x
x <- rest x
12:number/raw <- first x
20:address:list:number/raw <- rest x
12:num/raw <- first x
20:address:list:num/raw <- rest x
]
memory-should-contain [
10 <- 5
@ -48,12 +48,12 @@ scenario list-handling [
]
]
def length l:address:list:_elem -> result:number [
def length l:address:list:_elem -> result:num [
local-scope
load-ingredients
return-unless l, 0
rest:address:list:_elem <- rest l
length-of-rest:number <- length rest
length-of-rest:num <- length rest
result <- add length-of-rest, 1
]
@ -251,7 +251,7 @@ scenario removing-from-singleton-list [
local-scope
list:address:list:char <- push 3, 0
list <- remove list, list
1:number/raw <- copy list
1:num/raw <- copy list
]
memory-should-contain [
1 <- 0 # back to an empty list
@ -288,11 +288,11 @@ def to-buffer in:address:list:_elem, buf:address:buffer -> buf:address:buffer [
buf <- append buf, val
# now prepare next
next:address:list:_elem <- rest in
nextn:number <- copy next
nextn:num <- copy next
return-unless next
buf <- append buf, [ -> ]
# and recurse
remaining:number, optional-ingredient-found?:boolean <- next-ingredient
remaining:num, optional-ingredient-found?:boolean <- next-ingredient
{
break-if optional-ingredient-found?
# unlimited recursion

View File

@ -45,8 +45,8 @@ scenario duplex-list-handling [
run [
local-scope
# reserve locations 0-9 to check for missing null check
10:number/raw <- copy 34
11:number/raw <- copy 35
10:num/raw <- copy 34
11:num/raw <- copy 35
list:address:duplex-list:char <- push 3, 0
list <- push 4, list
list <- push 5, list
@ -330,7 +330,7 @@ scenario removing-from-singleton-duplex-list [
local-scope
list:address:duplex-list:char <- push 3, 0
list <- remove list, list
1:number/raw <- copy list
1:num/raw <- copy list
]
memory-should-contain [
1 <- 0 # back to an empty list

View File

@ -1,6 +1,6 @@
# new type to help incrementally scan arrays
container stream:_elem [
index:number
index:num
data:address:array:_elem
]
@ -22,9 +22,9 @@ def read in:address:stream:_elem -> result:_elem, empty?:boolean, in:address:str
local-scope
load-ingredients
empty? <- copy 0/false
idx:number <- get *in, index:offset
idx:num <- get *in, index:offset
s:address:array:_elem <- get *in, data:offset
len:number <- length *s
len:num <- length *s
at-end?:boolean <- greater-or-equal idx len
{
break-unless at-end?
@ -40,9 +40,9 @@ def peek in:address:stream:_elem -> result:_elem, empty?:boolean [
local-scope
load-ingredients
empty?:boolean <- copy 0/false
idx:number <- get *in, index:offset
idx:num <- get *in, index:offset
s:address:array:_elem <- get *in, data:offset
len:number <- length *s
len:num <- length *s
at-end?:boolean <- greater-or-equal idx len
{
break-unless at-end?
@ -55,9 +55,9 @@ def peek in:address:stream:_elem -> result:_elem, empty?:boolean [
def read-line in:address:stream:char -> result:text, in:address:stream:char [
local-scope
load-ingredients
idx:number <- get *in, index:offset
idx:num <- get *in, index:offset
s:text <- get *in, data:offset
next-idx:number <- find-next s, 10/newline, idx
next-idx:num <- find-next s, 10/newline, idx
result <- copy-range s, idx, next-idx
idx <- add next-idx, 1 # skip newline
# write back
@ -67,8 +67,8 @@ def read-line in:address:stream:char -> result:text, in:address:stream:char [
def end-of-stream? in:address:stream:_elem -> result:boolean [
local-scope
load-ingredients
idx:number <- get *in, index:offset
idx:num <- get *in, index:offset
s:address:array:_elem <- get *in, data:offset
len:number <- length *s
len:num <- length *s
result <- greater-or-equal idx, len
]

View File

@ -1,4 +1,4 @@
def random generator:address:stream:number -> result:number, fail?:boolean, generator:address:stream:number [
def random generator:address:stream:num -> result:num, fail?:boolean, generator:address:stream:num [
local-scope
load-ingredients
{
@ -11,11 +11,11 @@ def random generator:address:stream:number -> result:number, fail?:boolean, gene
]
# helper for tests
def assume-random-numbers -> result:address:stream:number [
def assume-random-numbers -> result:address:stream:num [
local-scope
load-ingredients
# compute result-len, space to allocate in result
result-len:number <- copy 0
result-len:num <- copy 0
{
_, arg-received?:boolean <- next-ingredient
break-unless arg-received?
@ -23,10 +23,10 @@ def assume-random-numbers -> result:address:stream:number [
loop
}
rewind-ingredients
result-data:address:array:number <- new number:type, result-len
idx:number <- copy 0
result-data:address:array:num <- new number:type, result-len
idx:num <- copy 0
{
curr:number, arg-received?:boolean <- next-ingredient
curr:num, arg-received?:boolean <- next-ingredient
break-unless arg-received?
*result-data <- put-index *result-data, idx, curr
idx <- add idx, 1
@ -37,11 +37,11 @@ def assume-random-numbers -> result:address:stream:number [
scenario random-numbers-in-scenario [
local-scope
source:address:stream:number <- assume-random-numbers 34, 35, 37
1:number/raw, 2:boolean/raw <- random source
3:number/raw, 4:boolean/raw <- random source
5:number/raw, 6:boolean/raw <- random source
7:number/raw, 8:boolean/raw <- random source
source:address:stream:num <- assume-random-numbers 34, 35, 37
1:num/raw, 2:boolean/raw <- random source
3:num/raw, 4:boolean/raw <- random source
5:num/raw, 6:boolean/raw <- random source
7:num/raw, 8:boolean/raw <- random source
memory-should-contain [
1 <- 34
2 <- 0 # everything went well

View File

@ -129,17 +129,17 @@ size_t hash_iter(size_t h, size_t input) {
:(scenario hash_container_checks_all_elements)
container foo [
x:number
x:num
y:char
]
def main [
1:foo <- merge 34, 97/a
3:number <- hash 1:foo
return-unless 3:number
3:num <- hash 1:foo
return-unless 3:num
4:foo <- merge 34, 98/a
6:number <- hash 4:foo
return-unless 6:number
7:bool <- equal 3:number, 6:number
6:num <- hash 4:foo
return-unless 6:num
7:bool <- equal 3:num, 6:num
]
# hash on containers includes all elements
+mem: storing 0 in location 7
@ -147,37 +147,37 @@ def main [
:(scenario hash_exclusive_container_checks_all_elements)
exclusive-container foo [
x:bar
y:number
y:num
]
container bar [
a:number
b:number
a:num
b:num
]
def main [
1:foo <- merge 0/x, 34, 35
4:number <- hash 1:foo
return-unless 4:number
4:num <- hash 1:foo
return-unless 4:num
5:foo <- merge 0/x, 34, 36
8:number <- hash 5:foo
return-unless 8:number
9:bool <- equal 4:number, 8:number
8:num <- hash 5:foo
return-unless 8:num
9:bool <- equal 4:num, 8:num
]
# hash on containers includes all elements
+mem: storing 0 in location 9
:(scenario hash_can_ignore_container_elements)
container foo [
x:number
x:num
y:char/ignore-for-hash
]
def main [
1:foo <- merge 34, 97/a
3:number <- hash 1:foo
return-unless 3:number
3:num <- hash 1:foo
return-unless 3:num
4:foo <- merge 34, 98/a
6:number <- hash 4:foo
return-unless 6:number
7:bool <- equal 3:number, 6:number
6:num <- hash 4:foo
return-unless 6:num
7:bool <- equal 3:num, 6:num
]
# hashes match even though y is different
+mem: storing 1 in location 7
@ -187,8 +187,8 @@ def main [
:(scenario hash_of_zero_address)
def main [
1:address:number <- copy 0
2:number <- hash 1:address:number
1:address:num <- copy 0
2:num <- hash 1:address:num
]
+mem: storing 0 in location 2
@ -196,116 +196,116 @@ def main [
//: on the precise bit pattern of a floating-point number.
:(scenario hash_of_numbers_ignores_fractional_part)
def main [
1:number <- hash 1.5
2:number <- hash 1
3:bool <- equal 1:number, 2:number
1:num <- hash 1.5
2:num <- hash 1
3:bool <- equal 1:num, 2:num
]
+mem: storing 1 in location 3
:(scenario hash_of_array_same_as_string)
def main [
10:number <- copy 3
11:number <- copy 97
12:number <- copy 98
13:number <- copy 99
2:number <- hash 10:array:number/unsafe
return-unless 2:number
10:num <- copy 3
11:num <- copy 97
12:num <- copy 98
13:num <- copy 99
2:num <- hash 10:array:num/unsafe
return-unless 2:num
3:text <- new [abc]
4:number <- hash 3:text
return-unless 4:number
5:bool <- equal 2:number, 4:number
4:num <- hash 3:text
return-unless 4:num
5:bool <- equal 2:num, 4:num
]
+mem: storing 1 in location 5
:(scenario hash_ignores_address_value)
def main [
1:address:number <- new number:type
*1:address:number <- copy 34
2:number <- hash 1:address:number
3:address:number <- new number:type
*3:address:number <- copy 34
4:number <- hash 3:address:number
5:bool <- equal 2:number, 4:number
1:address:num <- new number:type
*1:address:num <- copy 34
2:num <- hash 1:address:num
3:address:num <- new number:type
*3:address:num <- copy 34
4:num <- hash 3:address:num
5:bool <- equal 2:num, 4:num
]
# different addresses hash to the same result as long as the values the point to do so
+mem: storing 1 in location 5
:(scenario hash_ignores_address_refcount)
def main [
1:address:number <- new number:type
*1:address:number <- copy 34
2:number <- hash 1:address:number
return-unless 2:number
1:address:num <- new number:type
*1:address:num <- copy 34
2:num <- hash 1:address:num
return-unless 2:num
# increment refcount
3:address:number <- copy 1:address:number
4:number <- hash 3:address:number
return-unless 4:number
5:bool <- equal 2:number, 4:number
3:address:num <- copy 1:address:num
4:num <- hash 3:address:num
return-unless 4:num
5:bool <- equal 2:num, 4:num
]
# hash doesn't change when refcount changes
+mem: storing 1 in location 5
:(scenario hash_container_depends_only_on_elements)
container foo [
x:number
x:num
y:char
]
container bar [
x:number
x:num
y:char
]
def main [
1:foo <- merge 34, 97/a
3:number <- hash 1:foo
return-unless 3:number
3:num <- hash 1:foo
return-unless 3:num
4:bar <- merge 34, 97/a
6:number <- hash 4:bar
return-unless 6:number
7:bool <- equal 3:number, 6:number
6:num <- hash 4:bar
return-unless 6:num
7:bool <- equal 3:num, 6:num
]
# containers with identical elements return identical hashes
+mem: storing 1 in location 7
:(scenario hash_container_depends_only_on_elements_2)
container foo [
x:number
x:num
y:char
z:address:number
z:address:num
]
def main [
1:address:number <- new number:type
*1:address:number <- copy 34
2:foo <- merge 34, 97/a, 1:address:number
5:number <- hash 2:foo
return-unless 5:number
6:address:number <- new number:type
*6:address:number <- copy 34
7:foo <- merge 34, 97/a, 6:address:number
10:number <- hash 7:foo
return-unless 10:number
11:bool <- equal 5:number, 10:number
1:address:num <- new number:type
*1:address:num <- copy 34
2:foo <- merge 34, 97/a, 1:address:num
5:num <- hash 2:foo
return-unless 5:num
6:address:num <- new number:type
*6:address:num <- copy 34
7:foo <- merge 34, 97/a, 6:address:num
10:num <- hash 7:foo
return-unless 10:num
11:bool <- equal 5:num, 10:num
]
# containers with identical 'leaf' elements return identical hashes
+mem: storing 1 in location 11
:(scenario hash_container_depends_only_on_elements_3)
container foo [
x:number
x:num
y:char
z:bar
]
container bar [
x:number
y:number
x:num
y:num
]
def main [
1:foo <- merge 34, 97/a, 47, 48
6:number <- hash 1:foo
return-unless 6:number
6:num <- hash 1:foo
return-unless 6:num
7:foo <- merge 34, 97/a, 47, 48
12:number <- hash 7:foo
return-unless 12:number
13:bool <- equal 6:number, 12:number
12:num <- hash 7:foo
return-unless 12:num
13:bool <- equal 6:num, 12:num
]
# containers with identical 'leaf' elements return identical hashes
+mem: storing 1 in location 13
@ -313,20 +313,20 @@ def main [
:(scenario hash_exclusive_container_ignores_tag)
exclusive-container foo [
x:bar
y:number
y:num
]
container bar [
a:number
b:number
a:num
b:num
]
def main [
1:foo <- merge 0/x, 34, 35
4:number <- hash 1:foo
return-unless 4:number
4:num <- hash 1:foo
return-unless 4:num
5:bar <- merge 34, 35
7:number <- hash 5:bar
return-unless 7:number
8:bool <- equal 4:number, 7:number
7:num <- hash 5:bar
return-unless 7:num
8:bool <- equal 4:num, 7:num
]
# hash on containers includes all elements
+mem: storing 1 in location 8
@ -338,9 +338,9 @@ def main [
:(scenario hash_matches_old_version)
def main [
1:text <- new [abc]
2:number <- hash 1:text
3:number <- hash_old 1:text
4:bool <- equal 2:number, 3:number
2:num <- hash 1:text
3:num <- hash_old 1:text
4:bool <- equal 2:num, 3:num
]
+mem: storing 1 in location 4

View File

@ -4,9 +4,9 @@
scenario table-read-write [
run [
local-scope
tab:address:table:number:number <- new-table 30
tab:address:table:num:num <- new-table 30
put-index tab, 12, 34
1:number/raw <- index tab, 12
1:num/raw <- index tab, 12
]
memory-should-contain [
1 <- 34
@ -19,7 +19,7 @@ scenario table-read-write-non-integer [
key:text <- new [abc def]
{tab: (address table text number)} <- new-table 30
put-index tab, key, 34
1:number/raw <- index tab, key
1:num/raw <- index tab, key
]
memory-should-contain [
1 <- 34
@ -27,8 +27,8 @@ scenario table-read-write-non-integer [
]
container table:_key:_value [
length:number
capacity:number
length:num
capacity:num
data:address:array:table_row:_key:_value
]
@ -38,7 +38,7 @@ container table_row:_key:_value [
value:_value
]
def new-table capacity:number -> result:address:table:_key:_value [
def new-table capacity:num -> result:address:table:_key:_value [
local-scope
load-ingredients
result <- new {(table _key _value): type}
@ -49,9 +49,9 @@ def new-table capacity:number -> result:address:table:_key:_value [
def put-index table:address:table:_key:_value, key:_key, value:_value -> table:address:table:_key:_value [
local-scope
load-ingredients
hash:number <- hash key
hash:num <- hash key
hash <- abs hash
capacity:number <- get *table, capacity:offset
capacity:num <- get *table, capacity:offset
_, hash <- divide-with-remainder hash, capacity
hash <- abs hash # in case hash overflows into a negative integer
table-data:address:array:table_row:_key:_value <- get *table, data:offset
@ -63,7 +63,7 @@ def put-index table:address:table:_key:_value, key:_key, value:_value -> table:a
*table-data <- put-index *table-data, hash, new-row
]
def abs n:number -> result:number [
def abs n:num -> result:num [
local-scope
load-ingredients
positive?:boolean <- greater-or-equal n, 0
@ -74,9 +74,9 @@ def abs n:number -> result:number [
def index table:address:table:_key:_value, key:_key -> result:_value [
local-scope
load-ingredients
hash:number <- hash key
hash:num <- hash key
hash <- abs hash
capacity:number <- get *table, capacity:offset
capacity:num <- get *table, capacity:offset
_, hash <- divide-with-remainder hash, capacity
hash <- abs hash # in case hash overflows into a negative integer
table-data:address:array:table_row:_key:_value <- get *table, data:offset

View File

@ -6,9 +6,9 @@
:(scenario call_literal_recipe)
def main [
1:number <- call f, 34
1:num <- call f, 34
]
def f x:number -> y:number [
def f x:num -> y:num [
local-scope
load-ingredients
y <- copy x
@ -18,9 +18,9 @@ def f x:number -> y:number [
:(scenario call_variable)
def main [
{1: (recipe number -> number)} <- copy f
2:number <- call {1: (recipe number -> number)}, 34
2:num <- call {1: (recipe number -> number)}, 34
]
def f x:number -> y:number [
def f x:num -> y:num [
local-scope
load-ingredients
y <- copy x
@ -126,29 +126,29 @@ case CALL: {
:(scenario call_check_literal_recipe)
% Hide_errors = true;
def main [
1:number <- call f, 34
1:num <- call f, 34
]
def f x:point -> y:point [
local-scope
load-ingredients
y <- copy x
]
+error: main: ingredient 0 has the wrong type at '1:number <- call f, 34'
+error: main: product 0 has the wrong type at '1:number <- call f, 34'
+error: main: ingredient 0 has the wrong type at '1:num <- call f, 34'
+error: main: product 0 has the wrong type at '1:num <- call f, 34'
:(scenario call_check_variable_recipe)
% Hide_errors = true;
def main [
{1: (recipe point -> point)} <- copy f
2:number <- call {1: (recipe point -> point)}, 34
2:num <- call {1: (recipe point -> point)}, 34
]
def f x:point -> y:point [
local-scope
load-ingredients
y <- copy x
]
+error: main: ingredient 0 has the wrong type at '2:number <- call {1: (recipe point -> point)}, 34'
+error: main: product 0 has the wrong type at '2:number <- call {1: (recipe point -> point)}, 34'
+error: main: ingredient 0 has the wrong type at '2:num <- call {1: (recipe point -> point)}, 34'
+error: main: product 0 has the wrong type at '2:num <- call {1: (recipe point -> point)}, 34'
:(after "Transform.push_back(check_instruction)")
Transform.push_back(check_indirect_calls_against_header); // idempotent
@ -255,11 +255,11 @@ bool is_mu_recipe(const reagent& r) {
:(scenario copy_typecheck_recipe_variable)
% Hide_errors = true;
def main [
3:number <- copy 34 # abc def
3:num <- copy 34 # abc def
{1: (recipe number -> number)} <- copy f # store literal in a matching variable
{2: (recipe boolean -> boolean)} <- copy {1: (recipe number -> number)} # mismatch between recipe variables
]
def f x:number -> y:number [
def f x:num -> y:num [
local-scope
load-ingredients
y <- copy x
@ -300,10 +300,10 @@ if (is_mu_recipe(to)) {
:(scenario call_variable_compound_ingredient)
def main [
{1: (recipe (address number) -> number)} <- copy f
2:address:number <- copy 0
3:number <- call {1: (recipe (address number) -> number)}, 2:address:number
2:address:num <- copy 0
3:num <- call {1: (recipe (address number) -> number)}, 2:address:num
]
def f x:address:number -> y:number [
def f x:address:num -> y:num [
local-scope
load-ingredients
y <- copy x

View File

@ -6,11 +6,11 @@ def f1 [
start-running f2
# wait for f2 to run
{
jump-unless 1:number, -1
jump-unless 1:num, -1
}
]
def f2 [
1:number <- copy 1
1:num <- copy 1
]
+schedule: f1
+schedule: f2
@ -196,8 +196,8 @@ case START_RUNNING: {
:(scenario scheduler_runs_single_routine)
% Scheduling_interval = 1;
def f1 [
1:number <- copy 0
2:number <- copy 0
1:num <- copy 0
2:num <- copy 0
]
+schedule: f1
+run: {1: "number"} <- copy {0: "literal"}
@ -208,12 +208,12 @@ def f1 [
% Scheduling_interval = 1;
def f1 [
start-running f2
1:number <- copy 0
2:number <- copy 0
1:num <- copy 0
2:num <- copy 0
]
def f2 [
3:number <- copy 0
4:number <- copy 0
3:num <- copy 0
4:num <- copy 0
]
+schedule: f1
+run: start-running {f2: "recipe-literal"}
@ -231,12 +231,12 @@ def f1 [
start-running f2, 3
# wait for f2 to run
{
jump-unless 1:number, -1
jump-unless 1:num, -1
}
]
def f2 [
1:number <- next-ingredient
2:number <- add 1:number, 1
1:num <- next-ingredient
2:num <- add 1:num, 1
]
+mem: storing 4 in location 2
@ -248,20 +248,20 @@ def main [
local-scope
create-new-routine
# padding to make sure we run new-routine before returning
dummy:number <- copy 0
dummy:number <- copy 0
dummy:num <- copy 0
dummy:num <- copy 0
]
def create-new-routine [
local-scope
n:address:number <- new number:type
n:address:num <- new number:type
*n <- copy 34
start-running new-routine, n
# refcount of n decremented
]
def new-routine n:address:number [
def new-routine n:address:num [
local-scope
load-ingredients
1:number/raw <- copy *n
1:num/raw <- copy *n
]
# check that n wasn't reclaimed when create-new-routine returned
+mem: storing 34 in location 1
@ -281,25 +281,25 @@ if (inst.operation == NEXT_INGREDIENT || inst.operation == NEXT_INGREDIENT_WITHO
}
:(scenario next_ingredient_never_leaks_refcounts)
def create-scope n:address:number -> default-space:address:array:location [
def create-scope n:address:num -> default-space:address:array:location [
default-space <- new location:type, 2
load-ingredients
]
def use-scope [
local-scope
0:address:array:location/names:create-scope <- next-ingredient
n:address:number/space:1 <- next-ingredient # should decrement refcount
n:address:num/space:1 <- next-ingredient # should decrement refcount
*n/space:1 <- copy 34
n2:number <- add *n/space:1, 1
n2:num <- add *n/space:1, 1
reply n2
]
def main [
local-scope
n:address:number <- copy 12000/unsafe # pretend allocation with a known address
n:address:num <- copy 12000/unsafe # pretend allocation with a known address
*n <- copy 23
scope:address:array:location <- create-scope n
n2:address:number <- copy 13000/unsafe
n3:number <- use-scope scope, n2
n2:address:num <- copy 13000/unsafe
n3:num <- use-scope scope, n2
]
+run: {n: ("address" "number"), "space": "1"} <- next-ingredient
+mem: decrementing refcount of 12000: 2 -> 1
@ -309,24 +309,24 @@ def main [
:(scenario start_running_returns_routine_id)
def f1 [
1:number <- start-running f2
1:num <- start-running f2
]
def f2 [
12:number <- copy 44
12:num <- copy 44
]
+mem: storing 2 in location 1
//: this scenario will require some careful setup in escaped C++
//: (straining our tangle capabilities to near-breaking point)
:(scenario scheduler_skips_completed_routines)
% recipe_ordinal f1 = load("recipe f1 [\n1:number <- copy 0\n]\n").front();
% recipe_ordinal f2 = load("recipe f2 [\n2:number <- copy 0\n]\n").front();
% recipe_ordinal f1 = load("recipe f1 [\n1:num <- copy 0\n]\n").front();
% recipe_ordinal f2 = load("recipe f2 [\n2:num <- copy 0\n]\n").front();
% Routines.push_back(new routine(f1)); // f1 meant to run
% Routines.push_back(new routine(f2));
% Routines.back()->state = COMPLETED; // f2 not meant to run
# must have at least one routine without escaping
def f3 [
3:number <- copy 0
3:num <- copy 0
]
# by interleaving '+' lines with '-' lines, we allow f1 and f3 to run in any order
+schedule: f1
@ -340,8 +340,8 @@ def f3 [
% Routines.push_back(new routine(COPY));
% Routines.back()->state = COMPLETED;
def f1 [
1:number <- copy 0
2:number <- copy 0
1:num <- copy 0
2:num <- copy 0
]
+schedule: f1
-run: idle
@ -353,17 +353,17 @@ def f1 [
% Scheduling_interval = 2;
def f1 [
start-running f2
1:number <- copy 0
2:number <- copy 0
1:num <- copy 0
2:num <- copy 0
]
def f2 [
# divide by 0 twice
3:number <- divide-with-remainder 4, 0
4:number <- divide-with-remainder 4, 0
3:num <- divide-with-remainder 4, 0
4:num <- divide-with-remainder 4, 0
]
# f2 should stop after first divide by 0
+error: f2: divide by zero in '3:number <- divide-with-remainder 4, 0'
-error: f2: divide by zero in '4:number <- divide-with-remainder 4, 0'
+error: f2: divide by zero in '3:num <- divide-with-remainder 4, 0'
-error: f2: divide by zero in '4:num <- divide-with-remainder 4, 0'
:(after "operator<<(ostream& os, unused end)")
if (Trace_stream && Trace_stream->curr_label == "error" && Current_routine) {
@ -378,7 +378,7 @@ def main [
# f1 never actually runs because its parent completes without waiting for it
]
def f1 [
1:number <- copy 0
1:num <- copy 0
]
-schedule: f1
@ -406,13 +406,13 @@ bool has_completed_parent(int routine_index) {
:(scenario routine_state_test)
% Scheduling_interval = 2;
def f1 [
1:number/child-id <- start-running f2
12:number <- copy 0 # race condition since we don't care about location 12
1:num/child-id <- start-running f2
12:num <- copy 0 # race condition since we don't care about location 12
# thanks to Scheduling_interval, f2's one instruction runs in between here and completes
2:number/state <- routine-state 1:number/child-id
2:num/state <- routine-state 1:num/child-id
]
def f2 [
12:number <- copy 0
12:num <- copy 0
# trying to run a second instruction marks routine as completed
]
# recipe f2 should be in state COMPLETED
@ -500,12 +500,12 @@ case _DUMP_ROUTINES: {
:(scenario routine_discontinues_past_limit)
% Scheduling_interval = 2;
def f1 [
1:number/child-id <- start-running f2
limit-time 1:number/child-id, 10
1:num/child-id <- start-running f2
limit-time 1:num/child-id, 10
# padding loop just to make sure f2 has time to completed
2:number <- copy 20
2:number <- subtract 2:number, 1
jump-if 2:number, -2:offset
2:num <- copy 20
2:num <- subtract 2:num, 1
jump-if 2:num, -2:offset
]
def f2 [
jump -1:offset # run forever
@ -624,16 +624,16 @@ case NUMBER_OF_INSTRUCTIONS: {
:(scenario number_of_instructions)
def f1 [
10:number/child-id <- start-running f2
10:num/child-id <- start-running f2
{
loop-unless 20:number
loop-unless 20:num
}
11:number <- number-of-instructions 10:number
11:num <- number-of-instructions 10:num
]
def f2 [
# 2 instructions worth of work
1:number <- copy 34
20:number <- copy 1
1:num <- copy 34
20:num <- copy 1
]
# f2 runs an extra instruction for the implicit return added by the
# fill_in_reply_ingredients transform
@ -642,18 +642,18 @@ def f2 [
:(scenario number_of_instructions_across_multiple_scheduling_intervals)
% Scheduling_interval = 1;
def f1 [
10:number/child-id <- start-running f2
10:num/child-id <- start-running f2
{
loop-unless 20:number
loop-unless 20:num
}
11:number <- number-of-instructions 10:number
11:num <- number-of-instructions 10:num
]
def f2 [
# 4 instructions worth of work
1:number <- copy 34
2:number <- copy 1
2:number <- copy 3
20:number <- copy 1
1:num <- copy 34
2:num <- copy 1
2:num <- copy 3
20:num <- copy 1
]
# f2 runs an extra instruction for the implicit return added by the
# fill_in_reply_ingredients transform
@ -664,17 +664,17 @@ def f2 [
:(scenario new_concurrent)
def f1 [
start-running f2
1:address:number/raw <- new number:type
1:address:num/raw <- new number:type
# wait for f2 to complete
{
loop-unless 4:number/raw
loop-unless 4:num/raw
}
]
def f2 [
2:address:number/raw <- new number:type
2:address:num/raw <- new number:type
# hack: assumes scheduler implementation
3:bool/raw <- equal 1:address:number/raw, 2:address:number/raw
3:bool/raw <- equal 1:address:num/raw, 2:address:num/raw
# signal f2 complete
4:number/raw <- copy 1
4:num/raw <- copy 1
]
+mem: storing 0 in location 3

View File

@ -5,12 +5,12 @@
:(scenario wait_for_location)
def f1 [
10:number <- copy 34
10:num <- copy 34
start-running f2
20:location <- copy 10/unsafe
wait-for-reset-then-set 20:location
# wait for f2 to run and reset location 1
30:number <- copy 10:number
30:num <- copy 10:num
]
def f2 [
10:location <- copy 0/unsafe
@ -140,8 +140,8 @@ for (int i = 0; i < SIZE(Routines); ++i) {
:(scenario get_location)
def main [
12:number <- copy 34
13:number <- copy 35
12:num <- copy 34
13:num <- copy 35
15:location <- get-location 12:point, 1:offset
]
+mem: storing 13 in location 15
@ -223,9 +223,9 @@ bool is_mu_location(reagent/*copy*/ x) {
:(scenario get_location_out_of_bounds)
% Hide_errors = true;
def main [
12:number <- copy 34
13:number <- copy 35
14:number <- copy 36
12:num <- copy 34
13:num <- copy 35
14:num <- copy 36
get-location 12:point-number/raw, 2:offset # point-number occupies 3 locations but has only 2 fields; out of bounds
]
+error: main: invalid offset 2 for 'point-number'
@ -233,9 +233,9 @@ def main [
:(scenario get_location_out_of_bounds_2)
% Hide_errors = true;
def main [
12:number <- copy 34
13:number <- copy 35
14:number <- copy 36
12:num <- copy 34
13:num <- copy 35
14:num <- copy 36
get-location 12:point-number/raw, -1:offset
]
+error: main: invalid offset -1 for 'point-number'
@ -256,21 +256,21 @@ def main [
:(scenario get_location_indirect)
# 'get-location' can read from container address
def main [
1:number <- copy 10
1:num <- copy 10
# 10 reserved for refcount
11:number <- copy 34
12:number <- copy 35
11:num <- copy 34
12:num <- copy 35
4:location <- get-location 1:address:point/lookup, 0:offset
]
+mem: storing 11 in location 4
:(scenario get_location_indirect_2)
def main [
1:number <- copy 10
1:num <- copy 10
# 10 reserved for refcount
11:number <- copy 34
12:number <- copy 35
4:address:number <- copy 20/unsafe
11:num <- copy 34
12:num <- copy 35
4:address:num <- copy 20/unsafe
4:address:location/lookup <- get-location 1:address:point/lookup, 0:offset
]
+mem: storing 11 in location 21
@ -280,21 +280,21 @@ def main [
:(scenario wait_for_routine)
def f1 [
# add a few routines to run
1:number/routine <- start-running f2
2:number/routine <- start-running f3
wait-for-routine 1:number/routine
1:num/routine <- start-running f2
2:num/routine <- start-running f3
wait-for-routine 1:num/routine
# now wait for f2 to *complete* and modify location 13 before using its value
20:number <- copy 13:number
20:num <- copy 13:num
]
def f2 [
10:number <- copy 0 # just padding
10:num <- copy 0 # just padding
switch # simulate a block; routine f1 shouldn't restart at this point
13:number <- copy 34
13:num <- copy 34
]
def f3 [
# padding routine just to help simulate the block in f2 using 'switch'
11:number <- copy 0
12:number <- copy 0
11:num <- copy 0
12:num <- copy 0
]
+schedule: f1
+run: waiting for routine 2
@ -423,13 +423,13 @@ case CURRENT_ROUTINE_IS_UNBLOCKED: {
:(scenario wait_for_routine_to_block)
def f1 [
1:number/routine <- start-running f2
wait-for-routine-to-block 1:number/routine
1:num/routine <- start-running f2
wait-for-routine-to-block 1:num/routine
# now wait for f2 to run and modify location 10 before using its value
11:number <- copy 10:number
11:num <- copy 10:num
]
def f2 [
10:number <- copy 34
10:num <- copy 34
]
+schedule: f1
+run: waiting for routine 2 to block
@ -562,14 +562,14 @@ case RESTART: {
% Scheduling_interval = 1;
def main [
local-scope
r:number/routine-id <- start-running f
x:number <- copy 0 # wait for f to be scheduled
r:num/routine-id <- start-running f
x:num <- copy 0 # wait for f to be scheduled
# r is COMPLETED by this point
restart r # should have no effect
x:number <- copy 0 # give f time to be scheduled (though it shouldn't be)
x:num <- copy 0 # give f time to be scheduled (though it shouldn't be)
]
def f [
1:number/raw <- copy 1
1:num/raw <- copy 1
]
# shouldn't crash
@ -577,7 +577,7 @@ def f [
% Scheduling_interval = 1;
def main [
local-scope
r:number/routine-id <- start-running f
r:num/routine-id <- start-running f
wait-for-routine-to-block r # get past the block in f below
restart r
wait-for-routine-to-block r # should run f to completion
@ -586,15 +586,15 @@ def main [
def f [
current-routine-is-blocked
# 8 instructions of padding, many more than 'main' above
1:number <- add 1:number, 1
1:number <- add 1:number, 1
1:number <- add 1:number, 1
1:number <- add 1:number, 1
1:number <- add 1:number, 1
1:number <- add 1:number, 1
1:number <- add 1:number, 1
1:number <- add 1:number, 1
1:number <- add 1:number, 1
1:num <- add 1:num, 1
1:num <- add 1:num, 1
1:num <- add 1:num, 1
1:num <- add 1:num, 1
1:num <- add 1:num, 1
1:num <- add 1:num, 1
1:num <- add 1:num, 1
1:num <- add 1:num, 1
1:num <- add 1:num, 1
]
# make sure all of f ran
+mem: storing 8 in location 1

View File

@ -13,8 +13,8 @@
:(scenario deep_copy_number)
def main [
local-scope
x:number <- copy 34
y:number <- deep-copy x
x:num <- copy 34
y:num <- deep-copy x
10:bool/raw <- equal x, y
]
# non-address primitives are identical
@ -22,8 +22,8 @@ def main [
:(scenario deep_copy_container_without_address)
container foo [
x:number
y:number
x:num
y:num
]
def main [
local-scope
@ -39,12 +39,12 @@ def main [
def main [
# avoid all memory allocations except the implicit ones inside deep-copy, so
# that the result is deterministic
1:address:number <- copy 100/unsafe # pretend allocation
*1:address:number <- copy 34
2:address:number <- deep-copy 1:address:number
10:bool <- equal 1:address:number, 2:address:number
11:bool <- equal *1:address:number, *2:address:number
2:address:number <- copy 0
1:address:num <- copy 100/unsafe # pretend allocation
*1:address:num <- copy 34
2:address:num <- deep-copy 1:address:num
10:bool <- equal 1:address:num, 2:address:num
11:bool <- equal *1:address:num, *2:address:num
2:address:num <- copy 0
]
# the result of deep-copy is a new address
+mem: storing 0 in location 10
@ -77,13 +77,13 @@ def main [
def main [
# avoid all memory allocations except the implicit ones inside deep-copy, so
# that the result is deterministic
1:address:address:number <- copy 100/unsafe # pretend allocation
*1:address:address:number <- copy 150/unsafe
**1:address:address:number <- copy 34
2:address:address:number <- deep-copy 1:address:address:number
10:bool <- equal 1:address:address:number, 2:address:address:number
11:bool <- equal *1:address:address:number, *2:address:address:number
12:bool <- equal **1:address:address:number, **2:address:address:number
1:address:address:num <- copy 100/unsafe # pretend allocation
*1:address:address:num <- copy 150/unsafe
**1:address:address:num <- copy 34
2:address:address:num <- deep-copy 1:address:address:num
10:bool <- equal 1:address:address:num, 2:address:address:num
11:bool <- equal *1:address:address:num, *2:address:address:num
12:bool <- equal **1:address:address:num, **2:address:address:num
]
# the result of deep-copy is a new address
+mem: storing 0 in location 10
@ -97,18 +97,18 @@ def main [
def main [
# avoid all memory allocations except the implicit ones inside deep-copy, so
# that the result is deterministic
100:number <- copy 1 # pretend refcount
101:number <- copy 3 # pretend array length
1:address:array:number <- copy 100/unsafe # pretend allocation
put-index *1:address:array:number, 0, 34
put-index *1:address:array:number, 1, 35
put-index *1:address:array:number, 2, 36
stash [old:], *1:address:array:number
2:address:array:number <- deep-copy 1:address:array:number
stash 2:address:array:number
stash [new:], *2:address:array:number
10:bool <- equal 1:address:array:number, 2:address:array:number
11:bool <- equal *1:address:array:number, *2:address:array:number
100:num <- copy 1 # pretend refcount
101:num <- copy 3 # pretend array length
1:address:array:num <- copy 100/unsafe # pretend allocation
put-index *1:address:array:num, 0, 34
put-index *1:address:array:num, 1, 35
put-index *1:address:array:num, 2, 36
stash [old:], *1:address:array:num
2:address:array:num <- deep-copy 1:address:array:num
stash 2:address:array:num
stash [new:], *2:address:array:num
10:bool <- equal 1:address:array:num, 2:address:array:num
11:bool <- equal *1:address:array:num, *2:address:array:num
]
+app: old: 3 34 35 36
+app: new: 3 34 35 36
@ -119,19 +119,19 @@ def main [
:(scenario deep_copy_container_with_address)
container foo [
x:number
y:address:number
x:num
y:address:num
]
def main [
local-scope
y0:address:number <- new number:type
y0:address:num <- new number:type
*y0 <- copy 35
a:foo <- merge 34, y0
b:foo <- deep-copy a
10:bool/raw <- equal a, b
y1:address:number <- get b, y:offset
y1:address:num <- get b, y:offset
11:bool/raw <- equal y0, y1
12:number/raw <- copy *y1
12:num/raw <- copy *y1
]
# containers containing addresses are not identical to their deep copies
+mem: storing 0 in location 10
@ -141,19 +141,19 @@ def main [
:(scenario deep_copy_exclusive_container_with_address)
exclusive-container foo [
x:number
y:address:number
x:num
y:address:num
]
def main [
local-scope
y0:address:number <- new number:type
y0:address:num <- new number:type
*y0 <- copy 34
a:foo <- merge 1/y, y0
b:foo <- deep-copy a
10:bool/raw <- equal a, b
y1:address:number, z:bool <- maybe-convert b, y:variant
y1:address:num, z:bool <- maybe-convert b, y:variant
11:bool/raw <- equal y0, y1
12:number/raw <- copy *y1
12:num/raw <- copy *y1
]
# exclusive containers containing addresses are not identical to their deep copies
+mem: storing 0 in location 10
@ -163,24 +163,24 @@ def main [
:(scenario deep_copy_exclusive_container_with_container_with_address)
exclusive-container foo [
x:number
x:num
y:bar # inline
]
container bar [
x:address:number
x:address:num
]
def main [
local-scope
y0:address:number <- new number:type
y0:address:num <- new number:type
*y0 <- copy 34
a:bar <- merge y0
b:foo <- merge 1/y, a
c:foo <- deep-copy b
10:bool/raw <- equal b, c
d:bar, z:bool <- maybe-convert c, y:variant
y1:address:number <- get d, x:offset
y1:address:num <- get d, x:offset
11:bool/raw <- equal y0, y1
12:number/raw <- copy *y1
12:num/raw <- copy *y1
]
# exclusive containers containing addresses are not identical to their deep copies
+mem: storing 0 in location 10
@ -302,7 +302,7 @@ int payload_address(reagent/*copy*/ x) {
:(scenario deep_copy_stress_test_1)
container foo1 [
p:address:number
p:address:num
]
container foo2 [
p:address:foo1
@ -313,7 +313,7 @@ exclusive-container foo3 [
]
def main [
local-scope
x:address:number <- new number:type
x:address:num <- new number:type
*x <- copy 34
a:address:foo1 <- new foo1:type
*a <- merge x
@ -323,14 +323,14 @@ def main [
d:foo3 <- deep-copy c
e:address:foo2, z:bool <- maybe-convert d, q:variant
f:address:foo1 <- get *e, p:offset
g:address:number <- get *f, p:offset
1:number/raw <- copy *g
g:address:num <- get *f, p:offset
1:num/raw <- copy *g
]
+mem: storing 34 in location 1
:(scenario deep_copy_stress_test_2)
container foo1 [
p:address:number
p:address:num
]
container foo2 [
p:address:foo1
@ -340,12 +340,12 @@ exclusive-container foo3 [
q:address:foo2
]
container foo4 [
p:number
p:num
q:address:foo3
]
def main [
local-scope
x:address:number <- new number:type
x:address:num <- new number:type
*x <- copy 34
a:address:foo1 <- new foo1:type
*a <- merge x
@ -358,14 +358,14 @@ def main [
f:address:foo3 <- get e, q:offset
g:address:foo2, z:bool <- maybe-convert *f, q:variant
h:address:foo1 <- get *g, p:offset
y:address:number <- get *h, p:offset
1:number/raw <- copy *y
y:address:num <- get *h, p:offset
1:num/raw <- copy *y
]
+mem: storing 34 in location 1
:(scenario deep_copy_cycles)
container foo [
p:number
p:num
q:address:foo
]
def main [
@ -374,7 +374,7 @@ def main [
*x <- put *x, p:offset, 34
*x <- put *x, q:offset, x # create a cycle
y:address:foo <- deep-copy x
1:number/raw <- get *y, p:offset
1:num/raw <- get *y, p:offset
y2:address:foo <- get *y, q:offset
stash y [vs] y2
2:bool/raw <- equal y, y2 # is it still a cycle?

View File

@ -13,9 +13,9 @@
scenario channel [
run [
local-scope
source:address:source:number, sink:address:sink:number <- new-channel 3/capacity
source:address:source:num, sink:address:sink:num <- new-channel 3/capacity
sink <- write sink, 34
10:number/raw, 11:boolean/raw, source <- read source
10:num/raw, 11:boolean/raw, source <- read source
]
memory-should-contain [
10 <- 34
@ -25,8 +25,8 @@ scenario channel [
container channel:_elem [
lock:boolean # inefficient but simple: serialize all reads as well as writes
first-full:number # for write
first-free:number # for read
first-full:num # for write
first-free:num # for read
# A circular buffer contains values from index first-full up to (but not
# including) index first-empty. The reader always modifies it at first-full,
# while the writer always modifies it at first-empty.
@ -44,7 +44,7 @@ container sink:_elem [
chan:address:channel:_elem
]
def new-channel capacity:number -> in:address:source:_elem, out:address:sink:_elem [
def new-channel capacity:num -> in:address:source:_elem, out:address:sink:_elem [
local-scope
load-ingredients
result:address:channel:_elem <- new {(channel _elem): type}
@ -86,14 +86,14 @@ def write out:address:sink:_elem, val:_elem -> out:address:sink:_elem [
#? $print [performing write], 10/newline
# store a deep copy of val
circular-buffer:address:array:_elem <- get *chan, data:offset
free:number <- get *chan, first-free:offset
free:num <- get *chan, first-free:offset
val-copy:_elem <- deep-copy val # on this instruction rests all Mu's concurrency-safety
*circular-buffer <- put-index *circular-buffer, free, val-copy
# mark its slot as filled
free <- add free, 1
{
# wrap free around to 0 if necessary
len:number <- length *circular-buffer
len:num <- length *circular-buffer
at-end?:boolean <- greater-or-equal free, len
break-unless at-end?
free <- copy 0
@ -130,7 +130,7 @@ def read in:address:source:_elem -> result:_elem, eof?:boolean, in:address:sourc
}
current-routine-is-unblocked
# pull result off
full:number <- get *chan, first-full:offset
full:num <- get *chan, first-full:offset
circular-buffer:address:array:_elem <- get *chan, data:offset
result <- index *circular-buffer, full
# clear the slot
@ -140,7 +140,7 @@ def read in:address:source:_elem -> result:_elem, eof?:boolean, in:address:sourc
full <- add full, 1
{
# wrap full around to 0 if necessary
len:number <- length *circular-buffer
len:num <- length *circular-buffer
at-end?:boolean <- greater-or-equal full, len
break-unless at-end?
full <- copy 0
@ -165,10 +165,10 @@ def clear in:address:source:_elem -> in:address:source:_elem [
scenario channel-initialization [
run [
local-scope
source:address:source:number <- new-channel 3/capacity
chan:address:channel:number <- get *source, chan:offset
10:number/raw <- get *chan, first-full:offset
11:number/raw <- get *chan, first-free:offset
source:address:source:num <- new-channel 3/capacity
chan:address:channel:num <- get *source, chan:offset
10:num/raw <- get *chan, first-full:offset
11:num/raw <- get *chan, first-free:offset
]
memory-should-contain [
10 <- 0 # first-full
@ -179,11 +179,11 @@ scenario channel-initialization [
scenario channel-write-increments-free [
run [
local-scope
_, sink:address:sink:number <- new-channel 3/capacity
_, sink:address:sink:num <- new-channel 3/capacity
sink <- write sink, 34
chan:address:channel:number <- get *sink, chan:offset
10:number/raw <- get *chan, first-full:offset
11:number/raw <- get *chan, first-free:offset
chan:address:channel:num <- get *sink, chan:offset
10:num/raw <- get *chan, first-full:offset
11:num/raw <- get *chan, first-free:offset
]
memory-should-contain [
10 <- 0 # first-full
@ -194,12 +194,12 @@ scenario channel-write-increments-free [
scenario channel-read-increments-full [
run [
local-scope
source:address:source:number, sink:address:sink:number <- new-channel 3/capacity
source:address:source:num, sink:address:sink:num <- new-channel 3/capacity
sink <- write sink, 34
_, _, source <- read source
chan:address:channel:number <- get *source, chan:offset
10:number/raw <- get *chan, first-full:offset
11:number/raw <- get *chan, first-free:offset
chan:address:channel:num <- get *source, chan:offset
10:num/raw <- get *chan, first-full:offset
11:num/raw <- get *chan, first-free:offset
]
memory-should-contain [
10 <- 1 # first-full
@ -211,20 +211,20 @@ scenario channel-wrap [
run [
local-scope
# channel with just 1 slot
source:address:source:number, sink:address:sink:number <- new-channel 1/capacity
chan:address:channel:number <- get *source, chan:offset
source:address:source:num, sink:address:sink:num <- new-channel 1/capacity
chan:address:channel:num <- get *source, chan:offset
# write and read a value
sink <- write sink, 34
_, _, source <- read source
# first-free will now be 1
10:number/raw <- get *chan, first-free:offset
11:number/raw <- get *chan, first-free:offset
10:num/raw <- get *chan, first-free:offset
11:num/raw <- get *chan, first-free:offset
# write second value, verify that first-free wraps
sink <- write sink, 34
20:number/raw <- get *chan, first-free:offset
20:num/raw <- get *chan, first-free:offset
# read second value, verify that first-full wraps
_, _, source <- read source
30:number/raw <- get *chan, first-full:offset
30:num/raw <- get *chan, first-full:offset
]
memory-should-contain [
10 <- 1 # first-free after first write
@ -237,8 +237,8 @@ scenario channel-wrap [
scenario channel-new-empty-not-full [
run [
local-scope
source:address:source:number <- new-channel 3/capacity
chan:address:channel:number <- get *source, chan:offset
source:address:source:num <- new-channel 3/capacity
chan:address:channel:num <- get *source, chan:offset
10:boolean/raw <- channel-empty? chan
11:boolean/raw <- channel-full? chan
]
@ -250,8 +250,8 @@ scenario channel-new-empty-not-full [
scenario channel-write-not-empty [
run [
source:address:source:number, sink:address:sink:number <- new-channel 3/capacity
chan:address:channel:number <- get *source, chan:offset
source:address:source:num, sink:address:sink:num <- new-channel 3/capacity
chan:address:channel:num <- get *source, chan:offset
sink <- write sink, 34
10:boolean/raw <- channel-empty? chan
11:boolean/raw <- channel-full? chan
@ -265,8 +265,8 @@ scenario channel-write-not-empty [
scenario channel-write-full [
run [
local-scope
source:address:source:number, sink:address:sink:number <- new-channel 1/capacity
chan:address:channel:number <- get *source, chan:offset
source:address:source:num, sink:address:sink:num <- new-channel 1/capacity
chan:address:channel:num <- get *source, chan:offset
sink <- write sink, 34
10:boolean/raw <- channel-empty? chan
11:boolean/raw <- channel-full? chan
@ -280,8 +280,8 @@ scenario channel-write-full [
scenario channel-read-not-full [
run [
local-scope
source:address:source:number, sink:address:sink:number <- new-channel 1/capacity
chan:address:channel:number <- get *source, chan:offset
source:address:source:num, sink:address:sink:num <- new-channel 1/capacity
chan:address:channel:num <- get *source, chan:offset
sink <- write sink, 34
_, _, source <- read source
10:boolean/raw <- channel-empty? chan
@ -343,8 +343,8 @@ def channel-empty? chan:address:channel:_elem -> result:boolean [
local-scope
load-ingredients
# return chan.first-full == chan.first-free
full:number <- get *chan, first-full:offset
free:number <- get *chan, first-free:offset
full:num <- get *chan, first-full:offset
free:num <- get *chan, first-free:offset
result <- equal full, free
]
@ -354,21 +354,21 @@ def channel-full? chan:address:channel:_elem -> result:boolean [
local-scope
load-ingredients
# tmp = chan.first-free + 1
tmp:number <- get *chan, first-free:offset
tmp:num <- get *chan, first-free:offset
tmp <- add tmp, 1
{
# if tmp == chan.capacity, tmp = 0
len:number <- capacity chan
len:num <- capacity chan
at-end?:boolean <- greater-or-equal tmp, len
break-unless at-end?
tmp <- copy 0
}
# return chan.first-full == tmp
full:number <- get *chan, first-full:offset
full:num <- get *chan, first-full:offset
result <- equal full, tmp
]
def capacity chan:address:channel:_elem -> result:number [
def capacity chan:address:channel:_elem -> result:num [
local-scope
load-ingredients
q:address:array:_elem <- get *chan, data:offset
@ -395,7 +395,7 @@ def buffer-lines in:address:source:char, buffered-out:address:sink:char -> buffe
break-unless backspace?
# drop previous character
{
buffer-length:number <- get *line, length:offset
buffer-length:num <- get *line, length:offset
buffer-empty?:boolean <- equal buffer-length, 0
break-if buffer-empty?
buffer-length <- subtract buffer-length, 1
@ -411,9 +411,9 @@ def buffer-lines in:address:source:char, buffered-out:address:sink:char -> buffe
loop
}
# copy line into 'buffered-out'
i:number <- copy 0
i:num <- copy 0
line-contents:text <- get *line, data:offset
max:number <- get *line, length:offset
max:num <- get *line, length:offset
{
done?:boolean <- greater-or-equal i, max
break-if done?
@ -441,7 +441,7 @@ scenario buffer-lines-blocks-until-newline [
assert empty?, [
F buffer-lines-blocks-until-newline: channel should be empty after init]
# buffer stdin into buffered-stdin, try to read from buffered-stdin
buffer-routine:number <- start-running buffer-lines, source, buffered-stdin
buffer-routine:num <- start-running buffer-lines, source, buffered-stdin
wait-for-routine-to-block buffer-routine
empty? <- channel-empty? buffered-chan
assert empty?:boolean, [

View File

@ -2,23 +2,23 @@
# easier to test.
container screen [
num-rows:number
num-columns:number
cursor-row:number
cursor-column:number
num-rows:num
num-columns:num
cursor-row:num
cursor-column:num
data:address:array:screen-cell
]
container screen-cell [
contents:char
color:number
color:num
]
def new-fake-screen w:number, h:number -> result:address:screen [
def new-fake-screen w:num, h:num -> result:address:screen [
local-scope
load-ingredients
result <- new screen:type
bufsize:number <- multiply w, h
bufsize:num <- multiply w, h
data:address:array:screen-cell <- new screen-cell:type, bufsize
*result <- merge h/num-rows, w/num-columns, 0/cursor-row, 0/cursor-column, data
result <- clear-screen result
@ -32,8 +32,8 @@ def clear-screen screen:address:screen -> screen:address:screen [
break-unless screen
# clear fake screen
buf:address:array:screen-cell <- get *screen, data:offset
max:number <- length *buf
i:number <- copy 0
max:num <- length *buf
i:num <- copy 0
{
done?:boolean <- greater-or-equal i, max
break-if done?
@ -66,8 +66,8 @@ def fake-screen-is-empty? screen:address:screen -> result:boolean [
load-ingredients
return-unless screen, 1/true
buf:address:array:screen-cell <- get *screen, data:offset
i:number <- copy 0
len:number <- length *buf
i:num <- copy 0
len:num <- length *buf
{
done?:boolean <- greater-or-equal i, len
break-if done?
@ -84,33 +84,33 @@ def fake-screen-is-empty? screen:address:screen -> result:boolean [
def print screen:address:screen, c:char -> screen:address:screen [
local-scope
load-ingredients
color:number, color-found?:boolean <- next-ingredient
color:num, color-found?:boolean <- next-ingredient
{
# default color to white
break-if color-found?
color <- copy 7/white
}
bg-color:number, bg-color-found?:boolean <- next-ingredient
bg-color:num, bg-color-found?:boolean <- next-ingredient
{
# default bg-color to black
break-if bg-color-found?
bg-color <- copy 0/black
}
c2:number <- character-to-code c
c2:num <- character-to-code c
trace 90, [print-character], c2
{
# if x exists
# (handle special cases exactly like in the real screen)
break-unless screen
width:number <- get *screen, num-columns:offset
height:number <- get *screen, num-rows:offset
width:num <- get *screen, num-columns:offset
height:num <- get *screen, num-rows:offset
# if cursor is out of bounds, silently exit
row:number <- get *screen, cursor-row:offset
row:num <- get *screen, cursor-row:offset
legal?:boolean <- greater-or-equal row, 0
return-unless legal?
legal? <- lesser-than row, height
return-unless legal?
column:number <- get *screen, cursor-column:offset
column:num <- get *screen, cursor-column:offset
legal? <- greater-or-equal column, 0
return-unless legal?
legal? <- lesser-than column, width
@ -122,7 +122,7 @@ def print screen:address:screen, c:char -> screen:address:screen [
break-unless newline?
{
# unless cursor is already at bottom
bottom:number <- subtract height, 1
bottom:num <- subtract height, 1
at-bottom?:boolean <- greater-or-equal row, bottom
break-if at-bottom?
# move it to the next row
@ -134,10 +134,10 @@ def print screen:address:screen, c:char -> screen:address:screen [
return
}
# save character in fake screen
index:number <- multiply row, width
index:num <- multiply row, width
index <- add index, column
buf:address:array:screen-cell <- get *screen, data:offset
len:number <- length *buf
len:num <- length *buf
# special-case: backspace
{
backspace?:boolean <- equal c, 8
@ -159,7 +159,7 @@ def print screen:address:screen, c:char -> screen:address:screen [
*buf <- put-index *buf, index, cursor
# increment column unless it's already all the way to the right
{
right:number <- subtract width, 1
right:num <- subtract width, 1
at-right?:boolean <- greater-or-equal column, right
break-if at-right?
column <- add column, 1
@ -215,7 +215,7 @@ scenario print-backspace-character [
fake-screen <- print fake-screen, a
backspace:char <- copy 8/backspace
fake-screen <- print fake-screen, backspace
10:number/raw <- get *fake-screen, cursor-column:offset
10:num/raw <- get *fake-screen, cursor-column:offset
cell:address:array:screen-cell <- get *fake-screen, data:offset
11:array:screen-cell/raw <- copy *cell
]
@ -238,7 +238,7 @@ scenario print-extra-backspace-character [
backspace:char <- copy 8/backspace
fake-screen <- print fake-screen, backspace
fake-screen <- print fake-screen, backspace
1:number/raw <- get *fake-screen, cursor-column:offset
1:num/raw <- get *fake-screen, cursor-column:offset
cell:address:array:screen-cell <- get *fake-screen, data:offset
3:array:screen-cell/raw <- copy *cell
]
@ -262,7 +262,7 @@ scenario print-character-at-right-margin [
fake-screen <- print fake-screen, b
c:char <- copy 99/c
fake-screen <- print fake-screen, c
10:number/raw <- get *fake-screen, cursor-column:offset
10:num/raw <- get *fake-screen, cursor-column:offset
cell:address:array:screen-cell <- get *fake-screen, data:offset
11:array:screen-cell/raw <- copy *cell
]
@ -286,8 +286,8 @@ scenario print-newline-character [
a:char <- copy 97/a
fake-screen <- print fake-screen, a
fake-screen <- print fake-screen, newline
10:number/raw <- get *fake-screen, cursor-row:offset
11:number/raw <- get *fake-screen, cursor-column:offset
10:num/raw <- get *fake-screen, cursor-row:offset
11:num/raw <- get *fake-screen, cursor-column:offset
cell:address:array:screen-cell <- get *fake-screen, data:offset
12:array:screen-cell/raw <- copy *cell
]
@ -310,8 +310,8 @@ scenario print-newline-at-bottom-line [
fake-screen <- print fake-screen, newline
fake-screen <- print fake-screen, newline
fake-screen <- print fake-screen, newline
10:number/raw <- get *fake-screen, cursor-row:offset
11:number/raw <- get *fake-screen, cursor-column:offset
10:num/raw <- get *fake-screen, cursor-row:offset
11:num/raw <- get *fake-screen, cursor-column:offset
]
memory-should-contain [
10 <- 1 # cursor row
@ -334,8 +334,8 @@ scenario print-character-at-bottom-right [
fake-screen <- print fake-screen, newline
d:char <- copy 100/d
fake-screen <- print fake-screen, d
10:number/raw <- get *fake-screen, cursor-row:offset
11:number/raw <- get *fake-screen, cursor-column:offset
10:num/raw <- get *fake-screen, cursor-row:offset
11:num/raw <- get *fake-screen, cursor-column:offset
cell:address:array:screen-cell <- get *fake-screen, data:offset
20:array:screen-cell/raw <- copy *cell
]
@ -363,12 +363,12 @@ def clear-line screen:address:screen -> screen:address:screen [
# if x exists, clear line in fake screen
{
break-unless screen
width:number <- get *screen, num-columns:offset
column:number <- get *screen, cursor-column:offset
original-column:number <- copy column
width:num <- get *screen, num-columns:offset
column:num <- get *screen, cursor-column:offset
original-column:num <- copy column
# space over the entire line
{
right:number <- subtract width, 1
right:num <- subtract width, 1
done?:boolean <- greater-or-equal column, right
break-if done?
print screen, space
@ -383,12 +383,12 @@ def clear-line screen:address:screen -> screen:address:screen [
clear-line-on-display
]
def clear-line-until screen:address:screen, right:number/inclusive -> screen:address:screen [
def clear-line-until screen:address:screen, right:num/inclusive -> screen:address:screen [
local-scope
load-ingredients
_, column:number <- cursor-position screen
_, column:num <- cursor-position screen
space:char <- copy 32/space
bg-color:number, bg-color-found?:boolean <- next-ingredient
bg-color:num, bg-color-found?:boolean <- next-ingredient
{
# default bg-color to black
break-if bg-color-found?
@ -403,20 +403,20 @@ def clear-line-until screen:address:screen, right:number/inclusive -> screen:add
}
]
def cursor-position screen:address:screen -> row:number, column:number [
def cursor-position screen:address:screen -> row:num, column:num [
local-scope
load-ingredients
# if x exists, lookup cursor in fake screen
{
break-unless screen
row:number <- get *screen, cursor-row:offset
column:number <- get *screen, cursor-column:offset
row:num <- get *screen, cursor-row:offset
column:num <- get *screen, cursor-column:offset
return
}
row, column <- cursor-position-on-display
]
def move-cursor screen:address:screen, new-row:number, new-column:number -> screen:address:screen [
def move-cursor screen:address:screen, new-row:num, new-column:num -> screen:address:screen [
local-scope
load-ingredients
# if x exists, move cursor in fake screen
@ -470,9 +470,9 @@ def cursor-down screen:address:screen -> screen:address:screen [
break-unless screen
{
# increment row unless it's already all the way down
height:number <- get *screen, num-rows:offset
row:number <- get *screen, cursor-row:offset
max:number <- subtract height, 1
height:num <- get *screen, num-rows:offset
row:num <- get *screen, cursor-row:offset
max:num <- subtract height, 1
at-bottom?:boolean <- greater-or-equal row, max
break-if at-bottom?
row <- add row, 1
@ -492,7 +492,7 @@ def cursor-up screen:address:screen -> screen:address:screen [
break-unless screen
{
# decrement row unless it's already all the way up
row:number <- get *screen, cursor-row:offset
row:num <- get *screen, cursor-row:offset
at-top?:boolean <- lesser-or-equal row, 0
break-if at-top?
row <- subtract row, 1
@ -512,9 +512,9 @@ def cursor-right screen:address:screen -> screen:address:screen [
break-unless screen
{
# increment column unless it's already all the way to the right
width:number <- get *screen, num-columns:offset
column:number <- get *screen, cursor-column:offset
max:number <- subtract width, 1
width:num <- get *screen, num-columns:offset
column:num <- get *screen, cursor-column:offset
max:num <- subtract width, 1
at-bottom?:boolean <- greater-or-equal column, max
break-if at-bottom?
column <- add column, 1
@ -534,7 +534,7 @@ def cursor-left screen:address:screen -> screen:address:screen [
break-unless screen
{
# decrement column unless it's already all the way to the left
column:number <- get *screen, cursor-column:offset
column:num <- get *screen, cursor-column:offset
at-top?:boolean <- lesser-or-equal column, 0
break-if at-top?
column <- subtract column, 1
@ -549,8 +549,8 @@ def cursor-left screen:address:screen -> screen:address:screen [
def cursor-to-start-of-line screen:address:screen -> screen:address:screen [
local-scope
load-ingredients
row:number <- cursor-position screen
column:number <- copy 0
row:num <- cursor-position screen
column:num <- copy 0
screen <- move-cursor screen, row, column
]
@ -561,14 +561,14 @@ def cursor-to-next-line screen:address:screen -> screen:address:screen [
screen <- cursor-to-start-of-line screen
]
def move-cursor-to-column screen:address:screen, column:number -> screen:address:screen [
def move-cursor-to-column screen:address:screen, column:num -> screen:address:screen [
local-scope
load-ingredients
row:number, _ <- cursor-position screen
row:num, _ <- cursor-position screen
move-cursor screen, row, column
]
def screen-width screen:address:screen -> width:number [
def screen-width screen:address:screen -> width:num [
local-scope
load-ingredients
# if x exists, move cursor in fake screen
@ -581,7 +581,7 @@ def screen-width screen:address:screen -> width:number [
width <- display-width
]
def screen-height screen:address:screen -> height:number [
def screen-height screen:address:screen -> height:num [
local-scope
load-ingredients
# if x exists, move cursor in fake screen
@ -647,20 +647,20 @@ def show-screen screen:address:screen -> screen:address:screen [
def print screen:address:screen, s:text -> screen:address:screen [
local-scope
load-ingredients
color:number, color-found?:boolean <- next-ingredient
color:num, color-found?:boolean <- next-ingredient
{
# default color to white
break-if color-found?
color <- copy 7/white
}
bg-color:number, bg-color-found?:boolean <- next-ingredient
bg-color:num, bg-color-found?:boolean <- next-ingredient
{
# default bg-color to black
break-if bg-color-found?
bg-color <- copy 0/black
}
len:number <- length *s
i:number <- copy 0
len:num <- length *s
i:num <- copy 0
{
done?:boolean <- greater-or-equal i, len
break-if done?
@ -693,16 +693,16 @@ scenario print-text-stops-at-right-margin [
]
]
def print-integer screen:address:screen, n:number -> screen:address:screen [
def print-integer screen:address:screen, n:num -> screen:address:screen [
local-scope
load-ingredients
color:number, color-found?:boolean <- next-ingredient
color:num, color-found?:boolean <- next-ingredient
{
# default color to white
break-if color-found?
color <- copy 7/white
}
bg-color:number, bg-color-found?:boolean <- next-ingredient
bg-color:num, bg-color-found?:boolean <- next-ingredient
{
# default bg-color to black
break-if bg-color-found?
@ -714,16 +714,16 @@ def print-integer screen:address:screen, n:number -> screen:address:screen [
]
# for now, we can only print integers
def print screen:address:screen, n:number -> screen:address:screen [
def print screen:address:screen, n:num -> screen:address:screen [
local-scope
load-ingredients
color:number, color-found?:boolean <- next-ingredient
color:num, color-found?:boolean <- next-ingredient
{
# default color to white
break-if color-found?
color <- copy 7/white
}
bg-color:number, bg-color-found?:boolean <- next-ingredient
bg-color:num, bg-color-found?:boolean <- next-ingredient
{
# default bg-color to black
break-if bg-color-found?
@ -736,18 +736,18 @@ def print screen:address:screen, n:number -> screen:address:screen [
def print screen:address:screen, n:address:_elem -> screen:address:screen [
local-scope
load-ingredients
color:number, color-found?:boolean <- next-ingredient
color:num, color-found?:boolean <- next-ingredient
{
# default color to white
break-if color-found?
color <- copy 7/white
}
bg-color:number, bg-color-found?:boolean <- next-ingredient
bg-color:num, bg-color-found?:boolean <- next-ingredient
{
# default bg-color to black
break-if bg-color-found?
bg-color <- copy 0/black
}
n2:number <- copy n
n2:num <- copy n
screen <- print-integer screen, n2, color, bg-color
]

View File

@ -120,7 +120,7 @@ scenario screen-in-scenario-color [
:(scenario convert_names_does_not_fail_when_mixing_special_names_and_numeric_locations)
% Scenario_testing_scenario = true;
def main [
screen:number <- copy 1:number
screen:num <- copy 1:num
]
-error: mixing variable names and numeric addresses in main
$error: 0

View File

@ -3,25 +3,25 @@
exclusive-container event [
text:char
keycode:number # keys on keyboard without a unicode representation
keycode:num # keys on keyboard without a unicode representation
touch:touch-event # mouse, track ball, etc.
resize:resize-event
# update the assume-console handler if you add more variants
]
container touch-event [
type:number
row:number
column:number
type:num
row:num
column:num
]
container resize-event [
width:number
height:number
width:num
height:num
]
container console [
current-event-index:number
current-event-index:num
events:address:array:event
]
@ -37,10 +37,10 @@ def read-event console:address:console -> result:event, console:address:console,
load-ingredients
{
break-unless console
current-event-index:number <- get *console, current-event-index:offset
current-event-index:num <- get *console, current-event-index:offset
buf:address:array:event <- get *console, events:offset
{
max:number <- length *buf
max:num <- length *buf
done?:boolean <- greater-or-equal current-event-index, max
break-unless done?
dummy:address:event <- new event:type

View File

@ -16,16 +16,16 @@ def start-reading fs:address:filesystem, filename:text -> contents:address:sourc
{
break-if fs
# real file system
file:number <- $open-file-for-reading filename
file:num <- $open-file-for-reading filename
assert file, [file not found]
contents:address:source:char, sink:address:sink:char <- new-channel 30
start-running transmit-from-file file, sink
return
}
# fake file system
i:number <- copy 0
i:num <- copy 0
data:address:array:file-mapping <- get *fs, data:offset
len:number <- length *data
len:num <- length *data
{
done?:boolean <- greater-or-equal i, len
break-if done?
@ -42,7 +42,7 @@ def start-reading fs:address:filesystem, filename:text -> contents:address:sourc
return 0/not-found
]
def transmit-from-file file:number, sink:address:sink:char -> sink:address:sink:char [
def transmit-from-file file:num, sink:address:sink:char -> sink:address:sink:char [
local-scope
load-ingredients
{
@ -58,8 +58,8 @@ def transmit-from-file file:number, sink:address:sink:char -> sink:address:sink:
def transmit-from-text contents:text, sink:address:sink:char -> sink:address:sink:char [
local-scope
load-ingredients
i:number <- copy 0
len:number <- length *contents
i:num <- copy 0
len:num <- length *contents
{
done?:boolean <- greater-or-equal i, len
break-if done?
@ -71,14 +71,14 @@ def transmit-from-text contents:text, sink:address:sink:char -> sink:address:sin
sink <- close sink
]
def start-writing fs:address:filesystem, filename:text -> sink:address:sink:char, routine-id:number [
def start-writing fs:address:filesystem, filename:text -> sink:address:sink:char, routine-id:num [
local-scope
load-ingredients
source:address:source:char, sink:address:sink:char <- new-channel 30
{
break-if fs
# real file system
file:number <- $open-file-for-writing filename
file:num <- $open-file-for-writing filename
assert file, [no such file]
routine-id <- start-running transmit-to-file file, source
reply
@ -88,7 +88,7 @@ def start-writing fs:address:filesystem, filename:text -> sink:address:sink:char
routine-id <- start-running transmit-to-fake-file fs, filename, source
]
def transmit-to-file file:number, source:address:source:char -> source:address:source:char [
def transmit-to-file file:num, source:address:source:char -> source:address:source:char [
local-scope
load-ingredients
{
@ -117,8 +117,8 @@ def transmit-to-fake-file fs:address:filesystem, filename:text, source:address:s
curr-filename:text <- copy 0
data:address:array:file-mapping <- get *fs, data:offset
# replace file contents if it already exists
i:number <- copy 0
len:number <- length *data
i:num <- copy 0
len:num <- length *data
{
done?:boolean <- greater-or-equal i, len
break-if done?
@ -130,11 +130,11 @@ def transmit-to-fake-file fs:address:filesystem, filename:text, source:address:s
reply
}
# if file didn't already exist, make room for it
new-len:number <- add len, 1
new-len:num <- add len, 1
new-data:address:array:file-mapping <- new file-mapping:type, new-len
put *fs, data:offset, new-data
# copy over old files
i:number <- copy 0
i:num <- copy 0
{
done?:boolean <- greater-or-equal i, len
break-if done?

View File

@ -26,7 +26,7 @@ scenario write-to-fake-file [
local-scope
assume-filesystem [
]
sink:address:sink:char, writer:number/routine <- start-writing filesystem:address:filesystem, [a]
sink:address:sink:char, writer:num/routine <- start-writing filesystem:address:filesystem, [a]
sink <- write sink, 120/x
sink <- write sink, 121/y
close sink
@ -43,7 +43,7 @@ scenario write-to-fake-file-that-exists [
assume-filesystem [
[a] <- []
]
sink:address:sink:char, writer:number/routine <- start-writing filesystem:address:filesystem, [a]
sink:address:sink:char, writer:num/routine <- start-writing filesystem:address:filesystem, [a]
sink <- write sink, 120/x
sink <- write sink, 121/y
close sink
@ -63,7 +63,7 @@ scenario write-to-existing-file-preserves-other-files [
|bcd|
]
]
sink:address:sink:char, writer:number/routine <- start-writing filesystem:address:filesystem, [a]
sink:address:sink:char, writer:num/routine <- start-writing filesystem:address:filesystem, [a]
sink <- write sink, 120/x
sink <- write sink, 121/y
close sink

View File

@ -3,10 +3,10 @@
:(scenario run_interactive_code)
def main [
1:number/raw <- copy 0
2:text <- new [1:number/raw <- copy 34]
1:num/raw <- copy 0
2:text <- new [1:num/raw <- copy 34]
run-sandboxed 2:text
3:number/raw <- copy 1:number/raw
3:num/raw <- copy 1:num/raw
]
+mem: storing 34 in location 3
@ -195,12 +195,12 @@ load(string(
"recipe sandbox [\n" +
"local-scope\n" +
"screen:address:screen <- new-fake-screen 30, 5\n" +
"routine-id:number <- start-running interactive, screen\n" +
"routine-id:num <- start-running interactive, screen\n" +
"limit-time routine-id, 100000/instructions\n" +
"wait-for-routine routine-id\n" +
"instructions-run:number <- number-of-instructions routine-id\n" +
"instructions-run:num <- number-of-instructions routine-id\n" +
"stash instructions-run [instructions run]\n" +
"sandbox-state:number <- routine-state routine-id\n" +
"sandbox-state:num <- routine-state routine-id\n" +
"completed?:boolean <- equal sandbox-state, 1/completed\n" +
"output:text <- $most-recent-products\n" +
"errors:text <- save-errors\n" +
@ -337,8 +337,8 @@ def main [
:(scenario "run_interactive_returns_errors")
def main [
# run a command that generates an error
1:text <- new [x:number <- copy 34
get x:number, foo:offset]
1:text <- new [x:num <- copy 34
get x:num, foo:offset]
2:text, 3:text <- run-sandboxed 1:text
10:array:char <- copy 3:text/lookup
]
@ -352,8 +352,8 @@ get x:number, foo:offset]
:(scenario run_interactive_with_comment)
def main [
# 2 instructions, with a comment after the first
1:address:array:number <- new [a:number <- copy 0 # abc
b:number <- copy 0
1:address:array:num <- new [a:num <- copy 0 # abc
b:num <- copy 0
]
2:text, 3:text <- run-sandboxed 1:text
]
@ -503,10 +503,10 @@ case RELOAD: {
def main [
local-scope
x:text <- new [recipe foo [
get 1234:number, foo:offset
get 1234:num, foo:offset
]]
reload x
1:number/raw <- copy 34
1:num/raw <- copy 34
]
+mem: storing 34 in location 1
@ -516,8 +516,8 @@ def main [
local-scope
x:text <- new [
container foo [
x:number
y:number
x:num
y:num
]
recipe bar [
local-scope
@ -525,8 +525,8 @@ def main [
]
]
# save warning addresses in locations of type 'number' to avoid spurious changes to them due to 'abandon'
1:number/raw <- reload x
2:number/raw <- reload x
1:num/raw <- reload x
2:num/raw <- reload x
]
# no errors on either load
+mem: storing 0 in location 1