diff --git a/Makefile b/Makefile index f595ef4..5b00453 100644 --- a/Makefile +++ b/Makefile @@ -50,14 +50,40 @@ else CFLAGS += -DNO_RLINE endif -ifndef KRK_DISABLE_DEBUG - CFLAGS += -DKRK_ENABLE_DEBUG +ifdef KRK_DISABLE_DEBUG + CFLAGS += -DKRK_DISABLE_DEBUG +endif + +ifdef KRK_DISABLE_THREADS + CFLAGS += -DKRK_DISABLE_THREADS +endif + +ifdef KRK_NO_DISASSEMBLY + CFLAGS += -DKRK_NO_DISASSEMBLY=1 +endif + +ifdef KRK_NO_TRACING + CFLAGS += -DKRK_NO_TRACING=1 +endif + +ifdef KRK_NO_SCAN_TRACING + CFLAGS += -DKRK_NO_SCAN_TRACING=1 +endif + +ifdef KRK_NO_STRESS_GC + CFLAGS += -DKRK_NO_STRESS_GC=1 endif .PHONY: help help: @echo "Configuration options available:" + @echo " KRK_NO_... Compile without support for debugging features..." + @echo " DISASSEMBLY=1 Do not enable disassembly at compile time." + @echo " TRACING=1 Do not enable runtime tracing." + @echo " SCAN_TRACING=1 Do not enable lexer debugging." + @echo " STRESS_GC=1 Do not enable eager GC stress testing." + @echo " KRK_DISABLE_THREADS=1 Disable threads on platforms that otherwise support them." @echo " KRK_DISABLE_RLINE=1 Do not build with the rich line editing library enabled." @echo " KRK_DISABLE_DEBUG=1 Disable debugging features (might be faster)." @echo " KRK_DISABLE_DOCS=1 Do not include docstrings for builtins." diff --git a/README.md b/README.md index 18bc421..1d0effe 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,12 @@ WASM builds can be built from [kuroko-lang/kuroko-wasm-repl](https://github.com/ Kuroko can be built with the Asyncify option and as a worker. +### Fully Static + +Normally, the main interpreter binary statically links with the VM library, but is otherwise built as a dynamic executable and links to shared libraries for libc, pthreads, and so on. To build a fully static binary, adding `-static` to `CFLAGS` and building only the `kuroko` target should suffice. + +Whether a static build supports importing C extension modules depends on the specifics of your target platform. + ## Extend and Embed Kuroko Kuroko is easy to embed in a host application or extend with C modules. Please see [the documentation on our website](https://kuroko-lang.github.io/docs/embedding.html) for further information. diff --git a/src/compiler.c b/src/compiler.c index 016e3a2..23a0f47 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -77,7 +77,7 @@ typedef enum { typedef void (*ParseFn)(int); typedef struct { -#ifdef ENABLE_SCAN_TRACING +#ifndef KRK_NO_SCAN_TRACING const char * name; #endif ParseFn prefix; @@ -313,7 +313,7 @@ static void advance() { if (parser.eatingWhitespace && (parser.current.type == TOKEN_INDENTATION || parser.current.type == TOKEN_EOL)) continue; -#ifdef ENABLE_SCAN_TRACING +#ifndef KRK_NO_SCAN_TRACING if (krk_currentThread.flags & KRK_THREAD_ENABLE_SCAN_TRACING) { fprintf(stderr, " [%s<%d> %d:%d '%.*s']\n", getRule(parser.current.type)->name, @@ -442,7 +442,7 @@ static KrkCodeObject * endCompiler() { args++; } -#ifdef ENABLE_DISASSEMBLY +#ifndef KRK_NO_DISASSEMBLY if ((krk_currentThread.flags & KRK_THREAD_ENABLE_DISASSEMBLY) && !parser.hadError) { krk_disassembleCodeObject(stderr, function, function->name ? function->name->chars : "(module)"); } @@ -1012,7 +1012,7 @@ static void block(size_t indentation, const char * blockName) { advance(); } }; -#ifdef ENABLE_SCAN_TRACING +#ifndef KRK_NO_SCAN_TRACING if (krk_currentThread.flags & KRK_THREAD_ENABLE_SCAN_TRACING) { fprintf(stderr, "\n\nfinished with block %s (ind=%d) on line %d, sitting on a %s (len=%d)\n\n", blockName, (int)indentation, (int)parser.current.line, @@ -1340,7 +1340,7 @@ static KrkToken classDeclaration() { advance(); /* Pass the indentation */ method(currentIndentation); } -#ifdef ENABLE_SCAN_TRACING +#ifndef KRK_NO_SCAN_TRACING if (krk_currentThread.flags & KRK_THREAD_ENABLE_SCAN_TRACING) fprintf(stderr, "Exiting from class definition on %s\n", getRule(parser.current.type)->name); #endif /* Exit from block */ @@ -2751,7 +2751,7 @@ static void dict(int canAssign) { consume(TOKEN_RIGHT_BRACE,"Expected } at end of dict expression."); } -#ifndef ENABLE_SCAN_TRACING +#ifdef KRK_NO_SCAN_TRACING # define RULE(token, a, b, c) [token] = {a, b, c} #else # define RULE(token, a, b, c) [token] = {# token, a, b, c} diff --git a/src/debug.c b/src/debug.c index 677e441..f605310 100644 --- a/src/debug.c +++ b/src/debug.c @@ -6,7 +6,7 @@ #include #include -#ifdef KRK_ENABLE_DEBUG +#ifndef KRK_DISABLE_DEBUG /** * When tracing is enabled, we will present the elements on the stack with diff --git a/src/kuroko.c b/src/kuroko.c index 53a14c4..f042c81 100644 --- a/src/kuroko.c +++ b/src/kuroko.c @@ -359,7 +359,7 @@ _cleanup: } #endif -#ifdef KRK_ENABLE_DEBUG +#ifndef KRK_DISABLE_DEBUG static char * lastDebugCommand = NULL; static int debuggerHook(KrkCallFrame * frame) { @@ -849,7 +849,7 @@ _finishArgs: findInterpreter(argv); krk_initVM(flags); -#ifdef KRK_ENABLE_DEBUG +#ifndef KRK_DISABLE_DEBUG krk_debug_registerCallback(debuggerHook); #endif diff --git a/src/kuroko/debug.h b/src/kuroko/debug.h index 5e58ae6..0cee061 100644 --- a/src/kuroko/debug.h +++ b/src/kuroko/debug.h @@ -20,7 +20,7 @@ #include "chunk.h" #include "object.h" -#ifdef KRK_ENABLE_DEBUG +#ifndef KRK_DISABLE_DEBUG /** * @brief Print a disassembly of 'func' to the stream 'f'. diff --git a/src/kuroko/kuroko.h b/src/kuroko/kuroko.h index a116034..060a6bb 100644 --- a/src/kuroko/kuroko.h +++ b/src/kuroko/kuroko.h @@ -26,17 +26,10 @@ typedef int krk_integer_type; # define ENABLE_THREADING #endif -#ifdef STRICTLY_NO_THREADS +#ifdef KRK_DISABLE_THREADS # undef ENABLE_THREADING #endif -#ifdef KRK_ENABLE_DEBUG -# define ENABLE_DISASSEMBLY -# define ENABLE_TRACING -# define ENABLE_SCAN_TRACING -# define ENABLE_STRESS_GC -#endif - #ifndef _WIN32 # define PATH_SEP "/" # ifndef STATIC_ONLY diff --git a/src/memory.c b/src/memory.c index 4f9e9bd..3901306 100644 --- a/src/memory.c +++ b/src/memory.c @@ -9,7 +9,7 @@ void * krk_reallocate(void * ptr, size_t old, size_t new) { vm.bytesAllocated += new - old; if (new > old && ptr != krk_currentThread.stack && &krk_currentThread == vm.threads && !(vm.globalFlags & KRK_GLOBAL_GC_PAUSED)) { -#ifdef ENABLE_STRESS_GC +#ifndef KRK_NO_STRESS_GC if (vm.globalFlags & KRK_GLOBAL_ENABLE_STRESS_GC) { krk_collectGarbage(); } diff --git a/src/vm.c b/src/vm.c index fce8706..5f4faa9 100644 --- a/src/vm.c +++ b/src/vm.c @@ -62,7 +62,7 @@ __thread KrkThreadState krk_currentThread; KrkThreadState krk_currentThread; #endif -#if defined(ENABLE_TRACING) && !defined(__EMSCRIPTEN__) +#if !defined(KRK_NO_TRACING) && !defined(__EMSCRIPTEN__) # define FRAME_IN(frame) if (vm.globalFlags & KRK_GLOBAL_CALLGRIND) { clock_gettime(CLOCK_MONOTONIC, &frame->in_time); } # define FRAME_OUT(frame) \ if (vm.globalFlags & KRK_GLOBAL_CALLGRIND && !(frame->closure->function->flags & KRK_CODEOBJECT_FLAGS_IS_GENERATOR)) { \ @@ -1016,7 +1016,7 @@ int krk_isFalsey(KrkValue value) { return 0; /* Assume anything else is truthy */ } -#ifdef KRK_ENABLE_DEBUG +#ifndef KRK_DISABLE_DEBUG KRK_FUNC(set_tracing,{ if (hasKw) { KrkValue test; @@ -1234,7 +1234,7 @@ void krk_initVM(int flags) { _createAndBind_timeMod(); _createAndBind_osMod(); _createAndBind_fileioMod(); -#ifdef KRK_ENABLE_DEBUG +#ifndef KRK_DISABLE_DEBUG _createAndBind_disMod(); #endif #ifdef ENABLE_THREADING @@ -2023,7 +2023,7 @@ static KrkValue run() { KrkCallFrame* frame = &krk_currentThread.frames[krk_currentThread.frameCount - 1]; while (1) { -#ifdef ENABLE_TRACING +#ifndef KRK_NO_TRACING if (unlikely(krk_currentThread.flags & (KRK_THREAD_ENABLE_TRACING | KRK_THREAD_SINGLE_STEP | KRK_THREAD_SIGNALLED))) { if (krk_currentThread.flags & KRK_THREAD_ENABLE_TRACING) { krk_debug_dumpStack(stderr, frame); @@ -2357,7 +2357,7 @@ _finishReturn: (void)0; break; } case OP_BREAKPOINT: { -#ifdef KRK_ENABLE_DEBUG +#ifndef KRK_DISABLE_DEBUG /* First off, halt execution. */ krk_debugBreakpointHandler(); if (krk_currentThread.flags & KRK_THREAD_HAS_EXCEPTION) goto _finishException;