From 8aa711eeab812f0f51e38edd04f26b845fdd1069 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 29 Nov 2022 22:20:17 -0600 Subject: [PATCH] added time.to_epoch; bugfix with BufferStream --- core/io/stream.onyx | 2 +- core/time/time.onyx | 2 ++ runtime/onyx_runtime.c | 1 + runtime/src/ort_time.h | 7 +++++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/io/stream.onyx b/core/io/stream.onyx index 1916843d..0a58a7a8 100644 --- a/core/io/stream.onyx +++ b/core/io/stream.onyx @@ -192,7 +192,7 @@ buffer_stream_make :: #match #locked { (initial_size := 1024, allocator := context.allocator) -> BufferStream { return .{ .{ vtable = ^buffer_stream_vtable }, - make([..] u8, 1024, allocator = allocator) + make([..] u8, initial_size, allocator = allocator) }; } } diff --git a/core/time/time.onyx b/core/time/time.onyx index 0f2d61f6..0922c2fe 100644 --- a/core/time/time.onyx +++ b/core/time/time.onyx @@ -28,6 +28,7 @@ Timestamp :: struct #size (sizeof u32 * 12) { localtime :: __time_localtime gmtime :: __time_gmtime +to_epoch :: __time_mktime strftime :: (buf: [] u8, format: [] u8, tm: ^Timestamp) -> str { f := cast(cstr) core.alloc.from_stack(format.length + 1); @@ -272,6 +273,7 @@ parse_number_and_advance :: (buf: ^[] u8, result: ^i32, low, high, offset: i32) #foreign "onyx_runtime" { __time_localtime :: (time: u64, tm: ^Timestamp) -> void --- __time_gmtime :: (time: u64, tm: ^Timestamp) -> void --- + __time_mktime :: (tm: ^Timestamp) -> u64 --- __time_strftime :: (buf: [] u8, format: cstr, tm: ^Timestamp) -> u32 --- } } diff --git a/runtime/onyx_runtime.c b/runtime/onyx_runtime.c index f7eebfca..deb4d2ae 100644 --- a/runtime/onyx_runtime.c +++ b/runtime/onyx_runtime.c @@ -75,6 +75,7 @@ ONYX_LIBRARY { ONYX_FUNC(__time_localtime) ONYX_FUNC(__time_gmtime) ONYX_FUNC(__time_strftime) + ONYX_FUNC(__time_mktime) ONYX_FUNC(__net_create_socket) ONYX_FUNC(__net_close_socket) diff --git a/runtime/src/ort_time.h b/runtime/src/ort_time.h index 7dd76751..86f75ba6 100644 --- a/runtime/src/ort_time.h +++ b/runtime/src/ort_time.h @@ -19,3 +19,10 @@ ONYX_DEF(__time_strftime, (WASM_I32, WASM_I32, WASM_I32, WASM_I32), (WASM_I32)) results->data[0] = WASM_I32_VAL(len); return NULL; } + +ONYX_DEF(__time_mktime, (WASM_I32), (WASM_I64)) { + struct tm *time = (struct tm *) ONYX_PTR(params->data[0].of.i32); + results->data[0] = WASM_I64_VAL(mktime(time)); + return NULL; +} + -- 2.25.1