added load path

This commit is contained in:
FelixBrendel
2019-10-15 15:34:15 +02:00
parent c80478a2cb
commit af4f8cf630
5 changed files with 30 additions and 49 deletions
+23 -25
View File
@@ -42,6 +42,12 @@ proc lisp_object_equal(Lisp_Object* n1, Lisp_Object* n2) -> bool {
return false;
}
proc add_to_load_path(const char* path) -> void {
using Globals::load_path;
append_to_array_list(&load_path, (void*)path);
}
proc built_in_load(String* file_name) -> Lisp_Object* {
// char* full_file_name = find_slime_file(file_name);
char* file_content;
@@ -50,33 +56,25 @@ proc built_in_load(String* file_name) -> Lisp_Object* {
file_content = read_entire_file(Memory::get_c_str(file_name));
if (!file_content) {
// try slime's bin dir
// save the current working directory
// get the direction of the exe
char* exe_path = get_exe_dir();
defer {
free(exe_path);
};
fullpath[0] = '\0';
sprintf(fullpath, "%s%s", exe_path, Memory::get_c_str(file_name));
// printf("Fullpath: %s\n", fullpath);
file_content = read_entire_file(fullpath);
if (!file_content) {
char* cwd = get_cwd();
defer {
free(cwd);
};
create_generic_error("The file to load '%s' was not found: "
"neither in the cwd (%s) "
"nor in slime's exe dir (%s)",
Memory::get_c_str(file_name), cwd, fullpath);
return nullptr;
for_array_list (Globals::load_path) {
fullpath[0] = '\0';
sprintf(fullpath, "%s%s", (char*)it, Memory::get_c_str(file_name));
file_content = read_entire_file(fullpath);
if (file_content)
break;
}
if (!file_content) {
printf("Load path:\n");
for_array_list (Globals::load_path) {
printf(" - %s\n", (char*) it);
}
create_generic_error("The file to load '%s' was not found in the load path.",
Memory::get_c_str(file_name));
}
}
Lisp_Object* result = Memory::nil;
Lisp_Object_Array_List program;
try program = Parser::parse_program(Memory::create_string(fullpath), file_content);
@@ -175,7 +173,7 @@ proc load_built_ins_into_environment() -> void {
assert_type(label(params,__LINE__)->value.pair.first, Lisp_Object_Type::Symbol); \
auto label(sym,__LINE__) = label(params,__LINE__)->value.pair.first; \
auto label(sfun,__LINE__) = Memory::create_lisp_object_cfunction(special); \
/*NOTE(Felix): for evaluating default args*/ \
/*NOTE(Felix): for evaluating default args*/ \
/*push_environment(get_root_environment());*/ \
create_arguments_from_lambda_list_and_inject(label(params,__LINE__)->value.pair.rest, label(sfun,__LINE__)); \
/*pop_environment(); */ \
+2
View File
@@ -1,4 +1,5 @@
// proc assert_type(Lisp_Object*, Lisp_Object_Type) -> void;
proc add_to_load_path(const char*) -> void;
proc lisp_object_equal(Lisp_Object*,Lisp_Object*) -> bool;
proc built_in_load(String*) -> Lisp_Object*;
proc built_in_import(String*) -> Lisp_Object*;
@@ -45,6 +46,7 @@ namespace Globals {
char* bin_path = nullptr;
Log_Level log_level = Log_Level::Debug;
Void_Ptr_Array_List load_path = create_Void_Ptr_array_list();
namespace Current_Execution {
Lisp_Object_Array_List call_stack = create_Lisp_Object_array_list();
Environment_Array_List envi_stack = create_Environment_array_list();
+4
View File
@@ -174,6 +174,10 @@ namespace Memory {
}
proc init(int oms, int ems, int sms) {
char* exe_path = get_exe_dir();
defer {free(exe_path);};
add_to_load_path(exe_path);
global_symbol_table = create_String_hashmap();
global_keyword_table = create_String_hashmap();
+1 -4
View File
@@ -21,9 +21,6 @@
# include <signal.h>
#endif
#undef _CRT_SECURE_NO_DEPRECATE
#undef _CRT_SECURE_NO_WARNINGS
#include "./ftb/macros.hpp"
#include "./ftb/profiler.hpp"
#include "./ftb/hashmap.hpp"
@@ -45,5 +42,5 @@ namespace Slime {
# include "./docgeneration.cpp"
# include "./built_ins.cpp"
# include "./testing.cpp"
# include "./undefines.cpp"
// # include "./undefines.cpp"
}