From 902a81528b9d2edcf93226a2ca13da6fcc1839e5 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 23 Dec 2019 08:57:48 +0100 Subject: wip: function pointers and other stuff --- tests/bug.amal | 5 +++++ tests/closure.amal | 37 +++++++++++++++++++++++++++++++++++++ tests/conditions.amal | 16 ++++++++++++++++ tests/glfw.amal | 4 ++-- tests/hello_world.amal | 5 +++++ 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 tests/bug.amal create mode 100644 tests/closure.amal create mode 100644 tests/conditions.amal mode change 100644 => 100755 tests/glfw.amal create mode 100644 tests/hello_world.amal (limited to 'tests') 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 old mode 100644 new mode 100755 index 37608fc..7c4a8ab --- 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 -- cgit v1.2.3