diff options
| author | LLLL Colonq <llll@colonq> | 2026-06-09 20:12:45 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2026-06-09 20:12:45 -0400 |
| commit | 05117cef2423ddc5deedf5dd51df28806065d0c8 (patch) | |
| tree | 5e4140c5679122b1c37253e3843667c254934f46 | |
| parent | 2bed368821af4fcb06435bfe849332f5a813e470 (diff) | |
Make floating-point optional
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | flake.nix | 2 | ||||
| -rw-r--r-- | include/lcq/pit/runtime.h | 2 | ||||
| -rw-r--r-- | src/runtime.c | 6 |
4 files changed, 12 insertions, 4 deletions
@@ -3,9 +3,9 @@ EXE ?= pit CC ?= gcc AR ?= ar CHK_SOURCES ?= src/main.c $(SRCS) -CPPFLAGS ?= -MMD -MP -CFLAGS ?= -fPIC --std=c99 -g -Ideps/ -Isrc/ -Iinclude/ -Wall -Wextra -Wpedantic -Wconversion -Wformat-security -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wnull-dereference -Wfloat-equal -Wundef -Wpointer-arith -Wbad-function-cast -Wlogical-op -Wmissing-braces -Wcast-align -Wstrict-overflow=5 -ftrapv -LDFLAGS ?= -g -static +override CPPFLAGS += -MMD -MP +override CFLAGS += -fPIC --std=c99 -g -Ideps/ -Isrc/ -Iinclude/ -Wall -Wextra -Wpedantic -Wconversion -Wformat-security -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wnull-dereference -Wfloat-equal -Wundef -Wpointer-arith -Wbad-function-cast -Wlogical-op -Wmissing-braces -Wcast-align -Wstrict-overflow=5 # -ftrapv +override LDFLAGS += -g -static BUILD = build_$(CC) @@ -40,7 +40,7 @@ src = ./.; hardeningDisable = ["all"]; buildPhase = '' - make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar libcolonq-pit.a + make CPPFLAGS=-DPIT_NO_DOUBLE CC=arm-none-eabi-gcc AR=arm-none-eabi-ar libcolonq-pit.a ''; installPhase = '' make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar prefix=$out install-core install-headers diff --git a/include/lcq/pit/runtime.h b/include/lcq/pit/runtime.h index d4b1b9e..48e2bcd 100644 --- a/include/lcq/pit/runtime.h +++ b/include/lcq/pit/runtime.h @@ -115,8 +115,10 @@ void pit_error(pit_runtime *rt, char *format, ...); /* working with small values */ pit_value pit_value_new(pit_runtime *rt, enum pit_value_sort s, u64 data); +#ifndef PIT_NO_DOUBLE double pit_as_double(pit_runtime *rt, pit_value v); pit_value pit_double_new(pit_runtime *rt, double d); +#endif i64 pit_as_integer(pit_runtime *rt, pit_value v); pit_value pit_integer_new(pit_runtime *rt, i64 i); pit_value pit_bool_new(pit_runtime *rt, bool i); diff --git a/src/runtime.c b/src/runtime.c index 33c9db6..c382306 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -67,7 +67,11 @@ i64 pit_dump(pit_runtime *rt, char *buf, i64 len, pit_value v, bool readable) { if (len <= 0) return 0; switch (pit_value_sort(v)) { case PIT_VALUE_SORT_DOUBLE: + #ifndef PIT_NO_DOUBLE return pit_string_snprintf(buf, (size_t) len, "%lf", pit_as_double(rt, v)); + #else + return pit_string_snprintf(buf, (size_t) len, "<unsupported double>"); + #endif case PIT_VALUE_SORT_INTEGER: return pit_string_snprintf(buf, (size_t) len, "%ld", pit_as_integer(rt, v)); case PIT_VALUE_SORT_SYMBOL: { @@ -194,6 +198,7 @@ pit_value pit_value_new(pit_runtime *rt, enum pit_value_sort s, u64 data) { | (data & 0x1ffffffffffff); } +#ifndef PIT_NO_DOUBLE double pit_as_double(pit_runtime *rt, pit_value v) { if (pit_value_sort(v) != PIT_VALUE_SORT_DOUBLE) { pit_error(rt, "invalid use of value as double"); @@ -208,6 +213,7 @@ pit_value pit_double_new(pit_runtime *rt, double d) { x.dval = d; return pit_value_new(rt, PIT_VALUE_SORT_DOUBLE, x.ival); } +#endif i64 pit_as_integer(pit_runtime *rt, pit_value v) { if (pit_value_sort(v) != PIT_VALUE_SORT_INTEGER) { |
