Improve API
This commit is contained in:
@@ -8,7 +8,7 @@ bool add_dynamic_array_macro() {
|
|||||||
LC_RegisterPackageDir("../examples");
|
LC_RegisterPackageDir("../examples");
|
||||||
|
|
||||||
LC_Intern name = LC_ILit("add_dynamic_array_macro");
|
LC_Intern name = LC_ILit("add_dynamic_array_macro");
|
||||||
LC_ParsePackagesUsingRegistry(name);
|
LC_ParsePackagesPass(name);
|
||||||
LC_BuildIfPass();
|
LC_BuildIfPass();
|
||||||
if (L->errors) {
|
if (L->errors) {
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
@@ -159,14 +159,14 @@ bool add_dynamic_array_macro() {
|
|||||||
LC_DLLAdd(file->afile.fdecl, file->afile.ldecl, ast);
|
LC_DLLAdd(file->afile.fdecl, file->afile.ldecl, ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
LC_OrderAndResolveTopLevelDecls(name);
|
LC_OrderAndResolveTopLevelPass(name);
|
||||||
LC_ResolveAllProcBodies();
|
LC_ResolveProcBodiesPass();
|
||||||
if (L->errors) {
|
if (L->errors) {
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LC_String code = LC_GenerateUnityBuild(L->ordered_packages);
|
LC_String code = LC_GenerateUnityBuild();
|
||||||
OS_MakeDir("examples/add_dynamic_array_macro");
|
OS_MakeDir("examples/add_dynamic_array_macro");
|
||||||
OS_WriteFile("examples/add_dynamic_array_macro/add_dynamic_array_macro.c", code);
|
OS_WriteFile("examples/add_dynamic_array_macro/add_dynamic_array_macro.c", code);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
bool OnDeclParsed_AddInstrumentation(bool discard, LC_AST *n) {
|
void OnDeclParsed_AddInstrumentation(LC_AST *n) {
|
||||||
if (discard) return discard;
|
|
||||||
|
|
||||||
if (n->kind == LC_ASTKind_DeclProc && n->dproc.body) {
|
if (n->kind == LC_ASTKind_DeclProc && n->dproc.body) {
|
||||||
if (n->dbase.name == LC_ILit("BeginProc")) return false;
|
if (n->dbase.name == LC_ILit("BeginProc")) return;
|
||||||
if (n->dbase.name == LC_ILit("EndProc")) return false;
|
if (n->dbase.name == LC_ILit("EndProc")) return;
|
||||||
|
|
||||||
LC_AST *body = n->dproc.body;
|
LC_AST *body = n->dproc.body;
|
||||||
|
|
||||||
@@ -13,7 +11,6 @@ bool OnDeclParsed_AddInstrumentation(bool discard, LC_AST *n) {
|
|||||||
LC_DLLAddFront(body->sblock.first, body->sblock.last, end);
|
LC_DLLAddFront(body->sblock.first, body->sblock.last, end);
|
||||||
LC_DLLAddFront(body->sblock.first, body->sblock.last, begin);
|
LC_DLLAddFront(body->sblock.first, body->sblock.last, begin);
|
||||||
}
|
}
|
||||||
return discard;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool add_instrumentation() {
|
bool add_instrumentation() {
|
||||||
@@ -26,37 +23,30 @@ bool add_instrumentation() {
|
|||||||
LC_RegisterPackageDir("../pkgs");
|
LC_RegisterPackageDir("../pkgs");
|
||||||
LC_RegisterPackageDir("../examples");
|
LC_RegisterPackageDir("../examples");
|
||||||
|
|
||||||
LC_Intern name = LC_ILit("add_instrumentation");
|
LC_Intern name = LC_ILit("add_instrumentation");
|
||||||
LC_ASTRefList packages = LC_ResolvePackageByName(name);
|
LC_ParseAndResolve(name);
|
||||||
if (L->errors) {
|
if (lang->errors) {
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugVerifyAST(packages);
|
DebugVerifyAST(L->ordered_packages);
|
||||||
if (L->errors) {
|
if (lang->errors) {
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
S8_String code = LC_GenerateUnityBuild(packages);
|
LC_String code = LC_GenerateUnityBuild();
|
||||||
|
LC_LangEnd(lang);
|
||||||
|
|
||||||
S8_String path = "examples/add_instrumentation/add_instrumentation.c";
|
S8_String path = "examples/add_instrumentation/add_instrumentation.c";
|
||||||
OS_MakeDir("examples");
|
OS_MakeDir("examples");
|
||||||
OS_MakeDir("examples/add_instrumentation");
|
OS_MakeDir("examples/add_instrumentation");
|
||||||
OS_WriteFile(path, code);
|
OS_WriteFile(path, code);
|
||||||
if (!UseCL) {
|
if (!UseCL) return true;
|
||||||
LC_LangEnd(lang);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
S8_String cmd = Fmt("cl %.*s -Zi -std:c11 -nologo -FC -Fd:examples/add_instrumentation/a.pdb -Fe:examples/add_instrumentation/add_instrumentation.exe %.*s", S8_Expand(path), S8_Expand(RaylibLIB));
|
S8_String cmd = Fmt("cl %.*s -Zi -std:c11 -nologo -FC -Fd:examples/add_instrumentation/a.pdb -Fe:examples/add_instrumentation/add_instrumentation.exe %.*s", S8_Expand(path), S8_Expand(RaylibLIB));
|
||||||
int errcode = Run(cmd);
|
int errcode = Run(cmd);
|
||||||
if (errcode != 0) {
|
if (errcode != 0) return false;
|
||||||
LC_LangEnd(lang);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Run("examples/add_instrumentation/add_instrumentation.exe");
|
|
||||||
|
|
||||||
LC_LangEnd(lang);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@ bool add_printf_format_check() {
|
|||||||
LC_RegisterPackageDir("../examples");
|
LC_RegisterPackageDir("../examples");
|
||||||
|
|
||||||
LC_Intern name = LC_ILit("add_printf_format_check");
|
LC_Intern name = LC_ILit("add_printf_format_check");
|
||||||
LC_ResolvePackageByName(name);
|
LC_ParseAndResolve(name);
|
||||||
|
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -26,23 +26,18 @@ bool add_source_location_macro() {
|
|||||||
LC_RegisterPackageDir("../examples/");
|
LC_RegisterPackageDir("../examples/");
|
||||||
LC_RegisterPackageDir("../pkgs");
|
LC_RegisterPackageDir("../pkgs");
|
||||||
|
|
||||||
LC_Intern name = LC_ILit("add_source_location_macro");
|
LC_Intern name = LC_ILit("add_source_location_macro");
|
||||||
LC_ASTRefList packages = LC_ResolvePackageByName(name);
|
LC_ParseAndResolve(name);
|
||||||
if (L->errors) {
|
|
||||||
LC_LangEnd(lang);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
S8_String dir = "examples/add_source_location_macro";
|
|
||||||
OS_MakeDir(dir);
|
|
||||||
S8_String cfile = "examples/add_source_location_macro/add_source_location_macro.c";
|
|
||||||
S8_String code = LC_GenerateUnityBuild(packages);
|
|
||||||
OS_WriteFile(cfile, code);
|
|
||||||
if (L->errors) {
|
if (L->errors) {
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LC_String code = LC_GenerateUnityBuild();
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
|
|
||||||
|
OS_MakeDir("examples/add_source_location_macro");
|
||||||
|
OS_WriteFile("examples/add_source_location_macro/add_source_location_macro.c", code);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,8 @@ bool create_raylib_window() {
|
|||||||
LC_RegisterPackageDir("../examples/");
|
LC_RegisterPackageDir("../examples/");
|
||||||
LC_RegisterPackageDir("../pkgs");
|
LC_RegisterPackageDir("../pkgs");
|
||||||
|
|
||||||
LC_Intern name = LC_ILit("create_raylib_window");
|
LC_Intern name = LC_ILit("create_raylib_window");
|
||||||
LC_ASTRefList packages = LC_ResolvePackageByName(name);
|
LC_ParseAndResolve(name);
|
||||||
if (L->errors) {
|
if (L->errors) {
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
return false;
|
return false;
|
||||||
@@ -15,7 +15,7 @@ bool create_raylib_window() {
|
|||||||
|
|
||||||
OS_MakeDir("examples/create_raylib_window");
|
OS_MakeDir("examples/create_raylib_window");
|
||||||
S8_String path = "examples/create_raylib_window/create_raylib_window.c";
|
S8_String path = "examples/create_raylib_window/create_raylib_window.c";
|
||||||
S8_String code = LC_GenerateUnityBuild(packages);
|
LC_String code = LC_GenerateUnityBuild();
|
||||||
OS_WriteFile(path, code);
|
OS_WriteFile(path, code);
|
||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ bool generate_type_info() {
|
|||||||
|
|
||||||
LC_Intern name = LC_ILit("generate_type_info");
|
LC_Intern name = LC_ILit("generate_type_info");
|
||||||
|
|
||||||
LC_ParsePackagesUsingRegistry(name);
|
LC_ParsePackagesPass(name);
|
||||||
LC_BuildIfPass();
|
LC_BuildIfPass();
|
||||||
if (L->errors) {
|
if (L->errors) {
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LC_OrderAndResolveTopLevelDecls(name);
|
LC_OrderAndResolveTopLevelPass(name);
|
||||||
if (L->errors) {
|
if (L->errors) {
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
return false;
|
return false;
|
||||||
@@ -55,9 +55,9 @@ bool generate_type_info() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Resolve decls again with new content added in
|
// Resolve decls again with new content added in
|
||||||
LC_OrderAndResolveTopLevelDecls(name);
|
LC_OrderAndResolveTopLevelPass(name);
|
||||||
LC_ResolveAllProcBodies();
|
LC_ResolveProcBodiesPass();
|
||||||
LC_FindUnusedLocalsAndRemoveUnusedGlobalDecls();
|
LC_FindUnusedLocalsAndRemoveUnusedGlobalDeclsPass();
|
||||||
|
|
||||||
bool result = L->errors ? false : true;
|
bool result = L->errors ? false : true;
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
|
|||||||
@@ -6,24 +6,23 @@ bool hello_world() {
|
|||||||
LC_RegisterPackageDir("../examples/");
|
LC_RegisterPackageDir("../examples/");
|
||||||
LC_RegisterPackageDir("../pkgs");
|
LC_RegisterPackageDir("../pkgs");
|
||||||
|
|
||||||
LC_Intern name = LC_ILit("hello_world");
|
LC_Intern name = LC_ILit("hello_world");
|
||||||
LC_ASTRefList packages = LC_ResolvePackageByName(name);
|
LC_ParseAndResolve(name);
|
||||||
if (L->errors) {
|
if (lang->errors) {
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
OS_MakeDir("examples/hello_world");
|
OS_MakeDir("examples/hello_world");
|
||||||
S8_String code = LC_GenerateUnityBuild(packages);
|
LC_ParseAndResolve(name);
|
||||||
|
LC_String code = LC_GenerateUnityBuild();
|
||||||
|
LC_LangEnd(lang);
|
||||||
|
|
||||||
S8_String path = "examples/hello_world/hello_world.c";
|
S8_String path = "examples/hello_world/hello_world.c";
|
||||||
OS_WriteFile(path, code);
|
OS_WriteFile(path, code);
|
||||||
|
|
||||||
bool success = true;
|
|
||||||
if (UseCL) {
|
if (UseCL) {
|
||||||
S8_String cmd = Fmt("cl %.*s -Zi -std:c11 -nologo -FC -Fd:examples/hello_world/hello_world.pdb -Fe:examples/hello_world/hello_world.exe %.*s", S8_Expand(path), S8_Expand(RaylibLIB));
|
S8_String cmd = Fmt("cl %.*s -nologo -FC -Fd:examples/hello_world/hello_world.pdb -Fe:examples/hello_world/hello_world.exe", S8_Expand(path));
|
||||||
if (Run(cmd) != 0) success = false;
|
if (Run(cmd) != 0) return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
LC_LangEnd(lang);
|
|
||||||
return success;
|
|
||||||
}
|
}
|
||||||
@@ -7,15 +7,15 @@ bool pathfinding_visualizer() {
|
|||||||
LC_RegisterPackageDir("../examples/");
|
LC_RegisterPackageDir("../examples/");
|
||||||
LC_RegisterPackageDir("../pkgs");
|
LC_RegisterPackageDir("../pkgs");
|
||||||
|
|
||||||
LC_Intern name = LC_ILit("pathfinding_visualizer");
|
LC_Intern name = LC_ILit("pathfinding_visualizer");
|
||||||
LC_ASTRefList packages = LC_ResolvePackageByName(name);
|
LC_ParseAndResolve(name);
|
||||||
LC_FindUnusedLocalsAndRemoveUnusedGlobalDecls();
|
LC_FindUnusedLocalsAndRemoveUnusedGlobalDeclsPass();
|
||||||
if (L->errors) {
|
if (L->errors) {
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugVerifyAST(packages);
|
DebugVerifyAST(L->ordered_packages);
|
||||||
if (L->errors) {
|
if (L->errors) {
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
return false;
|
return false;
|
||||||
@@ -23,7 +23,7 @@ bool pathfinding_visualizer() {
|
|||||||
|
|
||||||
OS_MakeDir("examples");
|
OS_MakeDir("examples");
|
||||||
OS_MakeDir("examples/pathfinding_visualizer");
|
OS_MakeDir("examples/pathfinding_visualizer");
|
||||||
S8_String code = LC_GenerateUnityBuild(packages);
|
LC_String code = LC_GenerateUnityBuild();
|
||||||
S8_String path = "examples/pathfinding_visualizer/pathfinding_visualizer.c";
|
S8_String path = "examples/pathfinding_visualizer/pathfinding_visualizer.c";
|
||||||
OS_WriteFile(path, code);
|
OS_WriteFile(path, code);
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ bool sandbox() {
|
|||||||
LC_RegisterPackageDir("../examples");
|
LC_RegisterPackageDir("../examples");
|
||||||
|
|
||||||
LC_Intern name = LC_ILit("sandbox");
|
LC_Intern name = LC_ILit("sandbox");
|
||||||
LC_ParsePackagesUsingRegistry(name);
|
LC_ParsePackagesPass(name);
|
||||||
LC_BuildIfPass();
|
LC_BuildIfPass();
|
||||||
if (L->errors) {
|
if (L->errors) {
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
@@ -97,14 +97,14 @@ bool sandbox() {
|
|||||||
LC_DLLAdd(package->apackage.ffile, package->apackage.lfile, new_array_file);
|
LC_DLLAdd(package->apackage.ffile, package->apackage.lfile, new_array_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
LC_OrderAndResolveTopLevelDecls(name);
|
LC_OrderAndResolveTopLevelPass(name);
|
||||||
LC_ResolveAllProcBodies();
|
LC_ResolveProcBodiesPass();
|
||||||
if (L->errors) {
|
if (L->errors) {
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
S8_String code = LC_GenerateUnityBuild(L->ordered_packages);
|
LC_String code = LC_GenerateUnityBuild();
|
||||||
S8_String path = "examples/sandbox/sandbox.c";
|
S8_String path = "examples/sandbox/sandbox.c";
|
||||||
|
|
||||||
OS_MakeDir("examples/sandbox");
|
OS_MakeDir("examples/sandbox");
|
||||||
|
|||||||
@@ -8,20 +8,20 @@ bool text_editor() {
|
|||||||
LC_RegisterPackageDir("../pkgs");
|
LC_RegisterPackageDir("../pkgs");
|
||||||
LC_RegisterPackageDir("../examples");
|
LC_RegisterPackageDir("../examples");
|
||||||
|
|
||||||
LC_Intern name = LC_ILit("text_editor");
|
LC_Intern name = LC_ILit("text_editor");
|
||||||
LC_ASTRefList packages = LC_ResolvePackageByName(name);
|
LC_ParseAndResolve(name);
|
||||||
if (L->errors) return false;
|
if (L->errors) return false;
|
||||||
|
|
||||||
DebugVerifyAST(packages);
|
DebugVerifyAST(L->ordered_packages);
|
||||||
if (L->errors) return false;
|
if (L->errors) return false;
|
||||||
|
|
||||||
LC_FindUnusedLocalsAndRemoveUnusedGlobalDecls();
|
LC_FindUnusedLocalsAndRemoveUnusedGlobalDeclsPass();
|
||||||
|
|
||||||
OS_MakeDir("examples");
|
OS_MakeDir("examples");
|
||||||
OS_MakeDir("examples/text_editor");
|
OS_MakeDir("examples/text_editor");
|
||||||
OS_CopyFile(RaylibDLL, "examples/text_editor/raylib.dll", true);
|
OS_CopyFile(RaylibDLL, "examples/text_editor/raylib.dll", true);
|
||||||
|
|
||||||
S8_String code = LC_GenerateUnityBuild(packages);
|
LC_String code = LC_GenerateUnityBuild();
|
||||||
S8_String path = "examples/text_editor/text_editor.c";
|
S8_String path = "examples/text_editor/text_editor.c";
|
||||||
OS_WriteFile(path, code);
|
OS_WriteFile(path, code);
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ bool use_as_data_format_with_typechecking() {
|
|||||||
LC_RegisterPackageDir("../examples/");
|
LC_RegisterPackageDir("../examples/");
|
||||||
LC_RegisterPackageDir("../pkgs");
|
LC_RegisterPackageDir("../pkgs");
|
||||||
|
|
||||||
LC_Intern name = LC_ILit("use_as_data_format_with_typechecking");
|
LC_Intern name = LC_ILit("use_as_data_format_with_typechecking");
|
||||||
LC_ASTRefList packages = LC_ResolvePackageByName(name);
|
LC_ParseAndResolve(name);
|
||||||
if (L->errors) {
|
if (L->errors) {
|
||||||
LC_LangEnd(lang);
|
LC_LangEnd(lang);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ void TestReadme() {
|
|||||||
LC_RegisterPackageDir("../pkgs");
|
LC_RegisterPackageDir("../pkgs");
|
||||||
LC_Intern name = LC_ILit("readme_test");
|
LC_Intern name = LC_ILit("readme_test");
|
||||||
LC_AddSingleFilePackage(name, readme_path);
|
LC_AddSingleFilePackage(name, readme_path);
|
||||||
LC_ResolvePackageByName(name);
|
LC_ParseAndResolve(name);
|
||||||
// LC_FindUnusedLocalsAndRemoveUnusedGlobalDecls();
|
// LC_FindUnusedLocalsAndRemoveUnusedGlobalDeclsPass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -276,16 +276,16 @@ void RunTestFile(TestDesc it) {
|
|||||||
LC_AddSingleFilePackage(name, it.absolute_path);
|
LC_AddSingleFilePackage(name, it.absolute_path);
|
||||||
|
|
||||||
L->first_package = name;
|
L->first_package = name;
|
||||||
LC_ParsePackagesUsingRegistry(name);
|
LC_ParsePackagesPass(name);
|
||||||
LC_BuildIfPass();
|
LC_BuildIfPass();
|
||||||
if (L->errors) {
|
if (L->errors) {
|
||||||
result = Failed_Parse;
|
result = Failed_Parse;
|
||||||
goto end_of_test;
|
goto end_of_test;
|
||||||
}
|
}
|
||||||
|
|
||||||
LC_OrderAndResolveTopLevelDecls(name);
|
LC_OrderAndResolveTopLevelPass(name);
|
||||||
LC_ResolveAllProcBodies();
|
LC_ResolveProcBodiesPass();
|
||||||
LC_FindUnusedLocalsAndRemoveUnusedGlobalDecls();
|
LC_FindUnusedLocalsAndRemoveUnusedGlobalDeclsPass();
|
||||||
if (L->errors) {
|
if (L->errors) {
|
||||||
result = Failed_Resolve;
|
result = Failed_Resolve;
|
||||||
goto end_of_test;
|
goto end_of_test;
|
||||||
@@ -294,7 +294,7 @@ void RunTestFile(TestDesc it) {
|
|||||||
DebugVerifyAST(L->ordered_packages);
|
DebugVerifyAST(L->ordered_packages);
|
||||||
|
|
||||||
OS_MakeDir(it.filename);
|
OS_MakeDir(it.filename);
|
||||||
code = LC_GenerateUnityBuild(L->ordered_packages);
|
code = LC_GenerateUnityBuild();
|
||||||
out_path = S8_Format(L->arena, "%.*s/%.*s.c", S8_Expand(it.filename), S8_Expand(it.filename));
|
out_path = S8_Format(L->arena, "%.*s/%.*s.c", S8_Expand(it.filename), S8_Expand(it.filename));
|
||||||
OS_WriteFile(out_path, code);
|
OS_WriteFile(out_path, code);
|
||||||
|
|
||||||
@@ -333,15 +333,15 @@ void RunTestDir(TestDesc it, S8_String package_name) {
|
|||||||
LC_Intern first_package = LC_ILit(package_name.str);
|
LC_Intern first_package = LC_ILit(package_name.str);
|
||||||
LC_RegisterPackageDir(it.absolute_path.str);
|
LC_RegisterPackageDir(it.absolute_path.str);
|
||||||
LC_RegisterPackageDir("../../pkgs");
|
LC_RegisterPackageDir("../../pkgs");
|
||||||
LC_ASTRefList packages = LC_ResolvePackageByName(first_package);
|
LC_ParseAndResolve(first_package);
|
||||||
LC_FindUnusedLocalsAndRemoveUnusedGlobalDecls();
|
LC_FindUnusedLocalsAndRemoveUnusedGlobalDeclsPass();
|
||||||
if (L->errors != 0) result = Failed_Package;
|
if (L->errors != 0) result = Failed_Package;
|
||||||
|
|
||||||
if (result == OK && T->expected_result == OK) {
|
if (result == OK && T->expected_result == OK) {
|
||||||
DebugVerifyAST(packages);
|
DebugVerifyAST(L->ordered_packages);
|
||||||
|
|
||||||
OS_MakeDir(it.filename);
|
OS_MakeDir(it.filename);
|
||||||
S8_String code = LC_GenerateUnityBuild(packages);
|
S8_String code = LC_GenerateUnityBuild();
|
||||||
S8_String out_path = S8_Format(L->arena, "%.*s/%.*s.c", S8_Expand(it.filename), S8_Expand(it.filename));
|
S8_String out_path = S8_Format(L->arena, "%.*s/%.*s.c", S8_Expand(it.filename), S8_Expand(it.filename));
|
||||||
OS_WriteFile(out_path, code);
|
OS_WriteFile(out_path, code);
|
||||||
if (!T->dont_run) result = Compile(it.filename, out_path);
|
if (!T->dont_run) result = Compile(it.filename, out_path);
|
||||||
@@ -437,16 +437,16 @@ void RunTests() {
|
|||||||
lang->breakpoint_on_error = BreakpointOnError;
|
lang->breakpoint_on_error = BreakpointOnError;
|
||||||
LC_LangBegin(lang);
|
LC_LangBegin(lang);
|
||||||
LC_RegisterPackageDir(T->path);
|
LC_RegisterPackageDir(T->path);
|
||||||
LC_ASTRefList dll_packages = LC_ResolvePackageByName(LC_ILit("dll"));
|
LC_ParseAndResolve(LC_ILit("dll"));
|
||||||
LC_ASTRefList exe_packages = LC_ResolvePackageByName(LC_ILit("exe"));
|
LC_ParseAndResolve(LC_ILit("exe"));
|
||||||
result = L->errors >= 1 ? Failed_Package : OK;
|
result = L->errors >= 1 ? Failed_Package : OK;
|
||||||
|
|
||||||
if (result == OK) {
|
if (result == OK) {
|
||||||
DebugVerifyAST(dll_packages);
|
DebugVerifyAST(L->ordered_packages);
|
||||||
// DebugVerifyAST(exe_packages);
|
// DebugVerifyAST(exe_packages);
|
||||||
|
|
||||||
S8_String prev = PushDir("example_ui_and_hot_reloading");
|
S8_String prev = PushDir("example_ui_and_hot_reloading");
|
||||||
S8_String code = LC_GenerateUnityBuild(exe_packages);
|
LC_String code = LC_GenerateUnityBuild();
|
||||||
OS_WriteFile("example_ui_and_hot_reloading", code);
|
OS_WriteFile("example_ui_and_hot_reloading", code);
|
||||||
OS_SetWorkingDir(prev);
|
OS_SetWorkingDir(prev);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ LC_FUNCTION LC_Map LC_CountDeclRefs(LC_Arena *arena) {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
LC_FUNCTION void LC_RemoveUnreferencedGlobalDecls(LC_Map *map_of_visits) {
|
LC_FUNCTION void LC_RemoveUnreferencedGlobalDeclsPass(LC_Map *map_of_visits) {
|
||||||
for (LC_ASTRef *it = L->ordered_packages.first; it; it = it->next) {
|
for (LC_ASTRef *it = L->ordered_packages.first; it; it = it->next) {
|
||||||
for (LC_Decl *decl = it->ast->apackage.ext->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);
|
intptr_t ref_count = (intptr_t)LC_MapGetP(map_of_visits, decl);
|
||||||
@@ -43,7 +43,7 @@ LC_FUNCTION void LC_RemoveUnreferencedGlobalDecls(LC_Map *map_of_visits) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LC_FUNCTION void LC_ErrorOnUnreferencedLocals(LC_Map *map_of_visits) {
|
LC_FUNCTION void LC_ErrorOnUnreferencedLocalsPass(LC_Map *map_of_visits) {
|
||||||
LC_Decl *first = (LC_Decl *)L->decl_arena->memory.data;
|
LC_Decl *first = (LC_Decl *)L->decl_arena->memory.data;
|
||||||
for (int i = 0; i < L->decl_count; i += 1) {
|
for (int i = 0; i < L->decl_count; i += 1) {
|
||||||
LC_Decl *decl = first + i;
|
LC_Decl *decl = first + i;
|
||||||
@@ -60,13 +60,13 @@ LC_FUNCTION void LC_ErrorOnUnreferencedLocals(LC_Map *map_of_visits) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LC_FUNCTION void LC_FindUnusedLocalsAndRemoveUnusedGlobalDecls(void) {
|
LC_FUNCTION void LC_FindUnusedLocalsAndRemoveUnusedGlobalDeclsPass(void) {
|
||||||
if (L->errors) return;
|
if (L->errors) return;
|
||||||
LC_TempArena check = LC_BeginTemp(L->arena);
|
LC_TempArena check = LC_BeginTemp(L->arena);
|
||||||
|
|
||||||
LC_Map map = LC_CountDeclRefs(check.arena);
|
LC_Map map = LC_CountDeclRefs(check.arena);
|
||||||
LC_ErrorOnUnreferencedLocals(&map);
|
LC_ErrorOnUnreferencedLocalsPass(&map);
|
||||||
LC_RemoveUnreferencedGlobalDecls(&map);
|
LC_RemoveUnreferencedGlobalDeclsPass(&map);
|
||||||
|
|
||||||
LC_EndTemp(check);
|
LC_EndTemp(check);
|
||||||
}
|
}
|
||||||
@@ -449,6 +449,7 @@ LC_FUNCTION LC_Lex *LC_LexStream(char *file, char *str, int line) {
|
|||||||
LC_LexNext(x, t);
|
LC_LexNext(x, t);
|
||||||
if (t->kind == LC_TokenKind_EOF) break;
|
if (t->kind == LC_TokenKind_EOF) break;
|
||||||
}
|
}
|
||||||
|
if (L->on_tokens_lexed) L->on_tokens_lexed(x);
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
@@ -530,6 +531,7 @@ LC_FUNCTION void LC_InternTokens(LC_Lex *x) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (L->on_tokens_interned) L->on_tokens_interned(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef LC_IF
|
#undef LC_IF
|
||||||
|
|||||||
@@ -966,7 +966,9 @@ struct LC_Lang {
|
|||||||
bool breakpoint_on_error;
|
bool breakpoint_on_error;
|
||||||
bool use_colored_terminal_output;
|
bool use_colored_terminal_output;
|
||||||
|
|
||||||
bool (*on_decl_parsed)(bool discarded, LC_AST *n); // returning 'true' from here indicates that declaration should be discarded
|
void (*on_tokens_lexed)(LC_Lex *x);
|
||||||
|
void (*on_tokens_interned)(LC_Lex *x);
|
||||||
|
void (*on_decl_parsed)(LC_AST *n);
|
||||||
void (*on_expr_parsed)(LC_AST *n);
|
void (*on_expr_parsed)(LC_AST *n);
|
||||||
void (*on_stmt_parsed)(LC_AST *n);
|
void (*on_stmt_parsed)(LC_AST *n);
|
||||||
void (*on_typespec_parsed)(LC_AST *n);
|
void (*on_typespec_parsed)(LC_AST *n);
|
||||||
@@ -982,7 +984,6 @@ struct LC_Lang {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern LC_THREAD_LOCAL LC_Lang *L;
|
extern LC_THREAD_LOCAL LC_Lang *L;
|
||||||
extern LC_Operand LC_OPNull;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Main @api
|
// Main @api
|
||||||
@@ -992,23 +993,23 @@ LC_FUNCTION LC_Lang *LC_LangAlloc(void); // This allocates memory for LC_
|
|||||||
LC_FUNCTION void LC_LangBegin(LC_Lang *l); // Prepare for compilation: init types, init builtins, set architecture variables stuff like that
|
LC_FUNCTION void LC_LangBegin(LC_Lang *l); // Prepare for compilation: init types, init builtins, set architecture variables stuff like that
|
||||||
LC_FUNCTION void LC_LangEnd(LC_Lang *lang); // Deallocate language memory
|
LC_FUNCTION void LC_LangEnd(LC_Lang *lang); // Deallocate language memory
|
||||||
|
|
||||||
LC_FUNCTION void LC_RegisterPackageDir(char *dir); // Add a package search directory
|
LC_FUNCTION void LC_RegisterPackageDir(char *dir); // Add a package search directory
|
||||||
LC_FUNCTION LC_ASTRefList LC_ResolvePackageByName(LC_Intern name); // Fully resolve a package and all it's dependences
|
LC_FUNCTION void LC_ParseAndResolve(LC_Intern name); // Fully resolve a package and all it's dependences
|
||||||
LC_FUNCTION LC_String LC_GenerateUnityBuild(LC_ASTRefList packages); // Generate the C program and return as a string
|
LC_FUNCTION LC_String LC_GenerateUnityBuild(void); // Generate the C program and return as a string
|
||||||
|
|
||||||
// Smaller passes for AST modification
|
// Smaller passes for AST modification
|
||||||
LC_FUNCTION void LC_ParsePackagesUsingRegistry(LC_Intern name); // These 3 functions are equivalent to LC_ResolvePackageByName,
|
LC_FUNCTION void LC_ParsePackagesPass(LC_Intern name); // These functions are equivalent to LC_ParseAndResolve,
|
||||||
LC_FUNCTION void LC_OrderAndResolveTopLevelDecls(LC_Intern name); // you can use them to hook into the compilation process - you can modify the AST
|
LC_FUNCTION void LC_BuildIfPass(void); // you can use them to hook into the compilation process - you can modify the AST
|
||||||
LC_FUNCTION void LC_ResolveAllProcBodies(void); // before resolving or use resolved top declarations to generate some code.
|
LC_FUNCTION void LC_OrderAndResolveTopLevelPass(LC_Intern name); // before resolving or use resolved top declarations to generate some code.
|
||||||
// The Parse and Order functions can be called multiple times to accommodate this.
|
LC_FUNCTION void LC_ResolveProcBodiesPass(void); // The Parse and Order functions can be called multiple times to accommodate this.
|
||||||
|
|
||||||
// Extended pass / optimization
|
// Extended pass / optimization
|
||||||
LC_FUNCTION void LC_FindUnusedLocalsAndRemoveUnusedGlobalDecls(void); // Extended pass that you can execute once you have resolved all packages
|
LC_FUNCTION void LC_FindUnusedLocalsAndRemoveUnusedGlobalDeclsPass(void); // Extended pass that you can execute once you have resolved all packages
|
||||||
|
|
||||||
// These three functions are used to implement LC_FindUnusedLocalsAndRemoveUnusedGlobalDecls
|
// These three functions are used to implement LC_FindUnusedLocalsAndRemoveUnusedGlobalDeclsPass
|
||||||
LC_FUNCTION LC_Map LC_CountDeclRefs(LC_Arena *arena);
|
LC_FUNCTION LC_Map LC_CountDeclRefs(LC_Arena *arena);
|
||||||
LC_FUNCTION void LC_RemoveUnreferencedGlobalDecls(LC_Map *map_of_visits);
|
LC_FUNCTION void LC_RemoveUnreferencedGlobalDeclsPass(LC_Map *map_of_visits);
|
||||||
LC_FUNCTION void LC_ErrorOnUnreferencedLocals(LC_Map *map_of_visits);
|
LC_FUNCTION void LC_ErrorOnUnreferencedLocalsPass(LC_Map *map_of_visits);
|
||||||
|
|
||||||
// Notes
|
// Notes
|
||||||
LC_FUNCTION void LC_DeclareNote(LC_Intern intern);
|
LC_FUNCTION void LC_DeclareNote(LC_Intern intern);
|
||||||
@@ -1231,6 +1232,7 @@ LC_FUNCTION LC_Operand LC_ResolveTypeCast(LC_AST *pos, LC_Operan
|
|||||||
LC_FUNCTION LC_Operand LC_ResolveTypeVarDecl(LC_AST *pos, LC_Operand t, LC_Operand v);
|
LC_FUNCTION LC_Operand LC_ResolveTypeVarDecl(LC_AST *pos, LC_Operand t, LC_Operand v);
|
||||||
LC_FUNCTION LC_Operand LC_ResolveTypeAggregate(LC_AST *pos, LC_Type *type);
|
LC_FUNCTION LC_Operand LC_ResolveTypeAggregate(LC_AST *pos, LC_Type *type);
|
||||||
|
|
||||||
|
extern LC_Operand LC_OPNull;
|
||||||
LC_FUNCTION LC_Operand LC_OPError(void);
|
LC_FUNCTION LC_Operand LC_OPError(void);
|
||||||
LC_FUNCTION LC_Operand LC_OPConstType(LC_Type *type);
|
LC_FUNCTION LC_Operand LC_OPConstType(LC_Type *type);
|
||||||
LC_FUNCTION LC_Operand LC_OPDecl(LC_Decl *decl);
|
LC_FUNCTION LC_Operand LC_OPDecl(LC_Decl *decl);
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ LC_FUNCTION void LC_ParsePackage(LC_AST *n) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LC_FUNCTION void LC_ParsePackagesUsingRegistry(LC_Intern name) {
|
LC_FUNCTION void LC_ParsePackagesPass(LC_Intern name) {
|
||||||
LC_AST *n = LC_GetPackageByName(name);
|
LC_AST *n = LC_GetPackageByName(name);
|
||||||
if (!n) {
|
if (!n) {
|
||||||
LC_SendErrorMessagef(NULL, NULL, "no package with name '%s'\n", name);
|
LC_SendErrorMessagef(NULL, NULL, "no package with name '%s'\n", name);
|
||||||
@@ -218,7 +218,7 @@ LC_FUNCTION void LC_ParsePackagesUsingRegistry(LC_Intern name) {
|
|||||||
LC_ParsePackage(n);
|
LC_ParsePackage(n);
|
||||||
LC_ASTRefList imports = LC_GetPackageImports(n);
|
LC_ASTRefList imports = LC_GetPackageImports(n);
|
||||||
for (LC_ASTRef *it = imports.first; it; it = it->next) {
|
for (LC_ASTRef *it = imports.first; it; it = it->next) {
|
||||||
LC_ParsePackagesUsingRegistry(it->ast->gimport.path);
|
LC_ParsePackagesPass(it->ast->gimport.path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +320,7 @@ LC_FUNCTION LC_AST *LC_OrderPackagesAndBasicResolve(LC_AST *pos, LC_Intern name)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
LC_FUNCTION void LC_OrderAndResolveTopLevelDecls(LC_Intern name) {
|
LC_FUNCTION void LC_OrderAndResolveTopLevelPass(LC_Intern name) {
|
||||||
L->first_package = name;
|
L->first_package = name;
|
||||||
LC_OrderPackagesAndBasicResolve(NULL, name);
|
LC_OrderPackagesAndBasicResolve(NULL, name);
|
||||||
|
|
||||||
@@ -334,7 +334,7 @@ LC_FUNCTION void LC_OrderAndResolveTopLevelDecls(LC_Intern name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LC_FUNCTION void LC_ResolveAllProcBodies(void) {
|
LC_FUNCTION void LC_ResolveProcBodiesPass(void) {
|
||||||
// We don't need to check errors, only valid packages should have been put into
|
// We don't need to check errors, only valid packages should have been put into
|
||||||
// the list.
|
// the list.
|
||||||
for (LC_ASTRef *it = L->ordered_packages.first; it; it = it->next) {
|
for (LC_ASTRef *it = L->ordered_packages.first; it; it = it->next) {
|
||||||
@@ -344,19 +344,18 @@ LC_FUNCTION void LC_ResolveAllProcBodies(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LC_FUNCTION LC_ASTRefList LC_ResolvePackageByName(LC_Intern name) {
|
LC_FUNCTION void LC_ParseAndResolve(LC_Intern name) {
|
||||||
LC_ParsePackagesUsingRegistry(name);
|
LC_ParsePackagesPass(name);
|
||||||
LC_BuildIfPass();
|
LC_BuildIfPass();
|
||||||
LC_ASTRefList empty = {0};
|
if (L->errors) return;
|
||||||
if (L->errors) return empty;
|
|
||||||
|
|
||||||
LC_OrderAndResolveTopLevelDecls(name);
|
LC_OrderAndResolveTopLevelPass(name);
|
||||||
LC_ResolveAllProcBodies();
|
LC_ResolveProcBodiesPass();
|
||||||
return L->ordered_packages;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LC_FUNCTION LC_String LC_GenerateUnityBuild(LC_ASTRefList packages) {
|
LC_FUNCTION LC_String LC_GenerateUnityBuild(void) {
|
||||||
if (L->errors) return LC_MakeEmptyString();
|
if (L->errors) return LC_MakeEmptyString();
|
||||||
|
LC_ASTRefList packages = L->ordered_packages;
|
||||||
|
|
||||||
LC_BeginStringGen(L->arena);
|
LC_BeginStringGen(L->arena);
|
||||||
|
|
||||||
|
|||||||
@@ -987,8 +987,8 @@ LC_FUNCTION LC_AST *LC_ParseFileEx(LC_AST *package) {
|
|||||||
if (decl->kind == LC_ASTKind_Error) {
|
if (decl->kind == LC_ASTKind_Error) {
|
||||||
LC_EatUntilNextValidDecl();
|
LC_EatUntilNextValidDecl();
|
||||||
} else {
|
} else {
|
||||||
if (L->on_decl_parsed) L->on_decl_parsed(false, decl);
|
|
||||||
LC_DLLAdd(n->afile.fdecl, n->afile.ldecl, decl);
|
LC_DLLAdd(n->afile.fdecl, n->afile.ldecl, decl);
|
||||||
|
if (L->on_decl_parsed) L->on_decl_parsed(decl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ void WASM_EXPORT(test)(void) {
|
|||||||
|
|
||||||
LC_Intern name = LC_ILit("file");
|
LC_Intern name = LC_ILit("file");
|
||||||
LC_AddSingleFilePackage(name, LC_Lit("file.lc"));
|
LC_AddSingleFilePackage(name, LC_Lit("file.lc"));
|
||||||
LC_ASTRefList packages = LC_ResolvePackageByName(name);
|
LC_ASTRefList packages = LC_ParseAndResolve(name);
|
||||||
|
|
||||||
if (L->errors == 0) {
|
if (L->errors == 0) {
|
||||||
LC_BeginStringGen(L->arena);
|
LC_BeginStringGen(L->arena);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LC_Intern name = LC_InternStrLen(package.str, (int)package.len);
|
LC_Intern name = LC_InternStrLen(package.str, (int)package.len);
|
||||||
LC_ASTRefList packages = LC_ResolvePackageByName(name);
|
LC_ASTRefList packages = LC_ParseAndResolve(name);
|
||||||
if (lang->errors) return 1;
|
if (lang->errors) return 1;
|
||||||
|
|
||||||
LC_String code = LC_GenerateUnityBuild(packages);
|
LC_String code = LC_GenerateUnityBuild(packages);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LC_Intern name = LC_InternStrLen(package.str, (int)package.len);
|
LC_Intern name = LC_InternStrLen(package.str, (int)package.len);
|
||||||
LC_ASTRefList packages = LC_ResolvePackageByName(name);
|
LC_ASTRefList packages = LC_ParseAndResolve(name);
|
||||||
if (lang->errors) return 1;
|
if (lang->errors) return 1;
|
||||||
|
|
||||||
LC_String code = LC_GenerateUnityBuild(packages);
|
LC_String code = LC_GenerateUnityBuild(packages);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ int main(int argc, char **argv) {
|
|||||||
S8_For(it, dirs) { LC_RegisterPackageDir(it->string.str); }
|
S8_For(it, dirs) { LC_RegisterPackageDir(it->string.str); }
|
||||||
|
|
||||||
LC_Intern name = LC_InternStrLen(package.str, (int)package.len);
|
LC_Intern name = LC_InternStrLen(package.str, (int)package.len);
|
||||||
LC_ASTRefList packages = LC_ResolvePackageByName(name);
|
LC_ASTRefList packages = LC_ParseAndResolve(name);
|
||||||
if (lang->errors) return 1;
|
if (lang->errors) return 1;
|
||||||
|
|
||||||
S8_String code = LC_GenerateUnityBuild(packages);
|
S8_String code = LC_GenerateUnityBuild(packages);
|
||||||
|
|||||||
Reference in New Issue
Block a user