diff --git a/.gitignore b/.gitignore index 6a1864f..96f6639 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.o kuroko +builtins.c diff --git a/Makefile b/Makefile index 89cf9ce..78b515f 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,19 @@ CFLAGS = -g -O3 -Wall -Wextra -pedantic -Wno-unused-parameter -DDEBUG -OBJS = $(patsubst %.c, %.o, $(sort $(wildcard *.c))) +OBJS = $(patsubst %.c, %.o, $(filter-out builtins.o,$(sort $(wildcard *.c)))) builtins.o TARGET = kuroko all: ${TARGET} +builtins.c: builtins.krk + echo "const char _builtins_src[] = {\n" > builtins.c + hexdump -v -e '16/1 "0x%02x,"' -e '"\n"' builtins.krk | sed s'/0x ,//g' >> builtins.c + echo "};" >> builtins.c + kuroko: ${OBJS} .PHONY: clean clean: - @rm -f ${OBJS} ${TARGET} + @rm -f ${OBJS} ${TARGET} builtins.c tags: $(wildcard *.c) $(wildcard *.h) @ctags --c-kinds=+lx *.c *.h diff --git a/modules/__builtins__.krk b/builtins.krk similarity index 100% rename from modules/__builtins__.krk rename to builtins.krk diff --git a/vm.c b/vm.c index cb4239f..f09e77b 100644 --- a/vm.c +++ b/vm.c @@ -20,6 +20,8 @@ static int callValue(KrkValue callee, int argCount); static int bindMethod(KrkClass * _class, KrkString * name); static int call(KrkClosure * closure, int argCount); +extern const char _builtins_src[]; + static void resetStack() { vm.stackTop = vm.stack; vm.frameCount = 0; @@ -463,7 +465,7 @@ void krk_initVM(int flags) { krk_defineNative(&vm.builtins->fields, "set_tracing", krk_set_tracing); /* Now read the builtins module */ - KrkValue builtinsModule = krk_runfile(MODULE_PATH "/__builtins__.krk", 1, "__builtins__","__builtins__"); + KrkValue builtinsModule = krk_interpret(_builtins_src,1,"__builtins__","__builtins__"); if (!IS_OBJECT(builtinsModule)) { fprintf(stderr, "VM startup failure: Failed to load __builtins__ module.\n"); } else {