Skip to content

Commit

Permalink
0.5.4: Hash variables accept designated initializers. @safemacro over…
Browse files Browse the repository at this point in the history
…rides the need for `@` in macro names. Fixes to macro context evaluation. Updated allocator api. Removed install_win_reqs.bat. Deterministic @init for MacOS. Fixed temp memory issue with formatter. Support LLVM 19. Add support to compare bitstructs using == and !=. Support Windows `.def` files. Removed invalid grammar from grammar.y. Support compile time folding of &|^~ for bitstructs. `output` project setting now respected. Fix issue where constants were not properly constant folded. Add temp_push/pop. Aliased declarations caused errors when used in initializers. Fix export output. Fix of const ternary #1118. Fix of $$MODULE in nested macros #1117. Fix debug info on globals. `out` now correctly detects subscript[] use #1116.
  • Loading branch information
lerno committed Feb 11, 2024
1 parent deb4cc7 commit 154cd98
Show file tree
Hide file tree
Showing 116 changed files with 2,981 additions and 1,328 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ jobs:
cd test
..\build\${{ matrix.build_type }}\c3c.exe compile-test unit -O1
- name: Test python script
run: |
py msvc_build_libraries.py --accept-license
dir msvc_sdk
- name: upload artifacts
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -193,7 +198,7 @@ jobs:
fail-fast: false
matrix:
build_type: [Release, Debug]
llvm_version: [15, 16, 17, 18]
llvm_version: [15, 16, 17, 18, 19]

steps:
- uses: actions/checkout@v4
Expand All @@ -207,7 +212,7 @@ jobs:
if [[ "${{matrix.llvm_version}}" < 16 ]]; then
sudo apt remove libllvm15
fi
if [[ "${{matrix.llvm_version}}" < 18 ]]; then
if [[ "${{matrix.llvm_version}}" < 19 ]]; then
sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-${{matrix.llvm_version}} main"
sudo apt-get update
sudo apt-get install -y -t llvm-toolchain-focal-${{matrix.llvm_version}} libpolly-${{matrix.llvm_version}}-dev \
Expand All @@ -222,6 +227,7 @@ jobs:
libmlir-${{matrix.llvm_version}}-dev mlir-${{matrix.llvm_version}}-tools
fi
- name: CMake
if: matrix.llvm_version != 18
run: |
cmake -B build \
-G Ninja \
Expand All @@ -234,6 +240,20 @@ jobs:
-DCMAKE_DLLTOOL=llvm-dlltool-${{matrix.llvm_version}} \
-DC3_LLVM_VERSION=${{matrix.llvm_version}}
cmake --build build
- name: CMake18
if: matrix.llvm_version == 18
run: |
cmake -B build \
-G Ninja \
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
-DCMAKE_C_COMPILER=clang-${{matrix.llvm_version}} \
-DCMAKE_CXX_COMPILER=clang++-${{matrix.llvm_version}} \
-DCMAKE_LINKER=lld-link-${{matrix.llvm_version}} \
-DCMAKE_OBJCOPY=llvm-objcopy-${{matrix.llvm_version}} \
-DCMAKE_STRIP=llvm-strip-${{matrix.llvm_version}} \
-DCMAKE_DLLTOOL=llvm-dlltool-${{matrix.llvm_version}} \
-DC3_LLVM_VERSION=18.1
cmake --build build
- name: Compile and run some examples
run: |
Expand Down Expand Up @@ -418,7 +438,7 @@ jobs:
fail-fast: false
matrix:
build_type: [Release, Debug]
llvm_version: [15, 16]
llvm_version: [15, 16, 17]
steps:
- uses: actions/checkout@v4
- name: Download LLVM
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ if (NOT WIN32)
find_package(CURL)
endif()
if (NOT C3_LLVM_VERSION STREQUAL "auto")
if (${C3_LLVM_VERSION} VERSION_LESS 15 OR ${C3_LLVM_VERSION} VERSION_GREATER 18)
if (${C3_LLVM_VERSION} VERSION_LESS 15 OR ${C3_LLVM_VERSION} VERSION_GREATER 19)
message(FATAL_ERROR "LLVM ${C3_LLVM_VERSION} is not supported!")
endif()
endif()
Expand Down
17 changes: 0 additions & 17 deletions install_win_reqs.bat

This file was deleted.

6 changes: 3 additions & 3 deletions lib/std/collections/bitset.c3
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct GrowableBitSet
* @param initial_capacity
* @param [&inout] allocator "The allocator to use, defaults to the heap allocator"
**/
fn GrowableBitSet* GrowableBitSet.new_init(&self, usz initial_capacity = 1, Allocator* allocator = mem::heap())
fn GrowableBitSet* GrowableBitSet.new_init(&self, usz initial_capacity = 1, Allocator* allocator = allocator::heap())
{
self.data.new_init(initial_capacity, allocator);
return self;
Expand All @@ -96,14 +96,14 @@ fn GrowableBitSet* GrowableBitSet.new_init(&self, usz initial_capacity = 1, Allo
* @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")
fn GrowableBitSet* GrowableBitSet.init_new(&self, usz initial_capacity = 1, Allocator* allocator = allocator::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;
return self.new_init(initial_capacity, allocator::temp()) @inline;
}

fn GrowableBitSet* GrowableBitSet.init_temp(&self, usz initial_capacity = 1) @deprecated("Replaced by temp_init")
Expand Down
2 changes: 1 addition & 1 deletion lib/std/collections/enummap.c3
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn usz! EnumMap.to_format(&self, Formatter* formatter) @dynamic
return n;
}

fn String EnumMap.to_new_string(&self, Allocator* allocator = mem::heap()) @dynamic
fn String EnumMap.to_new_string(&self, Allocator* allocator = allocator::heap()) @dynamic
{
return string::new_format("%s", *self, .allocator = allocator);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/std/collections/enumset.c3
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ fn usz! EnumSet.to_format(&set, Formatter* formatter) @dynamic
return n;
}

fn String EnumSet.to_new_string(&set, Allocator* allocator = mem::heap()) @dynamic
fn String EnumSet.to_new_string(&set, Allocator* allocator = allocator::heap()) @dynamic
{
return string::new_format("%s", *set, .allocator = allocator);
}
Expand Down
13 changes: 7 additions & 6 deletions lib/std/collections/linkedlist.c3
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ 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.new_init(&self, Allocator* allocator = mem::heap())
fn LinkedList* LinkedList.new_init(&self, Allocator* allocator = allocator::heap())
{
*self = { .allocator = allocator };
return self;
Expand All @@ -42,14 +42,14 @@ fn LinkedList* LinkedList.new_init(&self, Allocator* allocator = mem::heap())
* @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")
fn LinkedList* LinkedList.init_new(&self, Allocator* allocator = allocator::heap()) @deprecated("Replaced by new_init")
{
return self.new_init(allocator);
}

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

fn LinkedList* LinkedList.init_temp(&self) @deprecated("Replaced by temp_init")
Expand All @@ -62,12 +62,13 @@ fn LinkedList* LinkedList.init_temp(&self) @deprecated("Replaced by temp_init")
**/
macro void LinkedList.free_node(&self, Node* node) @private
{
self.allocator.free(node);
allocator::free(self.allocator, node);
}

macro Node* LinkedList.alloc_node(&self) @private
{
if (!self.allocator) self.allocator = mem::heap();
return self.allocator.new(Node);
if (!self.allocator) self.allocator = allocator::heap();
return allocator::alloc(self.allocator, Node);
}

fn void LinkedList.link_first(&self, Type value) @private
Expand Down
29 changes: 17 additions & 12 deletions lib/std/collections/list.c3
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ struct List (Printable)
* @param initial_capacity "The initial capacity to reserve"
* @param [&inout] allocator "The allocator to use, defaults to the heap allocator"
**/
fn List* List.new_init(&self, usz initial_capacity = 16, Allocator* allocator = mem::heap())
fn List* List.new_init(&self, usz initial_capacity = 16, Allocator* allocator = allocator::heap())
{
self.allocator = allocator;
self.size = 0;
if (initial_capacity > 0)
{
initial_capacity = math::next_power_of_2(initial_capacity);
self.entries = allocator.alloc_aligned(Type.sizeof * initial_capacity, .alignment = Type[1].alignof)!!;
self.entries = allocator::malloc_aligned(allocator, Type.sizeof * initial_capacity, .alignment = Type[1].alignof)!!;
}
else
{
Expand All @@ -44,7 +44,7 @@ fn List* List.new_init(&self, usz initial_capacity = 16, Allocator* allocator =
* @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")
fn List* List.init_new(&self, usz initial_capacity = 16, Allocator* allocator = allocator::heap()) @deprecated("Replaced by new_init")
{
return self.new_init(initial_capacity, allocator) @inline;
}
Expand All @@ -56,7 +56,7 @@ fn List* List.init_new(&self, usz initial_capacity = 16, Allocator* allocator =
**/
fn List* List.temp_init(&self, usz initial_capacity = 16)
{
return self.new_init(initial_capacity, mem::temp()) @inline;
return self.new_init(initial_capacity, allocator::temp()) @inline;
}

/**
Expand All @@ -72,7 +72,7 @@ fn List* List.init_temp(&self, usz initial_capacity = 16) @deprecated("Replaced
/**
* @require self.size == 0 "The List must be empty"
**/
fn void List.init_wrapping_array(&self, Type[] types, Allocator* allocator = mem::heap())
fn void List.init_wrapping_array(&self, Type[] types, Allocator* allocator = allocator::heap())
{
self.allocator = allocator;
self.size = types.len;
Expand Down Expand Up @@ -100,7 +100,7 @@ fn usz! List.to_format(&self, Formatter* formatter) @dynamic
}
}

fn String List.to_new_string(&self, Allocator* allocator = mem::heap()) @dynamic
fn String List.to_new_string(&self, Allocator* allocator = allocator::heap()) @dynamic
{
return string::new_format("%s", *self, .allocator = allocator);
}
Expand Down Expand Up @@ -164,17 +164,17 @@ fn void List.add_all(&self, List* other_list)
}


fn Type[] List.to_new_array(&self, Allocator* allocator = mem::heap())
fn Type[] List.to_new_array(&self, Allocator* allocator = allocator::heap())
{
if (!self.size) return Type[] {};
Type[] result = allocator.new_array(Type, self.size);
Type[] result = allocator::alloc_array(allocator, Type, self.size);
result[..] = self.entries[:self.size];
return result;
}

fn Type[] List.to_tarray(&self)
{
return self.to_new_array(mem::temp());
return self.to_new_array(allocator::temp());
}

/**
Expand Down Expand Up @@ -264,6 +264,11 @@ fn bool List.is_empty(&self) @inline
return !self.size;
}

fn usz List.byte_size(&self) @inline
{
return Type.sizeof * self.size;
}

fn usz List.len(&self) @operator(len) @inline
{
return self.size;
Expand All @@ -277,7 +282,7 @@ fn Type List.get(&self, usz index) @inline
fn void List.free(&self)
{
if (!self.allocator) return;
self.allocator.free_aligned(self.entries);
allocator::free_aligned(self.allocator, self.entries);
self.capacity = 0;
self.size = 0;
self.entries = null;
Expand Down Expand Up @@ -373,9 +378,9 @@ fn void List.reserve(&self, usz min_capacity)
{
if (!min_capacity) return;
if (self.capacity >= min_capacity) return;
if (!self.allocator) self.allocator = mem::heap();
if (!self.allocator) self.allocator = allocator::heap();
min_capacity = math::next_power_of_2(min_capacity);
self.entries = self.allocator.realloc_aligned(self.entries, Type.sizeof * min_capacity, .alignment = Type[1].alignof) ?? null;
self.entries = allocator::realloc_aligned(self.allocator, self.entries, Type.sizeof * min_capacity, .alignment = Type[1].alignof) ?? null;
self.capacity = min_capacity;
}

Expand Down
Loading

0 comments on commit 154cd98

Please sign in to comment.