From 97ac957cb78fde74fe33fad8908eca0b823ca6df Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 28 May 2021 15:44:36 +0200 Subject: [PATCH] "Public by default" --- resources/lib/std/array.c3 | 279 ++++++++++++++++-- resources/lib/std/io.c3 | 6 +- resources/lib/std/math.c3 | 6 +- resources/lib/std/mem.c3 | 30 +- src/compiler/enums.h | 1 - src/compiler/parse_global.c | 22 +- src/compiler/parse_stmt.c | 1 - src/compiler/tokens.c | 2 - test/test_suite/arrays/array_struct.c3t | 2 +- .../test_suite/arrays/complex_array_const.c3t | 2 +- test/test_suite/assert/assert_variants.c3t | 4 +- test/test_suite/assert/unreachable.c3t | 4 +- test/test_suite/constants/char_literals.c3t | 18 +- test/test_suite/constants/constants.c3t | 20 +- test/test_suite/enumerations/compile_time.c3t | 10 +- .../expressions/casts/cast_expr.c3t | 2 +- test/test_suite/functions/missing_return.c3 | 2 +- test/test_suite/functions/multi_module.c3t2 | 58 ---- test/test_suite/macros/hash_ident.c3 | 6 +- test/test_suite/pointers/const_pointer.c3t | 8 +- test/test_suite/pointers/pointer_index.c3t | 6 +- .../statements/call_missing_paren.c3 | 2 +- test/test_suite/statements/defer_break.c3t | 24 +- .../statements/defer_break_simple.c3t | 10 +- test/test_suite/statements/defer_return.c3t | 2 +- test/test_suite/statements/for.c3 | 6 +- test/test_suite/statements/for_empty.c3 | 2 +- test/test_suite/statements/for_errors.c3 | 2 +- test/test_suite/statements/if_decl.c3 | 2 +- test/test_suite/statements/label_errors.c3 | 2 +- test/test_suite/struct/simple_struct.c3t | 2 +- .../struct/struct_const_construct_simple.c3t | 18 +- .../struct/struct_pack_and_align.c3t | 12 +- test/test_suite/union/union_codegen_const.c3t | 8 +- test/test_suite/union/union_in_struct.c3t | 8 +- test/test_suite/visibility/ambiguous_var.c3t | 12 +- .../visibility/no_shared_imports.c3t | 6 +- test/test_suite/visibility/not_visible.c3t | 4 +- test/test_suite/visibility/shared_module.c3t | 4 +- .../visibility/simple_visibility.c3t | 4 +- 40 files changed, 397 insertions(+), 222 deletions(-) delete mode 100644 test/test_suite/functions/multi_module.c3t2 diff --git a/resources/lib/std/array.c3 b/resources/lib/std/array.c3 index 3aa3708a6..9d750b34d 100644 --- a/resources/lib/std/array.c3 +++ b/resources/lib/std/array.c3 @@ -1,54 +1,299 @@ module std::array; import std::mem; -public macro make($Type, usize elements) +macro make($Type, usize elements) { assert(elements > 0); $Type* ptr = mem::alloc($Type.sizeof, elements); return ptr[0..(elements - 1)]; } -public macro make_zero($Type, usize elements) +macro make_zero($Type, usize elements) { assert(elements > 0); $Type* ptr = mem::calloc($Type.sizeof, elements); return ptr[0..(elements - 1)]; } -public template vararray +template vararray { - public struct VarArray + struct List { usize size; usize capacity; Type *entries; } - public func void VarArray.append(VarArray *array, Type element) + static func void List.ensureCapacity(List *list) @inline { - if (array.capacity == array.size) + if (list.capacity == list.size) { - array.capacity = array.capacity ? 2 * array.capacity : 16; - array.entries = mem::realloc(array.entries, Type.sizeof * array.capacity); + list.capacity = list.capacity ? 2 * list.capacity : 16; + list.entries = mem::realloc(list.entries, Type.sizeof * list.capacity); } - array.entries[array.size++] = element; } - public func usize VarArray.len(VarArray *array) + func void List.push(List *list, Type element) @inline { - return array.size; + list.append(element); } - public func Type VarArray.get(VarArray *array, usize index) + func void List.append(List *list, Type element) { - return array.entries[index]; + list.ensureCapacity(); + list.entries[list.size++] = element; } - public func void VarArray.free(VarArray *array) + /** + * @require list.size > 0 + */ + func Type List.pop(List *list) { - mem::free(array.entries); - array.capacity = 0; - array.size = 0; + return list.entries[--list.size]; + } + + /** + * @require list.size > 0 + */ + func Type List.popFirst(List *list) + { + Type value = list.entries[0]; + list.removeAt(0); + return value; + } + + func void List.removeAt(List *list, usize index) + { + for (usize i = index + 1; i < list.size; i++) + { + list.entries[i - 1] = list.entries[i]; + } + list.size--; + } + + func void List.pushFront(List *list, Type type) @inline + { + list.insertAt(0, type); + } + + func void List.insertAt(List *list, usize index, Type type) + { + list.ensureCapacity(); + for (usize i = list.size; i > index; i--) + { + list.entries[i] = list.entries[i - 1]; + } + list.size++; + list.entries[index] = type; + } + + func void List.removeLast(List *list) + { + list.size--; + } + + func void List.removeFirst(List *list) + { + list.removeAt(0); + } + + func Type* List.first(List *list) + { + return list.size ? &list.entries[0] : null; + } + + func Type* List.last(List *list) + { + return list.size ? &list.entries[list.size - 1] : null; + } + + func bool List.isEmpty(List *list) + { + return list.size; + } + + func usize List.len(List *list) + { + return list.size; + } + + func Type List.get(List *list, usize index) + { + return list.entries[index]; + } + + func void List.free(List *list) + { + mem::free(list.entries); + list.capacity = 0; + list.size = 0; } } +template linklist +{ + static struct Node + { + Node *next; + Node *prev; + Type value; + } + + struct LinkedList + { + usize size; + Node *first; + Node *last; + } + + func void LinkedList.push(LinkedList *list, Type value) + { + list.linkLast(value); + } + + static func void LinkedList.linkFirst(LinkedList *list, Type value) + { + Node *first = list.first; + Node *new_node = @mem::malloc(Node); + *new_node = { .next = first, .value = value }; + list.first = new_node; + if (!first) + { + list.last = new_node; + } + else + { + first.prev = new_node; + } + list.size++; + } + + static func void LinkedList.linkLast(LinkedList *list, Type value) + { + Node *last = list.last; + Node *new_node = mem::alloc(Node.sizeof); + *new_node = { .prev = last, .value = value }; + list.last = new_node; + if (!last) + { + list.first = new_node; + } + else + { + last.next = new_node; + } + list.size++; + } + + func void LinkedList.free(LinkedList *list) + { + for (Node* node = list.first; node != null;) + { + Node* next = node.next; + mem::free(node); + node = next; + } + list.first = null; + list.last = null; + list.size = 0; + } + + func usize LinkedList.len(LinkedList* list) @inline + { + return list.size; + } + + func Type LinkedList.get(LinkedList* list, usize index) + { + Node* node = list.first; + while (index--) + { + node = node.next; + } + return node.value; + } + /** + * @require succ != null + **/ + static func void LinkedList.linkBefore(LinkedList *list, Node *succ, Type value) + { + Node* pred = succ.prev; + Node* new_node = @mem::malloc(Node); + *new_node = { .prev = pred, .next = succ, .value = value }; + succ.prev = new_node; + if (!pred) + { + list.first = new_node; + } + else + { + pred.next = new_node; + } + list.size++; + } + + /** + * @require f == list.first && f != null + **/ + static func void unlinkFirst(LinkedList* list, Node* f) + { + Node* next = f.next; + mem::free(f); + list.first = next; + if (!next) + { + list.last = null; + } + else + { + next.prev = null; + } + list.size--; + } + + /** + * @require l == list.last && l != null + **/ + static func void LinkedList.unlinkLast(LinkedList *list, Node* l) + { + Node* prev = l.prev; + list.last = prev; + mem::free(l); + if (!prev) + { + list.first = null; + } + else + { + prev.next = null; + } + list.size--; + } + + /** + * @require x != null + **/ + static func void LinkedList.unlink(LinkedList* list, Node* x) + { + Node* next = x.next; + Node* prev = x.prev; + if (!prev) + { + list.first = next; + } + else + { + prev.next = next; + } + if (!next) + { + list.last = prev; + } + else + { + next.prev = prev; + } + mem::free(x); + list.size--; + } +} diff --git a/resources/lib/std/io.c3 b/resources/lib/std/io.c3 index a8d6db1ac..c693a96d7 100644 --- a/resources/lib/std/io.c3 +++ b/resources/lib/std/io.c3 @@ -29,12 +29,12 @@ extern func int _putchar(char c) @cname("putchar"); extern File *__stdinp; -public func int putchar(char c) @inline +func int putchar(char c) @inline { return _putchar(c); } -public func int print(char *message) +func int print(char *message) { char* pointer = message; while (*pointer != '\0') @@ -45,7 +45,7 @@ public func int print(char *message) return 1; } -public func int println(char *message) @inline +func int println(char *message) @inline { return _puts(message); } diff --git a/resources/lib/std/math.c3 b/resources/lib/std/math.c3 index ed82f7bad..ec206c8c6 100644 --- a/resources/lib/std/math.c3 +++ b/resources/lib/std/math.c3 @@ -1,12 +1,12 @@ module std::math; -union DoubleLong +static union DoubleLong { double f; ulong i; } -public func double log10(double x) +func double log10(double x) { const double IVLN10HI = 4.34294481878168880939e-01; /* 0x3fdbcb7b, 0x15200000 */ const double IVLN10LO = 2.50829467116452752298e-11; /* 0x3dbb9438, 0xca9aadd5 */ @@ -108,7 +108,7 @@ func double cos_limited(double x, double y) return w + (((1.0 - w) - hz) + (z*r - x*y)); } -public func double sin_limited(double x, double y, bool iy) +static func double sin_limited(double x, double y, bool iy) { const double S1 = -1.66666666666666324348e-01; // 0xBFC55555, 0x55555549 const double S2 = 8.33333333332248946124e-03; // 0x3F811111, 0x1110F8A6 diff --git a/resources/lib/std/mem.c3 b/resources/lib/std/mem.c3 index b30636005..e9f547943 100644 --- a/resources/lib/std/mem.c3 +++ b/resources/lib/std/mem.c3 @@ -5,32 +5,32 @@ extern func void* _realloc(void* ptr, usize bytes) @cname("realloc"); extern func void* _calloc(usize bytes, usize elements) @cname("calloc"); extern func void _free(void* ptr) @cname("free"); -public enum AllocationKind +enum AllocationKind { ALLOC, REALLOC, FREE, } -public enum AllocationFailureKind +enum AllocationFailureKind { OUT_OF_MEMORY } -public error AllocationFailure +error AllocationFailure { AllocationFailureKind failureKind; } -public define AllocatorFunction = func void!(void *data, void** pointer, usize bytes, usize alignment, AllocationKind kind); +define AllocatorFunction = func void!(void *data, void** pointer, usize bytes, usize alignment, AllocationKind kind); -public struct Allocator +struct Allocator { AllocatorFunction allocation_function; void *data; } -public func void! system_malloc_function(void *unused, void** pointer, usize bytes, usize alignment, AllocationKind kind) @inline +func void! system_malloc_function(void *unused, void** pointer, usize bytes, usize alignment, AllocationKind kind) @inline { switch (kind) { @@ -52,7 +52,7 @@ public func void! system_malloc_function(void *unused, void** pointer, usize byt $unreachable; } -public struct RingAllocator +struct RingAllocator { char *data; usize size; @@ -60,7 +60,7 @@ public struct RingAllocator } -public func void* RingAllocator.alloc(RingAllocator *allocator, usize size) +func void* RingAllocator.alloc(RingAllocator *allocator, usize size) { if (size > allocator.size) return null; // Wraparound? If so, start at the beginning. @@ -74,7 +74,7 @@ public func void* RingAllocator.alloc(RingAllocator *allocator, usize size) return data; } -public func void* RingAllocator.realloc(RingAllocator *allocator, void* ptr, usize size) +func void* RingAllocator.realloc(RingAllocator *allocator, void* ptr, usize size) { if (size > allocator.size) return null; assert(allocator.data >= ptr && ptr < allocator.data + size, "Realloc on other allocator."); @@ -111,29 +111,29 @@ public func void* RingAllocator.realloc(RingAllocator *allocator, void* ptr, usi return allocator.data; } -public Allocator main_allocator = { &system_malloc_function, null }; +Allocator main_allocator = { &system_malloc_function, null }; -public macro malloc($Type) +macro malloc($Type) { return ($Type*)(mem::alloc($Type.sizeof)); } -public func void* alloc(usize size, usize elements = 1) @inline +func void* alloc(usize size, usize elements = 1) @inline { return _malloc(size * elements); } -public func void* calloc(usize size, usize elements = 1) @inline +func void* calloc(usize size, usize elements = 1) @inline { return _calloc(size, elements); } -public func void* realloc(void *ptr, usize size) @inline +func void* realloc(void *ptr, usize size) @inline { return _realloc(ptr, size); } -public func void free(void* ptr) @inline +func void free(void* ptr) @inline { _free(ptr); } \ No newline at end of file diff --git a/src/compiler/enums.h b/src/compiler/enums.h index d81033b6c..3c8e61a19 100644 --- a/src/compiler/enums.h +++ b/src/compiler/enums.h @@ -427,7 +427,6 @@ typedef enum TOKEN_MODULE, TOKEN_NEXTCASE, TOKEN_NULL, - TOKEN_PUBLIC, TOKEN_RETURN, TOKEN_STATIC, TOKEN_STRUCT, diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 30f51f46a..712527004 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -71,7 +71,7 @@ void recover_top_level(Context *context) { switch (context->tok.type) { - case TOKEN_PUBLIC: + case TOKEN_STATIC: case TOKEN_STRUCT: case TOKEN_INTERFACE: case TOKEN_IMPORT: @@ -1999,7 +1999,7 @@ static inline Decl *parse_template_declaration(Context *context, Visibility visi Decl **body = NULL; while (!try_consume(context, TOKEN_RBRACE)) { - Decl *statement = parse_top_level_statement(context); + Decl *statement = TRY_DECL_OR(parse_top_level_statement(context), poisoned_decl); vec_add(body, statement); } decl->template_decl.body = body; @@ -2029,11 +2029,6 @@ static inline Decl *parse_interface_declaration(Context *context, Visibility vis while (!TOKEN_IS(TOKEN_RBRACE)) { - if (TOKEN_IS(TOKEN_PUBLIC)) - { - SEMA_TOKEN_ERROR(context->tok, "Interface functions cannot have visibility."); - return poisoned_decl; - } if (!TOKEN_IS(TOKEN_FUNC)) { SEMA_TOKEN_ERROR(context->tok, "Expected a function here."); @@ -2052,11 +2047,8 @@ static inline bool check_no_visibility_before(Context *context, Visibility visib { switch (visibility) { - case VISIBLE_PUBLIC: - SEMA_TOKEN_ERROR(context->tok, "Unexpected 'public' before '%.*s'.", TOKLEN(context->tok.id), TOKSTR(context->tok.id)); - return false; - case VISIBLE_LOCAL: - SEMA_TOKEN_ERROR(context->tok, "Unexpected 'local' before '%.*s'.", TOKLEN(context->tok.id), TOKSTR(context->tok.id)); + case VISIBLE_MODULE: + SEMA_TOKEN_ERROR(context->tok, "Unexpected 'static' before '%.*s'.", TOKLEN(context->tok.id), TOKSTR(context->tok.id)); return false; case VISIBLE_EXTERN: SEMA_TOKEN_ERROR(context->tok, "Unexpected 'extern' before '%.*s'.", TOKLEN(context->tok.id), TOKSTR(context->tok.id)); @@ -2261,11 +2253,11 @@ Decl *parse_top_level_statement(Context *context) { Ast *docs = NULL; if (!parse_docs(context, &docs)) return poisoned_decl; - Visibility visibility = VISIBLE_MODULE; + Visibility visibility = VISIBLE_PUBLIC; switch (context->tok.type) { - case TOKEN_PUBLIC: - visibility = VISIBLE_PUBLIC; + case TOKEN_STATIC: + visibility = VISIBLE_MODULE; advance(context); break; case TOKEN_EXTERN: diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c index 81362b059..642087c7e 100644 --- a/src/compiler/parse_stmt.c +++ b/src/compiler/parse_stmt.c @@ -1145,7 +1145,6 @@ Ast *parse_stmt(Context *context) case TOKEN_IMPORT: case TOKEN_MACRO: case TOKEN_MODULE: - case TOKEN_PUBLIC: case TOKEN_EXTERN: case TOKEN_STRUCT: case TOKEN_INTERFACE: diff --git a/src/compiler/tokens.c b/src/compiler/tokens.c index 02e2b4b2d..c1346ff56 100644 --- a/src/compiler/tokens.c +++ b/src/compiler/tokens.c @@ -232,8 +232,6 @@ const char *token_type_to_string(TokenType type) return "nextcase"; case TOKEN_NULL: return "null"; - case TOKEN_PUBLIC: - return "public"; case TOKEN_RETURN: return "return"; case TOKEN_STATIC: diff --git a/test/test_suite/arrays/array_struct.c3t b/test/test_suite/arrays/array_struct.c3t index cf46f5a5b..9a478053e 100644 --- a/test/test_suite/arrays/array_struct.c3t +++ b/test/test_suite/arrays/array_struct.c3t @@ -6,7 +6,7 @@ struct Foo int x, y; } -Foo[10] array; +static Foo[10] array; // #expect: test.ll diff --git a/test/test_suite/arrays/complex_array_const.c3t b/test/test_suite/arrays/complex_array_const.c3t index 717ecedfc..f1358c804 100644 --- a/test/test_suite/arrays/complex_array_const.c3t +++ b/test/test_suite/arrays/complex_array_const.c3t @@ -8,7 +8,7 @@ struct Connection long length; } -Connection[3] link +static Connection[3] link = { {1, "link1", 10}, {2, "link2", 20}, {3, "link3", 30} }; diff --git a/test/test_suite/assert/assert_variants.c3t b/test/test_suite/assert/assert_variants.c3t index 8abbbff64..e70c71c64 100644 --- a/test/test_suite/assert/assert_variants.c3t +++ b/test/test_suite/assert/assert_variants.c3t @@ -1,10 +1,10 @@ -public func int foo() +func int foo() { return 1; } -public func void test() +func void test() { int x = foo(); int y = foo(); diff --git a/test/test_suite/assert/unreachable.c3t b/test/test_suite/assert/unreachable.c3t index e7d585f1e..115459fb3 100644 --- a/test/test_suite/assert/unreachable.c3t +++ b/test/test_suite/assert/unreachable.c3t @@ -1,10 +1,10 @@ -public func int foo() +func int foo() { return 1; } -public func void test() +func void test() { int x = foo(); if (x > 0) return; diff --git a/test/test_suite/constants/char_literals.c3t b/test/test_suite/constants/char_literals.c3t index cc63b7a73..2a3aa06d0 100644 --- a/test/test_suite/constants/char_literals.c3t +++ b/test/test_suite/constants/char_literals.c3t @@ -1,15 +1,15 @@ // #file: file1.c3 module test; -public char a = ' '; -public char b = '\r'; -public char c = '\t'; -public char d = '\n'; -public char e = '\0'; -public char f = '\''; -public char g = '"'; -public char h = '\\'; -public char i = '\e'; +char a = ' '; +char b = '\r'; +char c = '\t'; +char d = '\n'; +char e = '\0'; +char f = '\''; +char g = '"'; +char h = '\\'; +char i = '\e'; // #expect: test.ll diff --git a/test/test_suite/constants/constants.c3t b/test/test_suite/constants/constants.c3t index 79826ad6f..d4c7a7d7c 100644 --- a/test/test_suite/constants/constants.c3t +++ b/test/test_suite/constants/constants.c3t @@ -1,15 +1,15 @@ -const char AA = ~(char)(0); +static const char AA = ~(char)(0); const char BB = 200 ; -const uint CC = ~(uint)(0); -const uint DD = FOO; +static const uint CC = ~(uint)(0); +static const uint DD = FOO; -const FOO = ~(uint)(0); +static const FOO = ~(uint)(0); -uint x = AA; -uint z = CC; -char w = (char)(FOO); -ushort v = (ushort)(FOO); -uint z2 = DD; +static uint x = AA; +static uint z = CC; +static char w = (char)(FOO); +static ushort v = (ushort)(FOO); +static uint z2 = DD; func void test() { @@ -20,7 +20,7 @@ func void test() // #expect: constants.ll @constants.AA = protected constant i8 -1, align 1 -@constants.BB = protected constant i8 -56, align 1 +@constants.BB = constant i8 -56, align 1 @constants.CC = protected constant i32 -1, align 4 @constants.DD = protected constant i32 -1, align 4 @constants.x = protected global i32 255, align 4 diff --git a/test/test_suite/enumerations/compile_time.c3t b/test/test_suite/enumerations/compile_time.c3t index 66307d26b..ee04a0ef8 100644 --- a/test/test_suite/enumerations/compile_time.c3t +++ b/test/test_suite/enumerations/compile_time.c3t @@ -13,8 +13,8 @@ int myenum_sizeof = MyEnum.sizeof; // #expect: compile_time.ll -@compile_time.myenum_max = protected global i32 14, align 4 -@compile_time.myenum_min = protected global i32 -5, align 4 -@compile_time.myenum_elements = protected global i32 3, align 4 -@compile_time.myenum_alignof = protected global i32 2, align 4 -@compile_time.myenum_sizeof = protected global i32 2, align 4 \ No newline at end of file +@compile_time.myenum_max = global i32 14, align 4 +@compile_time.myenum_min = global i32 -5, align 4 +@compile_time.myenum_elements = global i32 3, align 4 +@compile_time.myenum_alignof = global i32 2, align 4 +@compile_time.myenum_sizeof = global i32 2, align 4 \ No newline at end of file diff --git a/test/test_suite/expressions/casts/cast_expr.c3t b/test/test_suite/expressions/casts/cast_expr.c3t index 01f49855f..2b4752188 100644 --- a/test/test_suite/expressions/casts/cast_expr.c3t +++ b/test/test_suite/expressions/casts/cast_expr.c3t @@ -1,6 +1,6 @@ module cast_expr; -public func int main(int argc, char** argv) +func int main(int argc, char** argv) { int a = 10; diff --git a/test/test_suite/functions/missing_return.c3 b/test/test_suite/functions/missing_return.c3 index 861490032..c212663f2 100644 --- a/test/test_suite/functions/missing_return.c3 +++ b/test/test_suite/functions/missing_return.c3 @@ -1,3 +1,3 @@ -public func int test1() // #error: Missing return statement at the end of +func int test1() // #error: Missing return statement at the end of { } \ No newline at end of file diff --git a/test/test_suite/functions/multi_module.c3t2 b/test/test_suite/functions/multi_module.c3t2 deleted file mode 100644 index 0ac9ebda1..000000000 --- a/test/test_suite/functions/multi_module.c3t2 +++ /dev/null @@ -1,58 +0,0 @@ -// @recipe bin - $warnings no-unused - $generate-c - -// #file: file1 -module test1; - -import test2; - -public func void pub1() {} - -func void nonpub1() {} - -public func i32 main(i32 argc, const i8*[] argv) { - return 0; -} - -// #file: file2 -module test2; - -public func void pub2() {} - -func void nonpub2() {} - -// #expect: test1.h - -void test1_pub1(); - -// #expect: test1.c -#include "test1.h" - -static void test1_nonpub1(); - -void test1_pub1() { -} - -static void test1_nonpub1() { -} - -int32_t main(int32_t argc, const char* argv[]) { - return 0; -} - -// @expect{atleast, build/test2.h} - -void test2_pub2(); - -// @expect{atleast, build/test2.c} -#include "test2.h" - -static void test2_nonpub2(); - -void test2_pub2() { -} - -static void test2_nonpub2() { -} - diff --git a/test/test_suite/macros/hash_ident.c3 b/test/test_suite/macros/hash_ident.c3 index e4c9a7ace..a6b026223 100644 --- a/test/test_suite/macros/hash_ident.c3 +++ b/test/test_suite/macros/hash_ident.c3 @@ -4,15 +4,15 @@ macro int cofefe(#a) return #a + #a; } -int abc = 1; +static int abc = 1; -public func int xx() +func int xx() { abc++; return abc; } -public func void main() +func void main() { define $x = 0; int x = 0; diff --git a/test/test_suite/pointers/const_pointer.c3t b/test/test_suite/pointers/const_pointer.c3t index efce8a9ed..08432f82c 100644 --- a/test/test_suite/pointers/const_pointer.c3t +++ b/test/test_suite/pointers/const_pointer.c3t @@ -2,11 +2,11 @@ module const_pointer; -double foo = 17; -double bar = 12.0; -float xx = 12.0; +static double foo = 17; +static double bar = 12.0; +static float xx = 12.0; -void*[3] data = { &foo, &bar, &xx }; +static void*[3] data = { &foo, &bar, &xx }; // #expect: const_pointer.ll diff --git a/test/test_suite/pointers/pointer_index.c3t b/test/test_suite/pointers/pointer_index.c3t index 67dccb65d..2011c5424 100644 --- a/test/test_suite/pointers/pointer_index.c3t +++ b/test/test_suite/pointers/pointer_index.c3t @@ -1,6 +1,6 @@ module pointer_index; -public func void test1(int* x) +func void test1(int* x) { int a = x[0]; int b = *x; @@ -8,14 +8,14 @@ public func void test1(int* x) int d = x[-1]; } -public func void test2(char* x) +func void test2(char* x) { char a = x[0]; char b = *x; char c = x[1]; } -public func void test3(long* x) +func void test3(long* x) { long a = x[0]; long b = *x; diff --git a/test/test_suite/statements/call_missing_paren.c3 b/test/test_suite/statements/call_missing_paren.c3 index 4c42fd326..7cf028ba2 100644 --- a/test/test_suite/statements/call_missing_paren.c3 +++ b/test/test_suite/statements/call_missing_paren.c3 @@ -1,6 +1,6 @@ func void foo(int a) {} -public func int main() +func int main() { foo(10, foo(); // #error: Expected the ending ')' return 0; diff --git a/test/test_suite/statements/defer_break.c3t b/test/test_suite/statements/defer_break.c3t index 5eef58756..c9083e337 100644 --- a/test/test_suite/statements/defer_break.c3t +++ b/test/test_suite/statements/defer_break.c3t @@ -2,19 +2,19 @@ module foo; extern func void printf(char* message, ...); -public func void defer1() {} -public func void defer2() {} -public func void defer3() {} -public func void defer4() {} -public func void defer5() {} -public func void defer6() {} -public func void defer7() {} -public func void defer8() {} -public func void defer9() {} -public func void defer10() {} -public func void defer11() {} +func void defer1() {} +func void defer2() {} +func void defer3() {} +func void defer4() {} +func void defer5() {} +func void defer6() {} +func void defer7() {} +func void defer8() {} +func void defer9() {} +func void defer10() {} +func void defer11() {} -public func int main(int argc) +func int main(int argc) { int a = 0; { diff --git a/test/test_suite/statements/defer_break_simple.c3t b/test/test_suite/statements/defer_break_simple.c3t index fee09974b..c6fb9f74b 100644 --- a/test/test_suite/statements/defer_break_simple.c3t +++ b/test/test_suite/statements/defer_break_simple.c3t @@ -1,11 +1,11 @@ module test; -public func void test2() {} -public func void testA() {} -public func void testB() {} -public func void test3() {} +func void test2() {} +func void testA() {} +func void testB() {} +func void test3() {} -public func int main(int argc) +func int main(int argc) { int a = 0; while (a) diff --git a/test/test_suite/statements/defer_return.c3t b/test/test_suite/statements/defer_return.c3t index 995510b83..2b5617da2 100644 --- a/test/test_suite/statements/defer_return.c3t +++ b/test/test_suite/statements/defer_return.c3t @@ -9,7 +9,7 @@ func void test7() {} func void test8() {} func void test9() {} -public func int main(int argc) +func int main(int argc) { defer test1(); int a = 0; diff --git a/test/test_suite/statements/for.c3 b/test/test_suite/statements/for.c3 index 6f0f4521f..9c285002d 100644 --- a/test/test_suite/statements/for.c3 +++ b/test/test_suite/statements/for.c3 @@ -2,7 +2,7 @@ module for_test; -public func int test1() +func int test1() { for (int x = 0;;) { @@ -10,7 +10,7 @@ public func int test1() return 0; } -public func int test2() +func int test2() { for (int x = 0; 1 ;) { @@ -18,7 +18,7 @@ public func int test2() return 0; } -public func int test3() +func int test3() { for (; 1 ;2) { diff --git a/test/test_suite/statements/for_empty.c3 b/test/test_suite/statements/for_empty.c3 index 925b8893f..dce7890e7 100644 --- a/test/test_suite/statements/for_empty.c3 +++ b/test/test_suite/statements/for_empty.c3 @@ -1,4 +1,4 @@ -public func int main() +func int main() { for (;;); diff --git a/test/test_suite/statements/for_errors.c3 b/test/test_suite/statements/for_errors.c3 index ba89a19a5..f0980cfcd 100644 --- a/test/test_suite/statements/for_errors.c3 +++ b/test/test_suite/statements/for_errors.c3 @@ -1,6 +1,6 @@ func void foo() {} -public func int main() +func int main() { for (; foo() ; ) {} // #error: Cannot implicitly cast 'void' to 'bool' return 0; diff --git a/test/test_suite/statements/if_decl.c3 b/test/test_suite/statements/if_decl.c3 index 8e3e9a0ae..b6412d118 100644 --- a/test/test_suite/statements/if_decl.c3 +++ b/test/test_suite/statements/if_decl.c3 @@ -1,4 +1,4 @@ -public func int main() +func int main() { if (int a) {} // #error: Expected a declaration with initializer return 0; diff --git a/test/test_suite/statements/label_errors.c3 b/test/test_suite/statements/label_errors.c3 index 3ed8c4e58..0e5cf5bc7 100644 --- a/test/test_suite/statements/label_errors.c3 +++ b/test/test_suite/statements/label_errors.c3 @@ -1,5 +1,5 @@ -public func int main() +func int main() { do FOO: { diff --git a/test/test_suite/struct/simple_struct.c3t b/test/test_suite/struct/simple_struct.c3t index 7a85d15d8..d6a45db00 100644 --- a/test/test_suite/struct/simple_struct.c3t +++ b/test/test_suite/struct/simple_struct.c3t @@ -1,6 +1,6 @@ module test; -Foo a; +static Foo a; struct Foo { diff --git a/test/test_suite/struct/struct_const_construct_simple.c3t b/test/test_suite/struct/struct_const_construct_simple.c3t index db80a9b7d..e1d1269a9 100644 --- a/test/test_suite/struct/struct_const_construct_simple.c3t +++ b/test/test_suite/struct/struct_const_construct_simple.c3t @@ -6,16 +6,16 @@ struct Foo long bar; } -usize x = Foo.sizeof; +static usize x = Foo.sizeof; -Foo foo1 = { 1, 2 }; -Foo foo2 = { .foo = 2 }; -Foo foo3 = { .bar = 3 }; -Foo foo4 = { .bar = 4, .foo = 4, .bar = 1 }; -Foo foo5 = {}; -Foo foo6; -const Foo FOO7 = { 1, 2 }; -Foo foo8 = FOO7; +static Foo foo1 = { 1, 2 }; +static Foo foo2 = { .foo = 2 }; +static Foo foo3 = { .bar = 3 }; +static Foo foo4 = { .bar = 4, .foo = 4, .bar = 1 }; +static Foo foo5 = {}; +static Foo foo6; +static const Foo FOO7 = { 1, 2 }; +static Foo foo8 = FOO7; // #expect: structo.ll diff --git a/test/test_suite/struct/struct_pack_and_align.c3t b/test/test_suite/struct/struct_pack_and_align.c3t index d16a11338..dc87ff518 100644 --- a/test/test_suite/struct/struct_pack_and_align.c3t +++ b/test/test_suite/struct/struct_pack_and_align.c3t @@ -8,7 +8,7 @@ struct Foo1 @packed @align(4) } $assert(Foo1.sizeof == 12); -public Foo1 foo1 = { 1, 2 }; +Foo1 foo1 = { 1, 2 }; // <{ i8, i64, [3 x i8] }> struct Foo2 @packed @align(4) @@ -18,7 +18,7 @@ struct Foo2 @packed @align(4) } $assert(Foo2.sizeof == 12); -public Foo2 foo2 = { 1, 2 }; +Foo2 foo2 = { 1, 2 }; // <{ i8, i64, [7 x i8] }> struct Foo3 @packed @align(8) @@ -27,7 +27,7 @@ struct Foo3 @packed @align(8) long bar; } -public Foo3 foo3 = { 1, 2 }; +Foo3 foo3 = { 1, 2 }; $assert(Foo3.sizeof == 16); // <{ i8, i64 }> @@ -38,7 +38,7 @@ struct Foo4 @packed } $assert(Foo4.sizeof == 9); -public Foo4 foo4 = { 1, 2 }; +Foo4 foo4 = { 1, 2 }; // { i32, [12 x i8], i8, [15 x i8] } struct Foo5 @@ -48,7 +48,7 @@ struct Foo5 } $assert(Foo5.sizeof == 32); -public Foo5 foo5 = { 1, 2 }; +Foo5 foo5 = { 1, 2 }; func int test5(ichar x) { @@ -65,7 +65,7 @@ struct Foo6 @packed } $assert(Foo6.sizeof == 8); -public Foo6 foo6 = { 1, 2, 3 }; +Foo6 foo6 = { 1, 2, 3 }; // #expect: struct2.ll diff --git a/test/test_suite/union/union_codegen_const.c3t b/test/test_suite/union/union_codegen_const.c3t index 618dd557c..fb023fa5c 100644 --- a/test/test_suite/union/union_codegen_const.c3t +++ b/test/test_suite/union/union_codegen_const.c3t @@ -6,9 +6,9 @@ union Foo double b; } -Foo f = { .a = 23 }; -Foo g = { .b = 2.3 }; -Foo h = { .a = 23, .b = 2.3 }; +static Foo f = { .a = 23 }; +static Foo g = { .b = 2.3 }; +static Foo h = { .a = 23, .b = 2.3 }; Foo i = { .b = 2.3, .a = 23 }; // #expect: test.ll @@ -16,5 +16,5 @@ Foo i = { .b = 2.3, .a = 23 }; @test.f = protected global { i32, [4 x i8] } { i32 23, [4 x i8] undef }, align 8 @test.g = protected global %Foo { double 2.300000e+00 }, align 8 @test.h = protected global %Foo { double 2.300000e+00 }, align 8 -@test.i = protected global { i32, [4 x i8] } { i32 23, [4 x i8] undef }, align 8 +@test.i = global { i32, [4 x i8] } { i32 23, [4 x i8] undef }, align 8 diff --git a/test/test_suite/union/union_in_struct.c3t b/test/test_suite/union/union_in_struct.c3t index 8e71a4006..72a8003d5 100644 --- a/test/test_suite/union/union_in_struct.c3t +++ b/test/test_suite/union/union_in_struct.c3t @@ -23,7 +23,7 @@ func void test(Blend_Map_Entry* foo) %Blend_Map_Entry = type { %vals } %vals = type { [2 x double], [8 x i8] } -@test.a = protected global { { [5 x float], [4 x i8] } } { { [5 x float], [4 x i8] } { [5 x float] [float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00], [4 x i8] undef } }, align 8 -@test.b = protected global %Blend_Map_Entry { %vals { [2 x double] [double 6.000000e+00, double 7.000000e+00], [8 x i8] undef } }, align 8 -@test.c = protected global { { { [2 x float], float, [2 x float] }, [4 x i8] } } { { { [2 x float], float, [2 x float] }, [4 x i8] } { { [2 x float], float, [2 x float] } { [2 x float] zeroinitializer, float 1.000000e+00, [2 x float] zeroinitializer }, [4 x i8] undef } }, align 8 -@test.d = protected global { { [5 x float], [4 x i8] } } { { [5 x float], [4 x i8] } { [5 x float] [float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00], [4 x i8] undef } }, align 8 +@test.a = global { { [5 x float], [4 x i8] } } { { [5 x float], [4 x i8] } { [5 x float] [float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00], [4 x i8] undef } }, align 8 +@test.b = global %Blend_Map_Entry { %vals { [2 x double] [double 6.000000e+00, double 7.000000e+00], [8 x i8] undef } }, align 8 +@test.c = global { { { [2 x float], float, [2 x float] }, [4 x i8] } } { { { [2 x float], float, [2 x float] }, [4 x i8] } { { [2 x float], float, [2 x float] } { [2 x float] zeroinitializer, float 1.000000e+00, [2 x float] zeroinitializer }, [4 x i8] undef } }, align 8 +@test.d = global { { [5 x float], [4 x i8] } } { { [5 x float], [4 x i8] } { [5 x float] [float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00], [4 x i8] undef } }, align 8 diff --git a/test/test_suite/visibility/ambiguous_var.c3t b/test/test_suite/visibility/ambiguous_var.c3t index 1d689d516..afce417da 100644 --- a/test/test_suite/visibility/ambiguous_var.c3t +++ b/test/test_suite/visibility/ambiguous_var.c3t @@ -1,13 +1,13 @@ // #file: file1.c3 module foo; -public int a; -public int b; +int a; +int b; // #file: file2.c3 module bar; -public int a; -public int b; +int a; +int b; // #file: file3.c3 @@ -15,9 +15,9 @@ module baz; import foo; import bar; -public int a; +int a; -func void test2() +static func void test2() { int c = a; // This is fine. c = foo::b; diff --git a/test/test_suite/visibility/no_shared_imports.c3t b/test/test_suite/visibility/no_shared_imports.c3t index 166273181..591c01c02 100644 --- a/test/test_suite/visibility/no_shared_imports.c3t +++ b/test/test_suite/visibility/no_shared_imports.c3t @@ -1,7 +1,7 @@ // #file: file1.c3 module baz; -public func void runBar() +func void runBar() { visible(); bar::barFunc(); // #error: Unknown module 'bar' @@ -11,7 +11,7 @@ public func void runBar() module baz; import bar; -func void visible() +static func void visible() { bar::barFunc(); } @@ -19,5 +19,5 @@ func void visible() // #file: file3.c3 module bar; -public func void barFunc() +func void barFunc() {} \ No newline at end of file diff --git a/test/test_suite/visibility/not_visible.c3t b/test/test_suite/visibility/not_visible.c3t index a9e7c31cf..094da3eef 100644 --- a/test/test_suite/visibility/not_visible.c3t +++ b/test/test_suite/visibility/not_visible.c3t @@ -2,7 +2,7 @@ module baz; import bar; -public func void runBar() +func void runBar() { bar::notVisible(); // #error: 'notVisible' is not visible from this module. } @@ -10,7 +10,7 @@ public func void runBar() // #file: file2.c3 module bar; -func void notVisible() +static func void notVisible() { } \ No newline at end of file diff --git a/test/test_suite/visibility/shared_module.c3t b/test/test_suite/visibility/shared_module.c3t index 7c910a06a..77d0b7651 100644 --- a/test/test_suite/visibility/shared_module.c3t +++ b/test/test_suite/visibility/shared_module.c3t @@ -1,7 +1,7 @@ // #file: file1.c3 module baz; -public func void runBar() +func void runBar() { visible(); } @@ -9,7 +9,7 @@ public func void runBar() // #file: file2.c3 module baz; -func void visible() +static func void visible() { } \ No newline at end of file diff --git a/test/test_suite/visibility/simple_visibility.c3t b/test/test_suite/visibility/simple_visibility.c3t index 389784bcd..5f540c62e 100644 --- a/test/test_suite/visibility/simple_visibility.c3t +++ b/test/test_suite/visibility/simple_visibility.c3t @@ -2,7 +2,7 @@ module baz; import bar; -public func void runBar() +func void runBar() { bar::visible(); } @@ -10,7 +10,7 @@ public func void runBar() // #file: file2.c3 module bar; -public func void visible() +func void visible() { }