diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/load.c | 29 | ||||
-rw-r--r-- | src/parse.c | 8 | ||||
-rw-r--r-- | src/run.c | 5 |
3 files changed, 13 insertions, 29 deletions
@@ -6,6 +6,8 @@ #include <dlfcn.h> #include "common/err.h" #include "common/str.h" +#include "common/file.h" +#include "common/dl.h" #include "load.h" #include "parse.h" @@ -33,18 +35,6 @@ static char *dirname_wrapper(const char *name) return wrap_name_func(name, &dirname); } -static bool file_exists(const char *filename) -{ - FILE *f = fopen(filename, "r"); - - if (f) { - fclose(f); - return true; - } - - return false; -} - // type definitions typedef struct @@ -122,7 +112,7 @@ static Module *require_module(LoadState *state, char *module_path) char *filename = get_filename(module_path); if (! filename) - error("error: module %s not found\n", module_path); + error("module error: module %s not found\n", module_path); size_t filename_len = strlen(filename); UwUVMModuleType type = (filename_len >= 3 && strcmp(filename + filename_len - 3, ".so") == 0) ? MODULE_NATIVE : MODULE_PLAIN; @@ -148,9 +138,7 @@ static Module *require_module(LoadState *state, char *module_path) state->program.libraries = realloc(state->program.libraries, sizeof(void *) * ++state->program.num_libraries); state->program.libraries[state->program.num_libraries - 1] = module->handle.lib = dlopen(filename, RTLD_LAZY); - char *err = dlerror(); - if (err) - error("library error: %s\n", err); + check_dlerror(); } return module; @@ -192,7 +180,7 @@ static UwUVMFunction *resolve_function(LoadState *state, Module *caller_module, fnname++; if (*fnname == '\0') - error("error: empty function name\n"); + error("module error: empty function name referenced/called by module %s\n", caller_module->filename); Module *callee_module; @@ -287,16 +275,13 @@ static void load_functions(LoadState *state, Module *module) *function = NULL; } else { - error("error: no function %s in module %s\n", link->name, module->filename); + error("module error: no function %s in module %s\n", link->name, module->filename); } } else { char *symbol = asprintf_wrapper("uwu_%s", link->name); link->ref->value.native = dlsym(module->handle.lib, symbol); - char *err = dlerror(); - if (err) - error("library error: %s\n", err); - + check_dlerror(); free(symbol); } } diff --git a/src/parse.c b/src/parse.c index ed09de9..e8f1d38 100644 --- a/src/parse.c +++ b/src/parse.c @@ -285,7 +285,7 @@ AbstractSyntaxTree parse_file(const char *filename) FILE *f = fopen(filename, "r"); if (! f) - error("%s: unable to open\n", filename); + syserror("fopen", f); #if DEBUG printf("[File %s]\n[Line %d]\n", filename, lines); @@ -298,7 +298,7 @@ AbstractSyntaxTree parse_file(const char *filename) break; if (ferror(f)) - error("%s: I/O error\n", filename); + syserror("getc", f); if (c == '\n') ++lines; @@ -309,11 +309,11 @@ AbstractSyntaxTree parse_file(const char *filename) #endif if (! parse_character(&state, c)) - error("%s: syntax error in line %d\n", filename, lines); + error("syntax error: in file %s, line %d\n", filename, lines); } if (state.buffer || state.expression) - error("%s: syntax error at end of file\n", filename); + error("syntax error: at end of file %s\n", filename); fclose(f); @@ -2,6 +2,7 @@ #include <stdlib.h> #include <stdio.h> #include "common/err.h" +#include "common/dl.h" #include "load.h" #include "run.h" @@ -29,9 +30,7 @@ void run_module(const char *progname, const char *modname, size_t num_args, char char *(*uwuvm_print_value )(UwUVMValue ) = dlsym(program.api_library, "uwuvm_print_value" ); void (*uwuvm_delet_value )(UwUVMValue ) = dlsym(program.api_library, "uwuvm_delet_value" ); - char *err = dlerror(); - if (err) - error("library error: %s\n", err); + check_dlerror(); UwUVMExpression arg_expressions[num_args]; |