diff options
Diffstat (limited to 'progs/tests/constant')
| -rw-r--r-- | progs/tests/constant/declaration_order.sy | 6 | ||||
| -rw-r--r-- | progs/tests/constant/declaration_order_wrong.sy | 8 | ||||
| -rw-r--r-- | progs/tests/constant/function.sy | 4 | ||||
| -rw-r--r-- | progs/tests/constant/function_closure.sy | 13 | ||||
| -rw-r--r-- | progs/tests/constant/function_complex.sy | 19 | ||||
| -rw-r--r-- | progs/tests/constant/global_collision.sy | 10 | ||||
| -rw-r--r-- | progs/tests/constant/global_constants.sy | 17 | ||||
| -rw-r--r-- | progs/tests/constant/in_inner_functions.sy | 20 |
8 files changed, 97 insertions, 0 deletions
diff --git a/progs/tests/constant/declaration_order.sy b/progs/tests/constant/declaration_order.sy new file mode 100644 index 0000000..93e6117 --- /dev/null +++ b/progs/tests/constant/declaration_order.sy @@ -0,0 +1,6 @@ +b :: 1 +a :: b + 1 + +start :: fn { + a <=> b + 1 +} diff --git a/progs/tests/constant/declaration_order_wrong.sy b/progs/tests/constant/declaration_order_wrong.sy new file mode 100644 index 0000000..37f5050 --- /dev/null +++ b/progs/tests/constant/declaration_order_wrong.sy @@ -0,0 +1,8 @@ +a :: b + 1 +b :: 1 + +start :: fn { + a <=> b + 1 +} + +// errors: [ErrorKind::SyntaxError(1, _)] diff --git a/progs/tests/constant/function.sy b/progs/tests/constant/function.sy new file mode 100644 index 0000000..22ddfe2 --- /dev/null +++ b/progs/tests/constant/function.sy @@ -0,0 +1,4 @@ +a :: fn {} +start :: fn { + a() +} diff --git a/progs/tests/constant/function_closure.sy b/progs/tests/constant/function_closure.sy new file mode 100644 index 0000000..6c7f0d7 --- /dev/null +++ b/progs/tests/constant/function_closure.sy @@ -0,0 +1,13 @@ +q : int = 1 + +f :: fn -> int { + q += 1 + ret q +} + +start :: fn { + f() <=> 2 + f() <=> 3 + f() <=> 4 + f() <=> 5 +} diff --git a/progs/tests/constant/function_complex.sy b/progs/tests/constant/function_complex.sy new file mode 100644 index 0000000..6a60ebe --- /dev/null +++ b/progs/tests/constant/function_complex.sy @@ -0,0 +1,19 @@ +h :: fn -> int { + ret 3 +} + +k :: fn -> int { + ret h() +} + +a :: fn -> int { + ret q() +} + +q :: fn -> int { + ret k() +} + +start :: fn { + a() <=> 3 +} diff --git a/progs/tests/constant/global_collision.sy b/progs/tests/constant/global_collision.sy new file mode 100644 index 0000000..6bce509 --- /dev/null +++ b/progs/tests/constant/global_collision.sy @@ -0,0 +1,10 @@ +fac :: fn a: int -> int { + if a < 1 { ret 1 } + ret a * fac! a - 1 +} + +a :: fac! 4 + +start :: fn { + a <=> 24 +} diff --git a/progs/tests/constant/global_constants.sy b/progs/tests/constant/global_constants.sy new file mode 100644 index 0000000..7ee6ca5 --- /dev/null +++ b/progs/tests/constant/global_constants.sy @@ -0,0 +1,17 @@ +// TODO(ed): Pure functions +fac :: fn n: int -> int { + if n < 1 { ret 1 } + ret n * fac! n - 1 +} + +a :: fac! 4 +b :: a + fac! 2 +c := b + 1 + +start :: fn { + a <=> 24 + b <=> 24 + 2 + c <=> 24 + 2 + 1 + c += 1 + c <=> 24 + 2 + 2 +} diff --git a/progs/tests/constant/in_inner_functions.sy b/progs/tests/constant/in_inner_functions.sy new file mode 100644 index 0000000..99704e7 --- /dev/null +++ b/progs/tests/constant/in_inner_functions.sy @@ -0,0 +1,20 @@ +start :: fn { + + q : int = 0 + + f :: fn -> fn -> { + g :: fn { + q += 1 + } + ret g + } + + g := f() + g() + q <=> 1 + g() + q <=> 2 + g() + q <=> 3 + +} |
