diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-12-23 08:57:48 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:37:00 +0200 |
commit | 902a81528b9d2edcf93226a2ca13da6fcc1839e5 (patch) | |
tree | ea868fae662aab61f1caa50b16a8b02fe1e6836b /tests | |
parent | 111bd0c7cb4b446c4bfe192b1df82845de17c005 (diff) |
wip: function pointers and other stuff
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bug.amal | 5 | ||||
-rw-r--r-- | tests/closure.amal | 37 | ||||
-rw-r--r-- | tests/conditions.amal | 16 | ||||
-rwxr-xr-x[-rw-r--r--] | tests/glfw.amal | 4 | ||||
-rw-r--r-- | tests/hello_world.amal | 5 |
5 files changed, 65 insertions, 2 deletions
diff --git a/tests/bug.amal b/tests/bug.amal new file mode 100644 index 0000000..170e72c --- /dev/null +++ b/tests/bug.amal @@ -0,0 +1,5 @@ +const func = fn(arg: i32) i32 { return 20; } + +const main = fn { + func(23); +}
\ No newline at end of file diff --git a/tests/closure.amal b/tests/closure.amal new file mode 100644 index 0000000..c5b3e15 --- /dev/null +++ b/tests/closure.amal @@ -0,0 +1,37 @@ +// extern const printf: fn(fmt: &c_char, ...) c_int; + +/* +const apply = fn(func: fn() bool) i32 { + //const f = func; + const result = func(); + //const result2 = f(); +} + +const main = fn { + // TODO: Test this + // const f = printf; + // f("hello"); + + apply(fn() bool { + return true; + }); + + // Or store in a variable and use it + const func = fn() bool { + return true; + } + apply(func); +} +*/ + +const f = fn(func: fn() i32) i32 { + func(); +} + +const bla = fn() i32 { + +} + +const main = fn { + f(bla); +}
\ No newline at end of file diff --git a/tests/conditions.amal b/tests/conditions.amal new file mode 100644 index 0000000..89ded06 --- /dev/null +++ b/tests/conditions.amal @@ -0,0 +1,16 @@ +extern const printf: fn(fmt: &c_char, ...) c_int; + +const main = fn { + var value = 23 + 50; + if value == 0 + printf("zero!\n"); + else if value < 23 + printf("less!\n"); + else + printf("more!\n"); + + while value > 0 { + printf("value: %d\n", value); + value = value - 1; + } +}
\ No newline at end of file diff --git a/tests/glfw.amal b/tests/glfw.amal index 37608fc..7c4a8ab 100644..100755 --- a/tests/glfw.amal +++ b/tests/glfw.amal @@ -7,9 +7,9 @@ extern const glfwWindowShouldClose: fn(window: u64) i32; const main = fn { glfwInit(); - const window = glfwCreateWindow(50i32, 50i32, "hello, world", 0, 0); + const window = glfwCreateWindow(50i32, 50i32, "hello, world", 0u64, 0u64); while glfwWindowShouldClose(window) == 0 { } glfwTerminate(); -}
\ No newline at end of file +} diff --git a/tests/hello_world.amal b/tests/hello_world.amal new file mode 100644 index 0000000..7c68d3f --- /dev/null +++ b/tests/hello_world.amal @@ -0,0 +1,5 @@ +extern const printf: fn(fmt: &c_char, ...) c_int; + +const main = fn { + printf("hello, world!\n"); +}
\ No newline at end of file |