added map.as_iter; bugfixes
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 5 Nov 2022 04:58:07 +0000 (23:58 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 5 Nov 2022 04:58:07 +0000 (23:58 -0500)
core/container/map.onyx
core/net/tcp.onyx
shared/include/bh.h
shared/lib/linux_x86_64/lib/libovmwasm.so

index a372c3a3011c3e5cfc115fb59593019a10f2d57f..7e7ddceb93b55a83c8b3b6c6a91a39c83d6761ab 100644 (file)
@@ -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
 //
index 65bad059981fba36e3531ef76a66f91e8b6667e5..f9dc04450e0f16e4ef4964de5f83268520cdb4cf 100644 (file)
@@ -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;
index 430b15fb442a032f8c50377a030c159f76b6df07..e35a8f5eb950922aae758eab1591941598a91d18 100644 (file)
@@ -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
 
 
 
index 7d1249f7f18bd9cf784f01790378bfacf774d914..a05e2c83189ccbbc5702662a6b5d116ce60cd66e 100755 (executable)
Binary files a/shared/lib/linux_x86_64/lib/libovmwasm.so and b/shared/lib/linux_x86_64/lib/libovmwasm.so differ