From 74daa90c95ef69b44cc87adf1d6ff9c6185a6d63 Mon Sep 17 00:00:00 2001 From: haskal Date: Wed, 14 Oct 2020 17:33:47 -0400 Subject: [PATCH] update embedding launcher to cooperate with 3m GC --- Makefile | 7 +++++-- main.c | 25 ------------------------- main_bc.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 27 deletions(-) delete mode 100644 main.c create mode 100644 main_bc.c diff --git a/Makefile b/Makefile index 2077c0e..422c0b4 100644 --- a/Makefile +++ b/Makefile @@ -21,12 +21,15 @@ all: setup exec-in-container # rerun inside container exec-in-container: setup - rsync -av $(RKT_NAME) main.c Makefile $(CACHE_DIR)/alpine/build/ + rsync -av $(RKT_NAME) main_bc.c Makefile $(CACHE_DIR)/alpine/build/ sudo systemd-nspawn -UD $(CACHE_DIR)/alpine -- sh -c "cd build; make $(APP_NAME)" cp $(CACHE_DIR)/alpine/build/$(APP_NAME) . +clean-in-container: + sudo systemd-nspawn -UD $(CACHE_DIR)/alpine -- sh -c "cd build; rm -rf *" + # main build stuff -$(APP_NAME): main.c app.o +$(APP_NAME): main_bc.c app.o $(CC) -o $@ -pipe -O3 -DAPP_NAME='"$(APP_NAME)"' -static $^ -lracket3m -lrktio -lucontext -lffi # this is faster than --c-mods by a lot diff --git a/main.c b/main.c deleted file mode 100644 index 68af097..0000000 --- a/main.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -extern const char _binary_app_zo_start; -extern const char _binary_app_zo_end; - -static int run(Scheme_Env *e, int argc, char *argv[]) { - Scheme_Object *a[2]; - - size_t load_size = ((uintptr_t) &_binary_app_zo_end) - ((uintptr_t) &_binary_app_zo_start); - scheme_register_embedded_load(load_size, &_binary_app_zo_start); - scheme_embedded_load(load_size, &_binary_app_zo_start, 1); - - a[0] = scheme_make_pair(scheme_intern_symbol("quote"), - scheme_make_pair(scheme_intern_symbol(APP_NAME), scheme_make_null())); - a[1] = scheme_false; - - scheme_dynamic_require(2, a); - - return 0; -} - -int main(int argc, char *argv[]) { - return scheme_main_setup(1, run, argc, argv); -} diff --git a/main_bc.c b/main_bc.c new file mode 100644 index 0000000..ea911bb --- /dev/null +++ b/main_bc.c @@ -0,0 +1,38 @@ +#define MZ_PRECISE_GC + +#include +#include + +extern const char _binary_app_zo_start; +extern const char _binary_app_zo_end; + +static int run_bc(Scheme_Env *e, int argc, char *argv[]) { + Scheme_Object *l = NULL; + Scheme_Object *a[2] = { NULL, NULL }; + + MZ_GC_DECL_REG(5); + MZ_GC_VAR_IN_REG(0, e); + MZ_GC_VAR_IN_REG(1, l); + MZ_GC_ARRAY_VAR_IN_REG(2, a, 2); + MZ_GC_REG(); + + size_t load_size = ((uintptr_t) &_binary_app_zo_end) - ((uintptr_t) &_binary_app_zo_start); + scheme_register_embedded_load(load_size, &_binary_app_zo_start); + scheme_embedded_load(load_size, &_binary_app_zo_start, 1); + + l = scheme_make_null(); + l = scheme_make_pair(scheme_intern_symbol(APP_NAME), l); + l = scheme_make_pair(scheme_intern_symbol("quote"), l); + + a[0] = l; + a[1] = scheme_false; + + scheme_dynamic_require(2, a); + + MZ_GC_UNREG(); + return 0; +} + +int main(int argc, char *argv[]) { + return scheme_main_setup(1, run_bc, argc, argv); +}