Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperl committed Oct 23, 2024
1 parent d59d996 commit 6ef6018
Show file tree
Hide file tree
Showing 9 changed files with 942 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/compiler/propagation/type_primitive_encoding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ MODULE_TYPES(encoding, MODULE_ENCODING)

TYPE_PRIMITIVE_ANY(base64_encode)
TYPE_PRIMITIVE_ANY(base64_decode)
TYPE_PRIMITIVE_ANY(tison_encode)
TYPE_PRIMITIVE_ANY(tison_decode)

TYPE_PRIMITIVE(tison_encode) {
result.add_byte_array(program);
failure.add_string(program);
failure.add_array(program);
}

} // namespace toit::compiler
} // namespace toit
7 changes: 6 additions & 1 deletion src/compiler/propagation/type_primitive_programs_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ namespace compiler {
MODULE_TYPES(programs_registry, MODULE_PROGRAMS_REGISTRY)

TYPE_PRIMITIVE_ANY(next_group_id)
TYPE_PRIMITIVE_ANY(spawn)
TYPE_PRIMITIVE_ANY(is_running)
TYPE_PRIMITIVE_ANY(kill)
TYPE_PRIMITIVE_ANY(bundled_images)
TYPE_PRIMITIVE_ANY(assets)
TYPE_PRIMITIVE_ANY(config)

TYPE_PRIMITIVE(spawn) {
result.add_smi(program);
failure.add_string(program);
failure.add_array(program);
}

} // namespace toit::compiler
} // namespace toit
2 changes: 1 addition & 1 deletion tests/finally-params-test.toit
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test0:
expect-null exception

test1:
// With local. (shifting the try/finally locals.
// With local (shifting the try/finally locals).
was-in-finally := false
try:
null
Expand Down
41 changes: 41 additions & 0 deletions tests/type_propagation/default-arguments-test.toit
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) 2024 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the tests/LICENSE file.
main:
test-default-true --x
test-default-true --x=false
test-default-true --x=true
test-default-true --no-x
test-default-true --x=null

test-default-false --x
test-default-false --x=false
test-default-false --x=true
test-default-false --no-x
test-default-false --x=null

test-non-default --x
test-non-default --x=true
test-non-default --no-x
test-non-default --x=false

test-non-default-non-literal --x
test-non-default-non-literal --x=true
test-non-default-non-literal --no-x
test-non-default-non-literal --x=false

test-default-true --x/bool=true:
return x

test-default-false --x/bool=false:
return x

test-non-default --x/bool=true:
return x

test-non-default-non-literal --x/bool=gettrue:
return x

gettrue:
return true
92 changes: 92 additions & 0 deletions tests/type_propagation/finally-test.toit
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ main:
test-exception
test-catchy
test-nlb-out-of-try
test-throw-update-in-finally
test-break-update-in-finally
test-break-update-in-finally-block0
test-break-update-in-finally-block1
test-break-update-in-finally-block2
test-break-update-in-finally-block3
test-break-update-in-finally-nested

test-is-exception:
return-is-exception
Expand Down Expand Up @@ -57,6 +64,85 @@ test-nlb-out-of-try:
x = null
finally:
id x
test-throw-update-in-finally:
x := false
invoke-catch:
try:
throw "ugh"
finally:
x = true
id x

test-break-update-in-finally:
x := false
while true:
try:
break
finally:
x = true
id x

test-break-update-in-finally-block0:
x := false
while true:
invoke:
try:
break
finally:
x = true
id x

test-break-update-in-finally-block1:
x := false
while true:
block := (: break)
try:
block.call
finally:
x = true
id x

test-break-update-in-finally-block2:
x/any := null
while true:
block := (: break)
try:
block.call
finally:
x = true
try:
block.call
finally:
x = false
id x

test-break-update-in-finally-block3:
x := false
y := null
while true:
block := (: break)
while true:
try:
if pick: block.call
else: break
finally:
x = true
y = x
id x
id y

test-break-update-in-finally-nested:
x/any := null
while true:
try:
try:
x = 0
break
finally:
x = true
finally:
x = "horse"
id x

id x:
return x
Expand All @@ -66,3 +152,9 @@ pick:

invoke [block]:
block.call

invoke-catch [block]:
try:
block.call
finally:
return
107 changes: 107 additions & 0 deletions tests/type_propagation/gold/default-arguments-test.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
main tests/type_propagation/default-arguments-test.toit
0[020] - load literal true
2[053] - invoke static test-default-true tests/type_propagation/default-arguments-test.toit // [{True}] -> {True}
5[041] - pop 1
6[020] - load literal false
8[053] - invoke static test-default-true tests/type_propagation/default-arguments-test.toit // [{False}] -> {True|False}
11[041] - pop 1
12[020] - load literal true
14[053] - invoke static test-default-true tests/type_propagation/default-arguments-test.toit // [{True}] -> {True}
17[041] - pop 1
18[020] - load literal false
20[053] - invoke static test-default-true tests/type_propagation/default-arguments-test.toit // [{False}] -> {True|False}
23[041] - pop 1
24[022] - load null
25[053] - invoke static test-default-true tests/type_propagation/default-arguments-test.toit // [{Null_}] -> {True}
28[041] - pop 1
29[020] - load literal true
31[053] - invoke static test-default-false tests/type_propagation/default-arguments-test.toit // [{True}] -> {True|False}
34[041] - pop 1
35[020] - load literal false
37[053] - invoke static test-default-false tests/type_propagation/default-arguments-test.toit // [{False}] -> {False}
40[041] - pop 1
41[020] - load literal true
43[053] - invoke static test-default-false tests/type_propagation/default-arguments-test.toit // [{True}] -> {True|False}
46[041] - pop 1
47[020] - load literal false
49[053] - invoke static test-default-false tests/type_propagation/default-arguments-test.toit // [{False}] -> {False}
52[041] - pop 1
53[022] - load null
54[053] - invoke static test-default-false tests/type_propagation/default-arguments-test.toit // [{Null_}] -> {False}
57[041] - pop 1
58[020] - load literal true
60[053] - invoke static test-non-default tests/type_propagation/default-arguments-test.toit // [{True}] -> {True}
63[041] - pop 1
64[020] - load literal true
66[053] - invoke static test-non-default tests/type_propagation/default-arguments-test.toit // [{True}] -> {True}
69[041] - pop 1
70[020] - load literal false
72[053] - invoke static test-non-default tests/type_propagation/default-arguments-test.toit // [{False}] -> {True|False}
75[041] - pop 1
76[020] - load literal false
78[053] - invoke static test-non-default tests/type_propagation/default-arguments-test.toit // [{False}] -> {True|False}
81[041] - pop 1
82[020] - load literal true
84[053] - invoke static test-non-default-non-literal tests/type_propagation/default-arguments-test.toit // [{True}] -> {True}
87[041] - pop 1
88[020] - load literal true
90[053] - invoke static test-non-default-non-literal tests/type_propagation/default-arguments-test.toit // [{True}] -> {True}
93[041] - pop 1
94[020] - load literal false
96[053] - invoke static test-non-default-non-literal tests/type_propagation/default-arguments-test.toit // [{False}] -> {True|False}
99[041] - pop 1
100[020] - load literal false
102[053] - invoke static test-non-default-non-literal tests/type_propagation/default-arguments-test.toit // [{False}] -> {True|False}
105[090] - return null S1 0

test-default-true tests/type_propagation/default-arguments-test.toit
- argument 0: {Null_|True|False}
0[016] - load local 2
1[022] - load null
2[094] - identical
3[083] - branch if false T10
6[020] - load literal true
8[004] - store local, pop S3
10[052] - load local, as class, pop 2 - True(21 - 23) // {True|False}
12[016] - load local 2
13[089] - return S1 1

test-default-false tests/type_propagation/default-arguments-test.toit
- argument 0: {Null_|True|False}
0[016] - load local 2
1[022] - load null
2[094] - identical
3[083] - branch if false T10
6[020] - load literal false
8[004] - store local, pop S3
10[052] - load local, as class, pop 2 - True(21 - 23) // {True|False}
12[016] - load local 2
13[089] - return S1 1

test-non-default tests/type_propagation/default-arguments-test.toit
- argument 0: {True|False}
0[016] - load local 2
1[022] - load null
2[094] - identical
3[083] - branch if false T10
6[020] - load literal true
8[004] - store local, pop S3
10[052] - load local, as class, pop 2 - True(21 - 23) // {True}
12[016] - load local 2
13[089] - return S1 1

test-non-default-non-literal tests/type_propagation/default-arguments-test.toit
- argument 0: {True|False}
0[016] - load local 2
1[022] - load null
2[094] - identical
3[083] - branch if false T11
6[053] - invoke static gettrue tests/type_propagation/default-arguments-test.toit // {True}
9[004] - store local, pop S3
11[052] - load local, as class, pop 2 - True(21 - 23) // {True}
13[016] - load local 2
14[089] - return S1 1

gettrue tests/type_propagation/default-arguments-test.toit
0[020] - load literal true
2[089] - return S1 0
Loading

0 comments on commit 6ef6018

Please sign in to comment.