aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/collect.c20
-rw-r--r--src/expression.h2
-rw-r--r--src/parse.c24
-rw-r--r--src/parse.h2
-rw-r--r--src/vm.c4
5 files changed, 26 insertions, 26 deletions
diff --git a/src/collect.c b/src/collect.c
index fadb9d1..ae15513 100644
--- a/src/collect.c
+++ b/src/collect.c
@@ -72,11 +72,11 @@ typedef struct
} handle;
} Module;
-typedef struct
+typedef struct
{
Module **modules; // loaded modules
size_t num_modules; // count for modules
-
+
char *std_path; // path to standard library
UwUVMProgram program; // the result program
@@ -169,7 +169,7 @@ static UwUVMFunction *require_function(CollectorState *state, Module *module, co
ref->type = module->type;
state->program.functions = realloc(state->program.functions, sizeof *state->program.functions * ++state->program.num_functions);
- state->program.functions[state->program.num_functions - 1] = ref;
+ state->program.functions[state->program.num_functions - 1] = ref;
module->functions = realloc(module->functions, sizeof *module->functions * ++module->num_functions);
module->functions[module->num_functions - 1] = (FunctionLink) {
@@ -207,7 +207,7 @@ static UwUVMFunction *resolve_function(CollectorState *state, Module *caller_mod
callee_name++;
}
- size_t path_len = fnname - callee_name;
+ size_t path_len = fnname - callee_name;
char callee_path[path_len];
for (size_t i = 0; i < path_len; i++)
@@ -229,7 +229,7 @@ static void translate_expression(CollectorState *state, Module *module, UwUVMExp
vm_function = resolve_function(state, module, parse_expr->value.str_value);
free(parse_expr->value.str_value);
}
-
+
switch (vm_expr->type = parse_expr->type) {
case EX_INTLIT:
case EX_ARGNUM:
@@ -258,7 +258,7 @@ static void translate_expression(CollectorState *state, Module *module, UwUVMExp
default:
break;
- }
+ }
free(parse_expr);
}
@@ -299,7 +299,7 @@ static void load_functions(CollectorState *state, Module *module)
if (! dlerror())
found = true;
-
+
free(symbol);
}
@@ -321,7 +321,7 @@ static void free_expression(ParseExpression *expr)
if (expr->type != EX_INTLIT && expr->type != EX_ARGNUM)
free(expr->value.str_value);
- free(expr);
+ free(expr);
}
UwUVMProgram create_program(const char *progname, const char *modname)
@@ -345,7 +345,7 @@ UwUVMProgram create_program(const char *progname, const char *modname)
free(prog_dirname);
free(api_path);
-
+
state.program.main_function = require_function(&state, require_module(&state, strdup(modname)), "main");
while (true) {
@@ -396,7 +396,7 @@ UwUVMProgram create_program(const char *progname, const char *modname)
if (module->handle.ast.functions)
free(module->handle.ast.functions);
}
-
+
free(module);
}
diff --git a/src/expression.h b/src/expression.h
index da74620..55d10f7 100644
--- a/src/expression.h
+++ b/src/expression.h
@@ -1,7 +1,7 @@
#ifndef _EXPRESSION_H_
#define _EXPRESSION_H_
-typedef enum
+typedef enum
{
EX_UNINIT,
EX_INTLIT,
diff --git a/src/parse.c b/src/parse.c
index be0ee98..c8b430d 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -45,7 +45,7 @@ static void print_ast(AbstractSyntaxTree tree)
for (size_t f = 0; f < tree.num_functions; f++) {
ParseFunction *function = tree.functions[f];
-
+
printf("function %s\n", function->name);
print_expression(function->expression, 1);
}
@@ -63,7 +63,7 @@ static char *buffer_terminate(ParseState *state)
buffer_append(state, '\0');
char *buffer = state->buffer;
-
+
state->buffer = NULL;
state->buffer_size = 0;
@@ -73,7 +73,7 @@ static char *buffer_terminate(ParseState *state)
static void start_arg(ParseState *state)
{
DBG(__FUNCTION__)
-
+
ParseExpression *parent = state->expression;
parent->children = realloc(parent->children, sizeof *parent->children * ++parent->num_children);
ParseExpression *child = parent->children[parent->num_children - 1] = malloc(sizeof *child);
@@ -87,7 +87,7 @@ static void start_arg(ParseState *state)
static bool continue_arg(ParseState *state, char c)
{
DBG(__FUNCTION__)
-
+
if (c == ',')
start_arg(state);
else if (c == ')')
@@ -98,8 +98,8 @@ static bool continue_arg(ParseState *state, char c)
return true;
}
-static bool finish_arg(ParseState *state, char c)
-{
+static bool finish_arg(ParseState *state, char c)
+{
state->expression = state->expression->parent;
if (state->expression)
@@ -147,7 +147,7 @@ static bool parse_expression_init(ParseState *state, char c)
}
static bool parse_expression_finish(ParseState *state, char c)
-{
+{
DBG(__FUNCTION__)
if (state->expression->type == EX_ARGNUM && state->buffer_size == 0)
@@ -210,7 +210,7 @@ static bool parse_expression_continue(ParseState *state, char c)
}
static bool parse_expression(ParseState *state, char c)
-{
+{
DBG(__FUNCTION__)
return state->expression->type == EX_UNINIT
@@ -251,7 +251,7 @@ static bool parse_function(ParseState *state, char c)
}
static bool parse_character(ParseState *state, char c)
-{
+{
#if DEBUG
printf("\nparse_character ");
@@ -262,7 +262,7 @@ static bool parse_character(ParseState *state, char c)
printf("\n");
#endif
-
+
return state->expression
? parse_expression(state, c)
: parse_function(state, c);
@@ -279,7 +279,7 @@ AbstractSyntaxTree parse_file(const char *filename)
.buffer = NULL,
.expression = NULL,
};
-
+
int lines = 1;
FILE *f = fopen(filename, "r");
@@ -307,7 +307,7 @@ AbstractSyntaxTree parse_file(const char *filename)
if (c == '\n')
printf("\n[Line %d]\n", lines);
#endif
-
+
if (! parse_character(&state, c))
error("%s: syntax error in line %d\n", filename, lines);
}
diff --git a/src/parse.h b/src/parse.h
index 861ad1c..7aca6af 100644
--- a/src/parse.h
+++ b/src/parse.h
@@ -33,7 +33,7 @@ typedef struct
typedef struct
{
AbstractSyntaxTree tree;
-
+
size_t buffer_size;
char *buffer;
diff --git a/src/vm.c b/src/vm.c
index 7f0db99..335eb48 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -9,7 +9,7 @@ static void free_expression(UwUVMExpression *expr)
if (expr->type == EX_FNCALL) {
for (size_t i = 0; i < expr->value.cll_value.num_args; i++)
free_expression(&expr->value.cll_value.args[i]);
-
+
free(expr->value.cll_value.args);
}
@@ -36,7 +36,7 @@ void vm_run_file(const char *progname, const char *modname)
free_expression(function->value.plain);
free(function->value.plain);
}
-
+
free(function);
}