From: Brendan Hansen Date: Sat, 5 Nov 2022 04:58:07 +0000 (-0500) Subject: added map.as_iter; bugfixes X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=4629a0d8730ec7226220a647982fedbb8c8c4020;p=onyx.git added map.as_iter; bugfixes --- diff --git a/core/container/map.onyx b/core/container/map.onyx index a372c3a3..7e7ddceb 100644 --- a/core/container/map.onyx +++ b/core/container/map.onyx @@ -31,6 +31,9 @@ Map :: struct (Key_Type: type_expr, Value_Type: type_expr) where ValidKey(Key_Ty value : V; } +} + +#inject Map { // // These need to have aliases because some of them like // 'delete', collide with the global 'delete', which @@ -44,6 +47,8 @@ Map :: struct (Key_Type: type_expr, Value_Type: type_expr) where ValidKey(Key_Ty update :: update clear :: clear empty :: empty + literal :: literal + as_iter :: as_iter } make :: ($Key: type_expr, $Value: type_expr, default := Value.{}) -> Map(Key, Value) { @@ -166,6 +171,37 @@ format_map :: (output: ^conv.Format_Output, format: ^conv.Format, x: ^Map($K, $V } } +#local +MapLiteralValue :: struct (K: type_expr, V: type_expr) { + key: K; + value: V; +} + +literal :: ($Key: type_expr, $Value: type_expr, values: [] MapLiteralValue(Key, Value)) => { + m := core.map.make(Key, Value); + for ^ values { + m->put(it.key, it.value); + } + + return m; +} + + +#overload core.iter.as_iterator as_iter + +as_iter :: (m: ^Map) => + core.iter.generator( + ^.{ m = m, i = 0 }, + + (ctx) => { + if ctx.i >= ctx.m.entries.count { + return (typeof ctx.m.entries.data).{}, false; + } + + defer ctx.i += 1; + return ^ctx.m.entries.data[ctx.i], true; + }); + // // Private symbols // diff --git a/core/net/tcp.onyx b/core/net/tcp.onyx index 65bad059..f9dc0445 100644 --- a/core/net/tcp.onyx +++ b/core/net/tcp.onyx @@ -107,7 +107,9 @@ TCP_Server :: struct { pulse_time_ms := 500; emit_data_events := true; +} +#inject TCP_Server { listen :: tcp_server_listen stop :: tcp_server_stop pulse :: tcp_server_pulse @@ -298,15 +300,6 @@ tcp_server_pulse :: (use server: ^TCP_Server) -> bool { } } - array.sort(clients, (a, b) => { - a_val := 1 if a == null else 0; - b_val := 1 if b == null else 0; - - if a_val != b_val do return b_val - a_val; - - return cast(i32) a.state - cast(i32) b.state; - }); - client_count = array.count_where(clients, #(it != null)); return server.alive; diff --git a/shared/include/bh.h b/shared/include/bh.h index 430b15fb..e35a8f5e 100644 --- a/shared/include/bh.h +++ b/shared/include/bh.h @@ -282,6 +282,9 @@ BH_DEF BH_ALLOCATOR_PROC(bh_arena_allocator_proc); // ATOMIC ARENA ALLOCATOR +// Currently, this is only available on Linux, as it is using pthreads. +#ifdef _BH_LINUX + typedef struct bh_atomic_arena { bh_allocator backing; ptr first_arena, current_arena; @@ -300,6 +303,8 @@ BH_DEF void bh_atomic_arena_free(bh_atomic_arena* alloc); BH_DEF bh_allocator bh_atomic_arena_allocator(bh_atomic_arena* alloc); BH_DEF BH_ALLOCATOR_PROC(bh_atomic_arena_allocator_proc); +#endif + @@ -1158,6 +1163,7 @@ BH_ALLOCATOR_PROC(bh_arena_allocator_proc) { // ATOMIC ARENA ALLOCATOR IMPLEMENTATION +#ifdef _BH_LINUX BH_DEF void bh_atomic_arena_init(bh_atomic_arena* alloc, bh_allocator backing, isize arena_size) { arena_size = bh_max(arena_size, size_of(ptr)); ptr data = bh_alloc(backing, arena_size); @@ -1241,6 +1247,7 @@ BH_DEF BH_ALLOCATOR_PROC(bh_atomic_arena_allocator_proc) { pthread_mutex_unlock(&alloc_arena->mutex); return retval; } +#endif diff --git a/shared/lib/linux_x86_64/lib/libovmwasm.so b/shared/lib/linux_x86_64/lib/libovmwasm.so index 7d1249f7..a05e2c83 100755 Binary files a/shared/lib/linux_x86_64/lib/libovmwasm.so and b/shared/lib/linux_x86_64/lib/libovmwasm.so differ