Commit 0ca54a31

0ca54a313a97Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 8 files · +4 added · ~4 modified

Description

runtime: split sp_Time into libspinel_rt + Time.mktime/local/utc dispatch

Move the bulk of the Time implementation (~250 lines of libc-backed accessors, formatters, and arithmetic) from the static-inline sp_runtime.h block into lib/sp_time.{c,h}, compiled into libspinel_rt.a alongside sp_bigint / sp_crypto / sp_pack / sp_strscan. sp_runtime.h keeps only the GC-aware trampolines (sp_box_time and the *_gc string forwarders that sp_str_dup_external into the GC string heap).

The format helpers in libspinel_rt write into a caller-provided buffer; the GC-aware wrappers allocate a small stack buf, call the helper, then sp_str_dup_external the result. This keeps libspinel_rt zero-dependency on the runtime's static-inline helpers.

sp_time.h uses int64_t / double directly rather than mrb_int / mrb_float because sp_runtime.h and mruby_shim.h disagree on the mrb_bool typedef (bool vs int) — including either from sp_time.h would tip the conflict at every TU that consumes both.

Time.mktime / Time.local / Time.utc / Time.gm are now dispatched (aliases of Time.new in the local case; the UTC pair uses a new sp_time_new_utc that builds the epoch via days-from-civil so the value is timezone-independent — timegm is absent on MSVCRT).

Fixes #993

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
0ca54a313a97
Parent
5baef77b8fb8

MakefilemodifiedView file

@@ -280,9 +280,13 @@
280280 @mkdir -p build
281281 $(CC) -c -O2 -Wno-all $(SEC_FLAGS) -Ilib -Ilib/regexp lib/sp_strscan.c -o build/sp_strscan.o
282282
283+build/sp_time.o: lib/sp_time.c lib/sp_time.h
284+ @mkdir -p build
285+ $(CC) -c -O2 -Wno-all $(SEC_FLAGS) -Ilib lib/sp_time.c -o build/sp_time.o
286+
283287 SP_RT_LIB = lib/libspinel_rt.a
284288
285-$(SP_RT_LIB): $(RE_OBJ) build/sp_bigint.o build/sp_crypto.o build/sp_pack.o build/sp_strscan.o
289+$(SP_RT_LIB): $(RE_OBJ) build/sp_bigint.o build/sp_crypto.o build/sp_pack.o build/sp_strscan.o build/sp_time.o
286290 ar rcs $@ $^
287291
288292 regexp: $(SP_RT_LIB)