diff options
| author | Mustafa Quraish <[email protected]> | 2022-02-02 07:20:53 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-02-02 07:37:39 -0500 |
| commit | 1a8f96c65f94227faa9747ef876a60f3c313c6f1 (patch) | |
| tree | d80a396958ff2fc752b620cc5314e27e40b58ecb /tests/loops.sh | |
| parent | Use `type*` instead of `type&` to denote a pointer type (for now) (diff) | |
| download | cup-1a8f96c65f94227faa9747ef876a60f3c313c6f1.tar.xz cup-1a8f96c65f94227faa9747ef876a60f3c313c6f1.zip | |
Type checking of expressions / functions!
This is a bit of a chonky commit, but it adds in the basics of checking
the types of expressions / function calls / return types. There's still
a lot of work to be done, including:
(1) Adding new core types, and casting between allowed types
automatically
(2) Picking the corrent output type based on input types (for instance
float+int == float)
(3) We need much better error reporting, the error messages are really
vague and unhelpful as-is
(4) We also need to work to ensure that a function with a return type
actually returns
(5) Possible re-factoring to make stuff less hacky when we have more
types / structs / arrays / etc.
Diffstat (limited to 'tests/loops.sh')
| -rwxr-xr-x | tests/loops.sh | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/tests/loops.sh b/tests/loops.sh index 3fea60f..ab0a949 100755 --- a/tests/loops.sh +++ b/tests/loops.sh @@ -6,7 +6,7 @@ set -e echo -n "- While loops: " assert_exit_status_stdin 5 <<EOF -fn main() { +fn main(): int { while (1) { return 5; } @@ -15,7 +15,7 @@ fn main() { EOF assert_exit_status_stdin 3 <<EOF -fn main() { +fn main(): int { while (0) { return 5; } @@ -24,7 +24,7 @@ fn main() { EOF assert_exit_status_stdin 10 <<EOF -fn main() { +fn main(): int { let sum: int = 0; while (sum < 10) { sum = sum + 1; @@ -34,7 +34,7 @@ fn main() { EOF assert_exit_status_stdin 55 <<EOF -fn main() { +fn main(): int { let sum: int = 0; let N: int = 10; let i: int = 0; @@ -49,7 +49,7 @@ echo " OK" echo -n "- For loops: " assert_exit_status_stdin 5 <<EOF -fn main() { +fn main(): int { for (;;) { return 5; } @@ -58,7 +58,7 @@ fn main() { EOF assert_exit_status_stdin 3 <<EOF -fn main() { +fn main(): int { for (;0;) { return 5; } @@ -67,7 +67,7 @@ fn main() { EOF assert_exit_status_stdin 55 <<EOF -fn main() { +fn main(): int { let sum: int = 0; let i: int; for (i = 0; i <= 10; i = i + 1) { @@ -78,7 +78,7 @@ fn main() { EOF assert_exit_status_stdin 55 <<EOF -fn main() { +fn main(): int { let sum: int = 0; let i: int = 0; for (; i <= 10; i = i + 1) { @@ -89,7 +89,7 @@ fn main() { EOF assert_exit_status_stdin 45 <<EOF -fn main() { +fn main(): int { let sum: int = 0; let i: int = 0; for (;i < 10;) { @@ -101,7 +101,7 @@ fn main() { EOF assert_exit_status_stdin 55 <<EOF -fn main() { +fn main(): int { let sum: int = 0; let i: int = 0; for (;;) { |