diff --git a/Makefile b/Makefile index 1de7fbc..4226aa3 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,11 @@ -CC=clang +CC ?= clang +CFLAGS ?= all: - $(CC) -o lbr -O2 -Wall -Wextra -Wpedantic src/*.c + $(CC) -o lbr -O2 -Wall -Wextra -Wpedantic $(CFLAGS) src/*.c + +clean: + rm lbr test: - ./lbr tests/test.lb \ No newline at end of file + ./lbr tests/test.lb diff --git a/src/execute.c b/src/execute.c index 8b0b84d..d86a16d 100644 --- a/src/execute.c +++ b/src/execute.c @@ -532,11 +532,7 @@ void execute(Stack *stack, Stack *originstack, char *modname) if (!strcmp(NAME, "size")) { - int i = 0; - while (i < stack->pointer) - i++; - - stack_push(stack, i); + stack_push(stack, stack->pointer); continue; } diff --git a/tests/native_test.c b/tests/native_test.c new file mode 100644 index 0000000..d8126e4 --- /dev/null +++ b/tests/native_test.c @@ -0,0 +1,14 @@ +#include +#include + +// Build with +// cc -shared -fPIC native_test.c -o native_test.so +// or +// cc -shared -fPIC native_test.c -o native_test.dll + +int labashka(unsigned short (*pop)(void), void (*push)(unsigned short), size_t (*len)(void), size_t max_size ) { + printf("At %zu, there's %d.\n", len(), pop()); + push(12); + printf("Maximum size is %zu.\n", max_size); + return 0; +} diff --git a/tests/native_test.lb b/tests/native_test.lb new file mode 100644 index 0000000..2a42825 --- /dev/null +++ b/tests/native_test.lb @@ -0,0 +1,3 @@ +@ 0 + push -1 + #native native_test