From ba325f15a1183891904920c8d6b37fa2f28b2c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Mon, 17 Jun 2024 04:01:43 +0500 Subject: [PATCH 1/2] Small changes --- Makefile | 10 +++++++--- src/execute.c | 6 +----- 2 files changed, 8 insertions(+), 8 deletions(-) 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; } -- 2.39.5 From e8c5109fb0865f6a42213780957fabb30304c202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Mon, 17 Jun 2024 04:07:42 +0500 Subject: [PATCH 2/2] Add test for #native --- tests/native_test.c | 14 ++++++++++++++ tests/native_test.lb | 3 +++ 2 files changed, 17 insertions(+) create mode 100644 tests/native_test.c create mode 100644 tests/native_test.lb 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 -- 2.39.5