Add tools (and tools/kuroko contains symlinks to headers)
This commit is contained in:
parent
eb89495fba
commit
13371611e2
14
.gitignore
vendored
14
.gitignore
vendored
@ -1,9 +1,13 @@
|
||||
# Ignore executables in the root
|
||||
/kuroko
|
||||
/*.exe
|
||||
/*.deb
|
||||
/krk-*
|
||||
# I typically clone these subprojects in the root as well.
|
||||
/wasm/
|
||||
/jupyter/
|
||||
# Match library files anywhere.
|
||||
*.o
|
||||
*.so
|
||||
kuroko
|
||||
*.exe
|
||||
*.dll
|
||||
wasm/
|
||||
jupyter/
|
||||
*.deb
|
||||
*.dSYM
|
||||
|
8
Makefile
8
Makefile
@ -4,6 +4,7 @@ TARGET = kuroko
|
||||
OBJS = $(patsubst %.c, %.o, $(filter-out src/module_% src/rline.c src/kuroko.c,$(sort $(wildcard src/*.c))))
|
||||
MODULES = $(patsubst src/module_%.c, modules/%.so, $(sort $(wildcard src/module_*.c)))
|
||||
HEADERS = $(wildcard src/*.h)
|
||||
TOOLS = $(patsubst tools/%.c, krk-%, $(sort $(wildcard tools/*.c)))
|
||||
|
||||
# These are used by the install target. We call the local kuroko to get the
|
||||
# version string to use for the final library, so, uh, probably don't
|
||||
@ -30,7 +31,7 @@ ifndef KRK_ENABLE_STATIC
|
||||
# to actually rename it to kuroko.dll or whatever.
|
||||
LDLIBS += libkuroko.so
|
||||
endif
|
||||
all: ${TARGET} ${MODULES}
|
||||
all: ${TARGET} ${MODULES} ${TOOLS}
|
||||
KUROKO_LIBS = libkuroko.so
|
||||
else
|
||||
# Static builds are a little different...
|
||||
@ -102,10 +103,15 @@ help:
|
||||
@echo " KRK_ENABLE_STATIC=1 Build a single static binary."
|
||||
@echo " KRK_ENABLE_BUNDLE=1 Link C modules directly into the interpreter."
|
||||
@echo " KRK_ENABLE_THREAD=1 Enable EXPERIMENTAL threading support. (* enabled by default on Linux)"
|
||||
@echo ""
|
||||
@echo "Available tools: ${TOOLS}"
|
||||
|
||||
kuroko: src/kuroko.o ${KUROKO_LIBS}
|
||||
${CC} ${CFLAGS} ${LDFLAGS} -o $@ src/kuroko.o ${KUROKO_LIBS} ${LDLIBS}
|
||||
|
||||
krk-%: tools/%.c ${KUROKO_LIBS}
|
||||
${CC} -Itools ${CFLAGS} ${LDFLAGS} -o $@ $< ${KUROKO_LIBS} ${LDLIBS}
|
||||
|
||||
libkuroko.so: ${OBJS}
|
||||
${CC} ${CFLAGS} ${LDFLAGS} -shared -o $@ ${OBJS}
|
||||
|
||||
|
1
tools/kuroko/chunk.h
Symbolic link
1
tools/kuroko/chunk.h
Symbolic link
@ -0,0 +1 @@
|
||||
../../src/chunk.h
|
1
tools/kuroko/compiler.h
Symbolic link
1
tools/kuroko/compiler.h
Symbolic link
@ -0,0 +1 @@
|
||||
../../src/compiler.h
|
1
tools/kuroko/debug.h
Symbolic link
1
tools/kuroko/debug.h
Symbolic link
@ -0,0 +1 @@
|
||||
../../src/debug.h
|
1
tools/kuroko/kuroko.h
Symbolic link
1
tools/kuroko/kuroko.h
Symbolic link
@ -0,0 +1 @@
|
||||
../../src/kuroko.h
|
1
tools/kuroko/memory.h
Symbolic link
1
tools/kuroko/memory.h
Symbolic link
@ -0,0 +1 @@
|
||||
../../src/memory.h
|
1
tools/kuroko/object.h
Symbolic link
1
tools/kuroko/object.h
Symbolic link
@ -0,0 +1 @@
|
||||
../../src/object.h
|
1
tools/kuroko/scanner.h
Symbolic link
1
tools/kuroko/scanner.h
Symbolic link
@ -0,0 +1 @@
|
||||
../../src/scanner.h
|
1
tools/kuroko/table.h
Symbolic link
1
tools/kuroko/table.h
Symbolic link
@ -0,0 +1 @@
|
||||
../../src/table.h
|
1
tools/kuroko/threads.h
Symbolic link
1
tools/kuroko/threads.h
Symbolic link
@ -0,0 +1 @@
|
||||
../../src/threads.h
|
1
tools/kuroko/util.h
Symbolic link
1
tools/kuroko/util.h
Symbolic link
@ -0,0 +1 @@
|
||||
../../src/util.h
|
1
tools/kuroko/value.h
Symbolic link
1
tools/kuroko/value.h
Symbolic link
@ -0,0 +1 @@
|
||||
../../src/value.h
|
1
tools/kuroko/vm.h
Symbolic link
1
tools/kuroko/vm.h
Symbolic link
@ -0,0 +1 @@
|
||||
../../src/vm.h
|
49
tools/sandbox.c
Normal file
49
tools/sandbox.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include <stdio.h>
|
||||
#include <kuroko/kuroko.h>
|
||||
#include <kuroko/vm.h>
|
||||
#include <kuroko/util.h>
|
||||
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "expected a string to evaluate\n");
|
||||
return 1;
|
||||
}
|
||||
krk_initVM(0);
|
||||
|
||||
krk_tableDelete(&vm.system->fields, OBJECT_VAL(S("module_paths")));
|
||||
krk_tableDelete(&vm.modules, OBJECT_VAL(S("kuroko")));
|
||||
krk_tableDelete(&vm.builtins->fields, OBJECT_VAL(S("print")));
|
||||
|
||||
/* Don't automatically dump tracebacks. */
|
||||
krk_resetStack();
|
||||
krk_push(NONE_VAL());
|
||||
krk_currentThread.frames[0].outSlots = 1;
|
||||
|
||||
krk_startModule("<module>");
|
||||
krk_attachNamedValue(&krk_currentThread.module->fields,"__doc__", NONE_VAL());
|
||||
|
||||
int retval = 0;
|
||||
|
||||
KrkValue result = krk_interpret(argv[1], 0, "<stdin>","<stdin>");
|
||||
if (!IS_NONE(result)) {
|
||||
if (IS_INTEGER(result)) {
|
||||
retval = AS_INTEGER(result);
|
||||
}
|
||||
KrkClass * type = krk_getType(result);
|
||||
if (type->_reprer) {
|
||||
krk_push(result);
|
||||
result = krk_callSimple(OBJECT_VAL(type->_reprer), 1, 0);
|
||||
}
|
||||
if (IS_STRING(result)) {
|
||||
fprintf(stdout, "%s\n", AS_CSTRING(result));
|
||||
}
|
||||
} else if (krk_currentThread.flags & KRK_HAS_EXCEPTION) {
|
||||
krk_dumpTraceback();
|
||||
retval = 1;
|
||||
}
|
||||
|
||||
krk_freeVM();
|
||||
return retval;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user