mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
"Public by default"
This commit is contained in:
committed by
Christoffer Lerno
parent
13e95553bb
commit
97ac957cb7
@@ -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 <Type>
|
||||
template vararray <Type>
|
||||
{
|
||||
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 <Type>
|
||||
{
|
||||
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--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -427,7 +427,6 @@ typedef enum
|
||||
TOKEN_MODULE,
|
||||
TOKEN_NEXTCASE,
|
||||
TOKEN_NULL,
|
||||
TOKEN_PUBLIC,
|
||||
TOKEN_RETURN,
|
||||
TOKEN_STATIC,
|
||||
TOKEN_STRUCT,
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -6,7 +6,7 @@ struct Foo
|
||||
int x, y;
|
||||
}
|
||||
|
||||
Foo[10] array;
|
||||
static Foo[10] array;
|
||||
|
||||
// #expect: test.ll
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ struct Connection
|
||||
long length;
|
||||
}
|
||||
|
||||
Connection[3] link
|
||||
static Connection[3] link
|
||||
= { {1, "link1", 10},
|
||||
{2, "link2", 20},
|
||||
{3, "link3", 30} };
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@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
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
}
|
||||
@@ -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() {
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
public func int main()
|
||||
func int main()
|
||||
{
|
||||
for (;;);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
public func int main()
|
||||
func int main()
|
||||
{
|
||||
if (int a) {} // #error: Expected a declaration with initializer
|
||||
return 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
public func int main()
|
||||
func int main()
|
||||
{
|
||||
do FOO:
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module test;
|
||||
|
||||
Foo a;
|
||||
static Foo a;
|
||||
|
||||
struct Foo
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
{}
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user