diff options
author | Bad Diode <bd@badd10de.dev> | 2024-06-20 14:20:07 +0200 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2024-06-20 14:20:07 +0200 |
commit | 972c453a085bedb3de8d598cc4ae4486e24f0144 (patch) | |
tree | 02503240867fc8e77fbca4f7c900192e9a7873be /tests | |
parent | c0faac681a32ffc2e323917f8b54f33558b391a5 (diff) | |
download | bdl-972c453a085bedb3de8d598cc4ae4486e24f0144.tar.gz bdl-972c453a085bedb3de8d598cc4ae4486e24f0144.zip |
Move vm/chunk compiler to separate file
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functions.bad | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/functions.bad b/tests/functions.bad new file mode 100644 index 0000000..0d2e2d0 --- /dev/null +++ b/tests/functions.bad | |||
@@ -0,0 +1,29 @@ | |||
1 | ; Simple function declarations don't need a block. | ||
2 | fun add_two(a: int, b: int): int a + b | ||
3 | |||
4 | ; Functions return the result of the last expression implicitly. | ||
5 | fun add_three(a: int, b: int, c: int): int { | ||
6 | a + b + c | ||
7 | } | ||
8 | |||
9 | ; Functions that don't return anything must explicitly state it as returning | ||
10 | ; nil. | ||
11 | fun foo(): nil { | ||
12 | write("hello buddy") | ||
13 | } | ||
14 | |||
15 | ; An alternate form for empty return values. | ||
16 | fun bar(): () { | ||
17 | write("hello world") | ||
18 | } | ||
19 | |||
20 | ; We support multiple return values, in this case the "return" keyword must be | ||
21 | ; explict. | ||
22 | fun baz(a: int, b: str): (int, str) { | ||
23 | return(1, "hello") | ||
24 | } | ||
25 | |||
26 | ; Make sure we can use pointer types on params and return values. | ||
27 | fun test(a: @int[256], b: @str): @int { | ||
28 | a | ||
29 | } | ||