Embed __builtins__ source directly

This commit is contained in:
K. Lange 2020-12-29 18:04:02 +09:00
parent b0c2772937
commit eb17af8076
4 changed files with 11 additions and 3 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
*.o
kuroko
builtins.c

View File

@ -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

4
vm.c
View File

@ -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 {