},
}
+delete :: #match {
+ #precedence 1000 macro (x: ^$T, allocator := context.allocator) -> ^T {
+ raw_free(allocator, x);
+ }
+}
+
Iterator :: struct (Iter_Type: type_expr) {
data: rawptr;
arr.data = null;
}
-copy :: (arr: ^[..] $T, allocator := context.allocator) -> [..] T {
- new_arr : [..] T;
- init(^new_arr, arr.count, allocator);
- new_arr.count = arr.count;
+#match (package builtin).delete macro (x: ^[..] $T) {
+ (package core.array).free(x);
+}
- for i: 0 .. arr.count do new_arr.data[i] = arr.data[i];
- return new_arr;
+copy :: #match {
+ (arr: ^[..] $T, allocator := context.allocator) -> [..] T {
+ new_arr : [..] T;
+ init(^new_arr, arr.count, allocator);
+ new_arr.count = arr.count;
+
+ for i: 0 .. arr.count do new_arr.data[i] = arr.data[i];
+ return new_arr;
+ },
+
+ (arr: [] $T, allocator := context.allocator) -> [] T {
+ new_arr := make([] T, arr.count);
+ for i: 0 .. arr.count do new_arr.data[i] = arr.data[i];
+ return new_arr;
+ }
}
copy_range :: (arr: ^[..] $T, r: range, allocator := context.allocator) -> [..] T {
value : V;
}
- init :: init
- has :: has
- get :: get
- get_ptr :: get_ptr
- put :: put
- delete :: delete
- update :: update
- clear :: clear
- empty :: empty
+ //
+ // These need to have aliases because some of them like
+ // 'delete', collide with the global 'delete', which
+ // causes it to map to the wrong function.
+ init :: (package core.map).init
+ has :: (package core.map).has
+ get :: (package core.map).get
+ get_ptr :: (package core.map).get_ptr
+ put :: (package core.map).put
+ delete :: (package core.map).delete
+ update :: (package core.map).update
+ clear :: (package core.map).clear
+ empty :: (package core.map).empty
}
make :: ($Key: type_expr, $Value: type_expr, default := __zero_value(Value)) -> Map(Key, Value) {
default_value = default;
memory.alloc_slice(^hashes, 8, allocator=allocator);
- memory.fill_slice(hashes, -1);
+ array.fill(hashes, -1);
array.init(^entries, allocator=allocator);
}
if map.entries.data != null do array.free(^entries);
}
+#match (package builtin).delete (package core.map).free
+
put :: (use map: ^Map, key: map.Key_Type, value: map.Value_Type) {
lr := lookup(map, key);
rehash :: (use map: ^Map, new_size: i32) {
memory.free_slice(^hashes, allocator);
- memory.alloc_slice(^hashes, new_size, allocator);
- memory.fill_slice(hashes, -1);
+ hashes = make([] u32, new_size, allocator=allocator);
+ array.fill(hashes, -1);
for ^entry: entries do entry.next = -1;
set.default_value = default;
memory.alloc_slice(^set.hashes, 8, allocator=allocator);
- memory.fill_slice(set.hashes, -1);
+ array.fill(set.hashes, -1);
array.init(^set.entries, 4, allocator=allocator);
}
rehash :: (use set: ^Set, new_size: i32) {
memory.free_slice(^hashes, allocator);
- memory.alloc_slice(^hashes, new_size, allocator);
- memory.fill_slice(hashes, -1);
+ hashes = make([] u32, new_size, allocator=allocator);
+ array.fill(hashes, -1);
for ^entry: entries do entry.next = -1;
sl.count = 0;
}
+#match (package builtin).delete macro (x: ^[] $T) {
+ (package core.memory).free_slice(x);
+}
+
copy_slice :: (sl: [] $T, allocator := context.allocator) -> [] T {
data := raw_alloc(allocator, sl.count * sizeof T);
copy(data, sl.data, sl.count * sizeof T);
return new_slice;
}
-fill_slice :: macro (sl: [] $T, v: T) {
- for ^it: sl do *it = v;
-}
-
align :: #match {
(size: ^u64, align: u64) {
if *size % align != 0 {
server.client_count = 0;
server.client_allocator = allocator;
- memory.alloc_slice(^server.clients, max_clients, allocator=allocator);
- memory.fill_slice(server.clients, null);
+ server.clients = make([] ^TCP_Server.Client, max_clients, allocator=allocator);
+ array.fill(server.clients, null);
return server;
}
}
// Using the thread-local variable
- memory.alloc_slice(^partial_arr, 5);
+ partial_arr = make([] i32, 5);
for i: 5 do partial_arr[i] = i * i;
// Not printing on threads since the test case looks for EXACT string matches
println(test);
sd: Shared_Data;
- sd.arr = memory.make_slice(i32, 1000);
- memory.fill_slice(sd.arr, 0);
+ sd.arr = make([] i32, 1000);
+ array.fill(sd.arr, 0);
threads : [4] thread.Thread;
for ^t: threads {
// This is so much cleaner than the alternative.
ages := map.make(str, u32, default=0);
- defer map.free(^ages);
+ defer delete(^ages);
map.put(^ages, "Dwight", 32);
map.put(^ages, "Jim", 25);