new curly bracket coding convention

This commit is contained in:
cozis
2022-04-04 00:07:33 +02:00
parent 29e80c6319
commit 07137b50c6
28 changed files with 4036 additions and 4059 deletions
+138 -139
View File
@@ -57,14 +57,14 @@ static void print_error(const char *type, Error *error)
#ifdef DEBUG
if(error->file != NULL)
{
if(error->line > 0 && error->func != NULL)
fprintf(stderr, " (Reported in %s:%d in %s)", error->file, error->line, error->func);
else if(error->line > 0 && error->func == NULL)
fprintf(stderr, " (Reported in %s:%d)", error->file, error->line);
else if(error->line < 1 && error->func != NULL)
fprintf(stderr, " (Reported in %s in %s)", error->file, error->func);
}
{
if(error->line > 0 && error->func != NULL)
fprintf(stderr, " (Reported in %s:%d in %s)", error->file, error->line, error->func);
else if(error->line > 0 && error->func == NULL)
fprintf(stderr, " (Reported in %s:%d)", error->file, error->line);
else if(error->line < 1 && error->func != NULL)
fprintf(stderr, " (Reported in %s in %s)", error->file, error->func);
}
#endif
fprintf(stderr, "\n");
@@ -78,10 +78,10 @@ static Executable *build(Source *src)
BPAlloc *alloc = BPAlloc_Init(-1);
if(alloc == NULL)
{
fprintf(stderr, "Internal Error: Couldn't allocate bump-pointer allocator to hold the AST.\n");
return 0;
}
{
fprintf(stderr, "Internal Error: Couldn't allocate bump-pointer allocator to hold the AST.\n");
return 0;
}
Error error;
Error_Init(&error);
@@ -91,13 +91,13 @@ static Executable *build(Source *src)
AST *ast = parse(src, alloc, &error);
if(ast == NULL)
{
assert(error.occurred);
print_error("Parsing", &error);
Error_Free(&error);
BPAlloc_Free(alloc);
return 0;
}
{
assert(error.occurred);
print_error("Parsing", &error);
Error_Free(&error);
BPAlloc_Free(alloc);
return 0;
}
exe = compile(ast, alloc, &error);
@@ -106,12 +106,12 @@ static Executable *build(Source *src)
BPAlloc_Free(alloc);
if(exe == NULL)
{
assert(error.occurred);
print_error("Compilation", &error);
Error_Free(&error);
return 0;
}
{
assert(error.occurred);
print_error("Compilation", &error);
Error_Free(&error);
return 0;
}
return exe;
}
@@ -123,18 +123,18 @@ static _Bool interpret(Source *src)
if(exe == NULL)
return 0;
Runtime *runt = Runtime_New(-1, -1, NULL, NULL);
Runtime *runt = Runtime_New(-1, 1024*1024, NULL, NULL);
if(runt == NULL)
{
Error error;
Error_Init(&error);
Error_Report(&error, 1, "Couldn't initialize runtime");
print_error(NULL, &error);
Error_Free(&error);
Executable_Free(exe);
return 0;
}
{
Error error;
Error_Init(&error);
Error_Report(&error, 1, "Couldn't initialize runtime");
print_error(NULL, &error);
Error_Free(&error);
Executable_Free(exe);
return 0;
}
// We use a [RuntimeError] instead of a simple [Error]
// because the [RuntimeError] makes a snapshot of the
@@ -148,14 +148,14 @@ static _Bool interpret(Source *src)
Object *bins = Object_NewStaticMap(bins_basic, runt, (Error*) &error);
if(bins == NULL)
{
assert(error.base.occurred == 1);
print_error(NULL, (Error*) &error);
RuntimeError_Free(&error);
Executable_Free(exe);
Runtime_Free(runt);
return 0;
}
{
assert(error.base.occurred == 1);
print_error(NULL, (Error*) &error);
RuntimeError_Free(&error);
Executable_Free(exe);
Runtime_Free(runt);
return 0;
}
Runtime_SetBuiltins(runt, bins);
@@ -165,16 +165,16 @@ static _Bool interpret(Source *src)
// now because it may be moved by the garbage collector.
if(o == NULL)
{
print_error("Runtime", (Error*) &error);
{
print_error("Runtime", (Error*) &error);
if(error.snapshot == NULL)
fprintf(stderr, "No snapshot available.\n");
else
Snapshot_Print(error.snapshot, stderr);
if(error.snapshot == NULL)
fprintf(stderr, "No snapshot available.\n");
else
Snapshot_Print(error.snapshot, stderr);
RuntimeError_Free(&error);
}
RuntimeError_Free(&error);
}
Runtime_Free(runt);
Executable_Free(exe);
@@ -201,12 +201,12 @@ static _Bool interpret_file(const char *file)
Source *src = Source_FromFile(file, &error);
if(src == NULL)
{
assert(error.occurred == 1);
print_error(NULL, &error);
Error_Free(&error);
return 0;
}
{
assert(error.occurred == 1);
print_error(NULL, &error);
Error_Free(&error);
return 0;
}
_Bool r = interpret(src);
@@ -222,12 +222,12 @@ static _Bool interpret_code(const char *code)
Source *src = Source_FromString(NULL, code, -1, &error);
if(src == NULL)
{
assert(error.occurred);
print_error(NULL, &error);
Error_Free(&error);
return 0;
}
{
assert(error.occurred);
print_error(NULL, &error);
Error_Free(&error);
return 0;
}
_Bool r = interpret(src);
@@ -243,12 +243,12 @@ static _Bool disassemble_file(const char *file)
Source *src = Source_FromFile(file, &error);
if(src == NULL)
{
assert(error.occurred == 1);
print_error(NULL, &error);
Error_Free(&error);
return 0;
}
{
assert(error.occurred == 1);
print_error(NULL, &error);
Error_Free(&error);
return 0;
}
_Bool r = disassemble(src);
@@ -264,12 +264,12 @@ static _Bool disassemble_code(const char *code)
Source *src = Source_FromString(NULL, code, -1, &error);
if(src == NULL)
{
assert(error.occurred);
print_error(NULL, &error);
Error_Free(&error);
return 0;
}
{
assert(error.occurred);
print_error(NULL, &error);
Error_Free(&error);
return 0;
}
_Bool r = disassemble(src);
@@ -282,82 +282,81 @@ int main(int argc, char **argv)
assert(argc > 0);
if(argc == 1)
{
// $ noja
fprintf(stderr, "Error: Incorrect usage.\n\n");
fprintf(stderr, usage);
return -1;
}
if(!strcmp(argv[1], "run"))
{
Error error;
Error_Init(&error);
if(argc == 2)
{
// $ noja
fprintf(stderr, "Error: Incorrect usage.\n\n");
fprintf(stderr, usage);
Error_Report(&error, 0, "Missing source file");
print_error(NULL, &error);
Error_Free(&error);
return -1;
}
if(!strcmp(argv[1], "run"))
_Bool r;
if(!strcmp(argv[2], "inline"))
{
Error error;
Error_Init(&error);
if(argc == 2)
{
Error_Report(&error, 0, "Missing source file");
print_error(NULL, &error);
Error_Free(&error);
return -1;
}
_Bool r;
if(!strcmp(argv[2], "inline"))
{
if(argc == 3)
{
Error_Report(&error, 0, "Missing source string");
print_error(NULL, &error);
Error_Free(&error);
return -1;
}
r = interpret_code(argv[3]);
}
else
r = interpret_file(argv[2]);
return r ? 0 : -1;
if(argc == 3)
{
Error_Report(&error, 0, "Missing source string");
print_error(NULL, &error);
Error_Free(&error);
return -1;
}
r = interpret_code(argv[3]);
}
else
r = interpret_file(argv[2]);
return r ? 0 : -1;
}
if(!strcmp(argv[1], "dis"))
{
Error error;
Error_Init(&error);
{
Error error;
Error_Init(&error);
if(argc == 2)
{
Error_Report(&error, 0, "Missing source file");
print_error(NULL, &error);
Error_Free(&error);
return -1;
}
_Bool r;
if(!strcmp(argv[2], "inline"))
{
if(argc == 3)
{
Error_Report(&error, 0, "Missing source string");
print_error(NULL, &error);
Error_Free(&error);
return -1;
}
r = disassemble_code(argv[3]);
}
else
r = disassemble_file(argv[2]);
return r ? 0 : -1;
if(argc == 2)
{
Error_Report(&error, 0, "Missing source file");
print_error(NULL, &error);
Error_Free(&error);
return -1;
}
_Bool r;
if(!strcmp(argv[2], "inline"))
{
if(argc == 3)
{
Error_Report(&error, 0, "Missing source string");
print_error(NULL, &error);
Error_Free(&error);
return -1;
}
r = disassemble_code(argv[3]);
}
else
r = disassemble_file(argv[2]);
return r ? 0 : -1;
}
if(!strcmp(argv[1], "help"))
{
fprintf(stdout, usage);
return 0;
}
{
fprintf(stdout, usage);
return 0;
}
fprintf(stderr, "Error: Incorrect usage.\n\n");
fprintf(stderr, usage);