diff --git a/src/eval.cpp b/src/eval.cpp index ff0c35b..3120d35 100644 --- a/src/eval.cpp +++ b/src/eval.cpp @@ -1,5 +1,3 @@ -Source_Code_Location* current_source_code_location = nullptr; - proc apply_arguments_to_function(Lisp_Object* arguments, Function* function) -> Lisp_Object* { Environment* new_env = Memory::create_child_environment(function->parent_environment); @@ -389,7 +387,7 @@ proc eval_expr(Lisp_Object* node, Environment* env) -> Lisp_Object* { return symbol; } case Lisp_Object_Type::Pair: { - current_source_code_location = node->sourceCodeLocation; + current_source_code = node; Lisp_Object* lispOperator; if (node->value.pair.first->type != Lisp_Object_Type::CFunction && @@ -429,7 +427,7 @@ proc eval_expr(Lisp_Object* node, Environment* env) -> Lisp_Object* { } } default: { - create_generic_error("Not a function."); + create_generic_error("%s is not a function.", Lisp_Object_Type_to_string(node->type)); return nullptr; } } diff --git a/src/forward_decls.cpp b/src/forward_decls.cpp index 0a282f8..1b39434 100644 --- a/src/forward_decls.cpp +++ b/src/forward_decls.cpp @@ -15,3 +15,5 @@ proc Lisp_Object_Type_to_string(Lisp_Object_Type type) -> const char*; namespace Memory { proc get_or_create_lisp_object_keyword(const char* identifier) -> Lisp_Object*; } + +Lisp_Object* current_source_code = nullptr; diff --git a/src/io.cpp b/src/io.cpp index e20f154..d76ed4a 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -281,14 +281,16 @@ proc print(Lisp_Object* node, bool print_quotes = false, FILE* file = stdout) -> proc print_error_location() -> void { - // if (error->location) { - // printf("%s (line %d, position %d)", - // Memory::get_c_str(error->location->file), - // error->location->line, - // error->location->column); - // } else { - // printf("no source code location avaliable"); - // } + if (current_source_code) { + printf("%s (line %d, position %d) code:" console_red "\n ", + Memory::get_c_str( + current_source_code->sourceCodeLocation->file), + current_source_code->sourceCodeLocation->line, + current_source_code->sourceCodeLocation->column); + print(current_source_code); + } else { + printf("no source code location avaliable"); + } } proc log_error() -> void { diff --git a/src/memory.cpp b/src/memory.cpp index 3ab5694..3f85ebc 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -143,7 +143,7 @@ namespace Memory { t->type = Lisp_Object_Type::T; } - proc reset() { + proc reset() -> void { free_spots_in_object_memory->next_index = 0; free_spots_in_string_memory->next_index = 0; next_index_in_object_memory = 2; // because t and nil are always there diff --git a/src/slime.h b/src/slime.h index edf6f4f..9e32f1a 100644 --- a/src/slime.h +++ b/src/slime.h @@ -13,17 +13,17 @@ #undef _CRT_SECURE_NO_WARNINGS namespace Slime { -#include "./defines.cpp" -#include "./structs.cpp" -#include "./forward_decls.cpp" -#include "./memory.cpp" -#include "./lisp_object.cpp" -#include "./error.cpp" -#include "./io.cpp" -#include "./env.cpp" -#include "./parse.cpp" -#include "./eval.cpp" -#include "./built_ins.cpp" -#include "./testing.cpp" -#include "./undefines.cpp" +# include "./defines.cpp" +# include "./structs.cpp" +# include "./forward_decls.cpp" +# include "./memory.cpp" +# include "./lisp_object.cpp" +# include "./error.cpp" +# include "./io.cpp" +# include "./env.cpp" +# include "./parse.cpp" +# include "./eval.cpp" +# include "./built_ins.cpp" +# include "./testing.cpp" +# include "./undefines.cpp" } diff --git a/src/testing.cpp b/src/testing.cpp index e173e38..8fccd81 100644 --- a/src/testing.cpp +++ b/src/testing.cpp @@ -480,7 +480,7 @@ proc test_singular_t_and_nil() -> testresult { proc test_file(const char* file) -> testresult { Memory::reset(); - Environment* env = Memory::create_built_ins_environment(); + static Environment* env = Memory::create_built_ins_environment(); Parser::init(env);