From 9c5e97144d85c0f990c4d86e16871c82356e61c5 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 27 Jun 2020 12:39:16 -0500 Subject: [PATCH] More small changes to help with cross compilation via makefile. Add option to turn off built in getline via janetconf. --- Makefile | 24 ++++++++++++++++-------- src/conf/janetconf.h | 3 +++ src/core/bytecode.c | 2 +- src/core/corelib.c | 4 +++- src/include/janet.h | 12 ++++++------ src/mainclient/shell.c | 2 +- 6 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index fbbe91d2..64f49047 100644 --- a/Makefile +++ b/Makefile @@ -38,8 +38,15 @@ PKG_CONFIG_PATH?=$(LIBDIR)/pkgconfig DEBUGGER=gdb SONAME_SETTER=-Wl,-soname, -CFLAGS:=$(CFLAGS) -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fPIC -O2 -fvisibility=hidden -LDFLAGS:=$(LDFLAGS) -rdynamic +# For cross compilation +HOSTCC?=$(CC) +HOSTAR?=$(AR) +CFLAGS?=-fPIC -O2 +LDFLAGS?=-rdynamic + +COMMON_CFLAGS:=-std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden +BOOT_CFLAGS:=-DJANET_BOOTSTRAP -DJANET_BUILD=$(JANET_BUILD) -O0 -g $(COMMON_CFLAGS) +BUILD_CFLAGS:=$(CFLAGS) $(COMMON_CFLAGS) # For installation LDCONFIG:=ldconfig "$(LIBDIR)" @@ -131,7 +138,6 @@ JANET_BOOT_HEADERS=src/boot/tests.h ########################################################## JANET_BOOT_OBJECTS=$(patsubst src/%.c,build/%.boot.o,$(JANET_CORE_SOURCES) $(JANET_BOOT_SOURCES)) -BOOT_CFLAGS:=-DJANET_BOOTSTRAP -DJANET_BUILD=$(JANET_BUILD) $(CFLAGS) $(JANET_BOOT_OBJECTS): $(JANET_BOOT_HEADERS) @@ -161,24 +167,26 @@ build/janetconf.h: src/conf/janetconf.h cp $< $@ build/janet.o: build/janet.c build/janet.h build/janetconf.h - $(CC) $(CFLAGS) -c $< -o $@ -I build + $(HOSTCC) $(BUILD_CFLAGS) -c $< -o $@ -I build build/shell.o: build/shell.c build/janet.h build/janetconf.h - $(CC) $(CFLAGS) -c $< -o $@ -I build + $(HOSTCC) $(BUILD_CFLAGS) -c $< -o $@ -I build $(JANET_TARGET): build/janet.o build/shell.o - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(CLIBS) + $(HOSTCC) $(LDFLAGS) $(BUILD_CFLAGS) -o $@ $^ $(CLIBS) $(JANET_LIBRARY): build/janet.o build/shell.o - $(CC) $(LDFLAGS) $(CFLAGS) $(SONAME_SETTER)$(SONAME) -shared -o $@ $^ $(CLIBS) + $(HOSTCC) $(LDFLAGS) $(BUILD_CFLAGS) $(SONAME_SETTER)$(SONAME) -shared -o $@ $^ $(CLIBS) $(JANET_STATIC_LIBRARY): build/janet.o build/shell.o - $(AR) rcs $@ $^ + $(HOSTAR) rcs $@ $^ ################### ##### Testing ##### ################### +# Testing assumes HOSTCC=CC + TEST_SCRIPTS=$(wildcard test/suite*.janet) repl: $(JANET_TARGET) diff --git a/src/conf/janetconf.h b/src/conf/janetconf.h index 2343666b..f31a8b35 100644 --- a/src/conf/janetconf.h +++ b/src/conf/janetconf.h @@ -68,4 +68,7 @@ /* #define JANET_OS_NAME my-custom-os */ /* #define JANET_ARCH_NAME pdp-8 */ +/* Main client settings, does not affect library code */ +/* #define JANET_SIMPLE_GETLINE */ + #endif /* end of include guard: JANETCONF_H */ diff --git a/src/core/bytecode.c b/src/core/bytecode.c index 9c84a457..1349a10a 100644 --- a/src/core/bytecode.c +++ b/src/core/bytecode.c @@ -104,7 +104,7 @@ enum JanetInstructionType janet_instructions[JOP_INSTRUCTION_COUNT] = { }; /* Verify some bytecode */ -int32_t janet_verify(JanetFuncDef *def) { +int janet_verify(JanetFuncDef *def) { int vargs = !!(def->flags & JANET_FUNCDEF_FLAG_VARARG); int32_t i; int32_t maxslot = def->arity + vargs; diff --git a/src/core/corelib.c b/src/core/corelib.c index f2b187f8..a488365b 100644 --- a/src/core/corelib.c +++ b/src/core/corelib.c @@ -404,9 +404,11 @@ static Janet janet_core_gcsetinterval(int32_t argc, Janet *argv) { janet_fixarity(argc, 1); size_t s = janet_getsize(argv, 0); /* limit interval to 48 bits */ - if (s > 0xFFFFFFFFFFFFUl) { +#ifdef JANET_64 + if (s >> 48) { janet_panic("interval too large"); } +#endif janet_vm_gc_interval = s; return janet_wrap_nil(); } diff --git a/src/include/janet.h b/src/include/janet.h index 37c467fc..6b96ddf4 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -127,6 +127,12 @@ extern "C" { #define JANET_LITTLE_ENDIAN 1 #endif +/* Limits for converting doubles to 64 bit integers */ +#define JANET_INTMAX_DOUBLE 9007199254740991.0 +#define JANET_INTMIN_DOUBLE (-9007199254740991.0) +#define JANET_INTMAX_INT64 9007199254740991 +#define JANET_INTMIN_INT64 (-9007199254740991) + /* Check emscripten */ #ifdef __EMSCRIPTEN__ #define JANET_NO_DYNAMIC_MODULES @@ -542,12 +548,6 @@ JANET_API Janet janet_wrap_integer(int32_t x); #include -/* Limits for converting doubles to 64 bit integers */ -#define JANET_INTMAX_DOUBLE 9007199254740991.0 -#define JANET_INTMIN_DOUBLE (-9007199254740991.0) -#define JANET_INTMAX_INT64 9007199254740991 -#define JANET_INTMIN_INT64 (-9007199254740991) - #define janet_u64(x) ((x).u64) #define JANET_NANBOX_TAGBITS 0xFFFF800000000000llu diff --git a/src/mainclient/shell.c b/src/mainclient/shell.c index 3b240346..3855dce3 100644 --- a/src/mainclient/shell.c +++ b/src/mainclient/shell.c @@ -84,7 +84,7 @@ static void simpleline(JanetBuffer *buffer) { } /* Windows */ -#ifdef JANET_WINDOWS +#if defined(JANET_WINDOWS) || defined(JANET_SIMPLE_GETLINE) void janet_line_init() { ;