Rollback global.

This commit is contained in:
Christoffer Lerno
2021-11-17 10:37:23 +01:00
parent b52b42d4da
commit 974cd0acc5
44 changed files with 200 additions and 201 deletions

View File

@@ -6,7 +6,7 @@ const IA = 3877;
const IC = 29573; const IC = 29573;
const SEED = 42; const SEED = 42;
global uint seed = SEED; uint seed = SEED;
fn float fasta_rand(float max) fn float fasta_rand(float max)
{ {
@@ -14,7 +14,7 @@ fn float fasta_rand(float max)
return max * seed / IM; return max * seed / IM;
} }
private global char[] alu = private char[] alu =
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"
@@ -24,8 +24,8 @@ private global char[] alu =
"AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA"; "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
global char[] iub = "acgtBDHKMNRSVWY"; char[] iub = "acgtBDHKMNRSVWY";
global double[] iub_p = { double[] iub_p = {
0.27, 0.27,
0.12, 0.12,
0.12, 0.12,
@@ -42,8 +42,8 @@ global double[] iub_p = {
0.02, 0.02,
0.02 }; 0.02 };
global char[] homosapiens = "acgt"; char[] homosapiens = "acgt";
global double[] homosapiens_p = { double[] homosapiens_p = {
0.3029549426680, 0.3029549426680,
0.1979883004921, 0.1979883004921,
0.1975473066391, 0.1975473066391,

View File

@@ -388,11 +388,11 @@ fn void Value.setTop(Value* th as AintIdx idx)
} }
/* **************************************** /* ****************************************
GLOBAL VARIABLE ACCESS VARIABLE ACCESS
***************************************/ ***************************************/
/** /**
* Push and return the symbolically-named global variable's value * Push and return the symbolically-named variable's value
* @require vm(*th).global.isTbl() * @require vm(*th).global.isTbl()
**/ **/
fn Value Value.pushGloVar(Value* th, string var) fn Value Value.pushGloVar(Value* th, string var)
@@ -405,7 +405,7 @@ fn Value Value.pushGloVar(Value* th, string var)
} }
/** /**
* Alter the symbolically-named global variable to have the value popped off the local stack * Alter the symbolically-named variable to have the value popped off the local stack
* @require stkSz(th) > 0, vm(th).global.isTbl() * @require stkSz(th) > 0, vm(th).global.isTbl()
**/ **/
fn void Value.popGloVar(Value* th, string var) fn void Value.popGloVar(Value* th, string var)
@@ -417,7 +417,7 @@ fn void Value.popGloVar(Value* th, string var)
th(*th).stk_top -= 2; // Pop key & value after value is safely in Global th(*th).stk_top -= 2; // Pop key & value after value is safely in Global
} }
/* Push the value of the current process thread's global variable table. */ /* Push the value of the current process thread's variable table. */
Value pushGlobal(Value th) Value pushGlobal(Value th)
{ {
stkCanIncTop(th); /* Check if there is room */ stkCanIncTop(th); /* Check if there is room */

View File

@@ -381,7 +381,7 @@ void genAssign(CompInfo *comp, Value lval, Value rval) {
if (opcode) if (opcode)
genDoProp(comp, lval, opcode, rval, 1); genDoProp(comp, lval, opcode, rval, 1);
else { else {
// Handle parallel, local, closure, global variable assignments where rval is loaded first // Handle parallel, local, closure, variable assignments where rval is loaded first
int nlvals = lvalop==vmlit(SymComma)? arr_size(lval)-1 : 1; int nlvals = lvalop==vmlit(SymComma)? arr_size(lval)-1 : 1;
bool varrvals = false; bool varrvals = false;
AuintIdx rvalreg; AuintIdx rvalreg;
@@ -445,7 +445,7 @@ void genAssign(CompInfo *comp, Value lval, Value rval) {
genAddInstr(comp, BCINS_ABC(OpLoadReg, localreg, rvalreg, 0)); genAddInstr(comp, BCINS_ABC(OpLoadReg, localreg, rvalreg, 0));
else if ((localreg = findClosureVar(comp, symnm))!=-1) else if ((localreg = findClosureVar(comp, symnm))!=-1)
genAddInstr(comp, BCINS_ABC(OpSetClosure, localreg, rvalreg, 0)); genAddInstr(comp, BCINS_ABC(OpSetClosure, localreg, rvalreg, 0));
// Load into a global variable // Load into a variable
} else if (vmlit(SymGlobal) == lvalop) } else if (vmlit(SymGlobal) == lvalop)
genAddInstr(comp, BCINS_ABx(OpSetGlobal, rvalreg, genAddLit(comp, astGet(th, lval, 1)))); genAddInstr(comp, BCINS_ABx(OpSetGlobal, rvalreg, genAddLit(comp, astGet(th, lval, 1))));
} }

View File

@@ -143,7 +143,7 @@ void parseValue(CompInfo* comp, Value astseg)
astAddSeg2(th, astseg, vmlit(SYM_EXT), anInt(genAddUrlLit(comp, comp->lex->token))); astAddSeg2(th, astseg, vmlit(SYM_EXT), anInt(genAddUrlLit(comp, comp->lex->token)));
lexGetNextToken(comp->lex); lexGetNextToken(comp->lex);
} }
// Local or global variable / name token // Local or variable / name token
else if (comp->lex->toktype == Name_Token) { else if (comp->lex->toktype == Name_Token) {
Value symnm = pushValue(th, comp->lex->token); Value symnm = pushValue(th, comp->lex->token);
lexGetNextToken(comp->lex); lexGetNextToken(comp->lex);
@@ -240,7 +240,7 @@ void parseValue(CompInfo* comp, Value astseg)
Value symnm = comp->lex->token; Value symnm = comp->lex->token;
const char first = (toStr(symnm))[0]; const char first = (toStr(symnm))[0];
if (first=='$' || (first>='A' && first<='Z')) if (first=='$' || (first>='A' && first<='Z'))
lexLog(comp->lex, "A global name may not be a closure variable"); lexLog(comp->lex, "A name may not be a closure variable");
arrAdd(th, comp->clovarseg, symnm); arrAdd(th, comp->clovarseg, symnm);
lexGetNextToken(comp->lex); lexGetNextToken(comp->lex);
@@ -985,7 +985,7 @@ void parseProgram(CompInfo* comp) {
Value symnm = comp->lex->token; Value symnm = comp->lex->token;
const char first = (toStr(symnm))[0]; const char first = (toStr(symnm))[0];
if (first=='$' || (first>='A' && first<='Z')) if (first=='$' || (first>='A' && first<='Z'))
lexLog(comp->lex, "A global name may not be a method parameter"); lexLog(comp->lex, "A name may not be a method parameter");
else { else {
if (findLocalVar(comp, symnm)==-1) { if (findLocalVar(comp, symnm)==-1) {
arrAdd(th, comp->locvarseg, symnm); arrAdd(th, comp->locvarseg, symnm);

View File

@@ -13,7 +13,7 @@ void core_init(Value th); // Initialize all core types
* different encoding types. * different encoding types.
* - The symbol table, which is shared across everywhere * - The symbol table, which is shared across everywhere
* - The main thread, which is the recursive root for garbage collection. * - The main thread, which is the recursive root for garbage collection.
* The thread manages the global namespace, including all registered * The thread manages the namespace, including all registered
* core types (including the Acorn compiler and resource types). * core types (including the Acorn compiler and resource types).
* *
* See newVm() for more detailed information on VM initialization. * See newVm() for more detailed information on VM initialization.
@@ -34,12 +34,12 @@ struct VmInfo
ulong pcgrng_state; //!< PCG random-number generator state ulong pcgrng_state; //!< PCG random-number generator state
ulong pcgrng_inc; //!< PCG random-number generator inc value ulong pcgrng_inc; //!< PCG random-number generator inc value
Value global; //!< VM's "built in" Global hash table Value global; //!< VM's "built in" hash table
Value main_thread; //!< VM's main thread Value main_thread; //!< VM's main thread
ThreadInfo main_thr; //!< State space for main thread ThreadInfo main_thr; //!< State space for main thread
SymTable sym_table; //!< global symbol table SymTable sym_table; //!< symbol table
AuintIdx hashseed; //!< randomized seed for hashing strings AuintIdx hashseed; //!< randomized seed for hashing strings
Value literals; //!< array of all built-in symbol and type literals Value literals; //!< array of all built-in symbol and type literals
Value stdidx; //!< Table to convert std symbol to index Value stdidx; //!< Table to convert std symbol to index
@@ -252,7 +252,7 @@ macro memcpy_Auint(i, val)
* and which to discard. * and which to discard.
* - All value encodings are initialized next, including the single symbol table * - All value encodings are initialized next, including the single symbol table
* used across the VM. * used across the VM.
* - The main thread is started up, initializing its global namespace. * - The main thread is started up, initializing its namespace.
* - All core types are progressively loaded, establishing the default types for * - All core types are progressively loaded, establishing the default types for
* each encoding. This includes the resource types and Acorn compiler. */ * each encoding. This includes the resource types and Acorn compiler. */
fn Value new(void) fn Value new(void)
@@ -290,13 +290,13 @@ fn Value new(void)
memcpy_Auint(3, &newVM) // public function memcpy_Auint(3, &newVM) // public function
vm->hashseed = tblCalcStrHash(seedstr, sizeof(seedstr), (AuintIdx) timehash); vm->hashseed = tblCalcStrHash(seedstr, sizeof(seedstr), (AuintIdx) timehash);
// Initialize vm-wide symbol table, global table and literals // Initialize vm-wide symbol table, table and literals
sym_init(th); // Initialize hash table for symbols sym_init(th); // Initialize hash table for symbols
newTbl(th, &vm->global, aNull, GLOBAL_NEWSIZE); // Create global hash table newTbl(th, &vm->global, aNull, GLOBAL_NEWSIZE); // Create hash table
mem_markChk(th, vm, vm->global); mem_markChk(th, vm, vm->global);
vm_litinit(th); // Load reserved and standard symbols into literal list vm_litinit(th); // Load reserved and standard symbols into literal list
core_init(th); // Load up global table and literal list with core types core_init(th); // Load up table and literal list with core types
setType(th, vm->global, vmlit(TypeIndexm)); // Fix up type info for global table setType(th, vm->global, vmlit(TypeIndexm)); // Fix up type info for table
// Initialize byte-code standard methods and the Acorn compiler // Initialize byte-code standard methods and the Acorn compiler
vm_stdinit(th); vm_stdinit(th);

View File

@@ -1,6 +1,6 @@
module foo; module foo;
const int GLOBAL = 0; const int = 0;
struct Boo struct Boo
{ {

View File

@@ -365,7 +365,7 @@ typedef struct VarDecl_
bool unwrap : 1; bool unwrap : 1;
bool vararg : 1; bool vararg : 1;
bool is_static : 1; bool is_static : 1;
bool is_threadglobal : 1; bool is_threadlocal : 1;
TypeInfo *type_info; TypeInfo *type_info;
union union
{ {

View File

@@ -442,7 +442,7 @@ typedef enum
TOKEN_FN, TOKEN_FN,
TOKEN_FUNC, TOKEN_FUNC,
TOKEN_GENERIC, TOKEN_GENERIC,
TOKEN_GLOBAL, TOKEN_TLOCAL,
TOKEN_IF, TOKEN_IF,
TOKEN_IMPORT, TOKEN_IMPORT,
TOKEN_MACRO, TOKEN_MACRO,

View File

@@ -691,7 +691,7 @@ static inline bool scan_char(Lexer *lexer)
int width = 0; int width = 0;
char c; char c;
Int128 b = {}; Int128 b = { 0, 0 };
while ((c = next(lexer)) != '\'') while ((c = next(lexer)) != '\'')
{ {

View File

@@ -363,8 +363,7 @@ void llvm_emit_global_variable_init(GenContext *c, Decl *decl)
// TODO fix name // TODO fix name
LLVMValueRef old = decl->backend_ref; LLVMValueRef old = decl->backend_ref;
decl->backend_ref = LLVMAddGlobal(c->module, LLVMTypeOf(init_value), decl->extname ? decl->extname : decl->external_name); decl->backend_ref = LLVMAddGlobal(c->module, LLVMTypeOf(init_value), decl->extname ? decl->extname : decl->external_name);
bool thread_local = !decl->var.is_threadglobal && decl->var.kind != VARDECL_CONST; LLVMSetThreadLocal(decl->backend_ref, decl->var.is_threadlocal);
LLVMSetThreadLocal(decl->backend_ref, thread_local);
if (decl->section) if (decl->section)
{ {
LLVMSetSection(decl->backend_ref, decl->section); LLVMSetSection(decl->backend_ref, decl->section);
@@ -375,7 +374,7 @@ void llvm_emit_global_variable_init(GenContext *c, Decl *decl)
if (failable_ref) if (failable_ref)
{ {
llvm_set_alignment(failable_ref, type_alloca_alignment(type_anyerr)); llvm_set_alignment(failable_ref, type_alloca_alignment(type_anyerr));
LLVMSetThreadLocal(failable_ref, thread_local); LLVMSetThreadLocal(failable_ref, decl->var.is_threadlocal);
} }
if (init_expr && IS_FAILABLE(init_expr) && init_expr->expr_kind == EXPR_FAILABLE) if (init_expr && IS_FAILABLE(init_expr) && init_expr->expr_kind == EXPR_FAILABLE)
{ {

View File

@@ -805,8 +805,8 @@ Decl *parse_decl(Context *context)
return parse_const_declaration(context, VISIBLE_LOCAL); return parse_const_declaration(context, VISIBLE_LOCAL);
} }
bool is_threadglobal = try_consume(context, TOKEN_GLOBAL); bool is_threadlocal = try_consume(context, TOKEN_TLOCAL);
bool is_static = !is_threadglobal && try_consume(context, TOKEN_STATIC); bool is_static = !is_threadlocal && try_consume(context, TOKEN_STATIC);
ASSIGN_TYPE_ELSE(TypeInfo *type, parse_failable_type(context), poisoned_decl); ASSIGN_TYPE_ELSE(TypeInfo *type, parse_failable_type(context), poisoned_decl);
@@ -816,8 +816,8 @@ Decl *parse_decl(Context *context)
SEMA_ERROR(decl, "You cannot use unwrap with a failable variable."); SEMA_ERROR(decl, "You cannot use unwrap with a failable variable.");
return poisoned_decl; return poisoned_decl;
} }
decl->var.is_static = is_static || is_threadglobal; decl->var.is_static = is_static || is_threadlocal;
decl->var.is_threadglobal = is_threadglobal; decl->var.is_threadlocal = is_threadlocal;
return decl; return decl;
} }
@@ -1021,13 +1021,13 @@ bool parse_attributes(Context *context, Attr ***attributes_ref)
*/ */
static inline Decl *parse_global_declaration(Context *context, Visibility visibility) static inline Decl *parse_global_declaration(Context *context, Visibility visibility)
{ {
bool thread_global = try_consume(context, TOKEN_GLOBAL); bool threadlocal = try_consume(context, TOKEN_TLOCAL);
ASSIGN_TYPE_ELSE(TypeInfo *type, parse_failable_type(context), poisoned_decl); ASSIGN_TYPE_ELSE(TypeInfo *type, parse_failable_type(context), poisoned_decl);
Decl *decl = decl_new_var(context->tok.id, type, VARDECL_GLOBAL, visibility); Decl *decl = decl_new_var(context->tok.id, type, VARDECL_GLOBAL, visibility);
decl->var.is_threadglobal = thread_global; decl->var.is_threadlocal = threadlocal;
if (TOKEN_IS(TOKEN_CONST_IDENT)) if (TOKEN_IS(TOKEN_CONST_IDENT))
{ {
@@ -2366,7 +2366,7 @@ Decl *parse_top_level_statement(Context *context)
case TOKEN_IMPORT: case TOKEN_IMPORT:
SEMA_TOKEN_ERROR(context->tok, "Imports are only allowed directly after the module declaration."); SEMA_TOKEN_ERROR(context->tok, "Imports are only allowed directly after the module declaration.");
return poisoned_decl; return poisoned_decl;
case TOKEN_GLOBAL: case TOKEN_TLOCAL:
case TYPELIKE_TOKENS: case TYPELIKE_TOKENS:
{ {
ASSIGN_DECL_ELSE(decl, parse_global_declaration(context, visibility), poisoned_decl); ASSIGN_DECL_ELSE(decl, parse_global_declaration(context, visibility), poisoned_decl);

View File

@@ -800,7 +800,7 @@ Ast *parse_stmt(Context *context)
return parse_decl_or_expr_stmt(context); return parse_decl_or_expr_stmt(context);
case TOKEN_VAR: case TOKEN_VAR:
return parse_var_stmt(context); return parse_var_stmt(context);
case TOKEN_GLOBAL: // Global means declaration! case TOKEN_TLOCAL: // Global means declaration!
case TOKEN_STATIC: // Static means declaration! case TOKEN_STATIC: // Static means declaration!
case TOKEN_CONST: // Const means declaration! case TOKEN_CONST: // Const means declaration!
return parse_declaration_stmt(context); return parse_declaration_stmt(context);

View File

@@ -236,8 +236,6 @@ const char *token_type_to_string(TokenType type)
return "func"; return "func";
case TOKEN_GENERIC: case TOKEN_GENERIC:
return "generic"; return "generic";
case TOKEN_GLOBAL:
return "global";
case TOKEN_IF: case TOKEN_IF:
return "if"; return "if";
case TOKEN_IMPORT: case TOKEN_IMPORT:
@@ -260,6 +258,8 @@ const char *token_type_to_string(TokenType type)
return "struct"; return "struct";
case TOKEN_SWITCH: case TOKEN_SWITCH:
return "switch"; return "switch";
case TOKEN_TLOCAL:
return "tlocal";
case TOKEN_TRUE: case TOKEN_TRUE:
return "true"; return "true";
case TOKEN_TRY: case TOKEN_TRY:

View File

@@ -6,7 +6,7 @@ struct Foo
int x, y; int x, y;
} }
private global Foo[10] array; private Foo[10] array;
// #expect: test.ll // #expect: test.ll

View File

@@ -8,7 +8,7 @@ struct Connection
long length; long length;
} }
private global Connection[3] link private Connection[3] link
= { {1, "link1", 10}, = { {1, "link1", 10},
{2, "link2", 20}, {2, "link2", 20},
{3, "link3", 30} }; {3, "link3", 30} };

View File

@@ -2,12 +2,12 @@
module test; module test;
global int*[] blurp = { &ptr, &ptr, (&ptr + 1), &ptr - 1, (int*)((iptr)(&ptr) - 4) }; int*[] blurp = { &ptr, &ptr, (&ptr + 1), &ptr - 1, (int*)((iptr)(&ptr) - 4) };
global int* c = (int*)((iptr)(&ptr) - 4); int* c = (int*)((iptr)(&ptr) - 4);
global int* c2 = (int*)((iptr)(&ptr) + 4); int* c2 = (int*)((iptr)(&ptr) + 4);
global int* c3 = (int*)(4 + (iptr)(&ptr)); int* c3 = (int*)(4 + (iptr)(&ptr));
global iptr ff = (iptr)(&ptr); iptr ff = (iptr)(&ptr);
global int ptr = 0; int ptr = 0;
// #expect: test.ll // #expect: test.ll

View File

@@ -4,7 +4,7 @@ $else:
$elif (0): $elif (0):
$elif (0): $elif (0):
$else: $else:
global int x = 1; int x = 1;
$endif; $endif;
$endif; $endif;
@@ -18,7 +18,7 @@ $endif;
$if (1): $if (1):
$assert(true); $assert(true);
global int d = 5; int d = 5;
$elif (0): $elif (0):
$assert(false); $assert(false);
$else: $else:
@@ -29,7 +29,7 @@ $if (0):
$assert(true); $assert(true);
$elif (1): $elif (1):
$assert(true); $assert(true);
global int c = 5; int c = 5;
$else: $else:
$assert(false); $assert(false);
$endif; $endif;
@@ -38,7 +38,7 @@ $if (0):
$assert(true); $assert(true);
$elif (1): $elif (1):
$assert(true); $assert(true);
global int b = 4; int b = 4;
$elif (0): $elif (0):
$assert(false); $assert(false);
$else: $else:
@@ -51,7 +51,7 @@ $elif (0):
$assert(false); $assert(false);
$elif (1): $elif (1):
$assert(true); $assert(true);
global int a = 3; int a = 3;
$else: $else:
$assert(false); $assert(false);
$endif; $endif;

View File

@@ -1,8 +1,8 @@
// #target: x64-darwin // #target: x64-darwin
global int foo = 2.2 ? 1 : 2; int foo = 2.2 ? 1 : 2;
global double bar = false ? 1.0 : 2; double bar = false ? 1.0 : 2;
global bool baz = 1 ? false : true; bool baz = 1 ? false : true;
fn void test() fn void test()
{ {

View File

@@ -1,7 +1,7 @@
// #target: x64-darwin // #target: x64-darwin
module foo; module foo;
global int[100] zfe; int[100] zfe;
struct Bob struct Bob
{ {
Bob[] x; Bob[] x;
@@ -37,29 +37,29 @@ union Foob
Ar izzy; Ar izzy;
global long x = $alignof(zfe); long x = $alignof(zfe);
global short y = $alignof("Bob.y"); short y = $alignof("Bob.y");
global int z = $alignof("Bob.y"); int z = $alignof("Bob.y");
global int w = $alignof(Bob.y); int w = $alignof(Bob.y);
global int v = $alignof(v); int v = $alignof(v);
global int x1 = $alignof("Ex.c"); int x1 = $alignof("Ex.c");
global int x2 = $alignof(Ex.y); int x2 = $alignof(Ex.y);
global int x3 = $alignof(char[8]); int x3 = $alignof(char[8]);
global int x4 = $alignof("Ar.br[1]"); int x4 = $alignof("Ar.br[1]");
global int x5 = $alignof(Ar.br[1]); int x5 = $alignof(Ar.br[1]);
global int x6 = $alignof(Ar.br[1]); int x6 = $alignof(Ar.br[1]);
global int x7 = $alignof(Ar.br[1]); int x7 = $alignof(Ar.br[1]);
global int x8 = $alignof(Ar.br[2]); int x8 = $alignof(Ar.br[2]);
global int x9 = $alignof("izzy.br[1]"); int x9 = $alignof("izzy.br[1]");
global int x10 = $alignof("izzy.br[1]"); int x10 = $alignof("izzy.br[1]");
global int x11 = $alignof(izzy.br[1]); int x11 = $alignof(izzy.br[1]);
global int z0 = $alignof("Foob.c"); int z0 = $alignof("Foob.c");
global int z00 = $alignof("Foob.c[0]"); int z00 = $alignof("Foob.c[0]");
global int z01 = $alignof("Foob.c[1]"); int z01 = $alignof("Foob.c[1]");
global int z02 = $alignof("Foob.c[2]"); int z02 = $alignof("Foob.c[2]");
global int z03 = $alignof("Foob.c[3]"); int z03 = $alignof("Foob.c[3]");
global int z04 = $alignof("Foob.c[4]"); int z04 = $alignof("Foob.c[4]");
global int z05 = $alignof("Foob.c[5]"); int z05 = $alignof("Foob.c[5]");

View File

@@ -1,7 +1,7 @@
// #target: x64-darwin // #target: x64-darwin
module foo; module foo;
global int[100] zfe; int[100] zfe;
struct Bob struct Bob
{ {
Bob[] x; Bob[] x;
@@ -36,21 +36,21 @@ union Foob
} }
global short y = $offsetof("Bob.y"); short y = $offsetof("Bob.y");
global int z = $offsetof("Bob.y"); int z = $offsetof("Bob.y");
global int w = $offsetof(Bob.y); int w = $offsetof(Bob.y);
global int x1 = $offsetof("Ex.c[3]"); int x1 = $offsetof("Ex.c[3]");
global int x2 = $offsetof("Ex.y[1]"); int x2 = $offsetof("Ex.y[1]");
global int x4 = $offsetof("Ar.br[1]"); int x4 = $offsetof("Ar.br[1]");
global int x6 = $offsetof(Ar.br[1].x); int x6 = $offsetof(Ar.br[1].x);
global int x5 = $offsetof(Ar.br[1]); int x5 = $offsetof(Ar.br[1]);
global int x7 = $offsetof("Ar.br[2].x"); int x7 = $offsetof("Ar.br[2].x");
global int x8 = $offsetof(Ar.br[2]); int x8 = $offsetof(Ar.br[2]);
global int z0 = $offsetof("Foob.c"); int z0 = $offsetof("Foob.c");
global int z00 = $offsetof("Foob.c[0]"); int z00 = $offsetof("Foob.c[0]");
global int z01 = $offsetof("Foob.c[1]"); int z01 = $offsetof("Foob.c[1]");
global int z02 = $offsetof("Foob.c[5]"); int z02 = $offsetof("Foob.c[5]");
global int z03 = $offsetof("Foob.a"); int z03 = $offsetof("Foob.a");
// #expect: foo.ll // #expect: foo.ll
@foo.y = global i16 16, align 2 @foo.y = global i16 16, align 2

View File

@@ -2,22 +2,22 @@ module foo;
import bar; import bar;
import bar::abc; import bar::abc;
global long x = $sizeof(Baz); long x = $sizeof(Baz);
global short y = $sizeof("Baz"); short y = $sizeof("Baz");
global int z = $sizeof(bar::Baz); int z = $sizeof(bar::Baz);
global int w = $sizeof("bar::Baz"); int w = $sizeof("bar::Baz");
global int v = $sizeof("bar::abc::Foo"); int v = $sizeof("bar::abc::Foo");
global int x1 = $sizeof(x); int x1 = $sizeof(x);
global int y1 = $sizeof("y"); int y1 = $sizeof("y");
global int a = $sizeof("Baz.y"); int a = $sizeof("Baz.y");
global int b = $sizeof("Deep.a.b"); int b = $sizeof("Deep.a.b");
global int c = $sizeof("Deep.a.b.c"); int c = $sizeof("Deep.a.b.c");
global int d = $sizeof("Deep[][100]"); int d = $sizeof("Deep[][100]");
global int e = $sizeof("Deep[][100]**[100][]*"); int e = $sizeof("Deep[][100]**[100][]*");
global int a2 = $sizeof("Baz.y"); int a2 = $sizeof("Baz.y");
global int a3 = $sizeof(Baz.y); int a3 = $sizeof(Baz.y);
global int a4 = $sizeof(Baz.y); int a4 = $sizeof(Baz.y);
global int a5 = $sizeof(Baz.y); int a5 = $sizeof(Baz.y);
module bar; module bar;

View File

@@ -1,8 +1,8 @@
global char[*] foob = x"a0"; char[*] foob = x"a0";
global char[*] fooz = x"00aabbccddeeff"; char[*] fooz = x"00aabbccddeeff";
global char[*] fooy = x'dead beef'; char[*] fooy = x'dead beef';
global char[*] foow = x"4549234d e d"; char[*] foow = x"4549234d e d";
global char[*] foo64 = b64"SGVsbG8gV29ybGQ="; char[*] foo64 = b64"SGVsbG8gV29ybGQ=";
// #expect: byte_literals.ll // #expect: byte_literals.ll

View File

@@ -1,15 +1,15 @@
// #file: file1.c3 // #file: file1.c3
module test; module test;
global char a = ' '; char a = ' ';
global char b = '\r'; char b = '\r';
global char c = '\t'; char c = '\t';
global char d = '\n'; char d = '\n';
global char e = '\0'; char e = '\0';
global char f = '\''; char f = '\'';
global char g = '"'; char g = '"';
global char h = '\\'; char h = '\\';
global char i = '\e'; char i = '\e';
// #expect: test.ll // #expect: test.ll

View File

@@ -5,11 +5,11 @@ private const uint DD = FOO;
private const FOO = ~(uint)(0); private const FOO = ~(uint)(0);
private global uint x = AA; private uint x = AA;
private global uint z = CC; private uint z = CC;
private global char w = (char)(FOO); private char w = (char)(FOO);
private global ushort v = (ushort)(FOO); private ushort v = (ushort)(FOO);
private global uint z2 = DD; private uint z2 = DD;
fn void test() fn void test()
{ {

View File

@@ -5,11 +5,11 @@ enum MyEnum : short
BYE = -5 BYE = -5
} }
global int myenum_max = MyEnum.max; int myenum_max = MyEnum.max;
global int myenum_min = MyEnum.min; int myenum_min = MyEnum.min;
global int myenum_elements = MyEnum.elements; int myenum_elements = MyEnum.elements;
global int myenum_alignof = $alignof(MyEnum); int myenum_alignof = $alignof(MyEnum);
global int myenum_sizeof = $sizeof(MyEnum); int myenum_sizeof = $sizeof(MyEnum);
// #expect: compile_time.ll // #expect: compile_time.ll

View File

@@ -1,9 +1,9 @@
module numbers; module numbers;
global double a = 0x1.1p+1; double a = 0x1.1p+1;
global double b = -12.3e-12; double b = -12.3e-12;
global double c = 0x1.1p-1; double c = 0x1.1p-1;
global double d = 12.3e+12; double d = 12.3e+12;
// #expect: numbers.ll // #expect: numbers.ll

View File

@@ -3,15 +3,15 @@ module foo;
fn int test() fn int test()
{ {
static int x = 1; static int x = 1;
global int y = 2; tlocal int y = 2;
x++; x++;
return x; return x;
} }
// #expect: foo.ll // #expect: foo.ll
@test.x = hidden thread_local global i32 1, align 4 @test.x = hidden global i32 1, align 4
@test.y = hidden global i32 2, align 4 @test.y = hidden thread_local global i32 2, align 4
define i32 @foo.test() define i32 @foo.test()

View File

@@ -15,7 +15,7 @@ fn void helloWorld()
} }
fn int test_static() fn int test_static()
{ {
global int x = 1; static int x = 1;
x++; x++;
printf("Test static %d\n", x); printf("Test static %d\n", x);
return x; return x;
@@ -201,7 +201,7 @@ fn Type getMult(Type a)
{ {
return a * a; return a * a;
} }
global Type argh = 234; Type argh = 234;
errtype MyErr errtype MyErr
{ {

View File

@@ -15,7 +15,7 @@ fn void helloWorld()
} }
fn int test_static() fn int test_static()
{ {
global int x = 1; static int x = 1;
x++; x++;
printf("Test static %d\n", x); printf("Test static %d\n", x);
return x; return x;
@@ -203,7 +203,7 @@ fn Type getMult(Type a)
{ {
return a * a; return a * a;
} }
global Type argh = 234; Type argh = 234;
errtype MyErr errtype MyErr
{ {

View File

@@ -13,7 +13,7 @@ struct UzGlobs
MinInfo* pInfo; MinInfo* pInfo;
} }
extern global UzGlobs g; extern UzGlobs g;
fn int extract_or_test_files() fn int extract_or_test_files()
{ {

View File

@@ -1,6 +1,6 @@
module foo; module foo;
global int baz @extname("foobar") = 123; int baz @extname("foobar") = 123;
// #expect: foo.ll // #expect: foo.ll

View File

@@ -6,7 +6,7 @@ const IA = 3877u;
const IC = 29573u; const IC = 29573u;
const SEED = 42u; const SEED = 42u;
global uint seed = SEED; uint seed = SEED;
fn float fasta_rand(float max) fn float fasta_rand(float max)
{ {
@@ -14,7 +14,7 @@ fn float fasta_rand(float max)
return max * seed / IM; return max * seed / IM;
} }
private global char[] alu = private char[] alu =
"GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG"
"GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA"
"CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT"
@@ -27,8 +27,8 @@ extern fn int atoi(char *s);
extern fn int printf(char *s, ...); extern fn int printf(char *s, ...);
extern fn void putchar(int c); extern fn void putchar(int c);
global char[] iub = "acgtBDHKMNRSVWY"; char[] iub = "acgtBDHKMNRSVWY";
global double[] iub_p = { double[] iub_p = {
0.27, 0.27,
0.12, 0.12,
0.12, 0.12,
@@ -45,8 +45,8 @@ global double[] iub_p = {
0.02, 0.02,
0.02 }; 0.02 };
global char[] homosapiens = "acgt"; char[] homosapiens = "acgt";
global double[] homosapiens_p = { double[] homosapiens_p = {
0.3029549426680, 0.3029549426680,
0.1979883004921, 0.1979883004921,
0.1975473066391, 0.1975473066391,

View File

@@ -17,7 +17,7 @@ fn int test()
int[1] azz = {}; int[1] azz = {};
int[*] a = {}; int[*] a = {};
var $foo = { 11, 22, 33 }; var $foo = { 11, 22, 33 };
global int foo1 = $foo[1]; static int foo1 = $foo[1];
int foo2 = $foo[2]; int foo2 = $foo[2];
var $foos = { "Hello!" }; var $foos = { "Hello!" };
char* str = $foos[0]; char* str = $foos[0];

View File

@@ -16,7 +16,7 @@ struct Bar
fn void test() fn void test()
{ {
Bar[] b = { { 1, 2 } }; Bar[] b = { { 1, 2 } };
global Bar[] c = { { 1, 2 } }; static Bar[] c = { { 1, 2 } };
io::printf("%d %d\n", b[0].y, c[0].y); io::printf("%d %d\n", b[0].y, c[0].y);
b[0].y += 1; b[0].y += 1;
c[0].y += 1; c[0].y += 1;
@@ -30,7 +30,7 @@ fn int main()
return 1; return 1;
} }
// #expect: statics.ll /* #expect: statics.ll
%Bar = type { i32, i32 } %Bar = type { i32, i32 }
%"Bar[]" = type { %Bar*, i64 } %"Bar[]" = type { %Bar*, i64 }

View File

@@ -14,9 +14,9 @@ struct Bar
} }
global Bar[] arrbar = { { 3, 4 }, { 8, 9 }}; Bar[] arrbar = { { 3, 4 }, { 8, 9 }};
global int[] xd = { 1, 2 }; int[] xd = { 1, 2 };
global int* fofeo = &&(int[2]{ 3, 4 }); int* fofeo = &&(int[2]{ 3, 4 });
fn int main() fn int main()
{ {

View File

@@ -1,14 +1,14 @@
// #target: x64-darwin // #target: x64-darwin
module foo; module foo;
global int aa = 'ä'; int aa = 'ä';
global int x = 'ABCD'; int x = 'ABCD';
global uint y = 'Helo'; uint y = 'Helo';
global ushort z = '\x31\x32'; ushort z = '\x31\x32';
global int d = '\u0031'; int d = '\u0031';
global char b = '\x40'; char b = '\x40';
global uint abc = '\U133222AB'; uint abc = '\U133222AB';
global uint foo = ''; uint foo = '';
/* #expect: foo.ll /* #expect: foo.ll

View File

@@ -2,13 +2,13 @@
module const_pointer; module const_pointer;
private global double foo = 17; private double foo = 17;
private global double bar = 12.0; private double bar = 12.0;
private global float xx = 12.0; private float xx = 12.0;
private global void*[3] data = { &foo, &bar, &xx }; private void*[3] data = { &foo, &bar, &xx };
// #expect: const_pointer.ll /* #expect: const_pointer.ll
@const_pointer.foo = protected global double 1.700000e+01, align 8 @const_pointer.foo = protected global double 1.700000e+01, align 8
@const_pointer.bar = protected global double 1.200000e+01, align 8 @const_pointer.bar = protected global double 1.200000e+01, align 8

View File

@@ -1,6 +1,6 @@
// #target: x64-darwin // #target: x64-darwin
global char[] y = "hello"; char[] y = "hello";
fn void test() fn void test()
{ {

View File

@@ -1,6 +1,6 @@
module test; module test;
private global Foo a; private Foo a;
struct Foo struct Foo
{ {

View File

@@ -6,16 +6,16 @@ struct Foo
long bar; long bar;
} }
private global usize x = $sizeof(Foo); private usize x = $sizeof(Foo);
private global Foo foo1 = { 1, 2 }; private Foo foo1 = { 1, 2 };
private global Foo foo2 = { .foo = 2 }; private Foo foo2 = { .foo = 2 };
private global Foo foo3 = { .bar = 3 }; private Foo foo3 = { .bar = 3 };
private global Foo foo4 = { .bar = 4, .foo = 4, .bar = 1 }; private Foo foo4 = { .bar = 4, .foo = 4, .bar = 1 };
private global Foo foo5 = {}; private Foo foo5 = {};
private global Foo foo6; private Foo foo6;
private const Foo FOO7 = { 1, 2 }; private const Foo FOO7 = { 1, 2 };
private global Foo foo8 = FOO7; private Foo foo8 = FOO7;
// #expect: structo.ll // #expect: structo.ll

View File

@@ -8,7 +8,7 @@ struct Foo1 @packed @align(4)
} }
$assert($sizeof(Foo1) == 12); $assert($sizeof(Foo1) == 12);
global Foo1 foo1 = { 1, 2 }; Foo1 foo1 = { 1, 2 };
// <{ i8, i64, [3 x i8] }> // <{ i8, i64, [3 x i8] }>
struct Foo2 @packed @align(4) struct Foo2 @packed @align(4)
@@ -18,7 +18,7 @@ struct Foo2 @packed @align(4)
} }
$assert($sizeof(Foo2) == 12); $assert($sizeof(Foo2) == 12);
global Foo2 foo2 = { 1, 2 }; Foo2 foo2 = { 1, 2 };
// <{ i8, i64, [7 x i8] }> // <{ i8, i64, [7 x i8] }>
struct Foo3 @packed @align(8) struct Foo3 @packed @align(8)
@@ -27,7 +27,7 @@ struct Foo3 @packed @align(8)
long bar; long bar;
} }
global Foo3 foo3 = { 1, 2 }; Foo3 foo3 = { 1, 2 };
$assert($sizeof(Foo3) == 16); $assert($sizeof(Foo3) == 16);
// <{ i8, i64 }> // <{ i8, i64 }>
@@ -38,7 +38,7 @@ struct Foo4 @packed
} }
$assert($sizeof(Foo4) == 9); $assert($sizeof(Foo4) == 9);
global Foo4 foo4 = { 1, 2 }; Foo4 foo4 = { 1, 2 };
// { i32, [12 x i8], i8, [15 x i8] } // { i32, [12 x i8], i8, [15 x i8] }
struct Foo5 struct Foo5
@@ -48,7 +48,7 @@ struct Foo5
} }
$assert($sizeof(Foo5) == 32); $assert($sizeof(Foo5) == 32);
global Foo5 foo5 = { 1, 2 }; Foo5 foo5 = { 1, 2 };
fn int test5(ichar x) fn int test5(ichar x)
{ {
@@ -65,7 +65,7 @@ struct Foo6 @packed
} }
$assert($sizeof(Foo6) == 8); $assert($sizeof(Foo6) == 8);
global Foo6 foo6 = { 1, 2, 3 }; Foo6 foo6 = { 1, 2, 3 };
// #expect: struct2.ll // #expect: struct2.ll

View File

@@ -6,10 +6,10 @@ union Foo
double b; double b;
} }
private global Foo f = { .a = 23 }; private Foo f = { .a = 23 };
private global Foo g = { .b = 2.3 }; private Foo g = { .b = 2.3 };
private global Foo h = { .a = 23, .b = 2.3 }; private Foo h = { .a = 23, .b = 2.3 };
global Foo i = { .b = 2.3, .a = 23 }; Foo i = { .b = 2.3, .a = 23 };
// #expect: test.ll // #expect: test.ll

View File

@@ -11,8 +11,8 @@ struct Foo
int z; int z;
} }
global Foo foo1 = { .a = 3, .z = 4 }; Foo foo1 = { .a = 3, .z = 4 };
global Foo foo2 = { .b = 3, .z = 4 }; Foo foo2 = { .b = 3, .z = 4 };
struct Blend_Map_Entry struct Blend_Map_Entry
{ {
@@ -22,10 +22,10 @@ struct Blend_Map_Entry
} }
} }
global Blend_Map_Entry a = { .vals = { .colour = { 1, 2, 3, 4, 5 } } }; Blend_Map_Entry a = { .vals = { .colour = { 1, 2, 3, 4, 5 } } };
global Blend_Map_Entry b = { .vals = { .point_Slope = { 6, 7 } } }; Blend_Map_Entry b = { .vals = { .point_Slope = { 6, 7 } } };
global Blend_Map_Entry c = { .vals.colour[2] = 1 }; Blend_Map_Entry c = { .vals.colour[2] = 1 };
global Blend_Map_Entry d = { .vals.colour = { 1, 2, 3, 4, 5 } }; Blend_Map_Entry d = { .vals.colour = { 1, 2, 3, 4, 5 } };
fn void test(Blend_Map_Entry* foo) fn void test(Blend_Map_Entry* foo)
{ {

View File

@@ -1,5 +1,5 @@
// #target: x64-darwin // #target: x64-darwin
global int[<4>] baz = { 1, 4, 5, 7 }; int[<4>] baz = { 1, 4, 5, 7 };
fn void main() fn void main()
{ {