2024-06-12 11:46:11 +02:00
|
|
|
print('-- test functions --')
|
2024-06-07 11:37:53 +02:00
|
|
|
|
|
|
|
fn add(a, b) {
|
2024-06-12 11:46:11 +02:00
|
|
|
return a + b
|
2024-06-07 11:37:53 +02:00
|
|
|
}
|
|
|
|
fn add2(a, b) {
|
2024-06-12 11:46:11 +02:00
|
|
|
let c := a + b
|
|
|
|
return c
|
2024-06-07 11:37:53 +02:00
|
|
|
}
|
|
|
|
fn mult(a, b) {
|
2024-06-12 11:46:11 +02:00
|
|
|
return a * b
|
2024-06-07 11:37:53 +02:00
|
|
|
}
|
|
|
|
fn noArgs() {
|
2024-06-12 11:46:11 +02:00
|
|
|
let url := 'basdfasdf'
|
|
|
|
let second := 2 + 3
|
|
|
|
return second
|
2024-06-07 11:37:53 +02:00
|
|
|
}
|
|
|
|
fn empty() {}
|
2024-06-12 11:46:11 +02:00
|
|
|
fn empty2() {}
|
|
|
|
fn empty3() {}
|
2024-06-07 11:37:53 +02:00
|
|
|
fn noReturn() {
|
2024-06-12 11:46:11 +02:00
|
|
|
let a := 1
|
|
|
|
let b := 2
|
|
|
|
let c := a + b
|
2024-06-07 11:37:53 +02:00
|
|
|
}
|
2024-06-13 18:10:37 +02:00
|
|
|
fn emptyReturn() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fn emptyReturnBeforeOtherStuff() {
|
|
|
|
return
|
|
|
|
; 2 + 2
|
|
|
|
}
|
|
|
|
fn emptyReturnBeforeOtherStuffNoSemicolon() {
|
|
|
|
// This will return 4 because whitespace is omitted
|
|
|
|
return
|
|
|
|
2 + 2
|
|
|
|
}
|
2024-06-21 18:22:39 +02:00
|
|
|
fn ifThenReturn() {
|
|
|
|
// make sure this is not a placeholder {return}
|
|
|
|
if (false) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return 4
|
|
|
|
}
|
2024-06-07 11:37:53 +02:00
|
|
|
|
2024-06-12 11:46:11 +02:00
|
|
|
print(add(3, 4))
|
|
|
|
print(add(3, 4) + 100 + add(1, 1))
|
|
|
|
print(noArgs() ?? -1)
|
|
|
|
print(empty() ?? -1)
|
|
|
|
print(empty2() ?? -1)
|
|
|
|
print(empty3() ?? -1)
|
|
|
|
print(noReturn() ?? -1)
|
2024-06-13 18:10:37 +02:00
|
|
|
print(emptyReturn() ?? -1)
|
|
|
|
print(emptyReturnBeforeOtherStuff() ?? -1)
|
|
|
|
print(emptyReturnBeforeOtherStuffNoSemicolon() ?? -1)
|
2024-06-21 18:22:39 +02:00
|
|
|
print(ifThenReturn() ?? -1)
|
2024-06-13 18:10:37 +02:00
|
|
|
|
2024-06-12 11:46:11 +02:00
|
|
|
print(mult(add(3, 4) + 100 + add(2, 1), 2))
|
|
|
|
print(mult(add2(3, 4) + 100 + add2(2, 1), 10))
|