2019-07-02 01:49:15 +02:00
|
|
|
// 1 line comment
|
|
|
|
|
|
|
|
/* 1 line comment */
|
|
|
|
|
|
|
|
/*
|
|
|
|
multi line comment (1)
|
|
|
|
multi line comment (2)
|
|
|
|
multi line comment (3)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
multi line comment (1)
|
|
|
|
/*
|
|
|
|
nested comment
|
|
|
|
*/
|
|
|
|
/*nested comment*/
|
|
|
|
/*nested comment
|
|
|
|
*/
|
|
|
|
/* nested comment */
|
|
|
|
/* /* nested comment */ */
|
|
|
|
multi line comment (2)
|
|
|
|
*/
|
|
|
|
|
2019-06-27 14:28:12 +02:00
|
|
|
type myfn fn (int) string
|
|
|
|
|
|
|
|
type myfn2 fn (a int, b int) int
|
|
|
|
|
|
|
|
type myfn3 fn (int, int)
|
|
|
|
|
|
|
|
fn myfn4(string)
|
|
|
|
|
|
|
|
fn foobar()
|
|
|
|
|
|
|
|
fn slopediv(num u32, den u32) int
|
|
|
|
|
|
|
|
type f1 fn ()
|
|
|
|
|
|
|
|
type f2 fn (voidptr)
|
|
|
|
|
|
|
|
type f3 fn (voidptr, voidptr)
|
|
|
|
|
|
|
|
type f4 fn (voidptr) int
|
|
|
|
|
|
|
|
type f5 fn (int, int) int
|
|
|
|
|
|
|
|
type f6 fn (int, int)
|
|
|
|
|
|
|
|
fn C.atoi(byteptr) int
|
|
|
|
|
|
|
|
fn foo() {
|
|
|
|
}
|
|
|
|
|
2019-09-29 16:02:28 +02:00
|
|
|
type actionf_v fn ()
|
2019-06-27 14:28:12 +02:00
|
|
|
|
2019-09-29 16:02:28 +02:00
|
|
|
type actionf_p1 fn (voidptr)
|
2019-06-27 14:28:12 +02:00
|
|
|
|
2019-09-29 16:02:28 +02:00
|
|
|
type actionf_p2 fn (voidptr, voidptr)
|
2019-06-27 14:28:12 +02:00
|
|
|
|
2019-09-29 16:02:28 +02:00
|
|
|
// TODO
|
2019-07-24 13:04:57 +02:00
|
|
|
fn modify_array(a mut []int) {
|
2019-09-29 16:02:28 +02:00
|
|
|
a[0] = 10
|
2019-07-24 13:04:57 +02:00
|
|
|
for i in 0..a.len {
|
|
|
|
a[i] = a[i] * 2
|
|
|
|
}
|
2019-09-29 16:02:28 +02:00
|
|
|
//a << 888
|
|
|
|
}
|
2019-07-24 13:04:57 +02:00
|
|
|
|
2019-07-24 15:24:32 +02:00
|
|
|
fn test_mut_array() {
|
2019-09-29 16:02:28 +02:00
|
|
|
mut nums := [1, 2, 3]
|
|
|
|
modify_array(mut nums)
|
|
|
|
//assert nums.len == 4
|
2019-09-04 17:13:52 +02:00
|
|
|
// println(nums)
|
2019-09-29 16:02:28 +02:00
|
|
|
assert nums[0] == 20
|
2019-07-24 13:04:57 +02:00
|
|
|
assert nums[1] == 4
|
2019-09-29 16:02:28 +02:00
|
|
|
assert nums[2] == 6
|
2019-09-04 17:13:52 +02:00
|
|
|
//assert nums[3] == 888
|
|
|
|
// workaround for // [91, 32, -33686272] windows bug
|
|
|
|
println(nums.clone())
|
2019-09-29 16:02:28 +02:00
|
|
|
}
|
2019-07-24 13:04:57 +02:00
|
|
|
|
2019-07-24 15:24:32 +02:00
|
|
|
fn mod_struct(user mut User) {
|
2019-09-29 16:02:28 +02:00
|
|
|
user.age++
|
2019-07-24 15:24:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct User {
|
2019-09-29 16:02:28 +02:00
|
|
|
mut:
|
|
|
|
age int
|
|
|
|
}
|
2019-07-24 15:24:32 +02:00
|
|
|
|
|
|
|
fn test_mut_struct() {
|
2019-09-29 16:02:28 +02:00
|
|
|
mut user := User{18}
|
|
|
|
mod_struct(mut user)
|
|
|
|
assert user.age == 19
|
|
|
|
}
|
2019-07-24 15:24:32 +02:00
|
|
|
|
|
|
|
fn mod_ptr(buf mut byteptr) {
|
2019-09-29 16:02:28 +02:00
|
|
|
buf[0] = 77
|
|
|
|
}
|
2019-07-24 15:24:32 +02:00
|
|
|
|
|
|
|
fn test_mut_ptr() {
|
2019-09-29 16:02:28 +02:00
|
|
|
buf := malloc(10)
|
|
|
|
mod_ptr(mut buf)
|
|
|
|
assert buf[0] == 77
|
|
|
|
}
|
2019-07-24 15:24:32 +02:00
|
|
|
|
2019-08-05 03:31:22 +02:00
|
|
|
fn high_fn(f fn(int) int) {
|
2019-09-29 16:02:28 +02:00
|
|
|
|
|
|
|
}
|
2019-08-04 10:18:31 +02:00
|
|
|
|
2019-10-09 19:55:36 +02:00
|
|
|
fn high_fn_array(f fn(a []int) []int) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fn high_fn_multi_return(a int, b fn (c []int, d []string) ([]int, []string)) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-27 14:28:12 +02:00
|
|
|
fn test_fns() {
|
2019-09-29 16:02:28 +02:00
|
|
|
// no asserts for now, just test function declarations above
|
|
|
|
}
|
2019-06-27 14:28:12 +02:00
|
|
|
|