Skip to content

Commit

Permalink
0.5.3: Single-module not respected. Fix issue with compiler defined t…
Browse files Browse the repository at this point in the history
…ypes. Fix optimization levels for projects. Use GEP i8 on offsets. Optimize foreach on len 1 arrays. Move panic blocks last. Fix generic module wildcard imports. Deprecate init_temp / init_new. Fix issue with macro vaarg and untyped lists. Fix extern const globals.
  • Loading branch information
lerno committed Jan 14, 2024
1 parent e91f6e2 commit deb4cc7
Show file tree
Hide file tree
Showing 208 changed files with 9,751 additions and 9,565 deletions.
22 changes: 18 additions & 4 deletions lib/std/collections/bitset.c3
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,29 @@ struct GrowableBitSet
* @param initial_capacity
* @param [&inout] allocator "The allocator to use, defaults to the heap allocator"
**/
fn GrowableBitSet* GrowableBitSet.init_new(&self, usz initial_capacity = 1, Allocator* allocator = mem::heap())
fn GrowableBitSet* GrowableBitSet.new_init(&self, usz initial_capacity = 1, Allocator* allocator = mem::heap())
{
self.data.init_new(initial_capacity, allocator);
self.data.new_init(initial_capacity, allocator);
return self;
}

fn GrowableBitSet* GrowableBitSet.init_temp(&self, usz initial_capacity = 1)
/**
* @param initial_capacity
* @param [&inout] allocator "The allocator to use, defaults to the heap allocator"
**/
fn GrowableBitSet* GrowableBitSet.init_new(&self, usz initial_capacity = 1, Allocator* allocator = mem::heap()) @deprecated("Replaced by new_init")
{
return self.new_init(initial_capacity, allocator) @inline;
}

fn GrowableBitSet* GrowableBitSet.temp_init(&self, usz initial_capacity = 1)
{
return self.new_init(initial_capacity, mem::temp()) @inline;
}

fn GrowableBitSet* GrowableBitSet.init_temp(&self, usz initial_capacity = 1) @deprecated("Replaced by temp_init")
{
return self.init_new(initial_capacity, mem::temp()) @inline;
return self.temp_init(initial_capacity);
}

fn void GrowableBitSet.free(&self)
Expand Down
20 changes: 17 additions & 3 deletions lib/std/collections/linkedlist.c3
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,29 @@ fn void LinkedList.push_last(&self, Type value)
* @param [&inout] allocator "The allocator to use, defaults to the heap allocator"
* @return "the initialized list"
**/
fn LinkedList* LinkedList.init_new(&self, Allocator* allocator = mem::heap())
fn LinkedList* LinkedList.new_init(&self, Allocator* allocator = mem::heap())
{
*self = { .allocator = allocator };
return self;
}

fn LinkedList* LinkedList.init_temp(&self)
/**
* @param [&inout] allocator "The allocator to use, defaults to the heap allocator"
* @return "the initialized list"
**/
fn LinkedList* LinkedList.init_new(&self, Allocator* allocator = mem::heap()) @deprecated("Replaced by new_init")
{
return self.new_init(allocator);
}

fn LinkedList* LinkedList.temp_init(&self)
{
return self.new_init(mem::temp()) @inline;
}

fn LinkedList* LinkedList.init_temp(&self) @deprecated("Replaced by temp_init")
{
return self.init_new(mem::temp()) @inline;
return self.temp_init() @inline;
}

/**
Expand Down
33 changes: 25 additions & 8 deletions lib/std/collections/list.c3
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ struct List (Printable)
Type *entries;
}


/**
* @param initial_capacity "The initial capacity to reserve"
* @param [&inout] allocator "The allocator to use, defaults to the heap allocator"
**/
fn List* List.init_new(&self, usz initial_capacity = 16, Allocator* allocator = mem::heap())
fn List* List.new_init(&self, usz initial_capacity = 16, Allocator* allocator = mem::heap())
{
self.allocator = allocator;
self.size = 0;
Expand All @@ -39,14 +40,33 @@ fn List* List.init_new(&self, usz initial_capacity = 16, Allocator* allocator =
return self;
}

/**
* @param initial_capacity "The initial capacity to reserve"
* @param [&inout] allocator "The allocator to use, defaults to the heap allocator"
**/
fn List* List.init_new(&self, usz initial_capacity = 16, Allocator* allocator = mem::heap()) @deprecated("Replaced by new_init")
{
return self.new_init(initial_capacity, allocator) @inline;
}

/**
* Initialize the list using the temp allocator.
*
* @param initial_capacity "The initial capacity to reserve"
**/
fn List* List.init_temp(&self, usz initial_capacity = 16)
fn List* List.temp_init(&self, usz initial_capacity = 16)
{
return self.init_new(initial_capacity, mem::temp()) @inline;
return self.new_init(initial_capacity, mem::temp()) @inline;
}

/**
* Initialize the list using the temp allocator.
*
* @param initial_capacity "The initial capacity to reserve"
**/
fn List* List.init_temp(&self, usz initial_capacity = 16) @deprecated("Replaced by temp_init")
{
return self.temp_init(initial_capacity) @inline;
}

/**
Expand Down Expand Up @@ -129,11 +149,8 @@ fn Type List.pop_first(&self)
**/
fn void List.remove_at(&self, usz index)
{
for (usz i = index + 1; i < self.size; i++)
{
self.entries[i - 1] = self.entries[i];
}
self.size--;
if (!--self.size || index == self.size) return;
self.entries[index .. self.size - 1] = self.entries[index + 1 .. self.size];
}

fn void List.add_all(&self, List* other_list)
Expand Down
70 changes: 56 additions & 14 deletions lib/std/collections/map.c3
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,51 @@ struct HashMap
* @param [&inout] allocator "The allocator to use"
* @require capacity > 0 "The capacity must be 1 or higher"
* @require load_factor > 0.0 "The load factor must be higher than 0"
* @require !map.allocator "Map was already initialized"
* @require !self.allocator "Map was already initialized"
* @require capacity < MAXIMUM_CAPACITY "Capacity cannot exceed maximum"
**/
fn HashMap* HashMap.init_new(&map, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR, Allocator* allocator = mem::heap())
fn HashMap* HashMap.new_init(&self, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR, Allocator* allocator = mem::heap())
{
capacity = math::next_power_of_2(capacity);
map.allocator = allocator;
map.load_factor = load_factor;
map.threshold = (uint)(capacity * load_factor);
map.table = allocator.new_zero_array(Entry*, capacity);
return map;
self.allocator = allocator;
self.load_factor = load_factor;
self.threshold = (uint)(capacity * load_factor);
self.table = allocator.new_zero_array(Entry*, capacity);
return self;
}

/**
* @param [&inout] allocator "The allocator to use"
* @require capacity > 0 "The capacity must be 1 or higher"
* @require load_factor > 0.0 "The load factor must be higher than 0"
* @require !map.allocator "Map was already initialized"
* @require capacity < MAXIMUM_CAPACITY "Capacity cannot exceed maximum"
**/
fn HashMap* HashMap.init_temp(&map, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR)
fn HashMap* HashMap.init_new(&map, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR, Allocator* allocator = mem::heap()) @deprecated("Replaced by new_init")
{
return map.new_init(capacity, load_factor, allocator);
}

/**
* @require capacity > 0 "The capacity must be 1 or higher"
* @require load_factor > 0.0 "The load factor must be higher than 0"
* @require !self.allocator "Map was already initialized"
* @require capacity < MAXIMUM_CAPACITY "Capacity cannot exceed maximum"
**/
fn HashMap* HashMap.temp_init(&self, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR)
{
return map.init_new(capacity, load_factor, mem::temp());
return self.new_init(capacity, load_factor, mem::temp()) @inline;
}

/**
* @require capacity > 0 "The capacity must be 1 or higher"
* @require load_factor > 0.0 "The load factor must be higher than 0"
* @require !map.allocator "Map was already initialized"
* @require capacity < MAXIMUM_CAPACITY "Capacity cannot exceed maximum"
**/
fn HashMap* HashMap.init_temp(&map, uint capacity = DEFAULT_INITIAL_CAPACITY, float load_factor = DEFAULT_LOAD_FACTOR) @deprecated("Replaced by temp_init")
{
return map.temp_init(capacity, load_factor) @inline;
}

/**
Expand All @@ -62,21 +85,40 @@ fn bool HashMap.is_initialized(&map)
* @param [&inout] allocator "The allocator to use"
* @param [&in] other_map "The map to copy from."
**/
fn HashMap* HashMap.init_new_from_map(&self, HashMap* other_map, Allocator* allocator = mem::heap())
fn HashMap* HashMap.new_init_from_map(&self, HashMap* other_map, Allocator* allocator = mem::heap())
{
self.init_new(other_map.table.len, other_map.load_factor, allocator);
self.new_init(other_map.table.len, other_map.load_factor, allocator);
self.put_all_for_create(other_map);
return self;
}

/**
* @param [&inout] allocator "The allocator to use"
* @param [&in] other_map "The map to copy from."
**/
fn HashMap* HashMap.init_temp_from_map(&map, HashMap* other_map)
fn HashMap* HashMap.init_new_from_map(&self, HashMap* other_map, Allocator* allocator = mem::heap()) @deprecated("Replaced by new_init_from_map")

{
return map.init_new_from_map(other_map, mem::temp()) @inline;
return self.new_init_from_map(other_map, allocator) @inline;
}

/**
* @param [&in] other_map "The map to copy from."
**/
fn HashMap* HashMap.temp_init_from_map(&map, HashMap* other_map)
{
return map.new_init_from_map(other_map, mem::temp()) @inline;
}

/**
* @param [&in] other_map "The map to copy from."
**/
fn HashMap* HashMap.init_temp_from_map(&map, HashMap* other_map) @deprecated("Replaced by temp_init_from_map")
{
return map.temp_init_from_map(other_map) @inline;
}


fn bool HashMap.is_empty(&map) @inline
{
return !map.count;
Expand Down Expand Up @@ -146,7 +188,7 @@ fn bool HashMap.set(&map, Key key, Value value) @operator([]=)
// If the map isn't initialized, use the defaults to initialize it.
if (!map.allocator)
{
map.init_new();
map.new_init();
}
uint hash = rehash(key.hash());
uint index = index_for(hash, map.table.len);
Expand Down
4 changes: 2 additions & 2 deletions lib/std/collections/object.c3
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn void Object.init_map_if_needed(&self) @private
if (self.is_empty())
{
self.type = ObjectInternalMap.typeid;
self.map.init_new(.allocator = self.allocator);
self.map.new_init(.allocator = self.allocator);
}
}

Expand All @@ -180,7 +180,7 @@ fn void Object.init_array_if_needed(&self) @private
if (self.is_empty())
{
self.type = ObjectInternalList.typeid;
self.array.init_new(.allocator = self.allocator);
self.array.new_init(.allocator = self.allocator);
}
}

Expand Down
18 changes: 14 additions & 4 deletions lib/std/collections/priorityqueue.c3
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,24 @@ struct PrivatePriorityQueue (Printable)
Heap heap;
}

fn void PrivatePriorityQueue.init_new(&self, usz initial_capacity = 16, Allocator* allocator = mem::heap()) @inline
fn void PrivatePriorityQueue.init_new(&self, usz initial_capacity = 16, Allocator* allocator = mem::heap()) @inline @deprecated("Replaced by new_init")
{
self.heap.init_new(initial_capacity, allocator);
return self.new_init(initial_capacity, allocator);
}

fn void PrivatePriorityQueue.init_temp(&self, usz initial_capacity = 16) @inline
fn void PrivatePriorityQueue.new_init(&self, usz initial_capacity = 16, Allocator* allocator = mem::heap()) @inline
{
self.heap.init_new(initial_capacity, mem::temp()) @inline;
self.heap.new_init(initial_capacity, allocator);
}

fn void PrivatePriorityQueue.temp_init(&self, usz initial_capacity = 16) @inline
{
self.heap.new_init(initial_capacity, mem::temp()) @inline;
}

fn void PrivatePriorityQueue.init_temp(&self, usz initial_capacity = 16) @inline @deprecated("Replaced by temp_init")
{
return self.temp_init(initial_capacity) @inline;
}

fn void PrivatePriorityQueue.push(&self, Type element)
Expand Down
2 changes: 1 addition & 1 deletion lib/std/core/allocators/tracking_allocator.c3
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct TrackingAllocator (Allocator)
fn void TrackingAllocator.init(&self, Allocator* allocator)
{
*self = { .inner_allocator = allocator };
self.map.init_new(.allocator = allocator);
self.map.new_init(.allocator = allocator);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/std/core/builtin.c3
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn void panicf(String fmt, String file, String function, uint line, args...)
@stack_mem(512; Allocator* allocator)
{
DString s;
s.init_new(.allocator = allocator);
s.new_init(.allocator = allocator);
s.appendf(fmt, ...args);
panic(s.str_view(), file, function, line);
};
Expand Down
30 changes: 24 additions & 6 deletions lib/std/core/dstring.c3
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const usz MIN_CAPACITY @private = 16;
/**
* @require !self.data() "String already initialized"
**/
fn DString DString.init_new(&self, usz capacity = MIN_CAPACITY, Allocator* allocator = mem::heap())
fn DString DString.new_init(&self, usz capacity = MIN_CAPACITY, Allocator* allocator = mem::heap())
{
if (capacity < MIN_CAPACITY) capacity = MIN_CAPACITY;
StringData* data = allocator.new(StringData, .end_padding = capacity);
Expand All @@ -21,15 +21,31 @@ fn DString DString.init_new(&self, usz capacity = MIN_CAPACITY, Allocator* alloc
/**
* @require !self.data() "String already initialized"
**/
fn DString DString.init_temp(&self, usz capacity = MIN_CAPACITY)
fn DString DString.init_new(&self, usz capacity = MIN_CAPACITY, Allocator* allocator = mem::heap()) @deprecated("Replaced by new_init")
{
self.init_new(capacity, mem::temp()) @inline;
return self.new_init(capacity, allocator) @inline;
}

/**
* @require !self.data() "String already initialized"
**/
fn DString DString.temp_init(&self, usz capacity = MIN_CAPACITY)
{
self.new_init(capacity, mem::temp()) @inline;
return *self;
}

/**
* @require !self.data() "String already initialized"
**/
fn DString DString.init_temp(&self, usz capacity = MIN_CAPACITY) @deprecated("Replaced by temp_init")
{
return self.temp_init(capacity) @inline;
}

fn DString new_with_capacity(usz capacity, Allocator* allocator = mem::heap())
{
return DString{}.init_new(capacity, allocator);
return DString{}.new_init(capacity, allocator);
}

fn DString temp_with_capacity(usz capacity) => new_with_capacity(capacity, mem::temp()) @inline;
Expand All @@ -51,13 +67,15 @@ fn DString temp_new(String s = "") => new(s, mem::temp()) @inline;
fn DString DString.new_concat(self, DString b, Allocator* allocator = mem::heap())
{
DString string;
string.init_new(self.len() + b.len(), allocator);
string.new_init(self.len() + b.len(), allocator);
string.append(self);
string.append(b);
return string;
}

fn DString DString.new_tconcat(self, DString b) => self.new_concat(b, mem::temp());
fn DString DString.temp_concat(self, DString b) => self.new_concat(b, mem::temp());

fn DString DString.new_tconcat(self, DString b) @deprecated("Replaced by temp_concat") => self.new_concat(b, mem::temp());

fn ZString DString.zstr_view(&self)
{
Expand Down
4 changes: 2 additions & 2 deletions lib/std/io/os/ls.c3
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module std::io::file::os @if(env::POSIX);
fn PathList! native_ls(Path dir, bool no_dirs, bool no_symlinks, String mask, Allocator* allocator)
{
PathList list;
list.init_new(.allocator = allocator);
list.new_init(.allocator = allocator);
DIRPtr directory = posix::opendir(dir.str_view() ? dir.as_zstr() : (ZString)".");
defer if (directory) posix::closedir(directory);
if (!directory) return (path::is_dir(dir) ? IoError.CANNOT_READ_DIR : IoError.FILE_NOT_DIR)?;
Expand All @@ -25,7 +25,7 @@ module std::io::os @if(env::WIN32);
fn PathList! native_ls(Path dir, bool no_dirs, bool no_symlinks, String mask, Allocator* allocator)
{
PathList list;
list.init_new(.allocator = allocator);
list.new_init(.allocator = allocator);

@pool(allocator)
{
Expand Down
Loading

0 comments on commit deb4cc7

Please sign in to comment.