Minimize package size
This commit is contained in:
@@ -154,7 +154,7 @@ bool add_dynamic_array_macro() {
|
||||
// that is going to be imported into every other package, for now we use only the current package
|
||||
For(array_of_to_gen) {
|
||||
LC_AST *ast = LC_ParseDeclf("ArrayOf%s :: struct { data: *%s; len: int; cap: int; }", (char *)it, (char *)it);
|
||||
LC_AST *file = package->apackage.ffile;
|
||||
LC_AST *file = package->apackage.ext->ffile;
|
||||
|
||||
LC_DLLAdd(file->afile.fdecl, file->afile.ldecl, ast);
|
||||
}
|
||||
|
||||
@@ -78,11 +78,11 @@ bool sandbox() {
|
||||
//
|
||||
LC_AST *package = LC_GetPackageByName(name);
|
||||
LC_AST *dynamic_array_file = NULL;
|
||||
LC_ASTFor(it, package->apackage.ffile) {
|
||||
LC_ASTFor(it, package->apackage.ext->ffile) {
|
||||
S8_String path = S8_MakeFromChar((char *)it->afile.x->file);
|
||||
if (S8_EndsWith(path, "dynamic_array.lc")) {
|
||||
dynamic_array_file = it;
|
||||
DLL_QUEUE_REMOVE(package->apackage.ffile, package->apackage.lfile, it);
|
||||
DLL_QUEUE_REMOVE(package->apackage.ext->ffile, package->apackage.ext->lfile, it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ bool sandbox() {
|
||||
|
||||
walker.user_data = (void *)⁢
|
||||
LC_WalkAST(&walker, new_array_file);
|
||||
LC_DLLAdd(package->apackage.ffile, package->apackage.lfile, new_array_file);
|
||||
LC_DLLAdd(package->apackage.ext->ffile, package->apackage.ext->lfile, new_array_file);
|
||||
}
|
||||
|
||||
LC_OrderAndResolveTopLevelDecls(name);
|
||||
|
||||
@@ -19,18 +19,18 @@ bool use_as_data_format_with_typechecking() {
|
||||
|
||||
// Constants
|
||||
{
|
||||
LC_Decl *int_value = LC_FindDeclInScope(package->apackage.scope, LC_ILit("IntValue"));
|
||||
LC_Decl *int_value = LC_FindDeclInScope(package->apackage.ext->scope, LC_ILit("IntValue"));
|
||||
int64_t IntValue = LC_Bigint_as_signed(&int_value->val.i);
|
||||
IO_Assert(IntValue == 232);
|
||||
}
|
||||
|
||||
{
|
||||
LC_Decl *decl = LC_FindDeclInScope(package->apackage.scope, LC_ILit("FloatValue"));
|
||||
LC_Decl *decl = LC_FindDeclInScope(package->apackage.ext->scope, LC_ILit("FloatValue"));
|
||||
IO_Assert(decl->val.d == 13.0);
|
||||
}
|
||||
|
||||
{
|
||||
LC_Decl *decl = LC_FindDeclInScope(package->apackage.scope, LC_ILit("SomeString"));
|
||||
LC_Decl *decl = LC_FindDeclInScope(package->apackage.ext->scope, LC_ILit("SomeString"));
|
||||
IO_Assert(decl->val.name == LC_ILit("Thing"));
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ bool use_as_data_format_with_typechecking() {
|
||||
|
||||
int64_t LEVEL_BEGIN = -1;
|
||||
{
|
||||
LC_Decl *int_value = LC_FindDeclInScope(package->apackage.scope, LC_ILit("LEVEL_BEGIN"));
|
||||
LC_Decl *int_value = LC_FindDeclInScope(package->apackage.ext->scope, LC_ILit("LEVEL_BEGIN"));
|
||||
LEVEL_BEGIN = LC_Bigint_as_signed(&int_value->val.i);
|
||||
IO_Assert(LEVEL_BEGIN == 2);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ bool use_as_data_format_with_typechecking() {
|
||||
double Variable = GetFloatValue(p, "Variable");
|
||||
*/
|
||||
|
||||
LC_Decl *decl = LC_FindDeclInScope(package->apackage.scope, LC_ILit("Player"));
|
||||
LC_Decl *decl = LC_FindDeclInScope(package->apackage.ext->scope, LC_ILit("Player"));
|
||||
LC_ResolvedCompo *items = decl->ast->dvar.expr->ecompo.resolved_items;
|
||||
for (LC_ResolvedCompoItem *it = items->first; it; it = it->next) {
|
||||
LC_Intern name = it->t->name;
|
||||
@@ -71,12 +71,12 @@ bool use_as_data_format_with_typechecking() {
|
||||
}
|
||||
|
||||
{
|
||||
LC_Decl *decl = LC_FindDeclInScope(package->apackage.scope, LC_ILit("Variable"));
|
||||
LC_Decl *decl = LC_FindDeclInScope(package->apackage.ext->scope, LC_ILit("Variable"));
|
||||
IO_Assert(decl->val.d == 32.0);
|
||||
}
|
||||
|
||||
{
|
||||
LC_Decl *decl = LC_FindDeclInScope(package->apackage.scope, LC_ILit("Reference"));
|
||||
LC_Decl *decl = LC_FindDeclInScope(package->apackage.ext->scope, LC_ILit("Reference"));
|
||||
IO_Assert(decl->val.d == 64.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
This is a compiler frontend in a single-header-file library form.
|
||||
In **beta** version so things may change between versions!
|
||||
This is a **beta** so things may change between versions!
|
||||
|
||||
# How to use
|
||||
|
||||
@@ -8736,34 +8736,28 @@ LC_FUNCTION LC_AST *LC_ParseFile(LC_AST *package, char *filename, char *content,
|
||||
|
||||
LC_FUNCTION LC_AST *LC_ParseStmtf(const char *str, ...) {
|
||||
LC_FORMAT(L->arena, str, s8);
|
||||
|
||||
LC_Parser *old = L->parser;
|
||||
LC_Parser *p = LC_MakeParserQuick(s8.str);
|
||||
LC_AST *result = LC_ParseStmt(false);
|
||||
L->parser = old;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
LC_FUNCTION LC_AST *LC_ParseExprf(const char *str, ...) {
|
||||
LC_FORMAT(L->arena, str, s8);
|
||||
|
||||
LC_Parser *old = L->parser;
|
||||
LC_Parser *p = LC_MakeParserQuick(s8.str);
|
||||
LC_AST *result = LC_ParseExpr();
|
||||
L->parser = old;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
LC_FUNCTION LC_AST *LC_ParseDeclf(const char *str, ...) {
|
||||
LC_FORMAT(L->arena, str, s8);
|
||||
|
||||
LC_Parser *old = L->parser;
|
||||
LC_Parser *p = LC_MakeParserQuick(s8.str);
|
||||
LC_AST *result = LC_ParseDecl(&L->NullAST);
|
||||
L->parser = old;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ void VerifyCopy_Walk(LC_ASTWalker *ctx, LC_AST *n) {
|
||||
|
||||
void VerifyASTCopy(LC_ASTRefList packages) {
|
||||
for (LC_ASTRef *it = packages.first; it; it = it->next) {
|
||||
LC_ASTFor(file, it->ast->apackage.ffile) {
|
||||
LC_ASTFor(file, it->ast->apackage.ext->ffile) {
|
||||
LC_TempArena c = LC_BeginTemp(L->arena);
|
||||
LC_AST *copy = LC_CopyAST(L->arena, file);
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ LC_FUNCTION void LC_WalkAST(LC_ASTWalker *ctx, LC_AST *n) {
|
||||
case LC_ASTKind_StmtContinue: break;
|
||||
|
||||
case LC_ASTKind_Package: {
|
||||
LC_ASTFor(it, n->apackage.ffile) LC_WalkAST(ctx, it);
|
||||
LC_ASTFor(it, n->apackage.ext->ffile) LC_WalkAST(ctx, it);
|
||||
} break;
|
||||
|
||||
case LC_ASTKind_File: {
|
||||
|
||||
@@ -31,13 +31,13 @@ LC_FUNCTION LC_Map LC_CountDeclRefs(LC_Arena *arena) {
|
||||
|
||||
LC_FUNCTION void LC_RemoveUnreferencedGlobalDecls(LC_Map *map_of_visits) {
|
||||
for (LC_ASTRef *it = L->ordered_packages.first; it; it = it->next) {
|
||||
for (LC_Decl *decl = it->ast->apackage.first_ordered; decl;) {
|
||||
for (LC_Decl *decl = it->ast->apackage.ext->first_ordered; decl;) {
|
||||
intptr_t ref_count = (intptr_t)LC_MapGetP(map_of_visits, decl);
|
||||
|
||||
LC_Decl *remove = decl;
|
||||
decl = decl->next;
|
||||
if (ref_count == 0 && remove->foreign_name != LC_ILit("main")) {
|
||||
LC_DLLRemove(it->ast->apackage.first_ordered, it->ast->apackage.last_ordered, remove);
|
||||
LC_DLLRemove(it->ast->apackage.ext->first_ordered, it->ast->apackage.ext->last_ordered, remove);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -606,7 +606,7 @@ LC_FUNCTION void LC_GenCVarFDecl(LC_Decl *decl) {
|
||||
|
||||
LC_FUNCTION void LC_GenCHeader(LC_AST *package) {
|
||||
// C notes
|
||||
LC_ASTFor(file, package->apackage.ffile) {
|
||||
LC_ASTFor(file, package->apackage.ext->ffile) {
|
||||
LC_ASTFor(it, file->afile.fdecl) {
|
||||
if (it->kind != LC_ASTKind_DeclNote) continue;
|
||||
|
||||
@@ -618,7 +618,7 @@ LC_FUNCTION void LC_GenCHeader(LC_AST *package) {
|
||||
}
|
||||
|
||||
// struct forward decls
|
||||
LC_DeclFor(decl, package->apackage.first_ordered) {
|
||||
LC_DeclFor(decl, package->apackage.ext->first_ordered) {
|
||||
if (decl->is_foreign) continue;
|
||||
LC_AST *n = decl->ast;
|
||||
if (decl->kind == LC_DeclKind_Type && LC_IsAgg(n)) LC_GenCAggForwardDecl(decl);
|
||||
@@ -626,14 +626,14 @@ LC_FUNCTION void LC_GenCHeader(LC_AST *package) {
|
||||
|
||||
// type decls
|
||||
LC_GenLine();
|
||||
LC_DeclFor(decl, package->apackage.first_ordered) {
|
||||
LC_DeclFor(decl, package->apackage.ext->first_ordered) {
|
||||
if (decl->is_foreign) continue;
|
||||
LC_AST *n = decl->ast;
|
||||
if (decl->kind == LC_DeclKind_Type) LC_GenCTypeDecl(decl);
|
||||
}
|
||||
|
||||
// proc and var forward decls
|
||||
LC_DeclFor(decl, package->apackage.first_ordered) {
|
||||
LC_DeclFor(decl, package->apackage.ext->first_ordered) {
|
||||
if (decl->is_foreign) continue;
|
||||
LC_AST *n = decl->ast;
|
||||
if (decl->kind == LC_DeclKind_Var) {
|
||||
@@ -647,7 +647,7 @@ LC_FUNCTION void LC_GenCHeader(LC_AST *package) {
|
||||
|
||||
LC_FUNCTION void LC_GenCImpl(LC_AST *package) {
|
||||
// implementation of vars
|
||||
LC_DeclFor(decl, package->apackage.first_ordered) {
|
||||
LC_DeclFor(decl, package->apackage.ext->first_ordered) {
|
||||
if (decl->kind == LC_DeclKind_Var && !decl->is_foreign) {
|
||||
LC_AST *n = decl->ast;
|
||||
LC_Type *type = decl->type; // make string arrays assignable
|
||||
@@ -665,7 +665,7 @@ LC_FUNCTION void LC_GenCImpl(LC_AST *package) {
|
||||
}
|
||||
|
||||
// implementation of procs
|
||||
LC_DeclFor(decl, package->apackage.first_ordered) {
|
||||
LC_DeclFor(decl, package->apackage.ext->first_ordered) {
|
||||
LC_AST *n = decl->ast;
|
||||
if (decl->kind == LC_DeclKind_Proc && n->dproc.body && !decl->is_foreign) {
|
||||
LC_GenCLineDirective(n);
|
||||
|
||||
@@ -93,10 +93,11 @@ LC_FUNCTION void LC_LangBegin(LC_Lang *l) {
|
||||
}
|
||||
|
||||
{
|
||||
LC_AST *builtins = LC_CreateAST(0, LC_ASTKind_Package);
|
||||
L->builtin_package = builtins;
|
||||
builtins->apackage.name = LC_ILit("builtins");
|
||||
builtins->apackage.scope = LC_CreateScope(256);
|
||||
LC_AST *builtins = LC_CreateAST(0, LC_ASTKind_Package);
|
||||
L->builtin_package = builtins;
|
||||
builtins->apackage.ext = LC_PushStruct(L->arena, LC_ASTPackageExt);
|
||||
builtins->apackage.name = LC_ILit("builtins");
|
||||
builtins->apackage.ext->scope = LC_CreateScope(256);
|
||||
LC_AddPackageToList(builtins);
|
||||
}
|
||||
|
||||
@@ -179,7 +180,7 @@ LC_FUNCTION void LC_LangBegin(LC_Lang *l) {
|
||||
decl->state = LC_DeclState_Resolved;
|
||||
decl->type = t;
|
||||
t->decl = decl;
|
||||
LC_AddDeclToScope(L->builtin_package->apackage.scope, decl);
|
||||
LC_AddDeclToScope(L->builtin_package->apackage.ext->scope, decl);
|
||||
|
||||
if (t->kind == LC_TypeKind_uchar) decl->foreign_name = LC_ILit("unsigned char");
|
||||
if (t->kind == LC_TypeKind_ushort) decl->foreign_name = LC_ILit("unsigned short");
|
||||
@@ -223,7 +224,7 @@ LC_FUNCTION void LC_LangBegin(LC_Lang *l) {
|
||||
decl->state = LC_DeclState_Resolved;
|
||||
decl->type = L->tstring;
|
||||
L->tstring->decl = decl;
|
||||
LC_AddDeclToScope(L->builtin_package->apackage.scope, decl);
|
||||
LC_AddDeclToScope(L->builtin_package->apackage.ext->scope, decl);
|
||||
LC_Operand result = LC_ResolveTypeAggregate(ast, decl->type);
|
||||
LC_ASSERT(ast, !LC_IsError(result));
|
||||
}
|
||||
@@ -240,7 +241,7 @@ LC_FUNCTION void LC_LangBegin(LC_Lang *l) {
|
||||
decl->state = LC_DeclState_Resolved;
|
||||
decl->type = L->tany;
|
||||
L->tany->decl = decl;
|
||||
LC_AddDeclToScope(L->builtin_package->apackage.scope, decl);
|
||||
LC_AddDeclToScope(L->builtin_package->apackage.ext->scope, decl);
|
||||
LC_Operand result = LC_ResolveTypeAggregate(ast, decl->type);
|
||||
LC_ASSERT(ast, !LC_IsError(result));
|
||||
}
|
||||
|
||||
@@ -373,16 +373,14 @@ struct LC_ASTFile {
|
||||
LC_Token *doc_comment;
|
||||
};
|
||||
|
||||
struct LC_ASTPackage {
|
||||
LC_Intern name;
|
||||
LC_DeclState state;
|
||||
LC_String path;
|
||||
// To minimize package ast size, we want all nodes to be equal in size,
|
||||
// a lot of things are easier then and we can loop through all asts for free etc.
|
||||
typedef struct LC_ASTPackageExt LC_ASTPackageExt;
|
||||
struct LC_ASTPackageExt {
|
||||
LC_StringList injected_filepaths; // to sidestep regular file finding, implement single file packages etc.
|
||||
LC_AST *ffile;
|
||||
LC_AST *lfile;
|
||||
|
||||
LC_Token *doc_comment;
|
||||
|
||||
// These are resolved later:
|
||||
// @todo: add foreign name?
|
||||
LC_Decl *first_ordered;
|
||||
@@ -390,6 +388,14 @@ struct LC_ASTPackage {
|
||||
DeclScope *scope;
|
||||
};
|
||||
|
||||
struct LC_ASTPackage {
|
||||
LC_DeclState state;
|
||||
LC_Intern name;
|
||||
LC_String path;
|
||||
LC_Token *doc_comment;
|
||||
LC_ASTPackageExt *ext;
|
||||
};
|
||||
|
||||
struct LC_ASTNoteList {
|
||||
LC_AST *first;
|
||||
LC_AST *last;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
LC_FUNCTION LC_Operand LC_ImportPackage(LC_AST *import, LC_AST *dst, LC_AST *src) {
|
||||
DeclScope *dst_scope = dst->apackage.scope;
|
||||
int scope_size = LC_NextPow2(src->apackage.scope->len * 2 + 1);
|
||||
DeclScope *dst_scope = dst->apackage.ext->scope;
|
||||
int scope_size = LC_NextPow2(src->apackage.ext->scope->len * 2 + 1);
|
||||
if (import && import->gimport.name) {
|
||||
LC_PUSH_PACKAGE(dst);
|
||||
LC_Decl *decl = LC_CreateDecl(LC_DeclKind_Import, import->gimport.name, import);
|
||||
@@ -11,8 +11,8 @@ LC_FUNCTION LC_Operand LC_ImportPackage(LC_AST *import, LC_AST *dst, LC_AST *src
|
||||
dst_scope = decl->scope;
|
||||
}
|
||||
|
||||
for (int i = 0; i < src->apackage.scope->cap; i += 1) {
|
||||
LC_MapEntry entry = src->apackage.scope->entries[i];
|
||||
for (int i = 0; i < src->apackage.ext->scope->cap; i += 1) {
|
||||
LC_MapEntry entry = src->apackage.ext->scope->entries[i];
|
||||
if (entry.key != 0) {
|
||||
LC_Decl *decl = (LC_Decl *)entry.value;
|
||||
if (decl->package != src) continue;
|
||||
@@ -87,6 +87,7 @@ LC_FUNCTION void LC_AddPackageToList(LC_AST *n) {
|
||||
LC_FUNCTION LC_AST *LC_RegisterPackage(LC_String path) {
|
||||
LC_ASSERT(NULL, path.len != 0);
|
||||
LC_AST *n = LC_CreateAST(NULL, LC_ASTKind_Package);
|
||||
n->apackage.ext = LC_PushStruct(L->arena, LC_ASTPackageExt);
|
||||
n->apackage.name = LC_MakePackageNameFromPath(path);
|
||||
n->apackage.path = path;
|
||||
LC_AddPackageToList(n);
|
||||
@@ -110,7 +111,7 @@ LC_FUNCTION LC_ASTRefList LC_GetPackageImports(LC_AST *package) {
|
||||
LC_ASSERT(package, package->kind == LC_ASTKind_Package);
|
||||
|
||||
LC_ASTRefList refs = {0};
|
||||
LC_ASTFor(file, package->apackage.ffile) {
|
||||
LC_ASTFor(file, package->apackage.ext->ffile) {
|
||||
LC_ASTFor(import, file->afile.fimport) {
|
||||
LC_AST *found = LC_FindImportInRefList(&refs, import->gimport.path);
|
||||
if (found) {
|
||||
@@ -178,10 +179,10 @@ LC_FUNCTION LoadedFile LC_ReadFileHook(LC_AST *package, LC_String path) {
|
||||
|
||||
LC_FUNCTION void LC_ParsePackage(LC_AST *n) {
|
||||
LC_ASSERT(n, n->kind == LC_ASTKind_Package);
|
||||
LC_ASSERT(n, n->apackage.scope == NULL);
|
||||
n->apackage.scope = LC_CreateScope(256);
|
||||
LC_ASSERT(n, n->apackage.ext->scope == NULL);
|
||||
n->apackage.ext->scope = LC_CreateScope(256);
|
||||
|
||||
LC_StringList files = n->apackage.injected_filepaths;
|
||||
LC_StringList files = n->apackage.ext->injected_filepaths;
|
||||
if (files.node_count == 0) {
|
||||
files = LC_ListFilesInPackage(L->arena, n->apackage.path);
|
||||
if (files.first == NULL) {
|
||||
@@ -211,7 +212,7 @@ LC_FUNCTION void LC_ParsePackagesUsingRegistry(LC_Intern name) {
|
||||
L->errors += 1;
|
||||
return;
|
||||
}
|
||||
if (n->apackage.scope) {
|
||||
if (n->apackage.ext->scope) {
|
||||
return;
|
||||
}
|
||||
LC_ParsePackage(n);
|
||||
@@ -223,13 +224,13 @@ LC_FUNCTION void LC_ParsePackagesUsingRegistry(LC_Intern name) {
|
||||
|
||||
LC_FUNCTION void LC_BuildIfPass(void) {
|
||||
LC_ASTFor(n, L->fpackage) {
|
||||
for (LC_AST *fit = n->apackage.ffile; fit;) {
|
||||
for (LC_AST *fit = n->apackage.ext->ffile; fit;) {
|
||||
LC_AST *next = fit->next;
|
||||
|
||||
LC_AST *build_if = LC_HasNote(fit, L->ibuild_if);
|
||||
if (build_if) {
|
||||
if (!LC_ResolveBuildIf(build_if)) {
|
||||
LC_DLLRemove(n->apackage.ffile, n->apackage.lfile, fit);
|
||||
LC_DLLRemove(n->apackage.ext->ffile, n->apackage.ext->lfile, fit);
|
||||
LC_AddASTToRefList(&L->discarded, fit);
|
||||
fit = next;
|
||||
continue;
|
||||
@@ -387,8 +388,9 @@ LC_FUNCTION LC_String LC_GenerateUnityBuild(LC_ASTRefList packages) {
|
||||
|
||||
LC_FUNCTION void LC_AddSingleFilePackage(LC_Intern name, LC_String path) {
|
||||
LC_AST *n = LC_CreateAST(0, LC_ASTKind_Package);
|
||||
n->apackage.ext = LC_PushStruct(L->arena, LC_ASTPackageExt);
|
||||
n->apackage.name = name;
|
||||
n->apackage.path = path;
|
||||
LC_AddNode(L->arena, &n->apackage.injected_filepaths, path);
|
||||
LC_AddNode(L->arena, &n->apackage.ext->injected_filepaths, path);
|
||||
LC_AddPackageToList(n);
|
||||
}
|
||||
@@ -955,7 +955,7 @@ LC_FUNCTION LC_AST *LC_ParseImport(void) {
|
||||
|
||||
LC_FUNCTION void LC_AddFileToPackage(LC_AST *pkg, LC_AST *f) {
|
||||
f->afile.package = pkg;
|
||||
LC_DLLAdd(pkg->apackage.ffile, pkg->apackage.lfile, f);
|
||||
LC_DLLAdd(pkg->apackage.ext->ffile, pkg->apackage.ext->lfile, f);
|
||||
}
|
||||
|
||||
LC_FUNCTION LC_AST *LC_ParseFileEx(LC_AST *package) {
|
||||
|
||||
@@ -83,7 +83,7 @@ LC_FUNCTION char *LC_GenLCAggName(LC_Type *t) {
|
||||
LC_FUNCTION void LC_GenLCNode(LC_AST *n) {
|
||||
switch (n->kind) {
|
||||
case LC_ASTKind_Package: {
|
||||
LC_ASTFor(it, n->apackage.ffile) {
|
||||
LC_ASTFor(it, n->apackage.ext->ffile) {
|
||||
LC_GenLCNode(it);
|
||||
}
|
||||
} break;
|
||||
|
||||
@@ -35,7 +35,7 @@ LC_FUNCTION void LC_PackageDecls(LC_AST *package) {
|
||||
LC_PUSH_PACKAGE(package);
|
||||
|
||||
// Register top level declarations
|
||||
LC_ASTFor(file, package->apackage.ffile) {
|
||||
LC_ASTFor(file, package->apackage.ext->ffile) {
|
||||
LC_ASTFor(import, file->afile.fimport) {
|
||||
if (import->gimport.resolved == false) LC_ReportASTError(import, "internal compiler error: unresolved import got into typechecking stage");
|
||||
}
|
||||
@@ -43,7 +43,7 @@ LC_FUNCTION void LC_PackageDecls(LC_AST *package) {
|
||||
}
|
||||
|
||||
// Resolve declarations by name
|
||||
LC_ASTFor(file, package->apackage.ffile) {
|
||||
LC_ASTFor(file, package->apackage.ext->ffile) {
|
||||
LC_ResolveDeclsFromFile(file);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ LC_FUNCTION void LC_PackageDecls(LC_AST *package) {
|
||||
LC_FUNCTION void LC_ResolveProcBodies(LC_AST *package) {
|
||||
LC_PUSH_PACKAGE(package);
|
||||
|
||||
LC_ASTFor(file, package->apackage.ffile) {
|
||||
LC_ASTFor(file, package->apackage.ext->ffile) {
|
||||
LC_ASTFor(n, file->afile.fdecl) {
|
||||
if (n->kind == LC_ASTKind_DeclNote) continue;
|
||||
|
||||
@@ -71,7 +71,7 @@ LC_FUNCTION void LC_ResolveProcBodies(LC_AST *package) {
|
||||
LC_FUNCTION void LC_ResolveIncompleteTypes(LC_AST *package) {
|
||||
LC_PUSH_PACKAGE(package);
|
||||
|
||||
LC_ASTFor(file, package->apackage.ffile) {
|
||||
LC_ASTFor(file, package->apackage.ext->ffile) {
|
||||
LC_ASTFor(n, file->afile.fdecl) {
|
||||
if (n->kind == LC_ASTKind_DeclNote) continue;
|
||||
|
||||
@@ -1163,7 +1163,7 @@ LC_FUNCTION LC_Operand LC_ResolveName(LC_AST *pos, LC_Intern intern) {
|
||||
|
||||
if (L->on_decl_type_resolved) L->on_decl_type_resolved(decl);
|
||||
LC_AST *pkg = decl->package;
|
||||
LC_DLLAdd(pkg->apackage.first_ordered, pkg->apackage.last_ordered, decl);
|
||||
LC_DLLAdd(pkg->apackage.ext->first_ordered, pkg->apackage.ext->last_ordered, decl);
|
||||
return LC_OPDecl(decl);
|
||||
}
|
||||
|
||||
@@ -1408,7 +1408,7 @@ LC_FUNCTION LC_Operand LC_ResolveTypeAggregate(LC_AST *pos, LC_Type *type) {
|
||||
if (type->kind == LC_TypeKind_Error) return LC_OPError();
|
||||
LC_TYPE_IF(type->kind == LC_TypeKind_Completing, pos, "cyclic dependency in type '%s'", type->decl->name);
|
||||
if (type->kind != LC_TypeKind_Incomplete) return LC_OPNull;
|
||||
LC_PUSH_SCOPE(L->resolver.package->apackage.scope);
|
||||
LC_PUSH_SCOPE(L->resolver.package->apackage.ext->scope);
|
||||
|
||||
LC_AST *n = decl->ast;
|
||||
LC_ASSERT(n, decl);
|
||||
@@ -1485,7 +1485,7 @@ LC_FUNCTION LC_Operand LC_ResolveTypeAggregate(LC_AST *pos, LC_Type *type) {
|
||||
|
||||
if (L->on_decl_type_resolved) L->on_decl_type_resolved(decl);
|
||||
LC_AST *pkg = decl->package;
|
||||
LC_DLLAdd(pkg->apackage.first_ordered, pkg->apackage.last_ordered, decl);
|
||||
LC_DLLAdd(pkg->apackage.ext->first_ordered, pkg->apackage.ext->last_ordered, decl);
|
||||
LC_POP_SCOPE();
|
||||
return LC_OPNull;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#define LC_POP_SCOPE() L->resolver.active_scope = PREV_SCOPE
|
||||
#define LC_PUSH_LOCAL_SCOPE() int LOCAL_LEN = L->resolver.locals.len
|
||||
#define LC_POP_LOCAL_SCOPE() L->resolver.locals.len = LOCAL_LEN
|
||||
#define LC_PUSH_PACKAGE(PKG) LC_AST *PREV_PKG = L->resolver.package; L->resolver.package = PKG; LC_PUSH_SCOPE(PKG->apackage.scope)
|
||||
#define LC_PUSH_PACKAGE(PKG) LC_AST *PREV_PKG = L->resolver.package; L->resolver.package = PKG; LC_PUSH_SCOPE(PKG->apackage.ext->scope)
|
||||
#define LC_POP_PACKAGE() L->resolver.package = PREV_PKG; LC_POP_SCOPE()
|
||||
#define LC_PROP_ERROR(OP, n, ...) OP = __VA_ARGS__; if (LC_IsError(OP)) { n->kind = LC_ASTKind_Error; return OP; }
|
||||
#define LC_DECL_PROP_ERROR(OP, ...) OP = __VA_ARGS__; if (LC_IsError(OP)) { LC_MarkDeclError(decl); return OP; }
|
||||
@@ -113,14 +113,14 @@ LC_FUNCTION LC_Decl *LC_FindDeclInScope(DeclScope *scope, LC_Intern name) {
|
||||
|
||||
LC_FUNCTION LC_Decl *LC_GetLocalOrGlobalDecl(LC_Intern name) {
|
||||
LC_Decl *decl = LC_FindDeclInScope(L->resolver.active_scope, name);
|
||||
if (!decl && L->resolver.package->apackage.scope == L->resolver.active_scope) {
|
||||
if (!decl && L->resolver.package->apackage.ext->scope == L->resolver.active_scope) {
|
||||
decl = LC_FindDeclOnStack(&L->resolver.locals, name);
|
||||
}
|
||||
return decl;
|
||||
}
|
||||
|
||||
LC_FUNCTION LC_Operand LC_PutGlobalDecl(LC_Decl *decl) {
|
||||
LC_Operand LC_DECL_PROP_ERROR(op, LC_AddDeclToScope(L->resolver.package->apackage.scope, decl));
|
||||
LC_Operand LC_DECL_PROP_ERROR(op, LC_AddDeclToScope(L->resolver.package->apackage.ext->scope, decl));
|
||||
|
||||
// :Mangle global scope name
|
||||
if (!decl->is_foreign && decl->package != L->builtin_package) {
|
||||
@@ -153,7 +153,7 @@ LC_FUNCTION LC_Operand LC_PutGlobalDecl(LC_Decl *decl) {
|
||||
LC_FUNCTION LC_Operand LC_CreateLocalDecl(LC_DeclKind kind, LC_Intern name, LC_AST *ast) {
|
||||
LC_Decl *decl = LC_CreateDecl(kind, name, ast);
|
||||
decl->state = LC_DeclState_Resolving;
|
||||
LC_Operand LC_DECL_PROP_ERROR(operr0, LC_ThereIsNoDecl(L->resolver.package->apackage.scope, decl, true));
|
||||
LC_Operand LC_DECL_PROP_ERROR(operr0, LC_ThereIsNoDecl(L->resolver.package->apackage.ext->scope, decl, true));
|
||||
LC_AddDecl(&L->resolver.locals, decl);
|
||||
return LC_OPDecl(decl);
|
||||
}
|
||||
@@ -164,12 +164,12 @@ LC_FUNCTION LC_Decl *LC_AddConstIntDecl(char *key, int64_t value) {
|
||||
decl->state = LC_DeclState_Resolved;
|
||||
decl->type = L->tuntypedint;
|
||||
LC_Bigint_init_signed(&decl->v.i, value);
|
||||
LC_AddDeclToScope(L->resolver.package->apackage.scope, decl);
|
||||
LC_AddDeclToScope(L->resolver.package->apackage.ext->scope, decl);
|
||||
return decl;
|
||||
}
|
||||
|
||||
LC_FUNCTION LC_Decl *LC_GetBuiltin(LC_Intern name) {
|
||||
LC_Decl *decl = (LC_Decl *)LC_MapGetU64(L->builtin_package->apackage.scope, name);
|
||||
LC_Decl *decl = (LC_Decl *)LC_MapGetU64(L->builtin_package->apackage.ext->scope, name);
|
||||
return decl;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user