Ast_Kind_Package,
Ast_Kind_Load_File,
Ast_Kind_Load_Path,
+ Ast_Kind_Library_Path,
Ast_Kind_Memres,
Ast_Kind_Binding,
Runtime runtime;
bh_arr(const char *) included_folders;
+ bh_arr(const char *) included_library_folders;
bh_arr(const char *) files;
const char* target_file;
const char* documentation_file;
// This function can return a static variable which will change if this is called
// another time. -brendanfh 2020/10/09
// :RelativeFiles This should lookup for the file relative to "relative_to"
-char* lookup_included_file(char* filename, char* relative_to, b32 add_onyx_suffix, b32 search_included_folders);
+char* lookup_included_file(char* filename, char* relative_to, char *suffix, b32 add_suffix, bh_arr(const char *) included_folders, b32 search_included_folders);
u32 levenshtein_distance(const char *str1, const char *str2);
char *find_closest_symbol_in_node(AstNode *node, char *sym);
"PACKAGE",
"INCLUDE FILE",
"INCLUDE FOLDER",
+ "INCLUDE LIBRARY PATH",
"MEMORY RESERVATION",
"BINDING",
break;
}
+ case Ast_Kind_Library_Path:
case Ast_Kind_Load_Path: {
ent.state = Entity_State_Parse;
ent.type = Entity_Type_Load_Path;
bh_arr_new(alloc, options.files, 2);
bh_arr_new(alloc, options.included_folders, 2);
+ bh_arr_new(alloc, options.included_library_folders, 2);
// NOTE: Add the current folder
bh_arr_push(options.included_folders, CORE_INSTALLATION);
char* parent_folder = bh_path_get_parent(parent_file, global_scratch_allocator);
- char* filename = lookup_included_file(include->name, parent_folder, 1, 1);
+ char* filename = lookup_included_file(include->name, parent_folder, ".onyx", 1, context.options->included_folders, 1);
char* formatted_name = bh_strdup(global_heap_allocator, filename);
process_source_file(formatted_name, include->token->pos);
} else if (include->kind == Ast_Kind_Load_Path) {
bh_arr_push(context.options->included_folders, include->name);
+
+ } else if (include->kind == Ast_Kind_Library_Path) {
+ bh_arr_push(context.options->included_library_folders, include->name);
}
}
ENTITY_SUBMIT(include);
return;
}
+ else if (parse_possible_directive(parser, "library_path")) {
+ AstInclude* include = make_node(AstInclude, Ast_Kind_Library_Path);
+ include->token = dir_token;
+
+ OnyxToken* str_token = expect_token(parser, Token_Type_Literal_String);
+ if (str_token != NULL) {
+ token_toggle_end(str_token);
+ include->name = bh_strdup(parser->allocator, str_token->text);
+ token_toggle_end(str_token);
+ }
+
+ ENTITY_SUBMIT(include);
+ return;
+ }
else if (parse_possible_directive(parser, "error")) {
AstDirectiveError *error = make_node(AstDirectiveError, Ast_Kind_Directive_Error);
error->token = dir_token;
return total_len;
}
-char* lookup_included_file(char* filename, char* relative_to, b32 add_onyx_suffix, b32 search_included_folders) {
+char* lookup_included_file(char* filename, char* relative_to, char *suffix, b32 add_suffix, bh_arr(const char *) included_folders, b32 search_included_folders) {
assert(relative_to != NULL);
static char path[256];
static char fn[128];
fori (i, 0, 128) fn[i] = 0;
- if (!bh_str_ends_with(filename, ".onyx") && add_onyx_suffix) {
- bh_snprintf(fn, 128, "%s.onyx", filename);
+ if (!bh_str_ends_with(filename, suffix) && add_suffix) {
+ bh_snprintf(fn, 128, "%s%s", filename, suffix);
} else {
bh_snprintf(fn, 128, "%s", filename);
}
}
if (search_included_folders) {
- bh_arr_each(const char *, folder, context.options->included_folders) {
+ bh_arr_each(const char *, folder, included_folders) {
if ((*folder)[strlen(*folder) - 1] != DIR_SEPARATOR)
bh_snprintf(path, 256, "%s%c%s", *folder, DIR_SEPARATOR, fn);
else
char* temp_fn = bh_alloc_array(global_scratch_allocator, char, fc->filename_token->length);
i32 temp_fn_len = string_process_escape_seqs(temp_fn, fc->filename_token->text, fc->filename_token->length);
- char* filename = lookup_included_file(temp_fn, parent_folder, 0, 0);
+ char* filename = lookup_included_file(temp_fn, parent_folder, "", 0, NULL, 0);
fc->filename = bh_strdup(global_heap_allocator, filename);
}
LibraryLinker library_load;
#ifdef _BH_LINUX
- char *library_name = bh_aprintf(global_scratch_allocator, "%s.so", name);
+ char *library_name = lookup_included_file(name, ".", ".so", 1, context.options->included_library_folders, 1);
void* handle = dlopen(library_name, RTLD_LAZY);
if (handle == NULL) {
printf("ERROR LOADING LIBRARY %s: %s\n", name, dlerror());
#endif
#ifdef _BH_WINDOWS
- char *library_name = bh_aprintf(global_scratch_allocator, "%s.dll", name);
+ char *library_name = lookup_included_file(name, ".", ".dll", 1, context.options->included_library_folders, 1);
HMODULE handle = LoadLibraryA(library_name);
if (handle == NULL) {
printf("ERROR LOADING LIBRARY %s: %d\n", name, GetLastError());