| @@ -7,7 +7,7 @@ | |||||
| (define-minor-mode context-mode | (define-minor-mode context-mode | ||||
| "A temporary minor mode to be activated only specific to a buffer." | "A temporary minor mode to be activated only specific to a buffer." | ||||
| nil | nil | ||||
| :lighter " Context" | |||||
| :lighter " [f2]-Context" | |||||
| context-mode-map) | context-mode-map) | ||||
| (context-mode 1) | (context-mode 1) | ||||
| @@ -22,5 +22,4 @@ if %errorlevel% == 0 ( | |||||
| ) | ) | ||||
| popd | popd | ||||
| rem rd build /S /Q | |||||
| popd | popd | ||||
| @@ -0,0 +1,25 @@ | |||||
| @echo off | |||||
| @setlocal | |||||
| pushd %~dp0 | |||||
| set exeName=slime.exe | |||||
| set binDir=bin | |||||
| mkdir build 2>nul | |||||
| pushd build | |||||
| taskkill /F /IM %exeName% > NUL 2> NUL | |||||
| echo ---------- Compiling ---------- | |||||
| call timecmd clang++ -std=c++17 ../src/main.cpp -o %exeName% -D_DEBUG libucrtd.lib | |||||
| if %errorlevel% == 0 ( | |||||
| echo. | |||||
| echo Done | |||||
| ) else ( | |||||
| echo. | |||||
| echo Fuckin' ell | |||||
| ) | |||||
| popd | |||||
| popd | |||||
| @@ -270,7 +270,7 @@ proc built_in_exponentiate(Lisp_Object* arguments, Environment* env) -> Lisp_Obj | |||||
| } | } | ||||
| proc built_in_load(char* file_name, Environment* env) -> Lisp_Object* { | |||||
| proc built_in_load(const char* file_name, Environment* env) -> Lisp_Object* { | |||||
| char* file_content = read_entire_file(file_name); | char* file_content = read_entire_file(file_name); | ||||
| if (file_content) { | if (file_content) { | ||||
| Lisp_Object* result = Memory::create_lisp_object_nil(); | Lisp_Object* result = Memory::create_lisp_object_nil(); | ||||
| @@ -300,7 +300,7 @@ proc load_built_ins_into_environment(Environment* env) -> void { | |||||
| return nullptr; \ | return nullptr; \ | ||||
| } | } | ||||
| proc defun = [&](char* name, std::function<Lisp_Object*(Lisp_Object*, Environment*)> fun) { | |||||
| proc defun = [&](const char* name, std::function<Lisp_Object*(Lisp_Object*, Environment*)> fun) { | |||||
| define_symbol( | define_symbol( | ||||
| Memory::create_lisp_object_symbol(name), | Memory::create_lisp_object_symbol(name), | ||||
| Memory::create_lisp_object_cfunction(fun), | Memory::create_lisp_object_cfunction(fun), | ||||
| @@ -970,9 +970,7 @@ proc load_built_ins_into_environment(Environment* env) -> void { | |||||
| }); | }); | ||||
| defun("break", cLambda { | defun("break", cLambda { | ||||
| print_environment(env); | print_environment(env); | ||||
| if_debug { | |||||
| __debugbreak(); | |||||
| } | |||||
| debug_break(); | |||||
| return Memory::create_lisp_object_nil(); | return Memory::create_lisp_object_nil(); | ||||
| }); | }); | ||||
| defun("memstat", cLambda { | defun("memstat", cLambda { | ||||
| @@ -9,15 +9,20 @@ constexpr bool is_debug_build = false; | |||||
| #define if_debug if constexpr (is_debug_build) | #define if_debug if constexpr (is_debug_build) | ||||
| // #ifdef _MSC_VER | |||||
| # define debug_break() if_debug __debugbreak() | |||||
| // #else | |||||
| // # define debug_break() if_debug __builtin_trap() | |||||
| // #endif | |||||
| #define assert(cond) \ | #define assert(cond) \ | ||||
| if_debug { \ | if_debug { \ | ||||
| if (!cond) { \ | if (!cond) { \ | ||||
| printf("Assertion failed: %s %d", __FILE__, __LINE__); \ | printf("Assertion failed: %s %d", __FILE__, __LINE__); \ | ||||
| __debugbreak(); \ | |||||
| debug_break(); \ | |||||
| } \ | } \ | ||||
| } else {} \ | } else {} \ | ||||
| #define concat_( a, b) a##b | #define concat_( a, b) a##b | ||||
| #define label(prefix, lnum) concat_(prefix,lnum) | #define label(prefix, lnum) concat_(prefix,lnum) | ||||
| #define try \ | #define try \ | ||||
| @@ -10,14 +10,14 @@ proc delete_error() -> void { | |||||
| proc create_error(Error_Type type, Source_Code_Location* location) -> void { | proc create_error(Error_Type type, Source_Code_Location* location) -> void { | ||||
| delete_error(); | delete_error(); | ||||
| if_debug { | if_debug { | ||||
| __debugbreak(); | |||||
| debug_break(); | |||||
| } | } | ||||
| error = new(Error); | error = new(Error); | ||||
| error->type = type; | error->type = type; | ||||
| error->location = location; | error->location = location; | ||||
| } | } | ||||
| proc Error_Type_to_string(Error_Type type) -> char* { | |||||
| proc Error_Type_to_string(Error_Type type) -> const char* { | |||||
| switch (type) { | switch (type) { | ||||
| case Error_Type::Ill_Formed_Arguments: return "Evaluation-error: Ill formed arguments"; | case Error_Type::Ill_Formed_Arguments: return "Evaluation-error: Ill formed arguments"; | ||||
| case Error_Type::Ill_Formed_Lambda_List: return "Evaluation-error: Ill formed lambda list"; | case Error_Type::Ill_Formed_Lambda_List: return "Evaluation-error: Ill formed lambda list"; | ||||
| @@ -1,7 +1,7 @@ | |||||
| proc print_environment(Environment* env) -> void; | |||||
| proc eval_arguments(Lisp_Object* arguments, Environment* env, int *out_arguments_length) -> Lisp_Object*; | |||||
| proc print_environment(Environment*) -> void; | |||||
| proc eval_arguments(Lisp_Object*, Environment*, int*) -> Lisp_Object*; | |||||
| proc eval_expr(Lisp_Object*, Environment*) -> Lisp_Object*; | proc eval_expr(Lisp_Object*, Environment*) -> Lisp_Object*; | ||||
| proc is_truthy (Lisp_Object* expression, Environment* env) -> bool; | |||||
| proc is_truthy (Lisp_Object*, Environment*) -> bool; | |||||
| proc list_length(Lisp_Object*) -> int; | proc list_length(Lisp_Object*) -> int; | ||||
| proc load_built_ins_into_environment(Environment*) -> void; | proc load_built_ins_into_environment(Environment*) -> void; | ||||
| proc parse_argument_list(Lisp_Object*, Function*) -> void; | proc parse_argument_list(Lisp_Object*, Function*) -> void; | ||||
| @@ -1,4 +1,4 @@ | |||||
| proc string_equal(char input[],char check[]) -> bool { | |||||
| proc string_equal(const char input[], const char check[]) -> bool { | |||||
| int i; | int i; | ||||
| for(i = 0; input[i] != '\0' || check[i] != '\0'; i++) { | for(i = 0; input[i] != '\0' || check[i] != '\0'; i++) { | ||||
| if(input[i] != check[i]) { | if(input[i] != check[i]) { | ||||
| @@ -67,7 +67,7 @@ proc unescape_string(char* in) -> bool { | |||||
| return true; | return true; | ||||
| } | } | ||||
| proc read_entire_file (char* filename) -> char* { | |||||
| proc read_entire_file (const char* filename) -> char* { | |||||
| char *fileContent = nullptr; | char *fileContent = nullptr; | ||||
| FILE *fp = fopen(filename, "r"); | FILE *fp = fopen(filename, "r"); | ||||
| if (fp) { | if (fp) { | ||||
| @@ -132,7 +132,7 @@ proc read_expression() -> char* { | |||||
| linep = linen; | linep = linen; | ||||
| } | } | ||||
| *line++; | |||||
| line++; | |||||
| if((*line = (char)c) == '(') | if((*line = (char)c) == '(') | ||||
| ++nesting; | ++nesting; | ||||
| else if((*line = (char)c) == ')') | else if((*line = (char)c) == ')') | ||||
| @@ -144,6 +144,7 @@ proc read_expression() -> char* { | |||||
| (*line)--; // we dont want the \n actually | (*line)--; // we dont want the \n actually | ||||
| *line = '\0'; | *line = '\0'; | ||||
| // BUG(Felix): Why do we have to add 1 here? | // BUG(Felix): Why do we have to add 1 here? | ||||
| return linep + 1; | return linep + 1; | ||||
| } | } | ||||
| @@ -174,7 +175,7 @@ proc read_line() -> char* { | |||||
| linep = linen; | linep = linen; | ||||
| } | } | ||||
| *line++; | |||||
| line++; | |||||
| if((*line = (char)c) == '(') | if((*line = (char)c) == '(') | ||||
| ++nesting; | ++nesting; | ||||
| else if((*line = (char)c) == ')') | else if((*line = (char)c) == ')') | ||||
| @@ -196,7 +197,7 @@ proc log_message(Log_Level type, char* message) -> void { | |||||
| if (type > log_level) | if (type > log_level) | ||||
| return; | return; | ||||
| char* prefix; | |||||
| const char* prefix; | |||||
| switch (type) { | switch (type) { | ||||
| case Log_Level::Critical: prefix = "CRITICAL"; break; | case Log_Level::Critical: prefix = "CRITICAL"; break; | ||||
| case Log_Level::Warning: prefix = "WARNING"; break; | case Log_Level::Warning: prefix = "WARNING"; break; | ||||
| @@ -1,4 +1,4 @@ | |||||
| proc create_source_code_location(char* file, int line, int col) -> Source_Code_Location* { | |||||
| proc create_source_code_location(const char* file, int line, int col) -> Source_Code_Location* { | |||||
| if (!file) | if (!file) | ||||
| return nullptr; | return nullptr; | ||||
| @@ -9,7 +9,7 @@ proc create_source_code_location(char* file, int line, int col) -> Source_Code_L | |||||
| return ret; | return ret; | ||||
| } | } | ||||
| proc Lisp_Object_Type_to_string(Lisp_Object_Type type) -> char* { | |||||
| proc Lisp_Object_Type_to_string(Lisp_Object_Type type) -> const char* { | |||||
| switch (type) { | switch (type) { | ||||
| case(Lisp_Object_Type::Nil): return "nil"; | case(Lisp_Object_Type::Nil): return "nil"; | ||||
| case(Lisp_Object_Type::T): return "t"; | case(Lisp_Object_Type::T): return "t"; | ||||
| @@ -9,6 +9,6 @@ int main(int argc, char* argv[]) { | |||||
| } | } | ||||
| } else { | } else { | ||||
| run_all_tests(); | run_all_tests(); | ||||
| return interprete_stdin(); | |||||
| interprete_stdin(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -70,19 +70,19 @@ namespace Memory { | |||||
| return node; | return node; | ||||
| } | } | ||||
| proc create_lisp_object_symbol(char* identifier) -> Lisp_Object* { | |||||
| proc create_lisp_object_symbol(const char* identifier) -> Lisp_Object* { | |||||
| Lisp_Object* node = create_lisp_object(); | Lisp_Object* node = create_lisp_object(); | ||||
| node->type = Lisp_Object_Type::Symbol; | node->type = Lisp_Object_Type::Symbol; | ||||
| node->value.symbol = new(Symbol); | node->value.symbol = new(Symbol); | ||||
| node->value.symbol->identifier = identifier; | |||||
| node->value.symbol->identifier = (char*) identifier; | |||||
| return node; | return node; | ||||
| } | } | ||||
| proc create_lisp_object_keyword(char* keyword) -> Lisp_Object* { | |||||
| proc create_lisp_object_keyword(const char* keyword) -> Lisp_Object* { | |||||
| Lisp_Object* node = create_lisp_object(); | Lisp_Object* node = create_lisp_object(); | ||||
| node->type = Lisp_Object_Type::Keyword; | node->type = Lisp_Object_Type::Keyword; | ||||
| node->value.keyword = new(Keyword); | node->value.keyword = new(Keyword); | ||||
| node->value.keyword->identifier = keyword; | |||||
| node->value.keyword->identifier = (char*) keyword; | |||||
| return node; | return node; | ||||
| } | } | ||||
| @@ -1,12 +1,12 @@ | |||||
| namespace Parser { | namespace Parser { | ||||
| #define inject_scl(_ret) \ | |||||
| ret->sourceCodeLocation = new(Source_Code_Location); \ | |||||
| ret->sourceCodeLocation->file = parser_file; \ | |||||
| ret->sourceCodeLocation->line = parser_line; \ | |||||
| ret->sourceCodeLocation->column = parser_col | |||||
| #define inject_scl(_ret) \ | |||||
| _ret->sourceCodeLocation = new(Source_Code_Location); \ | |||||
| _ret->sourceCodeLocation->file = parser_file; \ | |||||
| _ret->sourceCodeLocation->line = parser_line; \ | |||||
| _ret->sourceCodeLocation->column = parser_col | |||||
| char* parser_file; | |||||
| const char* parser_file; | |||||
| int parser_line; | int parser_line; | ||||
| int parser_col; | int parser_col; | ||||
| @@ -466,8 +466,8 @@ namespace Parser { | |||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| void write_expanded_file(char* file_name, Lisp_Object_Array_List* program) { | |||||
| char* ext = ".expanded"; | |||||
| void write_expanded_file(const char* file_name, Lisp_Object_Array_List* program) { | |||||
| const char* ext = ".expanded"; | |||||
| char* newName = (char*)calloc(4 + strlen(file_name), sizeof(char)); | char* newName = (char*)calloc(4 + strlen(file_name), sizeof(char)); | ||||
| strcpy(newName, file_name); | strcpy(newName, file_name); | ||||
| strcat(newName, ext); | strcat(newName, ext); | ||||
| @@ -489,9 +489,9 @@ namespace Parser { | |||||
| fclose(f); | fclose(f); | ||||
| } | } | ||||
| Lisp_Object_Array_List* parse_program(char* file_name, char* text) { | |||||
| Lisp_Object_Array_List* parse_program(const char* file_name, char* text) { | |||||
| parser_file = (char*)malloc(strlen(file_name) * sizeof(char) + 1); | parser_file = (char*)malloc(strlen(file_name) * sizeof(char) + 1); | ||||
| strcpy(parser_file, file_name); | |||||
| strcpy((char *)parser_file, file_name); | |||||
| parser_line = 1; | parser_line = 1; | ||||
| parser_col = 0; | parser_col = 0; | ||||
| @@ -50,7 +50,7 @@ enum struct Log_Level { | |||||
| }; | }; | ||||
| struct Source_Code_Location { | struct Source_Code_Location { | ||||
| char* file; | |||||
| const char* file; | |||||
| int line; | int line; | ||||
| int column; | int column; | ||||
| }; | }; | ||||
| @@ -68,8 +68,8 @@ struct Number { | |||||
| }; | }; | ||||
| struct String { | struct String { | ||||
| char* value; | |||||
| int length; | int length; | ||||
| char* value; | |||||
| }; | }; | ||||
| struct Pair { | struct Pair { | ||||