One more place we were missing expanding type abbreviations: inside
container definitions.
This commit is contained in:
Kartik K. Agaram 2016-09-17 00:43:13 -07:00
parent 08f4628e8b
commit 192d59d3bb
43 changed files with 855 additions and 854 deletions

View File

@ -11,15 +11,15 @@
:(scenario copy_literal) :(scenario copy_literal)
def main [ def main [
1:number <- copy 23 1:num <- copy 23
] ]
+run: {1: "number"} <- copy {23: "literal"} +run: {1: "number"} <- copy {23: "literal"}
+mem: storing 23 in location 1 +mem: storing 23 in location 1
:(scenario copy) :(scenario copy)
def main [ def main [
1:number <- copy 23 1:num <- copy 23
2:number <- copy 1:number 2:num <- copy 1:num
] ]
+run: {2: "number"} <- copy {1: "number"} +run: {2: "number"} <- copy {1: "number"}
+mem: location 1 is 23 +mem: location 1 is 23
@ -27,7 +27,7 @@ def main [
:(scenario copy_multiple) :(scenario copy_multiple)
def main [ def main [
1:number, 2:number <- copy 23, 24 1:num, 2:num <- copy 23, 24
] ]
+mem: storing 23 in location 1 +mem: storing 23 in location 1
+mem: storing 24 in location 2 +mem: storing 24 in location 2
@ -365,8 +365,8 @@ void run(const string& form) {
:(scenario run_label) :(scenario run_label)
def main [ def main [
+foo +foo
1:number <- copy 23 1:num <- copy 23
2:number <- copy 1:number 2:num <- copy 1:num
] ]
+run: {1: "number"} <- copy {23: "literal"} +run: {1: "number"} <- copy {23: "literal"}
+run: {2: "number"} <- copy {1: "number"} +run: {2: "number"} <- copy {1: "number"}
@ -381,7 +381,7 @@ def main [
:(scenario write_to_0_disallowed) :(scenario write_to_0_disallowed)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
0:number <- copy 34 0:num <- copy 34
] ]
-mem: storing 34 in location 0 -mem: storing 34 in location 0
@ -390,24 +390,24 @@ def main [
:(scenario comma_without_space) :(scenario comma_without_space)
def main [ def main [
1:number, 2:number <- copy 2,2 1:num, 2:num <- copy 2,2
] ]
+mem: storing 2 in location 1 +mem: storing 2 in location 1
:(scenario space_without_comma) :(scenario space_without_comma)
def main [ def main [
1:number, 2:number <- copy 2 2 1:num, 2:num <- copy 2 2
] ]
+mem: storing 2 in location 1 +mem: storing 2 in location 1
:(scenario comma_before_space) :(scenario comma_before_space)
def main [ def main [
1:number, 2:number <- copy 2, 2 1:num, 2:num <- copy 2, 2
] ]
+mem: storing 2 in location 1 +mem: storing 2 in location 1
:(scenario comma_after_space) :(scenario comma_after_space)
def main [ def main [
1:number, 2:number <- copy 2 ,2 1:num, 2:num <- copy 2 ,2
] ]
+mem: storing 2 in location 1 +mem: storing 2 in location 1

View File

@ -46,35 +46,35 @@ void check_instruction(const recipe_ordinal r) {
:(scenario copy_checks_reagent_count) :(scenario copy_checks_reagent_count)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:number <- copy 34, 35 1:num <- copy 34, 35
] ]
+error: main: ingredients and products should match in '1:number <- copy 34, 35' +error: main: ingredients and products should match in '1:num <- copy 34, 35'
:(scenario write_scalar_to_array_disallowed) :(scenario write_scalar_to_array_disallowed)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:array:number <- copy 34 1:array:num <- copy 34
] ]
+error: main: can't copy '34' to '1:array:number'; types don't match +error: main: can't copy '34' to '1:array:num'; types don't match
:(scenario write_scalar_to_array_disallowed_2) :(scenario write_scalar_to_array_disallowed_2)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:number, 2:array:number <- copy 34, 35 1:num, 2:array:num <- copy 34, 35
] ]
+error: main: can't copy '35' to '2:array:number'; types don't match +error: main: can't copy '35' to '2:array:num'; types don't match
:(scenario write_scalar_to_address_disallowed) :(scenario write_scalar_to_address_disallowed)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:address:number <- copy 34 1:address:num <- copy 34
] ]
+error: main: can't copy '34' to '1:address:number'; types don't match +error: main: can't copy '34' to '1:address:num'; types don't match
:(scenario write_address_to_number_allowed) :(scenario write_address_to_number_allowed)
def main [ def main [
1:address:number <- copy 12/unsafe 1:address:num <- copy 12/unsafe
2:number <- copy 1:address:number 2:num <- copy 1:address:num
] ]
+mem: storing 12 in location 2 +mem: storing 12 in location 2
$error: 0 $error: 0
@ -82,15 +82,15 @@ $error: 0
:(scenario write_boolean_to_number_allowed) :(scenario write_boolean_to_number_allowed)
def main [ def main [
1:boolean <- copy 1/true 1:boolean <- copy 1/true
2:number <- copy 1:boolean 2:num <- copy 1:boolean
] ]
+mem: storing 1 in location 2 +mem: storing 1 in location 2
$error: 0 $error: 0
:(scenario write_number_to_boolean_allowed) :(scenario write_number_to_boolean_allowed)
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:boolean <- copy 1:number 2:boolean <- copy 1:num
] ]
+mem: storing 34 in location 2 +mem: storing 34 in location 2
$error: 0 $error: 0

View File

@ -36,37 +36,37 @@ case ADD: {
:(scenario add_literal) :(scenario add_literal)
def main [ def main [
1:number <- add 23, 34 1:num <- add 23, 34
] ]
+mem: storing 57 in location 1 +mem: storing 57 in location 1
:(scenario add) :(scenario add)
def main [ def main [
1:number <- copy 23 1:num <- copy 23
2:number <- copy 34 2:num <- copy 34
3:number <- add 1:number, 2:number 3:num <- add 1:num, 2:num
] ]
+mem: storing 57 in location 3 +mem: storing 57 in location 3
:(scenario add_multiple) :(scenario add_multiple)
def main [ def main [
1:number <- add 3, 4, 5 1:num <- add 3, 4, 5
] ]
+mem: storing 12 in location 1 +mem: storing 12 in location 1
:(scenario add_checks_type) :(scenario add_checks_type)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:number <- add 2:boolean, 1 1:num <- add 2:boolean, 1
] ]
+error: main: 'add' requires number ingredients, but got '2:boolean' +error: main: 'add' requires number ingredients, but got '2:boolean'
:(scenario add_checks_return_type) :(scenario add_checks_return_type)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:address:number <- add 2, 2 1:address:num <- add 2, 2
] ]
+error: main: 'add' should yield a number, but got '1:address:number' +error: main: 'add' should yield a number, but got '1:address:num'
:(before "End Primitive Recipe Declarations") :(before "End Primitive Recipe Declarations")
SUBTRACT, SUBTRACT,
@ -111,21 +111,21 @@ bool is_raw(const reagent& r) {
:(scenario subtract_literal) :(scenario subtract_literal)
def main [ def main [
1:number <- subtract 5, 2 1:num <- subtract 5, 2
] ]
+mem: storing 3 in location 1 +mem: storing 3 in location 1
:(scenario subtract) :(scenario subtract)
def main [ def main [
1:number <- copy 23 1:num <- copy 23
2:number <- copy 34 2:num <- copy 34
3:number <- subtract 1:number, 2:number 3:num <- subtract 1:num, 2:num
] ]
+mem: storing -11 in location 3 +mem: storing -11 in location 3
:(scenario subtract_multiple) :(scenario subtract_multiple)
def main [ def main [
1:number <- subtract 6, 3, 2 1:num <- subtract 6, 3, 2
] ]
+mem: storing 1 in location 1 +mem: storing 1 in location 1
@ -164,21 +164,21 @@ case MULTIPLY: {
:(scenario multiply_literal) :(scenario multiply_literal)
def main [ def main [
1:number <- multiply 2, 3 1:num <- multiply 2, 3
] ]
+mem: storing 6 in location 1 +mem: storing 6 in location 1
:(scenario multiply) :(scenario multiply)
def main [ def main [
1:number <- copy 4 1:num <- copy 4
2:number <- copy 6 2:num <- copy 6
3:number <- multiply 1:number, 2:number 3:num <- multiply 1:num, 2:num
] ]
+mem: storing 24 in location 3 +mem: storing 24 in location 3
:(scenario multiply_multiple) :(scenario multiply_multiple)
def main [ def main [
1:number <- multiply 2, 3, 4 1:num <- multiply 2, 3, 4
] ]
+mem: storing 24 in location 1 +mem: storing 24 in location 1
@ -220,21 +220,21 @@ case DIVIDE: {
:(scenario divide_literal) :(scenario divide_literal)
def main [ def main [
1:number <- divide 8, 2 1:num <- divide 8, 2
] ]
+mem: storing 4 in location 1 +mem: storing 4 in location 1
:(scenario divide) :(scenario divide)
def main [ def main [
1:number <- copy 27 1:num <- copy 27
2:number <- copy 3 2:num <- copy 3
3:number <- divide 1:number, 2:number 3:num <- divide 1:num, 2:num
] ]
+mem: storing 9 in location 3 +mem: storing 9 in location 3
:(scenario divide_multiple) :(scenario divide_multiple)
def main [ def main [
1:number <- divide 12, 3, 2 1:num <- divide 12, 3, 2
] ]
+mem: storing 2 in location 1 +mem: storing 2 in location 1
@ -288,39 +288,39 @@ case DIVIDE_WITH_REMAINDER: {
:(scenario divide_with_remainder_literal) :(scenario divide_with_remainder_literal)
def main [ def main [
1:number, 2:number <- divide-with-remainder 9, 2 1:num, 2:num <- divide-with-remainder 9, 2
] ]
+mem: storing 4 in location 1 +mem: storing 4 in location 1
+mem: storing 1 in location 2 +mem: storing 1 in location 2
:(scenario divide_with_remainder) :(scenario divide_with_remainder)
def main [ def main [
1:number <- copy 27 1:num <- copy 27
2:number <- copy 11 2:num <- copy 11
3:number, 4:number <- divide-with-remainder 1:number, 2:number 3:num, 4:num <- divide-with-remainder 1:num, 2:num
] ]
+mem: storing 2 in location 3 +mem: storing 2 in location 3
+mem: storing 5 in location 4 +mem: storing 5 in location 4
:(scenario divide_with_decimal_point) :(scenario divide_with_decimal_point)
def main [ def main [
1:number <- divide 5, 2 1:num <- divide 5, 2
] ]
+mem: storing 2.5 in location 1 +mem: storing 2.5 in location 1
:(scenario divide_by_zero) :(scenario divide_by_zero)
def main [ def main [
1:number <- divide 4, 0 1:num <- divide 4, 0
] ]
+mem: storing inf in location 1 +mem: storing inf in location 1
:(scenario divide_by_zero_2) :(scenario divide_by_zero_2)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:number <- divide-with-remainder 4, 0 1:num <- divide-with-remainder 4, 0
] ]
# integer division can't return floating-point infinity # integer division can't return floating-point infinity
+error: main: divide by zero in '1:number <- divide-with-remainder 4, 0' +error: main: divide by zero in '1:num <- divide-with-remainder 4, 0'
//: Bitwise shifts //: Bitwise shifts
@ -365,33 +365,33 @@ case SHIFT_LEFT: {
:(scenario shift_left_by_zero) :(scenario shift_left_by_zero)
def main [ def main [
1:number <- shift-left 1, 0 1:num <- shift-left 1, 0
] ]
+mem: storing 1 in location 1 +mem: storing 1 in location 1
:(scenario shift_left_1) :(scenario shift_left_1)
def main [ def main [
1:number <- shift-left 1, 4 1:num <- shift-left 1, 4
] ]
+mem: storing 16 in location 1 +mem: storing 16 in location 1
:(scenario shift_left_2) :(scenario shift_left_2)
def main [ def main [
1:number <- shift-left 3, 2 1:num <- shift-left 3, 2
] ]
+mem: storing 12 in location 1 +mem: storing 12 in location 1
:(scenario shift_left_by_negative) :(scenario shift_left_by_negative)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:number <- shift-left 3, -1 1:num <- shift-left 3, -1
] ]
+error: main: second ingredient can't be negative in '1:number <- shift-left 3, -1' +error: main: second ingredient can't be negative in '1:num <- shift-left 3, -1'
:(scenario shift_left_ignores_fractional_part) :(scenario shift_left_ignores_fractional_part)
def main [ def main [
1:number <- divide 3, 2 1:num <- divide 3, 2
2:number <- shift-left 1:number, 1 2:num <- shift-left 1:num, 1
] ]
+mem: storing 2 in location 2 +mem: storing 2 in location 2
@ -436,33 +436,33 @@ case SHIFT_RIGHT: {
:(scenario shift_right_by_zero) :(scenario shift_right_by_zero)
def main [ def main [
1:number <- shift-right 1, 0 1:num <- shift-right 1, 0
] ]
+mem: storing 1 in location 1 +mem: storing 1 in location 1
:(scenario shift_right_1) :(scenario shift_right_1)
def main [ def main [
1:number <- shift-right 1024, 1 1:num <- shift-right 1024, 1
] ]
+mem: storing 512 in location 1 +mem: storing 512 in location 1
:(scenario shift_right_2) :(scenario shift_right_2)
def main [ def main [
1:number <- shift-right 3, 1 1:num <- shift-right 3, 1
] ]
+mem: storing 1 in location 1 +mem: storing 1 in location 1
:(scenario shift_right_by_negative) :(scenario shift_right_by_negative)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:number <- shift-right 4, -1 1:num <- shift-right 4, -1
] ]
+error: main: second ingredient can't be negative in '1:number <- shift-right 4, -1' +error: main: second ingredient can't be negative in '1:num <- shift-right 4, -1'
:(scenario shift_right_ignores_fractional_part) :(scenario shift_right_ignores_fractional_part)
def main [ def main [
1:number <- divide 3, 2 1:num <- divide 3, 2
2:number <- shift-right 1:number, 1 2:num <- shift-right 1:num, 1
] ]
+mem: storing 0 in location 2 +mem: storing 0 in location 2
@ -502,25 +502,25 @@ case AND_BITS: {
:(scenario and_bits_1) :(scenario and_bits_1)
def main [ def main [
1:number <- and-bits 8, 3 1:num <- and-bits 8, 3
] ]
+mem: storing 0 in location 1 +mem: storing 0 in location 1
:(scenario and_bits_2) :(scenario and_bits_2)
def main [ def main [
1:number <- and-bits 3, 2 1:num <- and-bits 3, 2
] ]
+mem: storing 2 in location 1 +mem: storing 2 in location 1
:(scenario and_bits_3) :(scenario and_bits_3)
def main [ def main [
1:number <- and-bits 14, 3 1:num <- and-bits 14, 3
] ]
+mem: storing 2 in location 1 +mem: storing 2 in location 1
:(scenario and_bits_negative) :(scenario and_bits_negative)
def main [ def main [
1:number <- and-bits -3, 4 1:num <- and-bits -3, 4
] ]
+mem: storing 4 in location 1 +mem: storing 4 in location 1
@ -560,19 +560,19 @@ case OR_BITS: {
:(scenario or_bits_1) :(scenario or_bits_1)
def main [ def main [
1:number <- or-bits 3, 8 1:num <- or-bits 3, 8
] ]
+mem: storing 11 in location 1 +mem: storing 11 in location 1
:(scenario or_bits_2) :(scenario or_bits_2)
def main [ def main [
1:number <- or-bits 3, 10 1:num <- or-bits 3, 10
] ]
+mem: storing 11 in location 1 +mem: storing 11 in location 1
:(scenario or_bits_3) :(scenario or_bits_3)
def main [ def main [
1:number <- or-bits 4, 6 1:num <- or-bits 4, 6
] ]
+mem: storing 6 in location 1 +mem: storing 6 in location 1
@ -612,19 +612,19 @@ case XOR_BITS: {
:(scenario xor_bits_1) :(scenario xor_bits_1)
def main [ def main [
1:number <- xor-bits 3, 8 1:num <- xor-bits 3, 8
] ]
+mem: storing 11 in location 1 +mem: storing 11 in location 1
:(scenario xor_bits_2) :(scenario xor_bits_2)
def main [ def main [
1:number <- xor-bits 3, 10 1:num <- xor-bits 3, 10
] ]
+mem: storing 9 in location 1 +mem: storing 9 in location 1
:(scenario xor_bits_3) :(scenario xor_bits_3)
def main [ def main [
1:number <- xor-bits 4, 6 1:num <- xor-bits 4, 6
] ]
+mem: storing 2 in location 1 +mem: storing 2 in location 1
@ -663,25 +663,25 @@ case FLIP_BITS: {
:(scenario flip_bits_zero) :(scenario flip_bits_zero)
def main [ def main [
1:number <- flip-bits 0 1:num <- flip-bits 0
] ]
+mem: storing -1 in location 1 +mem: storing -1 in location 1
:(scenario flip_bits_negative) :(scenario flip_bits_negative)
def main [ def main [
1:number <- flip-bits -1 1:num <- flip-bits -1
] ]
+mem: storing 0 in location 1 +mem: storing 0 in location 1
:(scenario flip_bits_1) :(scenario flip_bits_1)
def main [ def main [
1:number <- flip-bits 3 1:num <- flip-bits 3
] ]
+mem: storing -4 in location 1 +mem: storing -4 in location 1
:(scenario flip_bits_2) :(scenario flip_bits_2)
def main [ def main [
1:number <- flip-bits 12 1:num <- flip-bits 12
] ]
+mem: storing -13 in location 1 +mem: storing -13 in location 1
@ -710,7 +710,7 @@ case ROUND: {
:(scenario round_to_nearest_integer) :(scenario round_to_nearest_integer)
def main [ def main [
1:number <- round 12.2 1:num <- round 12.2
] ]
+mem: storing 12 in location 1 +mem: storing 12 in location 1

View File

@ -3,7 +3,7 @@
:(scenario jump_can_skip_instructions) :(scenario jump_can_skip_instructions)
def main [ def main [
jump 1:offset jump 1:offset
1:number <- copy 1 1:num <- copy 1
] ]
+run: jump {1: "offset"} +run: jump {1: "offset"}
-run: {1: "number"} <- copy {1: "literal"} -run: {1: "number"} <- copy {1: "literal"}
@ -84,7 +84,7 @@ case JUMP_IF: {
:(scenario jump_if) :(scenario jump_if)
def main [ def main [
jump-if 999, 1:offset jump-if 999, 1:offset
123:number <- copy 1 123:num <- copy 1
] ]
+run: jump-if {999: "literal"}, {1: "offset"} +run: jump-if {999: "literal"}, {1: "offset"}
+run: jumping to instruction 2 +run: jumping to instruction 2
@ -94,7 +94,7 @@ def main [
:(scenario jump_if_fallthrough) :(scenario jump_if_fallthrough)
def main [ def main [
jump-if 0, 1:offset jump-if 0, 1:offset
123:number <- copy 1 123:num <- copy 1
] ]
+run: jump-if {0: "literal"}, {1: "offset"} +run: jump-if {0: "literal"}, {1: "offset"}
+run: jump-if fell through +run: jump-if fell through
@ -137,7 +137,7 @@ case JUMP_UNLESS: {
:(scenario jump_unless) :(scenario jump_unless)
def main [ def main [
jump-unless 0, 1:offset jump-unless 0, 1:offset
123:number <- copy 1 123:num <- copy 1
] ]
+run: jump-unless {0: "literal"}, {1: "offset"} +run: jump-unless {0: "literal"}, {1: "offset"}
+run: jumping to instruction 2 +run: jumping to instruction 2
@ -147,7 +147,7 @@ def main [
:(scenario jump_unless_fallthrough) :(scenario jump_unless_fallthrough)
def main [ def main [
jump-unless 999, 1:offset jump-unless 999, 1:offset
123:number <- copy 1 123:num <- copy 1
] ]
+run: jump-unless {999: "literal"}, {1: "offset"} +run: jump-unless {999: "literal"}, {1: "offset"}
+run: jump-unless fell through +run: jump-unless fell through

View File

@ -44,9 +44,9 @@ case EQUAL: {
:(scenario equal) :(scenario equal)
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:number <- copy 33 2:num <- copy 33
3:boolean <- equal 1:number, 2:number 3:boolean <- equal 1:num, 2:num
] ]
+mem: location 1 is 34 +mem: location 1 is 34
+mem: location 2 is 33 +mem: location 2 is 33
@ -54,9 +54,9 @@ def main [
:(scenario equal_2) :(scenario equal_2)
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:number <- copy 34 2:num <- copy 34
3:boolean <- equal 1:number, 2:number 3:boolean <- equal 1:num, 2:num
] ]
+mem: location 1 is 34 +mem: location 1 is 34
+mem: location 2 is 34 +mem: location 2 is 34
@ -110,9 +110,9 @@ case NOT_EQUAL: {
:(scenario not_equal) :(scenario not_equal)
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:number <- copy 33 2:num <- copy 33
3:boolean <- not-equal 1:number, 2:number 3:boolean <- not-equal 1:num, 2:num
] ]
+mem: location 1 is 34 +mem: location 1 is 34
+mem: location 2 is 33 +mem: location 2 is 33
@ -120,9 +120,9 @@ def main [
:(scenario not_equal_2) :(scenario not_equal_2)
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:number <- copy 34 2:num <- copy 34
3:boolean <- not-equal 1:number, 2:number 3:boolean <- not-equal 1:num, 2:num
] ]
+mem: location 1 is 34 +mem: location 1 is 34
+mem: location 2 is 34 +mem: location 2 is 34
@ -169,17 +169,17 @@ case GREATER_THAN: {
:(scenario greater_than) :(scenario greater_than)
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:number <- copy 33 2:num <- copy 33
3:boolean <- greater-than 1:number, 2:number 3:boolean <- greater-than 1:num, 2:num
] ]
+mem: storing 1 in location 3 +mem: storing 1 in location 3
:(scenario greater_than_2) :(scenario greater_than_2)
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:number <- copy 34 2:num <- copy 34
3:boolean <- greater-than 1:number, 2:number 3:boolean <- greater-than 1:num, 2:num
] ]
+mem: storing 0 in location 3 +mem: storing 0 in location 3
@ -236,17 +236,17 @@ case LESSER_THAN: {
:(scenario lesser_than) :(scenario lesser_than)
def main [ def main [
1:number <- copy 32 1:num <- copy 32
2:number <- copy 33 2:num <- copy 33
3:boolean <- lesser-than 1:number, 2:number 3:boolean <- lesser-than 1:num, 2:num
] ]
+mem: storing 1 in location 3 +mem: storing 1 in location 3
:(scenario lesser_than_2) :(scenario lesser_than_2)
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:number <- copy 33 2:num <- copy 33
3:boolean <- lesser-than 1:number, 2:number 3:boolean <- lesser-than 1:num, 2:num
] ]
+mem: storing 0 in location 3 +mem: storing 0 in location 3
@ -303,25 +303,25 @@ case GREATER_OR_EQUAL: {
:(scenario greater_or_equal) :(scenario greater_or_equal)
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:number <- copy 33 2:num <- copy 33
3:boolean <- greater-or-equal 1:number, 2:number 3:boolean <- greater-or-equal 1:num, 2:num
] ]
+mem: storing 1 in location 3 +mem: storing 1 in location 3
:(scenario greater_or_equal_2) :(scenario greater_or_equal_2)
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:number <- copy 34 2:num <- copy 34
3:boolean <- greater-or-equal 1:number, 2:number 3:boolean <- greater-or-equal 1:num, 2:num
] ]
+mem: storing 1 in location 3 +mem: storing 1 in location 3
:(scenario greater_or_equal_3) :(scenario greater_or_equal_3)
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:number <- copy 35 2:num <- copy 35
3:boolean <- greater-or-equal 1:number, 2:number 3:boolean <- greater-or-equal 1:num, 2:num
] ]
+mem: storing 0 in location 3 +mem: storing 0 in location 3
@ -378,25 +378,25 @@ case LESSER_OR_EQUAL: {
:(scenario lesser_or_equal) :(scenario lesser_or_equal)
def main [ def main [
1:number <- copy 32 1:num <- copy 32
2:number <- copy 33 2:num <- copy 33
3:boolean <- lesser-or-equal 1:number, 2:number 3:boolean <- lesser-or-equal 1:num, 2:num
] ]
+mem: storing 1 in location 3 +mem: storing 1 in location 3
:(scenario lesser_or_equal_2) :(scenario lesser_or_equal_2)
def main [ def main [
1:number <- copy 33 1:num <- copy 33
2:number <- copy 33 2:num <- copy 33
3:boolean <- lesser-or-equal 1:number, 2:number 3:boolean <- lesser-or-equal 1:num, 2:num
] ]
+mem: storing 1 in location 3 +mem: storing 1 in location 3
:(scenario lesser_or_equal_3) :(scenario lesser_or_equal_3)
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:number <- copy 33 2:num <- copy 33
3:boolean <- lesser-or-equal 1:number, 2:number 3:boolean <- lesser-or-equal 1:num, 2:num
] ]
+mem: storing 0 in location 3 +mem: storing 0 in location 3

View File

@ -5,20 +5,20 @@ def main [
f f
] ]
def f [ def f [
3:number <- add 2, 2 3:num <- add 2, 2
] ]
+mem: storing 4 in location 3 +mem: storing 4 in location 3
:(scenario return_on_fallthrough) :(scenario return_on_fallthrough)
def main [ def main [
f f
1:number <- copy 0 1:num <- copy 0
2:number <- copy 0 2:num <- copy 0
3:number <- copy 0 3:num <- copy 0
] ]
def f [ def f [
4:number <- copy 0 4:num <- copy 0
5:number <- copy 0 5:num <- copy 0
] ]
+run: f +run: f
# running f # running f
@ -138,9 +138,9 @@ def main [
:(scenario calling_undefined_recipe_handles_missing_result) :(scenario calling_undefined_recipe_handles_missing_result)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
x:number <- foo x:num <- foo
] ]
+error: main: undefined operation in 'x:number <- foo ' +error: main: undefined operation in 'x:num <- foo '
//:: finally, we need to fix the termination conditions for the run loop //:: finally, we need to fix the termination conditions for the run loop

View File

@ -6,8 +6,8 @@ def main [
f 2 f 2
] ]
def f [ def f [
12:number <- next-ingredient 12:num <- next-ingredient
13:number <- add 1, 12:number 13:num <- add 1, 12:num
] ]
+mem: storing 3 in location 13 +mem: storing 3 in location 13
@ -16,7 +16,7 @@ def main [
f f
] ]
def f [ def f [
_, 12:number <- next-ingredient _, 12:num <- next-ingredient
] ]
+mem: storing 0 in location 12 +mem: storing 0 in location 12
@ -91,19 +91,19 @@ def main [
f f
] ]
def f [ def f [
11:number <- next-ingredient 11:num <- next-ingredient
] ]
+error: f: no ingredient to save in '11:number' +error: f: no ingredient to save in '11:num'
:(scenario rewind_ingredients) :(scenario rewind_ingredients)
def main [ def main [
f 2 f 2
] ]
def f [ def f [
12:number <- next-ingredient # consume ingredient 12:num <- next-ingredient # consume ingredient
_, 1:boolean <- next-ingredient # will not find any ingredients _, 1:boolean <- next-ingredient # will not find any ingredients
rewind-ingredients rewind-ingredients
13:number, 2:boolean <- next-ingredient # will find ingredient again 13:num, 2:boolean <- next-ingredient # will find ingredient again
] ]
+mem: storing 2 in location 12 +mem: storing 2 in location 12
+mem: storing 0 in location 1 +mem: storing 0 in location 1
@ -129,8 +129,8 @@ def main [
f 1, 2 f 1, 2
] ]
def f [ def f [
12:number <- ingredient 1 # consume second ingredient first 12:num <- ingredient 1 # consume second ingredient first
13:number, 1:boolean <- next-ingredient # next-ingredient tries to scan past that 13:num, 1:boolean <- next-ingredient # next-ingredient tries to scan past that
] ]
+mem: storing 2 in location 12 +mem: storing 2 in location 12
+mem: storing 0 in location 1 +mem: storing 0 in location 1

View File

@ -2,12 +2,12 @@
:(scenario return) :(scenario return)
def main [ def main [
1:number, 2:number <- f 34 1:num, 2:num <- f 34
] ]
def f [ def f [
12:number <- next-ingredient 12:num <- next-ingredient
13:number <- add 1, 12:number 13:num <- add 1, 12:num
reply 12:number, 13:number reply 12:num, 13:num
] ]
+mem: storing 34 in location 1 +mem: storing 34 in location 1
+mem: storing 35 in location 2 +mem: storing 35 in location 2
@ -102,15 +102,15 @@ void check_types_of_reply_instructions(recipe_ordinal r) {
:(scenario return_type_mismatch) :(scenario return_type_mismatch)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
3:number <- f 2 3:num <- f 2
] ]
def f [ def f [
12:number <- next-ingredient 12:num <- next-ingredient
13:number <- copy 35 13:num <- copy 35
14:point <- copy 12:point/raw 14:point <- copy 12:point/raw
return 14:point return 14:point
] ]
+error: f: return ingredient '14:point' can't be saved in '3:number' +error: f: return ingredient '14:point' can't be saved in '3:num'
//: In mu we'd like to assume that any instruction doesn't modify its //: In mu we'd like to assume that any instruction doesn't modify its
//: ingredients unless they're also products. The /same-as-ingredient inside //: ingredients unless they're also products. The /same-as-ingredient inside
@ -120,23 +120,23 @@ def f [
:(scenario return_same_as_ingredient) :(scenario return_same_as_ingredient)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:number <- copy 0 1:num <- copy 0
2:number <- test1 1:number # call with different ingredient and product 2:num <- test1 1:num # call with different ingredient and product
] ]
def test1 [ def test1 [
10:number <- next-ingredient 10:num <- next-ingredient
return 10:number/same-as-ingredient:0 return 10:num/same-as-ingredient:0
] ]
+error: main: '2:number <- test1 1:number' should write to '1:number' rather than '2:number' +error: main: '2:num <- test1 1:num' should write to '1:num' rather than '2:num'
:(scenario return_same_as_ingredient_dummy) :(scenario return_same_as_ingredient_dummy)
def main [ def main [
1:number <- copy 0 1:num <- copy 0
_ <- test1 1:number # call with different ingredient and product _ <- test1 1:num # call with different ingredient and product
] ]
def test1 [ def test1 [
10:number <- next-ingredient 10:num <- next-ingredient
return 10:number/same-as-ingredient:0 return 10:num/same-as-ingredient:0
] ]
$error: 0 $error: 0

View File

@ -74,8 +74,8 @@ def main [
:(scenario stash_number) :(scenario stash_number)
def main [ def main [
1:number <- copy 34 1:num <- copy 34
stash [foo:], 1:number stash [foo:], 1:num
] ]
+app: foo: 34 +app: foo: 34

View File

@ -6,8 +6,8 @@ type_ordinal point = put(Type_ordinal, "point", Next_type_ordinal++);
get_or_insert(Type, point); // initialize get_or_insert(Type, point); // initialize
get(Type, point).kind = CONTAINER; get(Type, point).kind = CONTAINER;
get(Type, point).name = "point"; get(Type, point).name = "point";
get(Type, point).elements.push_back(reagent("x:number")); get(Type, point).elements.push_back(reagent("x:num"));
get(Type, point).elements.push_back(reagent("y:number")); get(Type, point).elements.push_back(reagent("y:num"));
//: Containers can be copied around with a single instruction just like //: Containers can be copied around with a single instruction just like
//: numbers, no matter how large they are. //: numbers, no matter how large they are.
@ -17,8 +17,8 @@ get(Type, point).elements.push_back(reagent("y:number"));
//: skip later checks. //: skip later checks.
:(scenario copy_multiple_locations) :(scenario copy_multiple_locations)
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:number <- copy 35 2:num <- copy 35
3:point <- copy 1:point/unsafe 3:point <- copy 1:point/unsafe
] ]
+mem: storing 34 in location 3 +mem: storing 34 in location 3
@ -28,9 +28,9 @@ def main [
:(scenario copy_checks_size) :(scenario copy_checks_size)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
2:point <- copy 1:number 2:point <- copy 1:num
] ]
+error: main: can't copy '1:number' to '2:point'; types don't match +error: main: can't copy '1:num' to '2:point'; types don't match
:(before "End Mu Types Initialization") :(before "End Mu Types Initialization")
// A more complex example container, containing another container as one of // A more complex example container, containing another container as one of
@ -40,13 +40,13 @@ get_or_insert(Type, point_number); // initialize
get(Type, point_number).kind = CONTAINER; get(Type, point_number).kind = CONTAINER;
get(Type, point_number).name = "point-number"; get(Type, point_number).name = "point-number";
get(Type, point_number).elements.push_back(reagent("xy:point")); get(Type, point_number).elements.push_back(reagent("xy:point"));
get(Type, point_number).elements.push_back(reagent("z:number")); get(Type, point_number).elements.push_back(reagent("z:num"));
:(scenario copy_handles_nested_container_elements) :(scenario copy_handles_nested_container_elements)
def main [ def main [
12:number <- copy 34 12:num <- copy 34
13:number <- copy 35 13:num <- copy 35
14:number <- copy 36 14:num <- copy 36
15:point-number <- copy 12:point-number/unsafe 15:point-number <- copy 12:point-number/unsafe
] ]
+mem: storing 36 in location 17 +mem: storing 36 in location 17
@ -57,8 +57,8 @@ def main [
3:point <- f 2 3:point <- f 2
] ]
def f [ def f [
12:number <- next-ingredient 12:num <- next-ingredient
13:number <- copy 35 13:num <- copy 35
return 12:point/raw return 12:point/raw
] ]
+run: result 0 is [2, 35] +run: result 0 is [2, 35]
@ -70,24 +70,24 @@ def f [
:(scenario compare_multiple_locations) :(scenario compare_multiple_locations)
def main [ def main [
1:number <- copy 34 # first 1:num <- copy 34 # first
2:number <- copy 35 2:num <- copy 35
3:number <- copy 36 3:num <- copy 36
4:number <- copy 34 # second 4:num <- copy 34 # second
5:number <- copy 35 5:num <- copy 35
6:number <- copy 36 6:num <- copy 36
7:boolean <- equal 1:point-number/raw, 4:point-number/unsafe 7:boolean <- equal 1:point-number/raw, 4:point-number/unsafe
] ]
+mem: storing 1 in location 7 +mem: storing 1 in location 7
:(scenario compare_multiple_locations_2) :(scenario compare_multiple_locations_2)
def main [ def main [
1:number <- copy 34 # first 1:num <- copy 34 # first
2:number <- copy 35 2:num <- copy 35
3:number <- copy 36 3:num <- copy 36
4:number <- copy 34 # second 4:num <- copy 34 # second
5:number <- copy 35 5:num <- copy 35
6:number <- copy 37 # different 6:num <- copy 37 # different
7:boolean <- equal 1:point-number/raw, 4:point-number/unsafe 7:boolean <- equal 1:point-number/raw, 4:point-number/unsafe
] ]
+mem: storing 0 in location 7 +mem: storing 0 in location 7
@ -213,7 +213,7 @@ void compute_container_sizes(const type_tree* type, set<type_tree>& pending_meta
} }
else if (type->left->name == "array") { else if (type->left->name == "array") {
const type_tree* element_type = type->right; const type_tree* element_type = type->right;
// hack: support both array:number:3 and array:address:number // hack: support both array:num:3 and array:address:num
if (!element_type->atom && element_type->right && element_type->right->atom && is_integer(element_type->right->name)) if (!element_type->atom && element_type->right && element_type->right->atom && is_integer(element_type->right->name))
element_type = element_type->left; element_type = element_type->left;
compute_container_sizes(element_type, pending_metadata); compute_container_sizes(element_type, pending_metadata);
@ -274,9 +274,9 @@ bool matches(const type_tree* a, const type_tree* b) {
:(scenario stash_container) :(scenario stash_container)
def main [ def main [
1:number <- copy 34 # first 1:num <- copy 34 # first
2:number <- copy 35 2:num <- copy 35
3:number <- copy 36 3:num <- copy 36
stash [foo:], 1:point-number/raw stash [foo:], 1:point-number/raw
] ]
+app: foo: 34 35 36 +app: foo: 34 35 36
@ -313,7 +313,7 @@ void test_container_sizes_nested() {
void test_container_sizes_recursive() { void test_container_sizes_recursive() {
// define a container containing an address to itself // define a container containing an address to itself
run("container foo [\n" run("container foo [\n"
" x:number\n" " x:num\n"
" y:address:foo\n" " y:address:foo\n"
"]\n"); "]\n");
reagent r("x:foo"); reagent r("x:foo");
@ -399,9 +399,9 @@ void test_container_sizes_from_repeated_address_and_array_types() {
:(scenario get) :(scenario get)
def main [ def main [
12:number <- copy 34 12:num <- copy 34
13:number <- copy 35 13:num <- copy 35
15:number <- get 12:point/raw, 1:offset # unsafe 15:num <- get 12:point/raw, 1:offset # unsafe
] ]
+mem: storing 35 in location 15 +mem: storing 35 in location 15
@ -491,19 +491,19 @@ const reagent element_type(const type_tree* type, int offset_value) {
:(scenario get_handles_nested_container_elements) :(scenario get_handles_nested_container_elements)
def main [ def main [
12:number <- copy 34 12:num <- copy 34
13:number <- copy 35 13:num <- copy 35
14:number <- copy 36 14:num <- copy 36
15:number <- get 12:point-number/raw, 1:offset # unsafe 15:num <- get 12:point-number/raw, 1:offset # unsafe
] ]
+mem: storing 36 in location 15 +mem: storing 36 in location 15
:(scenario get_out_of_bounds) :(scenario get_out_of_bounds)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
12:number <- copy 34 12:num <- copy 34
13:number <- copy 35 13:num <- copy 35
14:number <- copy 36 14:num <- copy 36
get 12:point-number/raw, 2:offset # point-number occupies 3 locations but has only 2 fields; out of bounds get 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' +error: main: invalid offset '2' for 'point-number'
@ -511,9 +511,9 @@ def main [
:(scenario get_out_of_bounds_2) :(scenario get_out_of_bounds_2)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
12:number <- copy 34 12:num <- copy 34
13:number <- copy 35 13:num <- copy 35
14:number <- copy 36 14:num <- copy 36
get 12:point-number/raw, -1:offset get 12:point-number/raw, -1:offset
] ]
+error: main: invalid offset '-1' for 'point-number' +error: main: invalid offset '-1' for 'point-number'
@ -521,10 +521,10 @@ def main [
:(scenario get_product_type_mismatch) :(scenario get_product_type_mismatch)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
12:number <- copy 34 12:num <- copy 34
13:number <- copy 35 13:num <- copy 35
14:number <- copy 36 14:num <- copy 36
15:address:number <- get 12:point-number/raw, 1:offset 15:address:num <- get 12:point-number/raw, 1:offset
] ]
+error: main: 'get 12:point-number/raw, 1:offset' should write to number but '15' has type (address number) +error: main: 'get 12:point-number/raw, 1:offset' should write to number but '15' has type (address number)
@ -532,8 +532,8 @@ def main [
:(scenario get_without_product) :(scenario get_without_product)
def main [ def main [
12:number <- copy 34 12:num <- copy 34
13:number <- copy 35 13:num <- copy 35
get 12:point/raw, 1:offset # unsafe get 12:point/raw, 1:offset # unsafe
] ]
# just don't die # just don't die
@ -542,8 +542,8 @@ def main [
:(scenario put) :(scenario put)
def main [ def main [
12:number <- copy 34 12:num <- copy 34
13:number <- copy 35 13:num <- copy 35
$clear-trace $clear-trace
12:point <- put 12:point, 1:offset, 36 12:point <- put 12:point, 1:offset, 36
] ]
@ -643,8 +643,8 @@ def main [
:(scenarios load) :(scenarios load)
:(scenario container) :(scenario container)
container foo [ container foo [
x:number x:num
y:number y:num
] ]
+parse: --- defining container foo +parse: --- defining container foo
+parse: element: {x: "number"} +parse: element: {x: "number"}
@ -652,12 +652,12 @@ container foo [
:(scenario container_use_before_definition) :(scenario container_use_before_definition)
container foo [ container foo [
x:number x:num
y:bar y:bar
] ]
container bar [ container bar [
x:number x:num
y:number y:num
] ]
+parse: --- defining container foo +parse: --- defining container foo
+parse: type number: 1000 +parse: type number: 1000
@ -675,17 +675,17 @@ container bar [
:(scenarios run) :(scenarios run)
:(scenario container_extend) :(scenario container_extend)
container foo [ container foo [
x:number x:num
] ]
# add to previous definition # add to previous definition
container foo [ container foo [
y:number y:num
] ]
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:number <- copy 35 2:num <- copy 35
3:number <- get 1:foo, 0:offset 3:num <- get 1:foo, 0:offset
4:number <- get 1:foo, 1:offset 4:num <- get 1:foo, 1:offset
] ]
+mem: storing 34 in location 3 +mem: storing 34 in location 3
+mem: storing 35 in location 4 +mem: storing 35 in location 4
@ -741,6 +741,7 @@ void insert_container(const string& command, kind_of_type kind, istream& in) {
break; break;
} }
info.elements.push_back(reagent(element)); info.elements.push_back(reagent(element));
expand_type_abbreviations(info.elements.back().type); // todo: use abbreviation before declaration
replace_unknown_types_with_unique_ordinals(info.elements.back().type, info); replace_unknown_types_with_unique_ordinals(info.elements.back().type, info);
trace(9993, "parse") << " element: " << to_string(info.elements.back()) << end(); trace(9993, "parse") << " element: " << to_string(info.elements.back()) << end();
// End Load Container Element Definition // End Load Container Element Definition
@ -777,7 +778,7 @@ void skip_bracket(istream& in, string message) {
:(scenario multi_word_line_in_container_declaration) :(scenario multi_word_line_in_container_declaration)
% Hide_errors = true; % Hide_errors = true;
container foo [ container foo [
x:number y:number x:num y:num
] ]
+error: container 'foo' contains multiple elements on a single line. Containers and exclusive containers must only contain elements, one to a line, no code. +error: container 'foo' contains multiple elements on a single line. Containers and exclusive containers must only contain elements, one to a line, no code.
@ -789,7 +790,7 @@ container bar [
x:foo x:foo
] ]
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:foo <- get 1:bar/unsafe, 0:offset 2:foo <- get 1:bar/unsafe, 0:offset
] ]
+mem: storing 34 in location 2 +mem: storing 34 in location 2
@ -817,14 +818,14 @@ assert(Next_type_ordinal < 1000);
void test_error_on_transform_all_between_container_definition_and_extension() { void test_error_on_transform_all_between_container_definition_and_extension() {
// define a container // define a container
run("container foo [\n" run("container foo [\n"
" a:number\n" " a:num\n"
"]\n"); "]\n");
// try to extend the container after transform // try to extend the container after transform
transform_all(); transform_all();
CHECK_TRACE_DOESNT_CONTAIN_ERROR(); CHECK_TRACE_DOESNT_CONTAIN_ERROR();
Hide_errors = true; Hide_errors = true;
run("container foo [\n" run("container foo [\n"
" b:number\n" " b:num\n"
"]\n"); "]\n");
CHECK_TRACE_CONTAINS_ERROR(); CHECK_TRACE_CONTAINS_ERROR();
} }
@ -845,7 +846,7 @@ def main [
1:bar <- copy 0/unsafe 1:bar <- copy 0/unsafe
] ]
container bar [ container bar [
x:number x:num
] ]
$error: 0 $error: 0
@ -887,16 +888,16 @@ void check_or_set_invalid_types(type_tree* type, const string& block, const stri
:(scenario container_unknown_field) :(scenario container_unknown_field)
% Hide_errors = true; % Hide_errors = true;
container foo [ container foo [
x:number x:num
y:bar y:bar
] ]
+error: foo: unknown type in y +error: foo: unknown type in y
:(scenario read_container_with_bracket_in_comment) :(scenario read_container_with_bracket_in_comment)
container foo [ container foo [
x:number x:num
# ']' in comment # ']' in comment
y:number y:num
] ]
+parse: --- defining container foo +parse: --- defining container foo
+parse: element: {x: "number"} +parse: element: {x: "number"}

View File

@ -2,8 +2,8 @@
:(scenario merge) :(scenario merge)
container foo [ container foo [
x:number x:num
y:number y:num
] ]
def main [ def main [
1:foo <- merge 3, 4 1:foo <- merge 3, 4
@ -212,9 +212,9 @@ void check_merge_call(const vector<reagent>& ingredients, const reagent& product
:(scenario merge_check_product) :(scenario merge_check_product)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:number <- merge 3 1:num <- merge 3
] ]
+error: main: 'merge' should yield a container in '1:number <- merge 3' +error: main: 'merge' should yield a container in '1:num <- merge 3'
:(before "End Includes") :(before "End Includes")
#include <stack> #include <stack>

View File

@ -9,7 +9,7 @@
:(scenario create_array) :(scenario create_array)
def main [ def main [
# create an array occupying locations 1 (for the size) and 2-4 (for the elements) # create an array occupying locations 1 (for the size) and 2-4 (for the elements)
1:array:number:3 <- create-array 1:array:num:3 <- create-array
] ]
+run: creating array of size 4 +run: creating array of size 4
@ -77,11 +77,11 @@ case CREATE_ARRAY: {
# 'static' array, and one without a 'dynamic' array since it can contain # 'static' array, and one without a 'dynamic' array since it can contain
# arrays of many different sizes. # arrays of many different sizes.
def main [ def main [
1:array:number:3 <- create-array 1:array:num:3 <- create-array
2:number <- copy 14 2:num <- copy 14
3:number <- copy 15 3:num <- copy 15
4:number <- copy 16 4:num <- copy 16
5:array:number <- copy 1:array:number:3 5:array:num <- copy 1:array:num:3
] ]
+mem: storing 3 in location 5 +mem: storing 3 in location 5
+mem: storing 14 in location 6 +mem: storing 14 in location 6
@ -90,11 +90,11 @@ def main [
:(scenario stash_array) :(scenario stash_array)
def main [ def main [
1:array:number:3 <- create-array 1:array:num:3 <- create-array
2:number <- copy 14 2:num <- copy 14
3:number <- copy 15 3:num <- copy 15
4:number <- copy 16 4:num <- copy 16
stash [foo:], 1:array:number:3 stash [foo:], 1:array:num:3
] ]
+app: foo: 3 14 15 16 +app: foo: 3 14 15 16
@ -120,14 +120,14 @@ if (x.type && !x.type->atom && x.type->left->value == get(Type_ordinal, "array")
:(scenario container_permits_static_array_element) :(scenario container_permits_static_array_element)
container foo [ container foo [
x:array:number:3 x:array:num:3
] ]
$error: 0 $error: 0
:(scenario container_disallows_dynamic_array_element) :(scenario container_disallows_dynamic_array_element)
% Hide_errors = true; % Hide_errors = true;
container foo [ container foo [
x:array:number x:array:num
] ]
+error: container 'foo' cannot determine size of element 'x' +error: container 'foo' cannot determine size of element 'x'
@ -141,12 +141,12 @@ if (current_call().running_step_index < SIZE(get(Recipe, current_call().running_
:(scenario merge_static_array_into_container) :(scenario merge_static_array_into_container)
container foo [ container foo [
x:number x:num
y:array:number:3 y:array:num:3
] ]
def main [ def main [
1:array:number:3 <- create-array 1:array:num:3 <- create-array
10:foo <- merge 34, 1:array:number:3 10:foo <- merge 34, 1:array:num:3
] ]
# no errors # no errors
@ -172,11 +172,11 @@ def main [
:(scenario code_inside_container) :(scenario code_inside_container)
% Hide_errors = true; % Hide_errors = true;
container card [ container card [
rank:number <- next-ingredient rank:num <- next-ingredient
] ]
def foo [ def foo [
1:card <- merge 3 1:card <- merge 3
2:number <- get 1:card rank:offset 2:num <- get 1:card rank:offset
] ]
# shouldn't die # shouldn't die
@ -184,32 +184,32 @@ def foo [
:(scenario index) :(scenario index)
def main [ def main [
1:array:number:3 <- create-array 1:array:num:3 <- create-array
2:number <- copy 14 2:num <- copy 14
3:number <- copy 15 3:num <- copy 15
4:number <- copy 16 4:num <- copy 16
5:number <- index 1:array:number:3, 0 5:num <- index 1:array:num:3, 0
] ]
+mem: storing 14 in location 5 +mem: storing 14 in location 5
:(scenario index_compound_element) :(scenario index_compound_element)
def main [ def main [
{1: (array (address number) 3)} <- create-array {1: (array (address number) 3)} <- create-array
2:number <- copy 14 2:num <- copy 14
3:number <- copy 15 3:num <- copy 15
4:number <- copy 16 4:num <- copy 16
5:address:number <- index {1: (array (address number) 3)}, 0 5:address:num <- index {1: (array (address number) 3)}, 0
] ]
+mem: storing 14 in location 5 +mem: storing 14 in location 5
:(scenario index_direct_offset) :(scenario index_direct_offset)
def main [ def main [
1:array:number:3 <- create-array 1:array:num:3 <- create-array
2:number <- copy 14 2:num <- copy 14
3:number <- copy 15 3:num <- copy 15
4:number <- copy 16 4:num <- copy 16
5:number <- copy 0 5:num <- copy 0
6:number <- index 1:array:number, 5:number 6:num <- index 1:array:num, 5:num
] ]
+mem: storing 14 in location 6 +mem: storing 14 in location 6
@ -278,7 +278,7 @@ case INDEX: {
:(code) :(code)
type_tree* copy_array_element(const type_tree* type) { type_tree* copy_array_element(const type_tree* type) {
assert(type->right); assert(type->right);
// hack: don't require parens for either array:number:3 array:address:number // hack: don't require parens for either array:num:3 array:address:num
if (!type->right->atom && type->right->right && type->right->right->atom && is_integer(type->right->right->name)) if (!type->right->atom && type->right->right && type->right->right->atom && is_integer(type->right->right->name))
return new type_tree(*type->right->left); return new type_tree(*type->right->left);
return new type_tree(*type->right); return new type_tree(*type->right);
@ -300,7 +300,7 @@ void test_array_length_compound() {
put(Memory, 2, 14); put(Memory, 2, 14);
put(Memory, 3, 15); put(Memory, 3, 15);
put(Memory, 4, 16); put(Memory, 4, 16);
reagent x("1:array:address:number"); // 3 types, but not a static array reagent x("1:array:address:num"); // 3 types, but not a static array
populate_value(x); populate_value(x);
CHECK_EQ(array_length(x), 3); CHECK_EQ(array_length(x), 3);
} }
@ -308,27 +308,27 @@ void test_array_length_compound() {
:(scenario index_out_of_bounds) :(scenario index_out_of_bounds)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:array:number:3 <- create-array 1:array:num:3 <- create-array
2:number <- copy 14 2:num <- copy 14
3:number <- copy 15 3:num <- copy 15
4:number <- copy 16 4:num <- copy 16
5:number <- copy 14 5:num <- copy 14
6:number <- copy 15 6:num <- copy 15
7:number <- copy 16 7:num <- copy 16
index 1:array:number:3, 4 # less than size of array in locations, but larger than its length in elements index 1:array:num:3, 4 # less than size of array in locations, but larger than its length in elements
] ]
+error: main: invalid index 4 in 'index 1:array:number:3, 4' +error: main: invalid index 4 in 'index 1:array:num:3, 4'
:(scenario index_out_of_bounds_2) :(scenario index_out_of_bounds_2)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:array:point:3 <- create-array 1:array:point:3 <- create-array
2:number <- copy 14 2:num <- copy 14
3:number <- copy 15 3:num <- copy 15
4:number <- copy 16 4:num <- copy 16
5:number <- copy 14 5:num <- copy 14
6:number <- copy 15 6:num <- copy 15
7:number <- copy 16 7:num <- copy 16
index 1:array:point, -1 index 1:array:point, -1
] ]
+error: main: invalid index -1 in 'index 1:array:point, -1' +error: main: invalid index -1 in 'index 1:array:point, -1'
@ -337,25 +337,25 @@ def main [
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:array:point:3 <- create-array 1:array:point:3 <- create-array
2:number <- copy 14 2:num <- copy 14
3:number <- copy 15 3:num <- copy 15
4:number <- copy 16 4:num <- copy 16
5:number <- copy 14 5:num <- copy 14
6:number <- copy 15 6:num <- copy 15
7:number <- copy 16 7:num <- copy 16
9:number <- index 1:array:point, 0 9:num <- index 1:array:point, 0
] ]
+error: main: 'index' on '1:array:point' can't be saved in '9:number'; type should be 'point' +error: main: 'index' on '1:array:point' can't be saved in '9:num'; type should be 'point'
//: we might want to call 'index' without saving the results, say in a sandbox //: we might want to call 'index' without saving the results, say in a sandbox
:(scenario index_without_product) :(scenario index_without_product)
def main [ def main [
1:array:number:3 <- create-array 1:array:num:3 <- create-array
2:number <- copy 14 2:num <- copy 14
3:number <- copy 15 3:num <- copy 15
4:number <- copy 16 4:num <- copy 16
index 1:array:number:3, 0 index 1:array:num:3, 0
] ]
# just don't die # just don't die
@ -363,11 +363,11 @@ def main [
:(scenario put_index) :(scenario put_index)
def main [ def main [
1:array:number:3 <- create-array 1:array:num:3 <- create-array
2:number <- copy 14 2:num <- copy 14
3:number <- copy 15 3:num <- copy 15
4:number <- copy 16 4:num <- copy 16
1:array:number <- put-index 1:array:number, 1, 34 1:array:num <- put-index 1:array:num, 1, 34
] ]
+mem: storing 34 in location 3 +mem: storing 34 in location 3
@ -445,12 +445,12 @@ case PUT_INDEX: {
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:array:point:3 <- create-array 1:array:point:3 <- create-array
2:number <- copy 14 2:num <- copy 14
3:number <- copy 15 3:num <- copy 15
4:number <- copy 16 4:num <- copy 16
5:number <- copy 14 5:num <- copy 14
6:number <- copy 15 6:num <- copy 15
7:number <- copy 16 7:num <- copy 16
8:point <- merge 34, 35 8:point <- merge 34, 35
1:array:point <- put-index 1:array:point, 4, 8:point # '4' is less than size of array in locations, but larger than its length in elements 1:array:point <- put-index 1:array:point, 4, 8:point # '4' is less than size of array in locations, but larger than its length in elements
] ]
@ -460,12 +460,12 @@ def main [
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:array:point:3 <- create-array 1:array:point:3 <- create-array
2:number <- copy 14 2:num <- copy 14
3:number <- copy 15 3:num <- copy 15
4:number <- copy 16 4:num <- copy 16
5:number <- copy 14 5:num <- copy 14
6:number <- copy 15 6:num <- copy 15
7:number <- copy 16 7:num <- copy 16
8:point <- merge 34, 35 8:point <- merge 34, 35
1:array:point <- put-index 1:array:point, -1, 8:point 1:array:point <- put-index 1:array:point, -1, 8:point
] ]
@ -476,20 +476,20 @@ def main [
def main [ def main [
local-scope local-scope
load-ingredients load-ingredients
1:array:number:3 <- create-array 1:array:num:3 <- create-array
4:array:number:3 <- put-index 1:array:number:3, 0, 34 4:array:num:3 <- put-index 1:array:num:3, 0, 34
] ]
+error: main: product of 'put-index' must be first ingredient '1:array:number:3', but got '4:array:number:3' +error: main: product of 'put-index' must be first ingredient '1:array:num:3', but got '4:array:num:3'
//:: compute the length of an array //:: compute the length of an array
:(scenario array_length) :(scenario array_length)
def main [ def main [
1:array:number:3 <- create-array 1:array:num:3 <- create-array
2:number <- copy 14 2:num <- copy 14
3:number <- copy 15 3:num <- copy 15
4:number <- copy 16 4:num <- copy 16
5:number <- length 1:array:number:3 5:num <- length 1:array:num:3
] ]
+mem: storing 3 in location 5 +mem: storing 3 in location 5

View File

@ -11,7 +11,7 @@ type_ordinal tmp = put(Type_ordinal, "number-or-point", Next_type_ordinal++);
get_or_insert(Type, tmp); // initialize get_or_insert(Type, tmp); // initialize
get(Type, tmp).kind = EXCLUSIVE_CONTAINER; get(Type, tmp).kind = EXCLUSIVE_CONTAINER;
get(Type, tmp).name = "number-or-point"; get(Type, tmp).name = "number-or-point";
get(Type, tmp).elements.push_back(reagent("i:number")); get(Type, tmp).elements.push_back(reagent("i:num"));
get(Type, tmp).elements.push_back(reagent("p:point")); get(Type, tmp).elements.push_back(reagent("p:point"));
} }
@ -21,9 +21,9 @@ get(Type, tmp).elements.push_back(reagent("p:point"));
:(scenario copy_exclusive_container) :(scenario copy_exclusive_container)
# Copying exclusive containers copies all their contents and an extra location for the tag. # Copying exclusive containers copies all their contents and an extra location for the tag.
def main [ def main [
1:number <- copy 1 # 'point' variant 1:num <- copy 1 # 'point' variant
2:number <- copy 34 2:num <- copy 34
3:number <- copy 35 3:num <- copy 35
4:number-or-point <- copy 1:number-or-point/unsafe 4:number-or-point <- copy 1:number-or-point/unsafe
] ]
+mem: storing 1 in location 4 +mem: storing 1 in location 4
@ -70,9 +70,9 @@ put(Type_ordinal, "variant", 0);
:(scenario maybe_convert) :(scenario maybe_convert)
def main [ def main [
12:number <- copy 1 12:num <- copy 1
13:number <- copy 35 13:num <- copy 35
14:number <- copy 36 14:num <- copy 36
20:point, 22:boolean <- maybe-convert 12:number-or-point/unsafe, 1:variant 20:point, 22:boolean <- maybe-convert 12:number-or-point/unsafe, 1:variant
] ]
# boolean # boolean
@ -83,10 +83,10 @@ def main [
:(scenario maybe_convert_fail) :(scenario maybe_convert_fail)
def main [ def main [
12:number <- copy 1 12:num <- copy 1
13:number <- copy 35 13:num <- copy 35
14:number <- copy 36 14:num <- copy 36
20:number, 21:boolean <- maybe-convert 12:number-or-point/unsafe, 0:variant 20:num, 21:boolean <- maybe-convert 12:number-or-point/unsafe, 0:variant
] ]
# boolean # boolean
+mem: storing 0 in location 21 +mem: storing 0 in location 21
@ -200,18 +200,18 @@ const reagent variant_type(const type_tree* type, int tag) {
:(scenario maybe_convert_product_type_mismatch) :(scenario maybe_convert_product_type_mismatch)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
12:number <- copy 1 12:num <- copy 1
13:number <- copy 35 13:num <- copy 35
14:number <- copy 36 14:num <- copy 36
20:number, 21:boolean <- maybe-convert 12:number-or-point/unsafe, 1:variant 20:num, 21:boolean <- maybe-convert 12:number-or-point/unsafe, 1:variant
] ]
+error: main: 'maybe-convert 12:number-or-point/unsafe, 1:variant' should write to point but '20' has type number +error: main: 'maybe-convert 12:number-or-point/unsafe, 1:variant' should write to point but '20' has type number
:(scenario maybe_convert_dummy_product) :(scenario maybe_convert_dummy_product)
def main [ def main [
12:number <- copy 1 12:num <- copy 1
13:number <- copy 35 13:num <- copy 35
14:number <- copy 36 14:num <- copy 36
_, 21:boolean <- maybe-convert 12:number-or-point/unsafe, 1:variant _, 21:boolean <- maybe-convert 12:number-or-point/unsafe, 1:variant
] ]
$error: 0 $error: 0
@ -220,8 +220,8 @@ $error: 0
:(scenario exclusive_container) :(scenario exclusive_container)
exclusive-container foo [ exclusive-container foo [
x:number x:num
y:number y:num
] ]
+parse: --- defining exclusive-container foo +parse: --- defining exclusive-container foo
+parse: element: {x: "number"} +parse: element: {x: "number"}
@ -237,27 +237,27 @@ else if (command == "exclusive-container") {
:(scenario exclusive_container_contains_array) :(scenario exclusive_container_contains_array)
exclusive-container foo [ exclusive-container foo [
x:array:number:3 x:array:num:3
] ]
$error: 0 $error: 0
:(scenario exclusive_container_disallows_dynamic_array_element) :(scenario exclusive_container_disallows_dynamic_array_element)
% Hide_errors = true; % Hide_errors = true;
exclusive-container foo [ exclusive-container foo [
x:array:number x:array:num
] ]
+error: container 'foo' cannot determine size of element 'x' +error: container 'foo' cannot determine size of element 'x'
//:: To construct exclusive containers out of variant types, use 'merge'. //:: To construct exclusive containers out of variant types, use 'merge'.
:(scenario lift_to_exclusive_container) :(scenario lift_to_exclusive_container)
exclusive-container foo [ exclusive-container foo [
x:number x:num
y:number y:num
] ]
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:foo <- merge 0/x, 1:number # tag must be a literal when merging exclusive containers 2:foo <- merge 0/x, 1:num # tag must be a literal when merging exclusive containers
4:foo <- merge 1/y, 1:number 4:foo <- merge 1/y, 1:num
] ]
+mem: storing 0 in location 2 +mem: storing 0 in location 2
+mem: storing 34 in location 3 +mem: storing 34 in location 3
@ -268,11 +268,11 @@ def main [
:(scenario merge_handles_exclusive_container) :(scenario merge_handles_exclusive_container)
exclusive-container foo [ exclusive-container foo [
x:number x:num
y:bar y:bar
] ]
container bar [ container bar [
z:number z:num
] ]
def main [ def main [
1:foo <- merge 0/x, 34 1:foo <- merge 0/x, 34
@ -284,29 +284,29 @@ $error: 0
:(scenario merge_requires_literal_tag_for_exclusive_container) :(scenario merge_requires_literal_tag_for_exclusive_container)
% Hide_errors = true; % Hide_errors = true;
exclusive-container foo [ exclusive-container foo [
x:number x:num
y:bar y:bar
] ]
container bar [ container bar [
z:number z:num
] ]
def main [ def main [
1:number <- copy 0 1:num <- copy 0
2:foo <- merge 1:number, 34 2:foo <- merge 1:num, 34
] ]
+error: main: ingredient 0 of 'merge' should be a literal, for the tag of exclusive-container 'foo' in '2:foo <- merge 1:number, 34' +error: main: ingredient 0 of 'merge' should be a literal, for the tag of exclusive-container 'foo' in '2:foo <- merge 1:num, 34'
:(scenario merge_handles_exclusive_container_inside_exclusive_container) :(scenario merge_handles_exclusive_container_inside_exclusive_container)
exclusive-container foo [ exclusive-container foo [
x:number x:num
y:bar y:bar
] ]
exclusive-container bar [ exclusive-container bar [
a:number a:num
b:number b:num
] ]
def main [ def main [
1:number <- copy 0 1:num <- copy 0
2:bar <- merge 0/a, 34 2:bar <- merge 0/a, 34
4:foo <- merge 1/y, 2:bar 4:foo <- merge 1/y, 2:bar
] ]
@ -342,12 +342,12 @@ case EXCLUSIVE_CONTAINER: {
:(scenario merge_check_container_containing_exclusive_container) :(scenario merge_check_container_containing_exclusive_container)
container foo [ container foo [
x:number x:num
y:bar y:bar
] ]
exclusive-container bar [ exclusive-container bar [
x:number x:num
y:number y:num
] ]
def main [ def main [
1:foo <- merge 23, 1/y, 34 1:foo <- merge 23, 1/y, 34
@ -360,12 +360,12 @@ $error: 0
:(scenario merge_check_container_containing_exclusive_container_2) :(scenario merge_check_container_containing_exclusive_container_2)
% Hide_errors = true; % Hide_errors = true;
container foo [ container foo [
x:number x:num
y:bar y:bar
] ]
exclusive-container bar [ exclusive-container bar [
x:number x:num
y:number y:num
] ]
def main [ def main [
1:foo <- merge 23, 1/y, 34, 35 1:foo <- merge 23, 1/y, 34, 35
@ -374,12 +374,12 @@ def main [
:(scenario merge_check_exclusive_container_containing_container) :(scenario merge_check_exclusive_container_containing_container)
exclusive-container foo [ exclusive-container foo [
x:number x:num
y:bar y:bar
] ]
container bar [ container bar [
x:number x:num
y:number y:num
] ]
def main [ def main [
1:foo <- merge 1/y, 23, 34 1:foo <- merge 1/y, 23, 34
@ -391,12 +391,12 @@ $error: 0
:(scenario merge_check_exclusive_container_containing_container_2) :(scenario merge_check_exclusive_container_containing_container_2)
exclusive-container foo [ exclusive-container foo [
x:number x:num
y:bar y:bar
] ]
container bar [ container bar [
x:number x:num
y:number y:num
] ]
def main [ def main [
1:foo <- merge 0/x, 23 1:foo <- merge 0/x, 23
@ -406,12 +406,12 @@ $error: 0
:(scenario merge_check_exclusive_container_containing_container_3) :(scenario merge_check_exclusive_container_containing_container_3)
% Hide_errors = true; % Hide_errors = true;
exclusive-container foo [ exclusive-container foo [
x:number x:num
y:bar y:bar
] ]
container bar [ container bar [
x:number x:num
y:number y:num
] ]
def main [ def main [
1:foo <- merge 1/y, 23 1:foo <- merge 1/y, 23
@ -420,12 +420,12 @@ def main [
:(scenario merge_check_exclusive_container_containing_container_4) :(scenario merge_check_exclusive_container_containing_container_4)
exclusive-container foo [ exclusive-container foo [
x:number x:num
y:bar y:bar
] ]
container bar [ container bar [
a:number a:num
b:number b:num
] ]
def main [ def main [
1:bar <- merge 23, 24 1:bar <- merge 23, 24
@ -450,18 +450,18 @@ if (current_step_index() < SIZE(Current_routine->steps())
:(scenario merge_exclusive_container_with_mismatched_sizes) :(scenario merge_exclusive_container_with_mismatched_sizes)
container foo [ container foo [
x:number x:num
y:number y:num
] ]
exclusive-container bar [ exclusive-container bar [
x:number x:num
y:foo y:foo
] ]
def main [ def main [
1:number <- copy 34 1:num <- copy 34
2:number <- copy 35 2:num <- copy 35
3:bar <- merge 0/x, 1:number 3:bar <- merge 0/x, 1:num
6:bar <- merge 1/foo, 1:number, 2:number 6:bar <- merge 1/foo, 1:num, 2:num
] ]
+mem: storing 0 in location 3 +mem: storing 0 in location 3
+mem: storing 34 in location 4 +mem: storing 34 in location 4

View File

@ -45,7 +45,7 @@
//: sufficient space to hold that type, and returns an address (bookmark) //: sufficient space to hold that type, and returns an address (bookmark)
//: to the allocated space. //: to the allocated space.
//: //:
//: x:address:number <- new number:type //: x:address:num <- new number:type
//: //:
//: +------------+ //: +------------+
//: x -------> | number | //: x -------> | number |
@ -83,7 +83,7 @@
//: The refcount of 1 here indicates that this number has one bookmark //: The refcount of 1 here indicates that this number has one bookmark
//: outstanding. If you then make a copy of x, the refcount increments: //: outstanding. If you then make a copy of x, the refcount increments:
//: //:
//: y:address:number <- copy x //: y:address:num <- copy x
//: //:
//: x ---+ +---+------------+ //: x ---+ +---+------------+
//: +---> | 2 | number | //: +---> | 2 | number |
@ -123,15 +123,15 @@
# call 'new' two times with identical types without modifying the results; you # call 'new' two times with identical types without modifying the results; you
# should get back different results # should get back different results
def main [ def main [
1:address:number/raw <- new number:type 1:address:num/raw <- new number:type
2:address:number/raw <- new number:type 2:address:num/raw <- new number:type
3:boolean/raw <- equal 1:address:number/raw, 2:address:number/raw 3:boolean/raw <- equal 1:address:num/raw, 2:address:num/raw
] ]
+mem: storing 0 in location 3 +mem: storing 0 in location 3
:(scenario dilated_reagent_with_new) :(scenario dilated_reagent_with_new)
def main [ def main [
1:address:address:number <- new {(address number): type} 1:address:address:num <- new {(address number): type}
] ]
+new: size of ("address" "number") is 1 +new: size of ("address" "number") is 1
@ -341,15 +341,15 @@ void ensure_space(int size) {
% Memory_allocated_until = 10; % Memory_allocated_until = 10;
% put(Memory, Memory_allocated_until, 1); % put(Memory, Memory_allocated_until, 1);
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
] ]
+mem: storing 0 in location 10 +mem: storing 0 in location 10
:(scenario new_array) :(scenario new_array)
def main [ def main [
1:address:array:number/raw <- new number:type, 5 1:address:array:num/raw <- new number:type, 5
2:address:number/raw <- new number:type 2:address:num/raw <- new number:type
3:number/raw <- subtract 2:address:number/raw, 1:address:array:number/raw 3:num/raw <- subtract 2:address:num/raw, 1:address:array:num/raw
] ]
+run: {1: ("address" "array" "number"), "raw": ()} <- new {number: "type"}, {5: "literal"} +run: {1: ("address" "array" "number"), "raw": ()} <- new {number: "type"}, {5: "literal"}
+mem: array length is 5 +mem: array length is 5
@ -358,9 +358,9 @@ def main [
:(scenario new_empty_array) :(scenario new_empty_array)
def main [ def main [
1:address:array:number/raw <- new number:type, 0 1:address:array:num/raw <- new number:type, 0
2:address:number/raw <- new number:type 2:address:num/raw <- new number:type
3:number/raw <- subtract 2:address:number/raw, 1:address:array:number/raw 3:num/raw <- subtract 2:address:num/raw, 1:address:array:num/raw
] ]
+run: {1: ("address" "array" "number"), "raw": ()} <- new {number: "type"}, {0: "literal"} +run: {1: ("address" "array" "number"), "raw": ()} <- new {number: "type"}, {0: "literal"}
+mem: array length is 0 +mem: array length is 0
@ -371,7 +371,7 @@ def main [
:(scenario new_overflow) :(scenario new_overflow)
% Initial_memory_per_routine = 3; // barely enough room for point allocation below % Initial_memory_per_routine = 3; // barely enough room for point allocation below
def main [ def main [
1:address:number/raw <- new number:type 1:address:num/raw <- new number:type
2:address:point/raw <- new point:type # not enough room in initial page 2:address:point/raw <- new point:type # not enough room in initial page
] ]
+new: routine allocated memory from 1000 to 1003 +new: routine allocated memory from 1000 to 1003

View File

@ -25,7 +25,7 @@
//: //:
//: You can also read from the payload in instructions like this: //: You can also read from the payload in instructions like this:
//: //:
//: z:number <- add *x, 1 //: z:num <- add *x, 1
//: //:
//: After this instruction runs the value of z will be 35. //: After this instruction runs the value of z will be 35.
//: //:
@ -34,10 +34,10 @@
:(scenario copy_indirect) :(scenario copy_indirect)
def main [ def main [
1:address:number <- copy 10/unsafe 1:address:num <- copy 10/unsafe
11:number <- copy 34 11:num <- copy 34
# This loads location 1 as an address and looks up *that* location. # This loads location 1 as an address and looks up *that* location.
2:number <- copy 1:address:number/lookup 2:num <- copy 1:address:num/lookup
] ]
# 1 contains 10. Skip refcount and lookup location 11. # 1 contains 10. Skip refcount and lookup location 11.
+mem: storing 34 in location 2 +mem: storing 34 in location 2
@ -49,8 +49,8 @@ canonize(x);
//: 'lookup' property //: 'lookup' property
:(scenario store_indirect) :(scenario store_indirect)
def main [ def main [
1:address:number <- copy 10/unsafe 1:address:num <- copy 10/unsafe
1:address:number/lookup <- copy 34 1:address:num/lookup <- copy 34
] ]
+mem: storing 34 in location 11 +mem: storing 34 in location 11
@ -61,11 +61,11 @@ canonize(x);
:(scenario store_to_0_fails) :(scenario store_to_0_fails)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:address:number <- copy 0 1:address:num <- copy 0
1:address:number/lookup <- copy 34 1:address:num/lookup <- copy 34
] ]
-mem: storing 34 in location 0 -mem: storing 34 in location 0
+error: can't write to location 0 in '1:address:number/lookup <- copy 34' +error: can't write to location 0 in '1:address:num/lookup <- copy 34'
:(code) :(code)
void canonize(reagent& x) { void canonize(reagent& x) {
@ -101,7 +101,7 @@ void lookup_memory_core(reagent& x) {
} }
void test_lookup_address_skips_refcount() { void test_lookup_address_skips_refcount() {
reagent x("*x:address:number"); reagent x("*x:address:num");
x.set_value(34); // unsafe x.set_value(34); // unsafe
put(Memory, 34, 1000); put(Memory, 34, 1000);
lookup_memory(x); lookup_memory(x);
@ -110,7 +110,7 @@ void test_lookup_address_skips_refcount() {
} }
void test_lookup_zero_address_does_not_skip_refcount() { void test_lookup_zero_address_does_not_skip_refcount() {
reagent x("*x:address:number"); reagent x("*x:address:num");
x.set_value(34); // unsafe x.set_value(34); // unsafe
put(Memory, 34, 0); put(Memory, 34, 0);
lookup_memory(x); lookup_memory(x);
@ -185,9 +185,9 @@ void drop_one_lookup(reagent& r) {
def main [ def main [
1:address:point <- copy 10/unsafe 1:address:point <- copy 10/unsafe
# 10 reserved for refcount # 10 reserved for refcount
11:number <- copy 34 11:num <- copy 34
12:number <- copy 35 12:num <- copy 35
2:number <- get 1:address:point/lookup, 0:offset 2:num <- get 1:address:point/lookup, 0:offset
] ]
+mem: storing 34 in location 2 +mem: storing 34 in location 2
@ -195,10 +195,10 @@ def main [
def main [ def main [
1:address:point <- copy 10/unsafe 1:address:point <- copy 10/unsafe
# 10 reserved for refcount # 10 reserved for refcount
11:number <- copy 34 11:num <- copy 34
12:number <- copy 35 12:num <- copy 35
2:address:number <- copy 20/unsafe 2:address:num <- copy 20/unsafe
2:address:number/lookup <- get 1:address:point/lookup, 0:offset 2:address:num/lookup <- get 1:address:point/lookup, 0:offset
] ]
+mem: storing 34 in location 21 +mem: storing 34 in location 21
@ -206,9 +206,9 @@ def main [
def main [ def main [
1:address:point <- copy 10/unsafe 1:address:point <- copy 10/unsafe
# 10 reserved for refcount # 10 reserved for refcount
11:number <- copy 34 11:num <- copy 34
12:number <- copy 35 12:num <- copy 35
2:number <- get 1:address:point/lookup/foo, 0:offset 2:num <- get 1:address:point/lookup/foo, 0:offset
] ]
+mem: storing 34 in location 2 +mem: storing 34 in location 2
@ -223,8 +223,8 @@ canonize(base);
def main [ def main [
1:address:point <- copy 10/unsafe 1:address:point <- copy 10/unsafe
# 10 reserved for refcount # 10 reserved for refcount
11:number <- copy 34 11:num <- copy 34
12:number <- copy 35 12:num <- copy 35
1:address:point/lookup <- put 1:address:point/lookup, 0:offset, 36 1:address:point/lookup <- put 1:address:point/lookup, 0:offset, 36
] ]
+mem: storing 36 in location 11 +mem: storing 36 in location 11
@ -241,8 +241,8 @@ canonize(base);
def main [ def main [
1:address:point <- copy 10/unsafe 1:address:point <- copy 10/unsafe
# 10 reserved for refcount # 10 reserved for refcount
11:number <- copy 34 11:num <- copy 34
12:number <- copy 35 12:num <- copy 35
1:address:point <- put 1:address:point/lookup, x:offset, 36 1:address:point <- put 1:address:point/lookup, x:offset, 36
] ]
+error: main: product of 'put' must be first ingredient '1:address:point/lookup', but got '1:address:point' +error: main: product of 'put' must be first ingredient '1:address:point/lookup', but got '1:address:point'
@ -260,9 +260,9 @@ if (!types_strictly_match(p, i)) {
:(scenario new_error) :(scenario new_error)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:number/raw <- new number:type 1:num/raw <- new number:type
] ]
+error: main: product of 'new' has incorrect type: '1:number/raw <- new number:type' +error: main: product of 'new' has incorrect type: '1:num/raw <- new number:type'
:(after "Update NEW product in Check") :(after "Update NEW product in Check")
canonize_type(product); canonize_type(product);
@ -270,12 +270,12 @@ canonize_type(product);
:(scenario copy_array_indirect) :(scenario copy_array_indirect)
def main [ def main [
# 10 reserved for refcount # 10 reserved for refcount
11:array:number:3 <- create-array 11:array:num:3 <- create-array
12:number <- copy 14 12:num <- copy 14
13:number <- copy 15 13:num <- copy 15
14:number <- copy 16 14:num <- copy 16
1:address:array:number <- copy 10/unsafe 1:address:array:num <- copy 10/unsafe
2:array:number <- copy 1:address:array:number/lookup 2:array:num <- copy 1:address:array:num/lookup
] ]
+mem: storing 3 in location 2 +mem: storing 3 in location 2
+mem: storing 14 in location 3 +mem: storing 14 in location 3
@ -284,9 +284,9 @@ def main [
:(scenario create_array_indirect) :(scenario create_array_indirect)
def main [ def main [
1000:number/raw <- copy 1 # pretend refcount 1000:num/raw <- copy 1 # pretend refcount
1:address:array:number:3 <- copy 1000/unsafe # pretend allocation 1:address:array:num:3 <- copy 1000/unsafe # pretend allocation
1:address:array:number:3/lookup <- create-array 1:address:array:num:3/lookup <- create-array
] ]
+mem: storing 3 in location 1001 +mem: storing 3 in location 1001
@ -298,12 +298,12 @@ canonize(product);
:(scenario index_indirect) :(scenario index_indirect)
def main [ def main [
# 10 reserved for refcount # 10 reserved for refcount
11:array:number:3 <- create-array 11:array:num:3 <- create-array
12:number <- copy 14 12:num <- copy 14
13:number <- copy 15 13:num <- copy 15
14:number <- copy 16 14:num <- copy 16
1:address:array:number <- copy 10/unsafe 1:address:array:num <- copy 10/unsafe
2:number <- index 1:address:array:number/lookup, 1 2:num <- index 1:address:array:num/lookup, 1
] ]
+mem: storing 15 in location 2 +mem: storing 15 in location 2
@ -322,25 +322,25 @@ canonize(index);
:(scenario put_index_indirect) :(scenario put_index_indirect)
def main [ def main [
# 10 reserved for refcount # 10 reserved for refcount
11:array:number:3 <- create-array 11:array:num:3 <- create-array
12:number <- copy 14 12:num <- copy 14
13:number <- copy 15 13:num <- copy 15
14:number <- copy 16 14:num <- copy 16
1:address:array:number <- copy 10/unsafe 1:address:array:num <- copy 10/unsafe
1:address:array:number/lookup <- put-index 1:address:array:number/lookup, 1, 34 1:address:array:num/lookup <- put-index 1:address:array:num/lookup, 1, 34
] ]
+mem: storing 34 in location 13 +mem: storing 34 in location 13
:(scenario put_index_indirect_2) :(scenario put_index_indirect_2)
def main [ def main [
1:array:number:3 <- create-array 1:array:num:3 <- create-array
2:number <- copy 14 2:num <- copy 14
3:number <- copy 15 3:num <- copy 15
4:number <- copy 16 4:num <- copy 16
5:address:number <- copy 10/unsafe 5:address:num <- copy 10/unsafe
# 10 reserved for refcount # 10 reserved for refcount
11:number <- copy 1 11:num <- copy 1
1:array:number:3 <- put-index 1:array:number:3, 5:address:number/lookup, 34 1:array:num:3 <- put-index 1:array:num:3, 5:address:num/lookup, 34
] ]
+mem: storing 34 in location 3 +mem: storing 34 in location 3
@ -348,14 +348,14 @@ def main [
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
# 10 reserved for refcount # 10 reserved for refcount
11:array:number:3 <- create-array 11:array:num:3 <- create-array
12:number <- copy 14 12:num <- copy 14
13:number <- copy 15 13:num <- copy 15
14:number <- copy 16 14:num <- copy 16
1:address:array:number <- copy 10/unsafe 1:address:array:num <- copy 10/unsafe
1:address:array:number <- put-index 1:address:array:number/lookup, 1, 34 1:address:array:num <- put-index 1:address:array:num/lookup, 1, 34
] ]
+error: main: product of 'put-index' must be first ingredient '1:address:array:number/lookup', but got '1:address:array:number' +error: main: product of 'put-index' must be first ingredient '1:address:array:num/lookup', but got '1:address:array:num'
:(before "End PUT_INDEX Product Checks") :(before "End PUT_INDEX Product Checks")
reagent/*copy*/ p = inst.products.at(0); reagent/*copy*/ p = inst.products.at(0);
@ -370,10 +370,10 @@ if (!types_strictly_match(p, i)) {
:(scenario dilated_reagent_in_static_array) :(scenario dilated_reagent_in_static_array)
def main [ def main [
{1: (array (address number) 3)} <- create-array {1: (array (address number) 3)} <- create-array
5:address:number <- new number:type 5:address:num <- new number:type
{1: (array (address number) 3)} <- put-index {1: (array (address number) 3)}, 0, 5:address:number {1: (array (address number) 3)} <- put-index {1: (array (address number) 3)}, 0, 5:address:num
*5:address:number <- copy 34 *5:address:num <- copy 34
6:number <- copy *5:address:number 6:num <- copy *5:address:num
] ]
+run: creating array of size 4 +run: creating array of size 4
+mem: storing 34 in location 6 +mem: storing 34 in location 6
@ -393,12 +393,12 @@ canonize(index);
:(scenario length_indirect) :(scenario length_indirect)
def main [ def main [
# 10 reserved for refcount # 10 reserved for refcount
11:array:number:3 <- create-array 11:array:num:3 <- create-array
12:number <- copy 14 12:num <- copy 14
13:number <- copy 15 13:num <- copy 15
14:number <- copy 16 14:num <- copy 16
1:address:array:number <- copy 10/unsafe 1:address:array:num <- copy 10/unsafe
2:number <- length 1:address:array:number/lookup 2:num <- length 1:address:array:num/lookup
] ]
+mem: storing 3 in location 2 +mem: storing 3 in location 2
@ -412,7 +412,7 @@ def main [
# 10 reserved for refcount # 10 reserved for refcount
11:number-or-point <- merge 0/number, 34 11:number-or-point <- merge 0/number, 34
1:address:number-or-point <- copy 10/unsafe 1:address:number-or-point <- copy 10/unsafe
2:number, 3:boolean <- maybe-convert 1:address:number-or-point/lookup, i:variant 2:num, 3:boolean <- maybe-convert 1:address:number-or-point/lookup, i:variant
] ]
+mem: storing 1 in location 3 +mem: storing 1 in location 3
+mem: storing 34 in location 2 +mem: storing 34 in location 2
@ -422,8 +422,8 @@ def main [
# 10 reserved for refcount # 10 reserved for refcount
11:number-or-point <- merge 0/number, 34 11:number-or-point <- merge 0/number, 34
1:address:number-or-point <- copy 10/unsafe 1:address:number-or-point <- copy 10/unsafe
2:address:number <- copy 20/unsafe 2:address:num <- copy 20/unsafe
2:address:number/lookup, 3:boolean <- maybe-convert 1:address:number-or-point/lookup, i:variant 2:address:num/lookup, 3:boolean <- maybe-convert 1:address:number-or-point/lookup, i:variant
] ]
+mem: storing 1 in location 3 +mem: storing 1 in location 3
+mem: storing 34 in location 21 +mem: storing 34 in location 21
@ -434,7 +434,7 @@ def main [
11:number-or-point <- merge 0/number, 34 11:number-or-point <- merge 0/number, 34
1:address:number-or-point <- copy 10/unsafe 1:address:number-or-point <- copy 10/unsafe
2:address:boolean <- copy 20/unsafe 2:address:boolean <- copy 20/unsafe
3:number, 2:address:boolean/lookup <- maybe-convert 1:address:number-or-point/lookup, i:variant 3:num, 2:address:boolean/lookup <- maybe-convert 1:address:number-or-point/lookup, i:variant
] ]
+mem: storing 1 in location 21 +mem: storing 1 in location 21
+mem: storing 34 in location 3 +mem: storing 34 in location 3

View File

@ -3,10 +3,10 @@
:(scenario refcounts) :(scenario refcounts)
def main [ def main [
1:address:number <- copy 1000/unsafe 1:address:num <- copy 1000/unsafe
2:address:number <- copy 1:address:number 2:address:num <- copy 1:address:num
1:address:number <- copy 0 1:address:num <- copy 0
2:address:number <- copy 0 2:address:num <- copy 0
] ]
+run: {1: ("address" "number")} <- copy {1000: "literal", "unsafe": ()} +run: {1: ("address" "number")} <- copy {1000: "literal", "unsafe": ()}
+mem: incrementing refcount of 1000: 0 -> 1 +mem: incrementing refcount of 1000: 0 -> 1
@ -87,9 +87,9 @@ int payload_size(reagent/*copy*/ x) {
:(scenario refcounts_reflexive) :(scenario refcounts_reflexive)
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
# idempotent copies leave refcount unchanged # idempotent copies leave refcount unchanged
1:address:number <- copy 1:address:number 1:address:num <- copy 1:address:num
] ]
+run: {1: ("address" "number")} <- new {number: "type"} +run: {1: ("address" "number")} <- new {number: "type"}
+mem: incrementing refcount of 1000: 0 -> 1 +mem: incrementing refcount of 1000: 0 -> 1
@ -99,14 +99,14 @@ def main [
:(scenario refcounts_call) :(scenario refcounts_call)
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
# passing in addresses to recipes increments refcount # passing in addresses to recipes increments refcount
foo 1:address:number foo 1:address:num
# return does NOT yet decrement refcount; memory must be explicitly managed # return does NOT yet decrement refcount; memory must be explicitly managed
1:address:number <- new number:type 1:address:num <- new number:type
] ]
def foo [ def foo [
2:address:number <- next-ingredient 2:address:num <- next-ingredient
] ]
+run: {1: ("address" "number")} <- new {number: "type"} +run: {1: ("address" "number")} <- new {number: "type"}
+mem: incrementing refcount of 1000: 0 -> 1 +mem: incrementing refcount of 1000: 0 -> 1
@ -122,12 +122,12 @@ def foo [
:(scenario refcounts_put) :(scenario refcounts_put)
container foo [ container foo [
x:address:number x:address:num
] ]
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:address:foo <- new foo:type 2:address:foo <- new foo:type
*2:address:foo <- put *2:address:foo, x:offset, 1:address:number *2:address:foo <- put *2:address:foo, x:offset, 1:address:num
] ]
+run: {1: ("address" "number")} <- new {number: "type"} +run: {1: ("address" "number")} <- new {number: "type"}
+mem: incrementing refcount of 1000: 0 -> 1 +mem: incrementing refcount of 1000: 0 -> 1
@ -145,9 +145,9 @@ update_any_refcounts(element, ingredients.at(2));
:(scenario refcounts_put_index) :(scenario refcounts_put_index)
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:address:array:address:number <- new {(address number): type}, 3 2:address:array:address:num <- new {(address number): type}, 3
*2:address:array:address:number <- put-index *2:address:array:address:number, 0, 1:address:number *2:address:array:address:num <- put-index *2:address:array:address:num, 0, 1:address:num
] ]
+run: {1: ("address" "number")} <- new {number: "type"} +run: {1: ("address" "number")} <- new {number: "type"}
+mem: incrementing refcount of 1000: 0 -> 1 +mem: incrementing refcount of 1000: 0 -> 1
@ -162,13 +162,13 @@ update_any_refcounts(element, value);
:(scenario refcounts_maybe_convert) :(scenario refcounts_maybe_convert)
exclusive-container foo [ exclusive-container foo [
x:number x:num
p:address:number p:address:num
] ]
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:foo <- merge 1/p, 1:address:number 2:foo <- merge 1/p, 1:address:num
4:address:number, 5:boolean <- maybe-convert 2:foo, 1:variant/p 4:address:num, 5:boolean <- maybe-convert 2:foo, 1:variant/p
] ]
+run: {1: ("address" "number")} <- new {number: "type"} +run: {1: ("address" "number")} <- new {number: "type"}
+mem: incrementing refcount of 1000: 0 -> 1 +mem: incrementing refcount of 1000: 0 -> 1
@ -190,12 +190,12 @@ update_any_refcounts(product, data);
:(scenario refcounts_copy_nested) :(scenario refcounts_copy_nested)
container foo [ container foo [
x:address:number # address inside container x:address:num # address inside container
] ]
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:address:foo <- new foo:type 2:address:foo <- new foo:type
*2:address:foo <- put *2:address:foo, x:offset, 1:address:number *2:address:foo <- put *2:address:foo, x:offset, 1:address:num
3:foo <- copy *2:address:foo 3:foo <- copy *2:address:foo
] ]
+transform: compute address offsets for container foo +transform: compute address offsets for container foo
@ -314,7 +314,7 @@ void compute_container_address_offsets(const type_tree* type) {
} }
else if (type->left->name == "array") { else if (type->left->name == "array") {
const type_tree* element_type = type->right; const type_tree* element_type = type->right;
// hack: support both array:number:3 and array:address:number // hack: support both array:num:3 and array:address:num
if (!element_type->atom && element_type->right && element_type->right->atom && is_integer(element_type->right->name)) if (!element_type->atom && element_type->right && element_type->right->atom && is_integer(element_type->right->name))
element_type = element_type->left; element_type = element_type->left;
compute_container_address_offsets(element_type); compute_container_address_offsets(element_type);
@ -428,7 +428,7 @@ void test_container_address_offsets() {
int old_size = SIZE(Container_metadata); int old_size = SIZE(Container_metadata);
// define a container with an address at offset 0 that we have the size for // define a container with an address at offset 0 that we have the size for
run("container foo [\n" run("container foo [\n"
" x:address:number\n" " x:address:num\n"
"]\n"); "]\n");
reagent r("x:foo"); reagent r("x:foo");
compute_container_sizes(r); // need to first pre-populate the metadata compute_container_sizes(r); // need to first pre-populate the metadata
@ -460,8 +460,8 @@ void test_container_address_offsets_2() {
int old_size = SIZE(Container_metadata); int old_size = SIZE(Container_metadata);
// define a container with an address at offset 1 that we have the size for // define a container with an address at offset 1 that we have the size for
run("container foo [\n" run("container foo [\n"
" x:number\n" " x:num\n"
" y:address:number\n" " y:address:num\n"
"]\n"); "]\n");
reagent r("x:foo"); reagent r("x:foo");
compute_container_sizes(r); // need to first pre-populate the metadata compute_container_sizes(r); // need to first pre-populate the metadata
@ -493,8 +493,8 @@ void test_container_address_offsets_nested() {
int old_size = SIZE(Container_metadata); int old_size = SIZE(Container_metadata);
// define a container with a nested container containing an address // define a container with a nested container containing an address
run("container foo [\n" run("container foo [\n"
" x:address:number\n" " x:address:num\n"
" y:number\n" " y:num\n"
"]\n" "]\n"
"container bar [\n" "container bar [\n"
" p:point\n" " p:point\n"
@ -530,7 +530,7 @@ void test_container_address_offsets_from_address() {
int old_size = SIZE(Container_metadata); int old_size = SIZE(Container_metadata);
// define a container with an address at offset 0 // define a container with an address at offset 0
run("container foo [\n" run("container foo [\n"
" x:address:number\n" " x:address:num\n"
"]\n"); "]\n");
reagent r("x:address:foo"); reagent r("x:address:foo");
compute_container_sizes(r); // need to first pre-populate the metadata compute_container_sizes(r); // need to first pre-populate the metadata
@ -555,7 +555,7 @@ void test_container_address_offsets_from_array() {
int old_size = SIZE(Container_metadata); int old_size = SIZE(Container_metadata);
// define a container with an address at offset 0 // define a container with an address at offset 0
run("container foo [\n" run("container foo [\n"
" x:address:number\n" " x:address:num\n"
"]\n"); "]\n");
reagent r("x:array:foo"); reagent r("x:array:foo");
compute_container_sizes(r); // need to first pre-populate the metadata compute_container_sizes(r); // need to first pre-populate the metadata
@ -580,7 +580,7 @@ void test_container_address_offsets_from_address_to_array() {
int old_size = SIZE(Container_metadata); int old_size = SIZE(Container_metadata);
// define a container with an address at offset 0 // define a container with an address at offset 0
run("container foo [\n" run("container foo [\n"
" x:address:number\n" " x:address:num\n"
"]\n"); "]\n");
reagent r("x:address:array:foo"); reagent r("x:address:array:foo");
compute_container_sizes(r); // need to first pre-populate the metadata compute_container_sizes(r); // need to first pre-populate the metadata
@ -605,7 +605,7 @@ void test_container_address_offsets_from_static_array() {
int old_size = SIZE(Container_metadata); int old_size = SIZE(Container_metadata);
// define a container with an address at offset 0 // define a container with an address at offset 0
run("container foo [\n" run("container foo [\n"
" x:address:number\n" " x:address:num\n"
"]\n"); "]\n");
reagent r("x:array:foo:10"); reagent r("x:array:foo:10");
compute_container_sizes(r); // need to first pre-populate the metadata compute_container_sizes(r); // need to first pre-populate the metadata
@ -630,7 +630,7 @@ void test_container_address_offsets_from_address_to_static_array() {
int old_size = SIZE(Container_metadata); int old_size = SIZE(Container_metadata);
// define a container with an address at offset 0 // define a container with an address at offset 0
run("container foo [\n" run("container foo [\n"
" x:address:number\n" " x:address:num\n"
"]\n"); "]\n");
reagent r("x:address:array:foo:10"); reagent r("x:address:array:foo:10");
compute_container_sizes(r); // need to first pre-populate the metadata compute_container_sizes(r); // need to first pre-populate the metadata
@ -655,7 +655,7 @@ void test_container_address_offsets_from_repeated_address_and_array_types() {
int old_size = SIZE(Container_metadata); int old_size = SIZE(Container_metadata);
// define a container with an address at offset 0 // define a container with an address at offset 0
run("container foo [\n" run("container foo [\n"
" x:address:number\n" " x:address:num\n"
"]\n"); "]\n");
// scan a deep nest of 'address' and 'array' types modifying a container // scan a deep nest of 'address' and 'array' types modifying a container
reagent r("x:address:array:address:address:array:foo:10"); reagent r("x:address:array:address:address:array:foo:10");
@ -720,11 +720,11 @@ container foo [
a:bar # contains an address a:bar # contains an address
] ]
container bar [ container bar [
x:address:number x:address:num
] ]
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:bar <- merge 1:address:number 2:bar <- merge 1:address:num
3:address:foo <- new foo:type 3:address:foo <- new foo:type
*3:address:foo <- put *3:address:foo, a:offset, 2:bar *3:address:foo <- put *3:address:foo, a:offset, 2:bar
] ]
@ -738,11 +738,11 @@ def main [
:(scenario refcounts_put_index_array) :(scenario refcounts_put_index_array)
container bar [ container bar [
x:address:number x:address:num
] ]
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:bar <- merge 1:address:number 2:bar <- merge 1:address:num
3:address:array:bar <- new bar:type, 3 3:address:array:bar <- new bar:type, 3
*3:address:array:bar <- put-index *3:address:array:bar, 0, 2:bar *3:address:array:bar <- put-index *3:address:array:bar, 0, 2:bar
] ]
@ -756,15 +756,15 @@ def main [
:(scenario refcounts_maybe_convert_container) :(scenario refcounts_maybe_convert_container)
exclusive-container foo [ exclusive-container foo [
a:number a:num
b:bar # contains an address b:bar # contains an address
] ]
container bar [ container bar [
x:address:number x:address:num
] ]
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:bar <- merge 1:address:number 2:bar <- merge 1:address:num
3:foo <- merge 1/b, 2:bar 3:foo <- merge 1/b, 2:bar
5:bar, 6:boolean <- maybe-convert 3:foo, 1:variant/b 5:bar, 6:boolean <- maybe-convert 3:foo, 1:variant/b
] ]
@ -783,17 +783,17 @@ container foo [
b:curr # contains addresses b:curr # contains addresses
] ]
container bar [ container bar [
x:number x:num
y:number y:num
] ]
container curr [ container curr [
x:number x:num
y:address:number # address inside container inside container y:address:num # address inside container inside container
] ]
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:address:curr <- new curr:type 2:address:curr <- new curr:type
*2:address:curr <- put *2:address:curr, 1:offset/y, 1:address:number *2:address:curr <- put *2:address:curr, 1:offset/y, 1:address:num
3:address:foo <- new foo:type 3:address:foo <- new foo:type
*3:address:foo <- put *3:address:foo, 1:offset/b, *2:address:curr *3:address:foo <- put *3:address:foo, 1:offset/b, *2:address:curr
4:foo <- copy *3:address:foo 4:foo <- copy *3:address:foo
@ -815,21 +815,21 @@ def main [
:(scenario refcounts_copy_exclusive_container_within_container) :(scenario refcounts_copy_exclusive_container_within_container)
container foo [ container foo [
a:number a:num
b:bar b:bar
] ]
exclusive-container bar [ exclusive-container bar [
x:number x:num
y:number y:num
z:address:number z:address:num
] ]
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:bar <- merge 0/x, 34 2:bar <- merge 0/x, 34
3:foo <- merge 12, 2:bar 3:foo <- merge 12, 2:bar
5:bar <- merge 1/y, 35 5:bar <- merge 1/y, 35
6:foo <- merge 13, 5:bar 6:foo <- merge 13, 5:bar
8:bar <- merge 2/z, 1:address:number 8:bar <- merge 2/z, 1:address:num
9:foo <- merge 14, 8:bar 9:foo <- merge 14, 8:bar
11:foo <- copy 9:foo 11:foo <- copy 9:foo
] ]
@ -845,19 +845,19 @@ def main [
:(scenario refcounts_copy_container_within_exclusive_container) :(scenario refcounts_copy_container_within_exclusive_container)
exclusive-container foo [ exclusive-container foo [
a:number a:num
b:bar b:bar
] ]
container bar [ container bar [
x:number x:num
y:number y:num
z:address:number z:address:num
] ]
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:foo <- merge 0/a, 34 2:foo <- merge 0/a, 34
6:foo <- merge 0/a, 35 6:foo <- merge 0/a, 35
10:bar <- merge 2/x, 15/y, 1:address:number 10:bar <- merge 2/x, 15/y, 1:address:num
13:foo <- merge 1/b, 10:bar 13:foo <- merge 1/b, 10:bar
17:foo <- copy 13:foo 17:foo <- copy 13:foo
] ]
@ -873,16 +873,16 @@ def main [
:(scenario refcounts_copy_exclusive_container_within_exclusive_container) :(scenario refcounts_copy_exclusive_container_within_exclusive_container)
exclusive-container foo [ exclusive-container foo [
a:number a:num
b:bar b:bar
] ]
exclusive-container bar [ exclusive-container bar [
x:number x:num
y:address:number y:address:num
] ]
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
10:foo <- merge 1/b, 1/y, 1:address:number 10:foo <- merge 1/b, 1/y, 1:address:num
20:foo <- copy 10:foo 20:foo <- copy 10:foo
] ]
+run: {1: ("address" "number")} <- new {number: "type"} +run: {1: ("address" "number")} <- new {number: "type"}
@ -895,13 +895,13 @@ def main [
:(scenario refcounts_copy_array_within_container) :(scenario refcounts_copy_array_within_container)
container foo [ container foo [
x:address:array:number x:address:array:num
] ]
def main [ def main [
1:address:array:number <- new number:type, 3 1:address:array:num <- new number:type, 3
2:foo <- merge 1:address:array:number 2:foo <- merge 1:address:array:num
3:address:array:number <- new number:type, 5 3:address:array:num <- new number:type, 5
2:foo <- merge 3:address:array:number 2:foo <- merge 3:address:array:num
] ]
+run: {1: ("address" "array" "number")} <- new {number: "type"}, {3: "literal"} +run: {1: ("address" "array" "number")} <- new {number: "type"}, {3: "literal"}
+mem: incrementing refcount of 1000: 0 -> 1 +mem: incrementing refcount of 1000: 0 -> 1
@ -912,24 +912,24 @@ def main [
:(scenario refcounts_handle_exclusive_containers_with_different_tags) :(scenario refcounts_handle_exclusive_containers_with_different_tags)
container foo1 [ container foo1 [
x:address:number x:address:num
y:number y:num
] ]
container foo2 [ container foo2 [
x:number x:num
y:address:number y:address:num
] ]
exclusive-container bar [ exclusive-container bar [
a:foo1 a:foo1
b:foo2 b:foo2
] ]
def main [ def main [
1:address:number <- copy 12000/unsafe # pretend allocation 1:address:num <- copy 12000/unsafe # pretend allocation
*1:address:number <- copy 34 *1:address:num <- copy 34
2:bar <- merge 0/foo1, 1:address:number, 97 2:bar <- merge 0/foo1, 1:address:num, 97
5:address:number <- copy 13000/unsafe # pretend allocation 5:address:num <- copy 13000/unsafe # pretend allocation
*5:address:number <- copy 35 *5:address:num <- copy 35
6:bar <- merge 1/foo2, 98, 5:address:number 6:bar <- merge 1/foo2, 98, 5:address:num
2:bar <- copy 6:bar 2:bar <- copy 6:bar
] ]
+run: {2: "bar"} <- merge {0: "literal", "foo1": ()}, {1: ("address" "number")}, {97: "literal"} +run: {2: "bar"} <- merge {0: "literal", "foo1": ()}, {1: ("address" "number")}, {97: "literal"}

View File

@ -3,12 +3,12 @@
:(scenario new_reclaim) :(scenario new_reclaim)
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:number <- copy 1:address:number # because 1 will get reset during abandon below 2:num <- copy 1:address:num # because 1 will get reset during abandon below
1:address:number <- copy 0 # abandon 1:address:num <- copy 0 # abandon
3:address:number <- new number:type # must be same size as abandoned memory to reuse 3:address:num <- new number:type # must be same size as abandoned memory to reuse
4:number <- copy 3:address:number 4:num <- copy 3:address:num
5:boolean <- equal 2:number, 4:number 5:boolean <- equal 2:num, 4:num
] ]
# both allocations should have returned the same address # both allocations should have returned the same address
+mem: storing 1 in location 5 +mem: storing 1 in location 5
@ -75,34 +75,34 @@ if (get_or_insert(Current_routine->free_list, size)) {
:(scenario new_differing_size_no_reclaim) :(scenario new_differing_size_no_reclaim)
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:number <- copy 1:address:number 2:num <- copy 1:address:num
1:address:number <- copy 0 # abandon 1:address:num <- copy 0 # abandon
3:address:array:number <- new number:type, 2 # different size 3:address:array:num <- new number:type, 2 # different size
4:number <- copy 3:address:array:number 4:num <- copy 3:address:array:num
5:boolean <- equal 2:number, 4:number 5:boolean <- equal 2:num, 4:num
] ]
# no reuse # no reuse
+mem: storing 0 in location 5 +mem: storing 0 in location 5
:(scenario new_reclaim_array) :(scenario new_reclaim_array)
def main [ def main [
1:address:array:number <- new number:type, 2 1:address:array:num <- new number:type, 2
2:number <- copy 1:address:array:number 2:num <- copy 1:address:array:num
1:address:array:number <- copy 0 # abandon 1:address:array:num <- copy 0 # abandon
3:address:array:number <- new number:type, 2 # same size 3:address:array:num <- new number:type, 2 # same size
4:number <- copy 3:address:array:number 4:num <- copy 3:address:array:num
5:boolean <- equal 2:number, 4:number 5:boolean <- equal 2:num, 4:num
] ]
# both calls to new returned identical addresses # both calls to new returned identical addresses
+mem: storing 1 in location 5 +mem: storing 1 in location 5
:(scenario abandon_on_overwrite) :(scenario abandon_on_overwrite)
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
# over-writing one allocation with another # over-writing one allocation with another
1:address:number <- new number:type 1:address:num <- new number:type
1:address:number <- copy 0 1:address:num <- copy 0
] ]
+run: {1: ("address" "number")} <- new {number: "type"} +run: {1: ("address" "number")} <- new {number: "type"}
+mem: incrementing refcount of 1000: 0 -> 1 +mem: incrementing refcount of 1000: 0 -> 1
@ -111,15 +111,15 @@ def main [
:(scenario abandon_after_call) :(scenario abandon_after_call)
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
# passing in addresses to recipes increments refcount # passing in addresses to recipes increments refcount
foo 1:address:number foo 1:address:num
1:address:number <- copy 0 1:address:num <- copy 0
] ]
def foo [ def foo [
2:address:number <- next-ingredient 2:address:num <- next-ingredient
# return does NOT yet decrement refcount; memory must be explicitly managed # return does NOT yet decrement refcount; memory must be explicitly managed
2:address:number <- copy 0 2:address:num <- copy 0
] ]
+run: {1: ("address" "number")} <- new {number: "type"} +run: {1: ("address" "number")} <- new {number: "type"}
+mem: incrementing refcount of 1000: 0 -> 1 +mem: incrementing refcount of 1000: 0 -> 1
@ -135,12 +135,12 @@ def foo [
:(scenario abandon_on_overwrite_array) :(scenario abandon_on_overwrite_array)
def main [ def main [
1:number <- copy 30 1:num <- copy 30
# allocate an array # allocate an array
10:address:array:number <- new number:type, 20 10:address:array:num <- new number:type, 20
11:number <- copy 10:address:array:number # doesn't increment refcount 11:num <- copy 10:address:array:num # doesn't increment refcount
# allocate another array in its place, implicitly freeing the previous allocation # allocate another array in its place, implicitly freeing the previous allocation
10:address:array:number <- new number:type, 25 10:address:array:num <- new number:type, 25
] ]
+run: {10: ("address" "array" "number")} <- new {number: "type"}, {25: "literal"} +run: {10: ("address" "array" "number")} <- new {number: "type"}, {25: "literal"}
# abandoned array is of old size (20, not 25) # abandoned array is of old size (20, not 25)
@ -149,13 +149,13 @@ def main [
:(scenario refcounts_abandon_address_in_container) :(scenario refcounts_abandon_address_in_container)
# container containing an address # container containing an address
container foo [ container foo [
x:address:number x:address:num
] ]
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:address:foo <- new foo:type 2:address:foo <- new foo:type
*2:address:foo <- put *2:address:foo, x:offset, 1:address:number *2:address:foo <- put *2:address:foo, x:offset, 1:address:num
1:address:number <- copy 0 1:address:num <- copy 0
2:address:foo <- copy 0 2:address:foo <- copy 0
] ]
+run: {1: ("address" "number")} <- new {number: "type"} +run: {1: ("address" "number")} <- new {number: "type"}
@ -178,11 +178,11 @@ def main [
# todo: move past dilated reagent # todo: move past dilated reagent
:(scenario refcounts_abandon_address_in_array) :(scenario refcounts_abandon_address_in_array)
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:address:array:address:number <- new {(address number): type}, 3 2:address:array:address:num <- new {(address number): type}, 3
*2:address:array:address:number <- put-index *2:address:array:address:number, 1, 1:address:number *2:address:array:address:num <- put-index *2:address:array:address:num, 1, 1:address:num
1:address:number <- copy 0 1:address:num <- copy 0
2:address:array:address:number <- copy 0 2:address:array:address:num <- copy 0
] ]
+run: {1: ("address" "number")} <- new {number: "type"} +run: {1: ("address" "number")} <- new {number: "type"}
+mem: incrementing refcount of 1000: 0 -> 1 +mem: incrementing refcount of 1000: 0 -> 1
@ -198,14 +198,14 @@ def main [
:(scenario refcounts_abandon_address_in_container_in_array) :(scenario refcounts_abandon_address_in_container_in_array)
# container containing an address # container containing an address
container foo [ container foo [
x:address:number x:address:num
] ]
def main [ def main [
1:address:number <- new number:type 1:address:num <- new number:type
2:address:array:foo <- new foo:type, 3 2:address:array:foo <- new foo:type, 3
3:foo <- merge 1:address:number 3:foo <- merge 1:address:num
*2:address:array:foo <- put-index *2:address:array:foo, 1, 3:foo *2:address:array:foo <- put-index *2:address:array:foo, 1, 3:foo
1:address:number <- copy 0 1:address:num <- copy 0
3:foo <- merge 0 3:foo <- merge 0
2:address:array:foo <- copy 0 2:address:array:foo <- copy 0
] ]

View File

@ -15,7 +15,7 @@ def main [
:(scenario new_string_handles_unicode) :(scenario new_string_handles_unicode)
def main [ def main [
1:text <- new [a«c] 1:text <- new [a«c]
2:number <- length *1:text 2:num <- length *1:text
3:char <- index *1:text, 1 3:char <- index *1:text, 1
] ]
+mem: storing 3 in location 2 +mem: storing 3 in location 2
@ -106,7 +106,7 @@ if (!canonize_type(x)) return false;
:(scenario new_string_overflow) :(scenario new_string_overflow)
% Initial_memory_per_routine = 3; % Initial_memory_per_routine = 3;
def main [ def main [
1:address:number/raw <- new number:type 1:address:num/raw <- new number:type
2:text/raw <- new [a] # not enough room in initial page, if you take the refcount and array length into account 2:text/raw <- new [a] # not enough room in initial page, if you take the refcount and array length into account
] ]
+new: routine allocated memory from 1000 to 1003 +new: routine allocated memory from 1000 to 1003

View File

@ -24,7 +24,7 @@
def main [ def main [
{ {
break break
1:number <- copy 0 1:num <- copy 0
} }
] ]
+transform: --- transform braces for recipe main +transform: --- transform braces for recipe main
@ -146,10 +146,10 @@ int matching_brace(int index, const list<pair<int, int> >& braces, recipe_ordina
:(scenario loop) :(scenario loop)
def main [ def main [
1:number <- copy 0 1:num <- copy 0
2:number <- copy 0 2:num <- copy 0
{ {
3:number <- copy 0 3:num <- copy 0
loop loop
} }
] ]
@ -161,7 +161,7 @@ def main [
:(scenario break_empty_block) :(scenario break_empty_block)
def main [ def main [
1:number <- copy 0 1:num <- copy 0
{ {
break break
} }
@ -172,7 +172,7 @@ def main [
:(scenario break_cascading) :(scenario break_cascading)
def main [ def main [
1:number <- copy 0 1:num <- copy 0
{ {
break break
} }
@ -187,11 +187,11 @@ def main [
:(scenario break_cascading_2) :(scenario break_cascading_2)
def main [ def main [
1:number <- copy 0 1:num <- copy 0
2:number <- copy 0 2:num <- copy 0
{ {
break break
3:number <- copy 0 3:num <- copy 0
} }
{ {
break break
@ -206,11 +206,11 @@ def main [
:(scenario break_if) :(scenario break_if)
def main [ def main [
1:number <- copy 0 1:num <- copy 0
2:number <- copy 0 2:num <- copy 0
{ {
break-if 2:number break-if 2:num
3:number <- copy 0 3:num <- copy 0
} }
{ {
break break
@ -225,36 +225,36 @@ def main [
:(scenario break_nested) :(scenario break_nested)
def main [ def main [
1:number <- copy 0 1:num <- copy 0
{ {
2:number <- copy 0 2:num <- copy 0
break break
{ {
3:number <- copy 0 3:num <- copy 0
} }
4:number <- copy 0 4:num <- copy 0
} }
] ]
+transform: jump 4:offset +transform: jump 4:offset
:(scenario break_nested_degenerate) :(scenario break_nested_degenerate)
def main [ def main [
1:number <- copy 0 1:num <- copy 0
{ {
2:number <- copy 0 2:num <- copy 0
break break
{ {
} }
4:number <- copy 0 4:num <- copy 0
} }
] ]
+transform: jump 3:offset +transform: jump 3:offset
:(scenario break_nested_degenerate_2) :(scenario break_nested_degenerate_2)
def main [ def main [
1:number <- copy 0 1:num <- copy 0
{ {
2:number <- copy 0 2:num <- copy 0
break break
{ {
} }
@ -265,7 +265,7 @@ def main [
:(scenario break_label) :(scenario break_label)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
1:number <- copy 0 1:num <- copy 0
{ {
break +foo:offset break +foo:offset
} }
@ -274,11 +274,11 @@ def main [
:(scenario break_unless) :(scenario break_unless)
def main [ def main [
1:number <- copy 0 1:num <- copy 0
2:number <- copy 0 2:num <- copy 0
{ {
break-unless 2:number break-unless 2:num
3:number <- copy 0 3:num <- copy 0
} }
] ]
+transform: --- transform braces for recipe main +transform: --- transform braces for recipe main
@ -289,11 +289,11 @@ def main [
:(scenario loop_unless) :(scenario loop_unless)
def main [ def main [
1:number <- copy 0 1:num <- copy 0
2:number <- copy 0 2:num <- copy 0
{ {
loop-unless 2:number loop-unless 2:num
3:number <- copy 0 3:num <- copy 0
} }
] ]
+transform: --- transform braces for recipe main +transform: --- transform braces for recipe main
@ -304,14 +304,14 @@ def main [
:(scenario loop_nested) :(scenario loop_nested)
def main [ def main [
1:number <- copy 0 1:num <- copy 0
{ {
2:number <- copy 0 2:num <- copy 0
{ {
3:number <- copy 0 3:num <- copy 0
} }
loop-if 4:boolean loop-if 4:boolean
5:number <- copy 0 5:num <- copy 0
} }
] ]
+transform: --- transform braces for recipe main +transform: --- transform braces for recipe main
@ -319,9 +319,9 @@ def main [
:(scenario loop_label) :(scenario loop_label)
def main [ def main [
1:number <- copy 0 1:num <- copy 0
+foo +foo
2:number <- copy 0 2:num <- copy 0
] ]
+transform: --- transform braces for recipe main +transform: --- transform braces for recipe main
+transform: copy ... +transform: copy ...
@ -331,17 +331,17 @@ def main [
:(scenarios run) :(scenarios run)
:(scenario brace_conversion_and_run) :(scenario brace_conversion_and_run)
def test-factorial [ def test-factorial [
1:number <- copy 5 1:num <- copy 5
2:number <- copy 1 2:num <- copy 1
{ {
3:boolean <- equal 1:number, 1 3:boolean <- equal 1:num, 1
break-if 3:boolean break-if 3:boolean
# $print 1:number # $print 1:num
2:number <- multiply 2:number, 1:number 2:num <- multiply 2:num, 1:num
1:number <- subtract 1:number, 1 1:num <- subtract 1:num, 1
loop loop
} }
4:number <- copy 2:number # trigger a read 4:num <- copy 2:num # trigger a read
] ]
+mem: location 2 is 120 +mem: location 2 is 120
@ -365,7 +365,7 @@ def main [
:(scenario return_if) :(scenario return_if)
def main [ def main [
1:number <- test1 1:num <- test1
] ]
def test1 [ def test1 [
return-if 0, 34 return-if 0, 34
@ -375,7 +375,7 @@ def test1 [
:(scenario return_if_2) :(scenario return_if_2)
def main [ def main [
1:number <- test1 1:num <- test1
] ]
def test1 [ def test1 [
return-if 1, 34 return-if 1, 34

View File

@ -10,7 +10,7 @@
:(scenario jump_to_label) :(scenario jump_to_label)
def main [ def main [
jump +target:label jump +target:label
1:number <- copy 0 1:num <- copy 0
+target +target
] ]
-mem: storing 0 in location 1 -mem: storing 0 in location 1
@ -96,7 +96,7 @@ def main [
{ {
{ {
break +target:label break +target:label
1:number <- copy 0 1:num <- copy 0
} }
} }
+target +target
@ -108,7 +108,7 @@ def main [
{ {
{ {
jump-if 1, +target:label jump-if 1, +target:label
1:number <- copy 0 1:num <- copy 0
} }
} }
+target +target
@ -120,7 +120,7 @@ def main [
{ {
{ {
loop-unless 0, +target:label # loop/break with a label don't care about braces loop-unless 0, +target:label # loop/break with a label don't care about braces
1:number <- copy 0 1:num <- copy 0
} }
} }
+target +target
@ -130,13 +130,13 @@ def main [
:(scenario jump_runs_code_after_label) :(scenario jump_runs_code_after_label)
def main [ def main [
# first a few lines of padding to exercise the offset computation # first a few lines of padding to exercise the offset computation
1:number <- copy 0 1:num <- copy 0
2:number <- copy 0 2:num <- copy 0
3:number <- copy 0 3:num <- copy 0
jump +target:label jump +target:label
4:number <- copy 0 4:num <- copy 0
+target +target
5:number <- copy 0 5:num <- copy 0
] ]
+mem: storing 0 in location 5 +mem: storing 0 in location 5
-mem: storing 0 in location 4 -mem: storing 0 in location 4
@ -159,9 +159,9 @@ def main [
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
+label +label
1:number <- copy 0 1:num <- copy 0
+label +label
2:number <- copy 0 2:num <- copy 0
] ]
+error: main: duplicate label '+label' +error: main: duplicate label '+label'
@ -169,12 +169,12 @@ def main [
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
# first a few lines of padding to exercise the offset computation # first a few lines of padding to exercise the offset computation
1:number <- copy 0 1:num <- copy 0
2:number <- copy 0 2:num <- copy 0
3:number <- copy 0 3:num <- copy 0
jump $target:label jump $target:label
4:number <- copy 0 4:num <- copy 0
$target $target
5:number <- copy 0 5:num <- copy 0
] ]
+error: main: can't jump to label '$target' +error: main: can't jump to label '$target'

View File

@ -4,7 +4,7 @@
:(scenario transform_names) :(scenario transform_names)
def main [ def main [
x:number <- copy 0 x:num <- copy 0
] ]
+name: assign x 1 +name: assign x 1
+mem: storing 0 in location 1 +mem: storing 0 in location 1
@ -13,7 +13,7 @@ def main [
:(scenario transform_names_fails_on_use_before_define) :(scenario transform_names_fails_on_use_before_define)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
x:number <- copy y:number x:num <- copy y:num
] ]
+error: main: use before set: 'y' +error: main: use before set: 'y'
# todo: detect conditional defines # todo: detect conditional defines
@ -156,7 +156,7 @@ bool is_special_name(const string& s) {
:(scenario transform_names_supports_containers) :(scenario transform_names_supports_containers)
def main [ def main [
x:point <- merge 34, 35 x:point <- merge 34, 35
y:number <- copy 3 y:num <- copy 3
] ]
+name: assign x 1 +name: assign x 1
# skip location 2 because x occupies two locations # skip location 2 because x occupies two locations
@ -164,8 +164,8 @@ def main [
:(scenario transform_names_supports_static_arrays) :(scenario transform_names_supports_static_arrays)
def main [ def main [
x:array:number:3 <- create-array x:array:num:3 <- create-array
y:number <- copy 3 y:num <- copy 3
] ]
+name: assign x 1 +name: assign x 1
# skip locations 2, 3, 4 because x occupies four locations # skip locations 2, 3, 4 because x occupies four locations
@ -174,7 +174,7 @@ def main [
:(scenario transform_names_passes_dummy) :(scenario transform_names_passes_dummy)
# _ is just a dummy result that never gets consumed # _ is just a dummy result that never gets consumed
def main [ def main [
_, x:number <- copy 0, 1 _, x:num <- copy 0, 1
] ]
+name: assign x 1 +name: assign x 1
-name: assign _ 1 -name: assign _ 1
@ -184,37 +184,37 @@ def main [
:(scenario transform_names_passes_raw) :(scenario transform_names_passes_raw)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
x:number/raw <- copy 0 x:num/raw <- copy 0
] ]
-name: assign x 1 -name: assign x 1
+error: can't write to location 0 in 'x:number/raw <- copy 0' +error: can't write to location 0 in 'x:num/raw <- copy 0'
:(scenarios transform) :(scenarios transform)
:(scenario transform_names_fails_when_mixing_names_and_numeric_locations) :(scenario transform_names_fails_when_mixing_names_and_numeric_locations)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
x:number <- copy 1:number x:num <- copy 1:num
] ]
+error: main: mixing variable names and numeric addresses +error: main: mixing variable names and numeric addresses
:(scenario transform_names_fails_when_mixing_names_and_numeric_locations_2) :(scenario transform_names_fails_when_mixing_names_and_numeric_locations_2)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
x:number <- copy 1 x:num <- copy 1
1:number <- copy x:number 1:num <- copy x:num
] ]
+error: main: mixing variable names and numeric addresses +error: main: mixing variable names and numeric addresses
:(scenario transform_names_does_not_fail_when_mixing_names_and_raw_locations) :(scenario transform_names_does_not_fail_when_mixing_names_and_raw_locations)
def main [ def main [
x:number <- copy 1:number/raw x:num <- copy 1:num/raw
] ]
-error: main: mixing variable names and numeric addresses -error: main: mixing variable names and numeric addresses
$error: 0 $error: 0
:(scenario transform_names_does_not_fail_when_mixing_names_and_literals) :(scenario transform_names_does_not_fail_when_mixing_names_and_literals)
def main [ def main [
x:number <- copy 1 x:num <- copy 1
] ]
-error: main: mixing variable names and numeric addresses -error: main: mixing variable names and numeric addresses
$error: 0 $error: 0
@ -225,8 +225,8 @@ $error: 0
:(scenario transform_names_transforms_container_elements) :(scenario transform_names_transforms_container_elements)
def main [ def main [
p:address:point <- copy 0 p:address:point <- copy 0
a:number <- get *p:address:point, y:offset a:num <- get *p:address:point, y:offset
b:number <- get *p:address:point, x:offset b:num <- get *p:address:point, x:offset
] ]
+name: element y of type point is at offset 1 +name: element y of type point is at offset 1
+name: element x of type point is at offset 0 +name: element x of type point is at offset 0
@ -258,7 +258,7 @@ if (inst.name == "get" || inst.name == "get-location" || inst.name == "put") {
:(scenario transform_names_handles_containers) :(scenario transform_names_handles_containers)
def main [ def main [
a:point <- copy 0/unsafe a:point <- copy 0/unsafe
b:number <- copy 0/unsafe b:num <- copy 0/unsafe
] ]
+name: assign a 1 +name: assign a 1
+name: assign b 3 +name: assign b 3
@ -268,9 +268,9 @@ def main [
:(scenarios run) :(scenarios run)
:(scenario transform_names_handles_exclusive_containers) :(scenario transform_names_handles_exclusive_containers)
def main [ def main [
12:number <- copy 1 12:num <- copy 1
13:number <- copy 35 13:num <- copy 35
14:number <- copy 36 14:num <- copy 36
20:point, 22:boolean <- maybe-convert 12:number-or-point/unsafe, p:variant 20:point, 22:boolean <- maybe-convert 12:number-or-point/unsafe, p:variant
] ]
+name: variant p of type number-or-point has tag 1 +name: variant p of type number-or-point has tag 1

View File

@ -7,24 +7,24 @@
# then local 0 is really location 12, local 1 is really location 13, and so on. # then local 0 is really location 12, local 1 is really location 13, and so on.
def main [ def main [
# pretend address:array:location; in practice we'll use new # pretend address:array:location; in practice we'll use new
10:number <- copy 0 # refcount 10:num <- copy 0 # refcount
11:number <- copy 5 # length 11:num <- copy 5 # length
default-space:address:array:location <- copy 10/unsafe default-space:address:array:location <- copy 10/unsafe
1:number <- copy 23 1:num <- copy 23
] ]
+mem: storing 23 in location 13 +mem: storing 23 in location 13
:(scenario lookup_sidesteps_default_space) :(scenario lookup_sidesteps_default_space)
def main [ def main [
# pretend pointer from outside (2000 reserved for refcount) # pretend pointer from outside (2000 reserved for refcount)
2001:number <- copy 34 2001:num <- copy 34
# pretend address:array:location; in practice we'll use new # pretend address:array:location; in practice we'll use new
1000:number <- copy 0 # refcount 1000:num <- copy 0 # refcount
1001:number <- copy 5 # length 1001:num <- copy 5 # length
# actual start of this recipe # actual start of this recipe
default-space:address:array:location <- copy 1000/unsafe default-space:address:array:location <- copy 1000/unsafe
1:address:number <- copy 2000/unsafe # even local variables always contain raw addresses 1:address:num <- copy 2000/unsafe # even local variables always contain raw addresses
8:number/raw <- copy *1:address:number 8:num/raw <- copy *1:address:num
] ]
+mem: storing 34 in location 8 +mem: storing 34 in location 8
@ -32,7 +32,7 @@ def main [
:(scenario convert_names_passes_default_space) :(scenario convert_names_passes_default_space)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
default-space:number, x:number <- copy 0, 1 default-space:num, x:num <- copy 0, 1
] ]
+name: assign x 1 +name: assign x 1
-name: assign default-space 1 -name: assign default-space 1
@ -112,15 +112,15 @@ if (x.name == "default-space") {
:(scenario lookup_sidesteps_default_space_in_get) :(scenario lookup_sidesteps_default_space_in_get)
def main [ def main [
# pretend pointer to container from outside (2000 reserved for refcount) # pretend pointer to container from outside (2000 reserved for refcount)
2001:number <- copy 34 2001:num <- copy 34
2002:number <- copy 35 2002:num <- copy 35
# pretend address:array:location; in practice we'll use new # pretend address:array:location; in practice we'll use new
1000:number <- copy 0 # refcount 1000:num <- copy 0 # refcount
1001:number <- copy 5 # length 1001:num <- copy 5 # length
# actual start of this recipe # actual start of this recipe
default-space:address:array:location <- copy 1000/unsafe default-space:address:array:location <- copy 1000/unsafe
1:address:point <- copy 2000/unsafe 1:address:point <- copy 2000/unsafe
9:number/raw <- get *1:address:point, 1:offset 9:num/raw <- get *1:address:point, 1:offset
] ]
+mem: storing 35 in location 9 +mem: storing 35 in location 9
@ -132,16 +132,16 @@ element.properties.push_back(pair<string, string_tree*>("raw", NULL));
:(scenario lookup_sidesteps_default_space_in_index) :(scenario lookup_sidesteps_default_space_in_index)
def main [ def main [
# pretend pointer to array from outside (2000 reserved for refcount) # pretend pointer to array from outside (2000 reserved for refcount)
2001:number <- copy 2 # length 2001:num <- copy 2 # length
2002:number <- copy 34 2002:num <- copy 34
2003:number <- copy 35 2003:num <- copy 35
# pretend address:array:location; in practice we'll use new # pretend address:array:location; in practice we'll use new
1000:number <- copy 0 # refcount 1000:num <- copy 0 # refcount
1001:number <- copy 5 # length 1001:num <- copy 5 # length
# actual start of this recipe # actual start of this recipe
default-space:address:array:location <- copy 1000/unsafe default-space:address:array:location <- copy 1000/unsafe
1:address:array:number <- copy 2000/unsafe 1:address:array:num <- copy 2000/unsafe
9:number/raw <- index *1:address:array:number, 1 9:num/raw <- index *1:address:array:num, 1
] ]
+mem: storing 35 in location 9 +mem: storing 35 in location 9
@ -154,8 +154,8 @@ element.properties.push_back(pair<string, string_tree*>("raw", NULL));
:(scenario new_default_space) :(scenario new_default_space)
def main [ def main [
new-default-space new-default-space
x:number <- copy 0 x:num <- copy 0
y:number <- copy 3 y:num <- copy 3
] ]
# allocate space for x and y, as well as the chaining slot at 0 # allocate space for x and y, as well as the chaining slot at 0
+mem: array length is 3 +mem: array length is 3
@ -198,7 +198,7 @@ def main [
] ]
def foo [ def foo [
local-scope local-scope
x:number <- copy 34 x:num <- copy 34
return default-space:address:array:location return default-space:address:array:location
] ]
# both calls to foo should have received the same default-space # both calls to foo should have received the same default-space
@ -309,16 +309,16 @@ void rewrite_default_space_instruction(instruction& curr) {
:(scenario local_scope_frees_up_addresses_inside_containers) :(scenario local_scope_frees_up_addresses_inside_containers)
container foo [ container foo [
x:number x:num
y:address:number y:address:num
] ]
def main [ def main [
local-scope local-scope
x:address:number <- new number:type x:address:num <- new number:type
y:foo <- merge 34, x:address:number y:foo <- merge 34, x:address:num
# x and y are both cleared when main returns # x and y are both cleared when main returns
] ]
+mem: clearing x:address:number +mem: clearing x:address:num
+mem: decrementing refcount of 1006: 2 -> 1 +mem: decrementing refcount of 1006: 2 -> 1
+mem: clearing y:foo +mem: clearing y:foo
+mem: decrementing refcount of 1006: 1 -> 0 +mem: decrementing refcount of 1006: 1 -> 0
@ -326,24 +326,24 @@ def main [
:(scenario local_scope_returns_addresses_inside_containers) :(scenario local_scope_returns_addresses_inside_containers)
container foo [ container foo [
x:number x:num
y:address:number y:address:num
] ]
def f [ def f [
local-scope local-scope
x:address:number <- new number:type x:address:num <- new number:type
*x:address:number <- copy 12 *x:address:num <- copy 12
y:foo <- merge 34, x:address:number y:foo <- merge 34, x:address:num
# since y is 'escaping' f, it should not be cleared # since y is 'escaping' f, it should not be cleared
return y:foo return y:foo
] ]
def main [ def main [
1:foo <- f 1:foo <- f
3:number <- get 1:foo, x:offset 3:num <- get 1:foo, x:offset
4:address:number <- get 1:foo, y:offset 4:address:num <- get 1:foo, y:offset
5:number <- copy *4:address:number 5:num <- copy *4:address:num
1:foo <- put 1:foo, y:offset, 0 1:foo <- put 1:foo, y:offset, 0
4:address:number <- copy 0 4:address:num <- copy 0
] ]
+mem: storing 34 in location 1 +mem: storing 34 in location 1
+mem: storing 1006 in location 2 +mem: storing 1006 in location 2
@ -363,8 +363,8 @@ def main [
:(scenario local_scope_claims_return_values_when_not_saved) :(scenario local_scope_claims_return_values_when_not_saved)
def f [ def f [
local-scope local-scope
x:address:number <- new number:type x:address:num <- new number:type
reply x:address:number reply x:address:num
] ]
def main [ def main [
f # doesn't save result f # doesn't save result

View File

@ -8,16 +8,16 @@
# location 1 in space 1 refers to the space surrounding the default space, here 20. # location 1 in space 1 refers to the space surrounding the default space, here 20.
def main [ def main [
# pretend address:array:location; in practice we'll use new # pretend address:array:location; in practice we'll use new
10:number <- copy 0 # refcount 10:num <- copy 0 # refcount
11:number <- copy 5 # length 11:num <- copy 5 # length
# pretend address:array:location; in practice we'll use new # pretend address:array:location; in practice we'll use new
20:number <- copy 0 # refcount 20:num <- copy 0 # refcount
21:number <- copy 5 # length 21:num <- copy 5 # length
# actual start of this recipe # actual start of this recipe
default-space:address:array:location <- copy 10/unsafe default-space:address:array:location <- copy 10/unsafe
0:address:array:location/names:dummy <- copy 20/unsafe # later layers will explain the /names: property 0:address:array:location/names:dummy <- copy 20/unsafe # later layers will explain the /names: property
1:number <- copy 32 1:num <- copy 32
1:number/space:1 <- copy 33 1:num/space:1 <- copy 33
] ]
def dummy [ # just for the /names: property above def dummy [ # just for the /names: property above
] ]
@ -61,5 +61,5 @@ int space_index(const reagent& x) {
:(scenario permit_space_as_variable_name) :(scenario permit_space_as_variable_name)
def main [ def main [
space:number <- copy 0 space:num <- copy 0
] ]

View File

@ -7,21 +7,21 @@
def main [ def main [
default-space:address:array:location <- new location:type, 30 default-space:address:array:location <- new location:type, 30
1:address:array:location/names:new-counter <- new-counter 1:address:array:location/names:new-counter <- new-counter
2:number/raw <- increment-counter 1:address:array:location/names:new-counter 2:num/raw <- increment-counter 1:address:array:location/names:new-counter
3:number/raw <- increment-counter 1:address:array:location/names:new-counter 3:num/raw <- increment-counter 1:address:array:location/names:new-counter
] ]
def new-counter [ def new-counter [
default-space:address:array:location <- new location:type, 30 default-space:address:array:location <- new location:type, 30
x:number <- copy 23 x:num <- copy 23
y:number <- copy 3 # variable that will be incremented y:num <- copy 3 # variable that will be incremented
return default-space:address:array:location return default-space:address:array:location
] ]
def increment-counter [ def increment-counter [
default-space:address:array:location <- new location:type, 30 default-space:address:array:location <- new location:type, 30
0:address:array:location/names:new-counter <- next-ingredient # outer space must be created by 'new-counter' above 0:address:array:location/names:new-counter <- next-ingredient # outer space must be created by 'new-counter' above
y:number/space:1 <- add y:number/space:1, 1 # increment y:num/space:1 <- add y:num/space:1, 1 # increment
y:number <- copy 234 # dummy y:num <- copy 234 # dummy
return y:number/space:1 return y:num/space:1
] ]
+name: lexically surrounding space for recipe increment-counter comes from new-counter +name: lexically surrounding space for recipe increment-counter comes from new-counter
+mem: storing 5 in location 3 +mem: storing 5 in location 3
@ -142,7 +142,7 @@ bool already_transformed(const reagent& r, const map<string, int>& names) {
% Hide_errors = true; % Hide_errors = true;
def f [ def f [
local-scope local-scope
x:number/space:1 <- copy 34 x:num/space:1 <- copy 34
] ]
+error: don't know surrounding recipe of 'f' +error: don't know surrounding recipe of 'f'
+error: f: can't find a place to store 'x' +error: f: can't find a place to store 'x'
@ -151,18 +151,18 @@ def f [
:(scenario local_scope_ignores_nonlocal_spaces) :(scenario local_scope_ignores_nonlocal_spaces)
def new-scope [ def new-scope [
new-default-space new-default-space
x:address:number <- new number:type x:address:num <- new number:type
*x:address:number <- copy 34 *x:address:num <- copy 34
return default-space:address:array:location return default-space:address:array:location
] ]
def use-scope [ def use-scope [
local-scope local-scope
outer:address:array:location <- next-ingredient outer:address:array:location <- next-ingredient
0:address:array:location/names:new-scope <- copy outer:address:array:location 0:address:array:location/names:new-scope <- copy outer:address:array:location
return *x:address:number/space:1 return *x:address:num/space:1
] ]
def main [ def main [
1:address:array:location/raw <- new-scope 1:address:array:location/raw <- new-scope
2:number/raw <- use-scope 1:address:array:location/raw 2:num/raw <- use-scope 1:address:array:location/raw
] ]
+mem: storing 34 in location 2 +mem: storing 34 in location 2

View File

@ -12,16 +12,16 @@
:(scenario global_space) :(scenario global_space)
def main [ def main [
# pretend address:array:location; in practice we'll use new # pretend address:array:location; in practice we'll use new
10:number <- copy 0 # refcount 10:num <- copy 0 # refcount
11:number <- copy 5 # length 11:num <- copy 5 # length
# pretend address:array:location; in practice we'll use new # pretend address:array:location; in practice we'll use new
20:number <- copy 0 # refcount 20:num <- copy 0 # refcount
21:number <- copy 5 # length 21:num <- copy 5 # length
# actual start of this recipe # actual start of this recipe
global-space:address:array:location <- copy 20/unsafe global-space:address:array:location <- copy 20/unsafe
default-space:address:array:location <- copy 10/unsafe default-space:address:array:location <- copy 10/unsafe
1:number <- copy 23 1:num <- copy 23
1:number/space:global <- copy 24 1:num/space:global <- copy 24
] ]
# store to default space: 10 + (skip refcount and length) 2 + (index) 1 # store to default space: 10 + (skip refcount and length) 2 + (index) 1
+mem: storing 23 in location 13 +mem: storing 23 in location 13
@ -64,8 +64,8 @@ if (x.name == "global-space") {
:(scenario global_space_with_names) :(scenario global_space_with_names)
def main [ def main [
global-space:address:array:location <- new location:type, 10 global-space:address:array:location <- new location:type, 10
x:number <- copy 23 x:num <- copy 23
1:number/space:global <- copy 24 1:num/space:global <- copy 24
] ]
# don't complain about mixing numeric addresses and names # don't complain about mixing numeric addresses and names
$error: 0 $error: 0

View File

@ -9,7 +9,7 @@
:(scenario transform_fails_on_reusing_name_with_different_type) :(scenario transform_fails_on_reusing_name_with_different_type)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
x:number <- copy 1 x:num <- copy 1
x:boolean <- copy 1 x:boolean <- copy 1
] ]
+error: main: 'x' used with multiple types +error: main: 'x' used with multiple types
@ -68,15 +68,15 @@ void check_type(set<reagent>& known, const reagent& x, const recipe& caller) {
:(scenario transform_fills_in_missing_types) :(scenario transform_fills_in_missing_types)
def main [ def main [
x:number <- copy 1 x:num <- copy 1
y:number <- add x, 1 y:num <- add x, 1
] ]
# x is in location 1, y in location 2 # x is in location 1, y in location 2
+mem: storing 2 in location 2 +mem: storing 2 in location 2
:(scenario transform_fills_in_missing_types_in_product) :(scenario transform_fills_in_missing_types_in_product)
def main [ def main [
x:number <- copy 1 x:num <- copy 1
x <- copy 2 x <- copy 2
] ]
# x is in location 1 # x is in location 1
@ -84,7 +84,7 @@ def main [
:(scenario transform_fills_in_missing_types_in_product_and_ingredient) :(scenario transform_fills_in_missing_types_in_product_and_ingredient)
def main [ def main [
x:number <- copy 1 x:num <- copy 1
x <- add x, 1 x <- add x, 1
] ]
# x is in location 1 # x is in location 1
@ -94,7 +94,7 @@ def main [
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
x <- copy 1 x <- copy 1
x:number <- copy 2 x:num <- copy 2
] ]
+error: main: missing type for 'x' in 'x <- copy 1' +error: main: missing type for 'x' in 'x <- copy 1'
@ -109,7 +109,7 @@ def main [
:(scenario array_type_without_size_fails) :(scenario array_type_without_size_fails)
% Hide_errors = true; % Hide_errors = true;
def main [ def main [
x:array:number <- merge 2, 12, 13 x:array:num <- merge 2, 12, 13
] ]
+error: main can't determine the size of array variable 'x'. Either allocate it separately and make the type of 'x' an address, or specify the length of the array in the type of 'x'. +error: main can't determine the size of array variable 'x'. Either allocate it separately and make the type of 'x' an address, or specify the length of the array in the type of 'x'.
@ -121,7 +121,7 @@ def main [
local-scope local-scope
0:address:array:location/names:foo <- copy 0 # specify surrounding space 0:address:array:location/names:foo <- copy 0 # specify surrounding space
x:boolean <- copy 1/true x:boolean <- copy 1/true
x:number/space:1 <- copy 34 x:num/space:1 <- copy 34
x/space:1 <- copy 35 x/space:1 <- copy 35
] ]
$error: 0 $error: 0

View File

@ -38,8 +38,8 @@ def main [
local-scope local-scope
source:address:source:char, sink:address:sink:char <- new-channel 3/capacity source:address:source:char, sink:address:sink:char <- new-channel 3/capacity
# create two background 'routines' that communicate by a channel # create two background 'routines' that communicate by a channel
routine1:number <- start-running producer, sink routine1:num <- start-running producer, sink
routine2:number <- start-running consumer, source routine2:num <- start-running consumer, source
wait-for-routine routine1 wait-for-routine routine1
wait-for-routine routine2 wait-for-routine routine2
] ]

View File

@ -106,12 +106,12 @@ def new-board initial-position:address:array:char -> board:board [
local-scope local-scope
load-ingredients load-ingredients
# assert(length(initial-position) == 64) # assert(length(initial-position) == 64)
len:number <- length *initial-position len:num <- length *initial-position
correct-length?:boolean <- equal len, 64 correct-length?:boolean <- equal len, 64
assert correct-length?, [chessboard had incorrect size] assert correct-length?, [chessboard had incorrect size]
# board is an array of pointers to files; file is an array of characters # board is an array of pointers to files; file is an array of characters
board <- new {(address array character): type}, 8 board <- new {(address array character): type}, 8
col:number <- copy 0 col:num <- copy 0
{ {
done?:boolean <- equal col, 8 done?:boolean <- equal col, 8
break-if done? break-if done?
@ -122,12 +122,12 @@ def new-board initial-position:address:array:char -> board:board [
} }
] ]
def new-file position:address:array:char, index:number -> result:address:array:char [ def new-file position:address:array:char, index:num -> result:address:array:char [
local-scope local-scope
load-ingredients load-ingredients
index <- multiply index, 8 index <- multiply index, 8
result <- new character:type, 8 result <- new character:type, 8
row:number <- copy 0 row:num <- copy 0
{ {
done?:boolean <- equal row, 8 done?:boolean <- equal row, 8
break-if done? break-if done?
@ -142,20 +142,20 @@ def new-file position:address:array:char, index:number -> result:address:array:c
def print-board screen:address:screen, board:board -> screen:address:screen [ def print-board screen:address:screen, board:board -> screen:address:screen [
local-scope local-scope
load-ingredients load-ingredients
row:number <- copy 7 # start printing from the top of the board row:num <- copy 7 # start printing from the top of the board
space:char <- copy 32/space space:char <- copy 32/space
# print each row # print each row
{ {
done?:boolean <- lesser-than row, 0 done?:boolean <- lesser-than row, 0
break-if done? break-if done?
# print rank number as a legend # print rank number as a legend
rank:number <- add row, 1 rank:num <- add row, 1
print-integer screen, rank print-integer screen, rank
print screen, [ | ] print screen, [ | ]
# print each square in the row # print each square in the row
col:number <- copy 0 col:num <- copy 0
{ {
done?:boolean <- equal col:number, 8 done?:boolean <- equal col:num, 8
break-if done?:boolean break-if done?:boolean
f:address:array:char <- index *board, col f:address:array:char <- index *board, col
c:char <- index *f, row c:char <- index *f, row
@ -226,33 +226,33 @@ scenario printing-the-board [
container move [ container move [
# valid range: 0-7 # valid range: 0-7
from-file:number from-file:num
from-rank:number from-rank:num
to-file:number to-file:num
to-rank:number to-rank:num
] ]
# prints only error messages to screen # prints only error messages to screen
def read-move stdin:address:source:char, screen:address:screen -> result:address:move, quit?:boolean, error?:boolean, stdin:address:source:char, screen:address:screen [ def read-move stdin:address:source:char, screen:address:screen -> result:address:move, quit?:boolean, error?:boolean, stdin:address:source:char, screen:address:screen [
local-scope local-scope
load-ingredients load-ingredients
from-file:number, quit?:boolean, error?:boolean <- read-file stdin, screen from-file:num, quit?:boolean, error?:boolean <- read-file stdin, screen
return-if quit?, 0/dummy return-if quit?, 0/dummy
return-if error?, 0/dummy return-if error?, 0/dummy
# construct the move object # construct the move object
result:address:move <- new move:type result:address:move <- new move:type
*result <- put *result, from-file:offset, from-file *result <- put *result, from-file:offset, from-file
from-rank:number, quit?, error? <- read-rank stdin, screen from-rank:num, quit?, error? <- read-rank stdin, screen
return-if quit?, 0/dummy return-if quit?, 0/dummy
return-if error?, 0/dummy return-if error?, 0/dummy
*result <- put *result, from-rank:offset, from-rank *result <- put *result, from-rank:offset, from-rank
error? <- expect-from-channel stdin, 45/dash, screen error? <- expect-from-channel stdin, 45/dash, screen
return-if error?, 0/dummy, 0/quit return-if error?, 0/dummy, 0/quit
to-file:number, quit?, error? <- read-file stdin, screen to-file:num, quit?, error? <- read-file stdin, screen
return-if quit?:boolean, 0/dummy return-if quit?:boolean, 0/dummy
return-if error?:boolean, 0/dummy return-if error?:boolean, 0/dummy
*result <- put *result, to-file:offset, to-file *result <- put *result, to-file:offset, to-file
to-rank:number, quit?, error? <- read-rank stdin, screen to-rank:num, quit?, error? <- read-rank stdin, screen
return-if quit?, 0/dummy return-if quit?, 0/dummy
return-if error?, 0/dummy return-if error?, 0/dummy
*result <- put *result, to-rank:offset, to-rank *result <- put *result, to-rank:offset, to-rank
@ -261,7 +261,7 @@ def read-move stdin:address:source:char, screen:address:screen -> result:address
] ]
# valid values for file: 0-7 # valid values for file: 0-7
def read-file stdin:address:source:char, screen:address:screen -> file:number, quit:boolean, error:boolean, stdin:address:source:char, screen:address:screen [ def read-file stdin:address:source:char, screen:address:screen -> file:num, quit:boolean, error:boolean, stdin:address:source:char, screen:address:screen [
local-scope local-scope
load-ingredients load-ingredients
c:char, eof?:boolean, stdin <- read stdin c:char, eof?:boolean, stdin <- read stdin
@ -287,7 +287,7 @@ def read-file stdin:address:source:char, screen:address:screen -> file:number, q
print screen, [that's not enough] print screen, [that's not enough]
return 0/dummy, 0/quit, 1/error return 0/dummy, 0/quit, 1/error
} }
file:number <- subtract c, 97/a file:num <- subtract c, 97/a
# 'a' <= file <= 'h' # 'a' <= file <= 'h'
{ {
above-min:boolean <- greater-or-equal file, 0 above-min:boolean <- greater-or-equal file, 0
@ -308,7 +308,7 @@ def read-file stdin:address:source:char, screen:address:screen -> file:number, q
] ]
# valid values for rank: 0-7 # valid values for rank: 0-7
def read-rank stdin:address:source:char, screen:address:screen -> rank:number, quit?:boolean, error?:boolean, stdin:address:source:char, screen:address:screen [ def read-rank stdin:address:source:char, screen:address:screen -> rank:num, quit?:boolean, error?:boolean, stdin:address:source:char, screen:address:screen [
local-scope local-scope
load-ingredients load-ingredients
c:char, eof?:boolean, stdin <- read stdin c:char, eof?:boolean, stdin <- read stdin
@ -329,7 +329,7 @@ def read-rank stdin:address:source:char, screen:address:screen -> rank:number, q
print screen, [that's not enough] print screen, [that's not enough]
return 0/dummy, 0/quit, 1/error return 0/dummy, 0/quit, 1/error
} }
rank:number <- subtract c, 49/'1' rank:num <- subtract c, 49/'1'
# assert'1' <= rank <= '8' # assert'1' <= rank <= '8'
{ {
above-min:boolean <- greater-or-equal rank, 0 above-min:boolean <- greater-or-equal rank, 0
@ -368,10 +368,10 @@ scenario read-move-blocking [
run [ run [
local-scope local-scope
source:address:source:char, sink:address:sink:char <- new-channel 2/capacity source:address:source:char, sink:address:sink:char <- new-channel 2/capacity
read-move-routine:number/routine <- start-running read-move, source, screen:address:screen read-move-routine:num/routine <- start-running read-move, source, screen:address:screen
# 'read-move' is waiting for input # 'read-move' is waiting for input
wait-for-routine-to-block read-move-routine wait-for-routine-to-block read-move-routine
read-move-state:number <- routine-state read-move-routine read-move-state:num <- routine-state read-move-routine
waiting?:boolean <- not-equal read-move-state, 2/discontinued waiting?:boolean <- not-equal read-move-state, 2/discontinued
assert waiting?, [ assert waiting?, [
F read-move-blocking: routine failed to pause after coming up (before any keys were pressed)] F read-move-blocking: routine failed to pause after coming up (before any keys were pressed)]
@ -441,10 +441,10 @@ scenario read-move-quit [
run [ run [
local-scope local-scope
source:address:source:char, sink:address:sink:char <- new-channel 2/capacity source:address:source:char, sink:address:sink:char <- new-channel 2/capacity
read-move-routine:number <- start-running read-move, source, screen:address:screen read-move-routine:num <- start-running read-move, source, screen:address:screen
# 'read-move' is waiting for input # 'read-move' is waiting for input
wait-for-routine-to-block read-move-routine wait-for-routine-to-block read-move-routine
read-move-state:number <- routine-state read-move-routine read-move-state:num <- routine-state read-move-routine
waiting?:boolean <- not-equal read-move-state, 2/discontinued waiting?:boolean <- not-equal read-move-state, 2/discontinued
assert waiting?, [ assert waiting?, [
F read-move-quit: routine failed to pause after coming up (before any keys were pressed)] F read-move-quit: routine failed to pause after coming up (before any keys were pressed)]
@ -469,10 +469,10 @@ scenario read-move-illegal-file [
run [ run [
local-scope local-scope
source:address:source:char, sink:address:sink:char <- new-channel 2/capacity source:address:source:char, sink:address:sink:char <- new-channel 2/capacity
read-move-routine:number <- start-running read-move, source, screen:address:screen read-move-routine:num <- start-running read-move, source, screen:address:screen
# 'read-move' is waiting for input # 'read-move' is waiting for input
wait-for-routine-to-block read-move-routine wait-for-routine-to-block read-move-routine
read-move-state:number <- routine-state read-move-routine read-move-state:num <- routine-state read-move-routine
waiting?:boolean <- not-equal read-move-state, 2/discontinued waiting?:boolean <- not-equal read-move-state, 2/discontinued
assert waiting?, [ assert waiting?, [
F read-move-illegal-file: routine failed to pause after coming up (before any keys were pressed)] F read-move-illegal-file: routine failed to pause after coming up (before any keys were pressed)]
@ -491,10 +491,10 @@ scenario read-move-illegal-rank [
run [ run [
local-scope local-scope
source:address:source:char, sink:address:sink:char <- new-channel 2/capacity source:address:source:char, sink:address:sink:char <- new-channel 2/capacity
read-move-routine:number <- start-running read-move, source, screen:address:screen read-move-routine:num <- start-running read-move, source, screen:address:screen
# 'read-move' is waiting for input # 'read-move' is waiting for input
wait-for-routine-to-block read-move-routine wait-for-routine-to-block read-move-routine
read-move-state:number <- routine-state read-move-routine read-move-state:num <- routine-state read-move-routine
waiting?:boolean <- not-equal read-move-state, 2/discontinued waiting?:boolean <- not-equal read-move-state, 2/discontinued
assert waiting?, [ assert waiting?, [
F read-move-illegal-rank: routine failed to pause after coming up (before any keys were pressed)] F read-move-illegal-rank: routine failed to pause after coming up (before any keys were pressed)]
@ -514,10 +514,10 @@ scenario read-move-empty [
run [ run [
local-scope local-scope
source:address:source:char, sink:address:sink:char <- new-channel 2/capacity source:address:source:char, sink:address:sink:char <- new-channel 2/capacity
read-move-routine:number <- start-running read-move, source, screen:address:screen read-move-routine:num <- start-running read-move, source, screen:address:screen
# 'read-move' is waiting for input # 'read-move' is waiting for input
wait-for-routine-to-block read-move-routine wait-for-routine-to-block read-move-routine
read-move-state:number <- routine-state read-move-routine read-move-state:num <- routine-state read-move-routine
waiting?:boolean <- not-equal read-move-state, 2/discontinued waiting?:boolean <- not-equal read-move-state, 2/discontinued
assert waiting?, [ assert waiting?, [
F read-move-empty: routine failed to pause after coming up (before any keys were pressed)] F read-move-empty: routine failed to pause after coming up (before any keys were pressed)]
@ -535,10 +535,10 @@ F read-move-empty: routine failed to pause after coming up (before any keys were
def make-move board:board, m:address:move -> board:board [ def make-move board:board, m:address:move -> board:board [
local-scope local-scope
load-ingredients load-ingredients
from-file:number <- get *m, from-file:offset from-file:num <- get *m, from-file:offset
from-rank:number <- get *m, from-rank:offset from-rank:num <- get *m, from-rank:offset
to-file:number <- get *m, to-file:offset to-file:num <- get *m, to-file:offset
to-rank:number <- get *m, to-rank:offset to-rank:num <- get *m, to-rank:offset
from-f:address:array:char <- index *board, from-file from-f:address:array:char <- index *board, from-file
to-f:address:array:char <- index *board, to-file to-f:address:array:char <- index *board, to-file
src:char/square <- index *from-f, from-rank src:char/square <- index *from-f, from-rank

View File

@ -1,12 +1,12 @@
# example program: maintain multiple counters with isolated lexical scopes # example program: maintain multiple counters with isolated lexical scopes
# (spaces) # (spaces)
def new-counter n:number -> default-space:address:array:location [ def new-counter n:num -> default-space:address:array:location [
default-space <- new location:type, 30 default-space <- new location:type, 30
load-ingredients load-ingredients
] ]
def increment-counter outer:address:array:location/names:new-counter, x:number -> n:number/space:1 [ def increment-counter outer:address:array:location/names:new-counter, x:num -> n:num/space:1 [
local-scope local-scope
load-ingredients load-ingredients
0:address:array:location/names:new-counter <- copy outer # setup outer space; it *must* come from 'new-counter' 0:address:array:location/names:new-counter <- copy outer # setup outer space; it *must* come from 'new-counter'
@ -21,8 +21,8 @@ def main [
b:address:array:location <- new-counter 23 b:address:array:location <- new-counter 23
# increment both by 2 but in different ways # increment both by 2 but in different ways
increment-counter a, 1 increment-counter a, 1
b-value:number <- increment-counter b, 2 b-value:num <- increment-counter b, 2
a-value:number <- increment-counter a, 1 a-value:num <- increment-counter a, 1
# check results # check results
$print [Contents of counters], 10/newline $print [Contents of counters], 10/newline
$print [a: ], a-value, [ b: ], b-value, 10/newline $print [a: ], a-value, [ b: ], b-value, 10/newline

View File

@ -3,7 +3,7 @@
def main [ def main [
open-console open-console
print-character-to-display 97, 1/red, 2/green print-character-to-display 97, 1/red, 2/green
1:number/raw, 2:number/raw <- cursor-position-on-display 1:num/raw, 2:num/raw <- cursor-position-on-display
wait-for-some-interaction wait-for-some-interaction
clear-display clear-display
move-cursor-on-display 0, 4 move-cursor-on-display 0, 4

View File

@ -1,5 +1,5 @@
def example1 [ def example1 [
local-scope local-scope
a:number <- add 2, 2 a:num <- add 2, 2
a <- multiply a, 3 a <- multiply a, 3
] ]

View File

@ -2,12 +2,12 @@
def main [ def main [
local-scope local-scope
x:number <- factorial 5 x:num <- factorial 5
$print [result: ], x, [ $print [result: ], x, [
] ]
] ]
def factorial n:number -> result:number [ def factorial n:num -> result:num [
local-scope local-scope
load-ingredients load-ingredients
{ {
@ -17,15 +17,15 @@ def factorial n:number -> result:number [
return 1 return 1
} }
# return n * factorial(n-1) # return n * factorial(n-1)
x:number <- subtract n, 1 x:num <- subtract n, 1
subresult:number <- factorial x subresult:num <- factorial x
result <- multiply subresult, n result <- multiply subresult, n
] ]
# unit test # unit test
scenario factorial-test [ scenario factorial-test [
run [ run [
1:number <- factorial 5 1:num <- factorial 5
] ]
memory-should-contain [ memory-should-contain [
1 <- 120 1 <- 120

View File

@ -6,7 +6,7 @@
def main [ def main [
local-scope local-scope
source-file:address:source:char <- start-reading 0/real-filesystem, [/tmp/mu-x] source-file:address:source:char <- start-reading 0/real-filesystem, [/tmp/mu-x]
sink-file:address:sink:char, write-routine:number <- start-writing 0/real-filesystem, [/tmp/mu-y] sink-file:address:sink:char, write-routine:num <- start-writing 0/real-filesystem, [/tmp/mu-y]
{ {
c:char, done?:boolean, source-file <- read source-file c:char, done?:boolean, source-file <- read source-file
break-if done? break-if done?

View File

@ -4,11 +4,11 @@ def main [
# allocate 5 locations for globals # allocate 5 locations for globals
global-space:address:array:location <- new location:type, 5 global-space:address:array:location <- new location:type, 5
# read to globals by using /space:global # read to globals by using /space:global
1:number/space:global <- copy 3 1:num/space:global <- copy 3
foo foo
] ]
def foo [ def foo [
# ditto for writing to globals # ditto for writing to globals
$print 1:number/space:global, 10/newline $print 1:num/space:global, 10/newline
] ]

View File

@ -2,11 +2,11 @@
def main [ def main [
local-scope local-scope
x:address:number <- new number:type x:address:num <- new number:type
foo x foo x
] ]
def foo x:address:number [ def foo x:address:num [
local-scope local-scope
load-ingredients load-ingredients
*x <- copy 34 # will cause an error because x is immutable in this function *x <- copy 34 # will cause an error because x is immutable in this function

View File

@ -2,11 +2,11 @@
def main [ def main [
local-scope local-scope
x:address:number <- new number:type x:address:num <- new number:type
foo x foo x
] ]
def foo x:address:number -> x:address:number [ def foo x:address:num -> x:address:num [
local-scope local-scope
load-ingredients load-ingredients
*x <- copy 34 *x <- copy 34

View File

@ -2,15 +2,15 @@
# port of the Arc solution at http://arclanguage.org/item?id=19743 # port of the Arc solution at http://arclanguage.org/item?id=19743
container square [ container square [
rank:number rank:num
file:number file:num
] ]
def nqueens n:number, queens:address:list:square -> result:number [ def nqueens n:num, queens:address:list:square -> result:num [
local-scope local-scope
load-ingredients load-ingredients
# if 'queens' is already long enough, print it and return # if 'queens' is already long enough, print it and return
added-so-far:number <- length queens added-so-far:num <- length queens
{ {
done?:boolean <- greater-or-equal added-so-far, n done?:boolean <- greater-or-equal added-so-far, n
break-unless done? break-unless done?
@ -18,15 +18,15 @@ def nqueens n:number, queens:address:list:square -> result:number [
return 1 return 1
} }
# still work to do # still work to do
next-rank:number <- copy 0 next-rank:num <- copy 0
{ {
break-unless queens break-unless queens
first:square <- first queens first:square <- first queens
existing-rank:number <- get first, rank:offset existing-rank:num <- get first, rank:offset
next-rank <- add existing-rank, 1 next-rank <- add existing-rank, 1
} }
result <- copy 0 result <- copy 0
next-file:number <- copy 0 next-file:num <- copy 0
{ {
done?:boolean <- greater-or-equal next-file, n done?:boolean <- greater-or-equal next-file, n
break-if done? break-if done?
@ -35,7 +35,7 @@ def nqueens n:number, queens:address:list:square -> result:number [
curr-conflicts?:boolean <- conflict? curr, queens curr-conflicts?:boolean <- conflict? curr, queens
break-if curr-conflicts? break-if curr-conflicts?
new-queens:address:list:square <- push curr, queens new-queens:address:list:square <- push curr, queens
sub-result:number <- nqueens n, new-queens sub-result:num <- nqueens n, new-queens
result <- add result, sub-result result <- add result, sub-result
} }
next-file <- add next-file, 1 next-file <- add next-file, 1
@ -55,11 +55,11 @@ def conflict? curr:square, queens:address:list:square -> result:boolean [
def conflicting-file? curr:square, queens:address:list:square -> result:boolean [ def conflicting-file? curr:square, queens:address:list:square -> result:boolean [
local-scope local-scope
load-ingredients load-ingredients
curr-file:number <- get curr, file:offset curr-file:num <- get curr, file:offset
{ {
break-unless queens break-unless queens
q:square <- first queens q:square <- first queens
qfile:number <- get q, file:offset qfile:num <- get q, file:offset
file-match?:boolean <- equal curr-file, qfile file-match?:boolean <- equal curr-file, qfile
reply-if file-match?, 1/conflict-found reply-if file-match?, 1/conflict-found
queens <- rest queens queens <- rest queens
@ -71,15 +71,15 @@ def conflicting-file? curr:square, queens:address:list:square -> result:boolean
def conflicting-diagonal? curr:square, queens:address:list:square -> result:boolean [ def conflicting-diagonal? curr:square, queens:address:list:square -> result:boolean [
local-scope local-scope
load-ingredients load-ingredients
curr-rank:number <- get curr, rank:offset curr-rank:num <- get curr, rank:offset
curr-file:number <- get curr, file:offset curr-file:num <- get curr, file:offset
{ {
break-unless queens break-unless queens
q:square <- first queens q:square <- first queens
qrank:number <- get q, rank:offset qrank:num <- get q, rank:offset
qfile:number <- get q, file:offset qfile:num <- get q, file:offset
rank-delta:number <- subtract qrank, curr-rank rank-delta:num <- subtract qrank, curr-rank
file-delta:number <- subtract qfile, curr-file file-delta:num <- subtract qfile, curr-file
rank-delta <- abs rank-delta rank-delta <- abs rank-delta
file-delta <- abs file-delta file-delta <- abs file-delta
diagonal-match?:boolean <- equal rank-delta, file-delta diagonal-match?:boolean <- equal rank-delta, file-delta

View File

@ -5,7 +5,7 @@
def main [ def main [
local-scope local-scope
f:number/file <- $open-file-for-reading [/tmp/mu-x] f:num/file <- $open-file-for-reading [/tmp/mu-x]
$print [file to read from: ], f, 10/newline $print [file to read from: ], f, 10/newline
c:char, eof?:boolean <- $read-from-file f c:char, eof?:boolean <- $read-from-file f
$print [copying ], c, 10/newline $print [copying ], c, 10/newline

View File

@ -6,7 +6,7 @@ def main [
open-console open-console
10:char <- copy 97/a 10:char <- copy 97/a
print 0/screen, 10:char/a, 2/red print 0/screen, 10:char/a, 2/red
1:number/raw, 2:number/raw <- cursor-position 0/screen 1:num/raw, 2:num/raw <- cursor-position 0/screen
wait-for-event 0/console wait-for-event 0/console
clear-screen 0/screen clear-screen 0/screen
move-cursor 0/screen, 0/row, 4/column move-cursor 0/screen, 0/row, 4/column

View File

@ -1,8 +1,8 @@
def main [ def main [
local-scope local-scope
socket:number <- $socket 8080/port socket:num <- $socket 8080/port
$print [Mu socket creation returned ], socket, 10/newline $print [Mu socket creation returned ], socket, 10/newline
session:number <- $accept socket session:num <- $accept socket
{ {
client-message:address:buffer <- new-buffer 1024 client-message:address:buffer <- new-buffer 1024
c:char <- $read-from-socket session c:char <- $read-from-socket session

View File

@ -1,10 +1,10 @@
def test a:number -> b:number [ def test a:num -> b:num [
local-scope local-scope
load-ingredients load-ingredients
b <- add a, 1 b <- add a, 1
] ]
def test a:number, b:number -> c:number [ def test a:num, b:num -> c:num [
local-scope local-scope
load-ingredients load-ingredients
c <- add a, b c <- add a, b
@ -12,10 +12,10 @@ def test a:number, b:number -> c:number [
def main [ def main [
local-scope local-scope
a:number <- test 3 # selects single-ingredient version a:num <- test 3 # selects single-ingredient version
$print a, 10/newline $print a, 10/newline
b:number <- test 3, 4 # selects double-ingredient version b:num <- test 3, 4 # selects double-ingredient version
$print b, 10/newline $print b, 10/newline
c:number <- test 3, 4, 5 # prefers double- to single-ingredient version c:num <- test 3, 4, 5 # prefers double- to single-ingredient version
$print c, 10/newline $print c, 10/newline
] ]

View File

@ -6,7 +6,7 @@
# This isn't a very tasteful example, just a simple demonstration of # This isn't a very tasteful example, just a simple demonstration of
# possibilities. # possibilities.
def factorial n:number -> result:number [ def factorial n:num -> result:num [
local-scope local-scope
load-ingredients load-ingredients
{ {
@ -24,14 +24,14 @@ after <base-case> [
after <recursive-case> [ after <recursive-case> [
# return n * factorial(n - 1) # return n * factorial(n - 1)
x:number <- subtract n, 1 x:num <- subtract n, 1
subresult:number <- factorial x subresult:num <- factorial x
result <- multiply subresult, n result <- multiply subresult, n
] ]
def main [ def main [
1:number <- factorial 5 1:num <- factorial 5
# trailing space in next line is to help with syntax highlighting # trailing space in next line is to help with syntax highlighting
$print [result: ], 1:number, [ $print [result: ], 1:num, [
] ]
] ]

6
x.mu
View File

@ -1,8 +1,8 @@
# example program: add two numbers # example program: add two numbers
def main [ def main [
11:number <- copy 1 11:num <- copy 1
12:number <- copy 3 12:num <- copy 3
13:number <- add 11:number, 12:number 13:num <- add 11:num, 12:num
$dump-memory $dump-memory
] ]