diff --git a/.dir-locals.el b/.dir-locals.el index 39bb4e6..0ee656d 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -7,7 +7,7 @@ (define-minor-mode context-mode "A temporary minor mode to be activated only specific to a buffer." nil - :lighter " Context" + :lighter " [f2]-Context" context-mode-map) (context-mode 1) diff --git a/build.bat b/build.bat index 3799856..51e924a 100644 --- a/build.bat +++ b/build.bat @@ -22,5 +22,4 @@ if %errorlevel% == 0 ( ) popd -rem rd build /S /Q popd diff --git a/build/libucrtd.lib b/build/libucrtd.lib new file mode 100644 index 0000000..4607828 Binary files /dev/null and b/build/libucrtd.lib differ diff --git a/build_clang.bat b/build_clang.bat new file mode 100644 index 0000000..d746f93 --- /dev/null +++ b/build_clang.bat @@ -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 diff --git a/src/built_ins.cpp b/src/built_ins.cpp index 5774aa1..396859b 100644 --- a/src/built_ins.cpp +++ b/src/built_ins.cpp @@ -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); if (file_content) { Lisp_Object* result = Memory::create_lisp_object_nil(); @@ -300,7 +300,7 @@ proc load_built_ins_into_environment(Environment* env) -> void { return nullptr; \ } - proc defun = [&](char* name, std::function fun) { + proc defun = [&](const char* name, std::function fun) { define_symbol( Memory::create_lisp_object_symbol(name), Memory::create_lisp_object_cfunction(fun), @@ -970,9 +970,7 @@ proc load_built_ins_into_environment(Environment* env) -> void { }); defun("break", cLambda { print_environment(env); - if_debug { - __debugbreak(); - } + debug_break(); return Memory::create_lisp_object_nil(); }); defun("memstat", cLambda { diff --git a/src/defines.cpp b/src/defines.cpp index c97314f..4230ed2 100644 --- a/src/defines.cpp +++ b/src/defines.cpp @@ -9,15 +9,20 @@ constexpr bool is_debug_build = false; #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) \ if_debug { \ if (!cond) { \ printf("Assertion failed: %s %d", __FILE__, __LINE__); \ - __debugbreak(); \ + debug_break(); \ } \ } else {} \ - #define concat_( a, b) a##b #define label(prefix, lnum) concat_(prefix,lnum) #define try \ diff --git a/src/error.cpp b/src/error.cpp index 3dfdcaf..5141eb3 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -10,14 +10,14 @@ proc delete_error() -> void { proc create_error(Error_Type type, Source_Code_Location* location) -> void { delete_error(); if_debug { - __debugbreak(); + debug_break(); } error = new(Error); error->type = type; error->location = location; } -proc Error_Type_to_string(Error_Type type) -> char* { +proc Error_Type_to_string(Error_Type type) -> const char* { switch (type) { 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"; diff --git a/src/forward_decls.cpp b/src/forward_decls.cpp index fc1893d..f3b0e61 100644 --- a/src/forward_decls.cpp +++ b/src/forward_decls.cpp @@ -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 is_truthy (Lisp_Object* expression, Environment* env) -> bool; +proc is_truthy (Lisp_Object*, Environment*) -> bool; proc list_length(Lisp_Object*) -> int; proc load_built_ins_into_environment(Environment*) -> void; proc parse_argument_list(Lisp_Object*, Function*) -> void; diff --git a/src/io.cpp b/src/io.cpp index 2321f39..02a917c 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -1,4 +1,4 @@ -proc string_equal(char input[],char check[]) -> bool { +proc string_equal(const char input[], const char check[]) -> bool { int i; for(i = 0; input[i] != '\0' || check[i] != '\0'; i++) { if(input[i] != check[i]) { @@ -67,7 +67,7 @@ proc unescape_string(char* in) -> bool { return true; } -proc read_entire_file (char* filename) -> char* { +proc read_entire_file (const char* filename) -> char* { char *fileContent = nullptr; FILE *fp = fopen(filename, "r"); if (fp) { @@ -132,7 +132,7 @@ proc read_expression() -> char* { linep = linen; } - *line++; + line++; if((*line = (char)c) == '(') ++nesting; else if((*line = (char)c) == ')') @@ -144,6 +144,7 @@ proc read_expression() -> char* { (*line)--; // we dont want the \n actually *line = '\0'; // BUG(Felix): Why do we have to add 1 here? + return linep + 1; } @@ -174,7 +175,7 @@ proc read_line() -> char* { linep = linen; } - *line++; + line++; if((*line = (char)c) == '(') ++nesting; else if((*line = (char)c) == ')') @@ -196,7 +197,7 @@ proc log_message(Log_Level type, char* message) -> void { if (type > log_level) return; - char* prefix; + const char* prefix; switch (type) { case Log_Level::Critical: prefix = "CRITICAL"; break; case Log_Level::Warning: prefix = "WARNING"; break; diff --git a/src/lisp_object.cpp b/src/lisp_object.cpp index a95091a..0876ce3 100644 --- a/src/lisp_object.cpp +++ b/src/lisp_object.cpp @@ -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) return nullptr; @@ -9,7 +9,7 @@ proc create_source_code_location(char* file, int line, int col) -> Source_Code_L 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) { case(Lisp_Object_Type::Nil): return "nil"; case(Lisp_Object_Type::T): return "t"; diff --git a/src/main.cpp b/src/main.cpp index cedb515..4090244 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,6 @@ int main(int argc, char* argv[]) { } } else { run_all_tests(); - return interprete_stdin(); + interprete_stdin(); } } diff --git a/src/memory.cpp b/src/memory.cpp index 0c78623..0a4447a 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -70,19 +70,19 @@ namespace Memory { 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(); node->type = Lisp_Object_Type::Symbol; node->value.symbol = new(Symbol); - node->value.symbol->identifier = identifier; + node->value.symbol->identifier = (char*) identifier; 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(); node->type = Lisp_Object_Type::Keyword; node->value.keyword = new(Keyword); - node->value.keyword->identifier = keyword; + node->value.keyword->identifier = (char*) keyword; return node; } diff --git a/src/parse.cpp b/src/parse.cpp index ad6654d..4deeb31 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -1,12 +1,12 @@ 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_col; @@ -466,8 +466,8 @@ namespace Parser { 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)); strcpy(newName, file_name); strcat(newName, ext); @@ -489,9 +489,9 @@ namespace Parser { 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); - strcpy(parser_file, file_name); + strcpy((char *)parser_file, file_name); parser_line = 1; parser_col = 0; diff --git a/src/structs.cpp b/src/structs.cpp index bff4a49..1327612 100644 --- a/src/structs.cpp +++ b/src/structs.cpp @@ -50,7 +50,7 @@ enum struct Log_Level { }; struct Source_Code_Location { - char* file; + const char* file; int line; int column; }; @@ -68,8 +68,8 @@ struct Number { }; struct String { - char* value; int length; + char* value; }; struct Pair {