| @@ -1 +1 @@ | |||||
| Subproject commit 3959dd2fc12eefbd4955fd20a1e4220562730508 | |||||
| Subproject commit d2133205a73c3ae3455e8cc3e0a910ce0aaae518 | |||||
| @@ -8,11 +8,10 @@ taskkill /F /IM %exeName% > NUL 2> NUL | |||||
| echo ---------- Compiling ---------- | echo ---------- Compiling ---------- | ||||
| call ..\timecmd cl ^ | call ..\timecmd cl ^ | ||||
| ../src/main.cpp ^ | |||||
| ../src/main.cpp^ | |||||
| /I../3rd/ ^ | /I../3rd/ ^ | ||||
| /D_PROFILING /D_DEBUG /D_DONT_BREAK_ON_ERRORS ^ | /D_PROFILING /D_DEBUG /D_DONT_BREAK_ON_ERRORS ^ | ||||
| /Zi /std:c++latest /Fe%exeName% /W3 /wd4003 /nologo /EHsc ^ | |||||
| /link /NODEFAULTLIB:libucrt libucrtd.lib | |||||
| /Zi /std:c++latest /Fe%exeName% /W3 /wd4003 /nologo /EHsc | |||||
| rem call ..\timecmd clang-cl ../src/main.cpp -o %exeName% /O2 /std:c++latest /W3 /Zi /EHsc | rem call ..\timecmd clang-cl ../src/main.cpp -o %exeName% /O2 /std:c++latest /W3 /Zi /EHsc | ||||
| @@ -52,3 +52,5 @@ | |||||
| # define assert_type(_node, _type) do {} while (0) | # define assert_type(_node, _type) do {} while (0) | ||||
| # define assert(condition) do {} while (0) | # define assert(condition) do {} while (0) | ||||
| #endif | #endif | ||||
| @@ -14,11 +14,11 @@ | |||||
| } \ | } \ | ||||
| } while(0) | } while(0) | ||||
| #define if_error_log_location_and_return() \ | |||||
| #define if_error_log_location_and_return(val) \ | |||||
| do { \ | do { \ | ||||
| if (Globals::error) { \ | if (Globals::error) { \ | ||||
| log_location(); \ | log_location(); \ | ||||
| return; \ | |||||
| return val; \ | |||||
| } \ | } \ | ||||
| } while(0) | } while(0) | ||||
| @@ -114,13 +114,13 @@ | |||||
| Parser::parser_col = 0; \ | Parser::parser_col = 0; \ | ||||
| auto label(params,__LINE__) = Parser::parse_single_expression( \ | auto label(params,__LINE__) = Parser::parse_single_expression( \ | ||||
| Memory::get_c_str(Memory::create_string(#def))); \ | Memory::get_c_str(Memory::create_string(#def))); \ | ||||
| if_error_log_location_and_return(); \ | |||||
| if_error_log_location_and_return(nullptr); \ | |||||
| assert_type(label(params,__LINE__), Lisp_Object_Type::Pair); \ | assert_type(label(params,__LINE__), Lisp_Object_Type::Pair); \ | ||||
| assert_type(label(params,__LINE__)->value.pair.first, Lisp_Object_Type::Symbol); \ | assert_type(label(params,__LINE__)->value.pair.first, Lisp_Object_Type::Symbol); \ | ||||
| auto label(sym,__LINE__) = label(params,__LINE__)->value.pair.first; \ | auto label(sym,__LINE__) = label(params,__LINE__)->value.pair.first; \ | ||||
| auto label(sfun,__LINE__) = Memory::create_lisp_object_cfunction(special); \ | auto label(sfun,__LINE__) = Memory::create_lisp_object_cfunction(special); \ | ||||
| create_arguments_from_lambda_list_and_inject(label(params,__LINE__)->value.pair.rest, label(sfun,__LINE__)); \ | create_arguments_from_lambda_list_and_inject(label(params,__LINE__)->value.pair.rest, label(sfun,__LINE__)); \ | ||||
| if_error_log_location_and_return(); \ | |||||
| if_error_log_location_and_return(nullptr); \ | |||||
| label(sfun,__LINE__)->docstring = Memory::create_string(docs); \ | label(sfun,__LINE__)->docstring = Memory::create_string(docs); \ | ||||
| define_symbol(label(sym,__LINE__), label(sfun,__LINE__)); \ | define_symbol(label(sym,__LINE__), label(sfun,__LINE__)); \ | ||||
| label(sfun,__LINE__)->value.cFunction->body = []() -> Lisp_Object* | label(sfun,__LINE__)->value.cFunction->body = []() -> Lisp_Object* | ||||
| @@ -132,6 +132,7 @@ | |||||
| Globals::Current_Execution::envi_stack.next_index-1) | Globals::Current_Execution::envi_stack.next_index-1) | ||||
| /* | /* | ||||
| * iterate over lisp vectors | * iterate over lisp vectors | ||||
| */ | */ | ||||
| @@ -151,3 +152,9 @@ | |||||
| for (Lisp_Object* head = l, *it; \ | for (Lisp_Object* head = l, *it; \ | ||||
| Memory::get_type(head) == Lisp_Object_Type::Pair && (it = head->value.pair.first); \ | Memory::get_type(head) == Lisp_Object_Type::Pair && (it = head->value.pair.first); \ | ||||
| head = head->value.pair.rest, ++it_index) | head = head->value.pair.rest, ++it_index) | ||||
| @@ -67,16 +67,6 @@ namespace Slime { | |||||
| int column; | int column; | ||||
| }; | }; | ||||
| struct Symbol { | |||||
| String* identifier; | |||||
| u64 hash; | |||||
| }; | |||||
| struct Keyword { | |||||
| String* identifier; | |||||
| u64 hash; | |||||
| }; | |||||
| struct Pair { | struct Pair { | ||||
| Lisp_Object* first; | Lisp_Object* first; | ||||
| Lisp_Object* rest; | Lisp_Object* rest; | ||||
| @@ -110,6 +100,11 @@ namespace Slime { | |||||
| struct Environment { | struct Environment { | ||||
| Array_List<Environment*> parents; | Array_List<Environment*> parents; | ||||
| Hash_Map<void*, Lisp_Object*> hm; | Hash_Map<void*, Lisp_Object*> hm; | ||||
| ~Environment() { | |||||
| parents.~Array_List(); | |||||
| hm.~Hash_Map(); | |||||
| } | |||||
| }; | }; | ||||
| struct Function { | struct Function { | ||||
| @@ -120,7 +115,7 @@ namespace Slime { | |||||
| }; | }; | ||||
| struct cFunction { | struct cFunction { | ||||
| std::function<Lisp_Object* ()> body; | |||||
| Lisp_Object* (*body)(); | |||||
| Arguments args; | Arguments args; | ||||
| bool is_special_form; | bool is_special_form; | ||||
| }; | }; | ||||
| @@ -130,18 +125,20 @@ namespace Slime { | |||||
| u64 flags; | u64 flags; | ||||
| Lisp_Object* userType; // keyword | Lisp_Object* userType; // keyword | ||||
| String* docstring; | String* docstring; | ||||
| union { | |||||
| Symbol symbol; // used for symbols and keywords | |||||
| union value { | |||||
| String* symbol; // used for symbols and keywords | |||||
| double number; | double number; | ||||
| String* string; | String* string; | ||||
| Pair pair; | Pair pair; | ||||
| Vector vector; | Vector vector; | ||||
| Function function; | |||||
| Function* function; | |||||
| cFunction* cFunction; | cFunction* cFunction; | ||||
| void* pointer; | void* pointer; | ||||
| Continuation continuation; | |||||
| Hash_Map<Lisp_Object*, Lisp_Object*> hashMap; | |||||
| Continuation* continuation; | |||||
| Hash_Map<Lisp_Object*, Lisp_Object*>* hashMap; | |||||
| ~value() {} | |||||
| } value; | } value; | ||||
| ~Lisp_Object(); | |||||
| }; | }; | ||||
| struct Error { | struct Error { | ||||
| @@ -151,6 +148,7 @@ namespace Slime { | |||||
| String* message; | String* message; | ||||
| }; | }; | ||||
| const wchar_t* char_to_wchar(const char* c); | const wchar_t* char_to_wchar(const char* c); | ||||
| char* read_entire_file(char* filename); | char* read_entire_file(char* filename); | ||||
| void add_to_load_path(const char*); | void add_to_load_path(const char*); | ||||
| @@ -165,7 +163,7 @@ namespace Slime { | |||||
| Lisp_Object* eval_expr(Lisp_Object*); | Lisp_Object* eval_expr(Lisp_Object*); | ||||
| bool is_truthy (Lisp_Object*); | bool is_truthy (Lisp_Object*); | ||||
| int list_length(Lisp_Object*); | int list_length(Lisp_Object*); | ||||
| void load_built_ins_into_environment(); | |||||
| void* load_built_ins_into_environment(); | |||||
| void create_arguments_from_lambda_list_and_inject(Lisp_Object* formal_arguments, Lisp_Object* function); | void create_arguments_from_lambda_list_and_inject(Lisp_Object* formal_arguments, Lisp_Object* function); | ||||
| Lisp_Object* lookup_symbol(Lisp_Object* symbol, Environment*); | Lisp_Object* lookup_symbol(Lisp_Object* symbol, Environment*); | ||||
| @@ -111,7 +111,7 @@ proc built_in_import(String* file_name) -> Lisp_Object* { | |||||
| return Memory::nil; | return Memory::nil; | ||||
| } | } | ||||
| proc load_built_ins_into_environment() -> void { | |||||
| proc load_built_ins_into_environment() -> void* { | |||||
| String* file_name_built_ins = Memory::create_string(__FILE__); | String* file_name_built_ins = Memory::create_string(__FILE__); | ||||
| define((helper), "") { | define((helper), "") { | ||||
| @@ -1065,4 +1065,5 @@ proc load_built_ins_into_environment() -> void { | |||||
| return Memory::create_lisp_object_string(resulting_string); | return Memory::create_lisp_object_string(resulting_string); | ||||
| }; | }; | ||||
| return nullptr; | |||||
| } | } | ||||
| @@ -114,13 +114,13 @@ | |||||
| Parser::parser_col = 0; \ | Parser::parser_col = 0; \ | ||||
| auto label(params,__LINE__) = Parser::parse_single_expression( \ | auto label(params,__LINE__) = Parser::parse_single_expression( \ | ||||
| Memory::get_c_str(Memory::create_string(#def))); \ | Memory::get_c_str(Memory::create_string(#def))); \ | ||||
| if_error_log_location_and_return(); \ | |||||
| if_error_log_location_and_return(nullptr); \ | |||||
| assert_type(label(params,__LINE__), Lisp_Object_Type::Pair); \ | assert_type(label(params,__LINE__), Lisp_Object_Type::Pair); \ | ||||
| assert_type(label(params,__LINE__)->value.pair.first, Lisp_Object_Type::Symbol); \ | assert_type(label(params,__LINE__)->value.pair.first, Lisp_Object_Type::Symbol); \ | ||||
| auto label(sym,__LINE__) = label(params,__LINE__)->value.pair.first; \ | auto label(sym,__LINE__) = label(params,__LINE__)->value.pair.first; \ | ||||
| auto label(sfun,__LINE__) = Memory::create_lisp_object_cfunction(special); \ | auto label(sfun,__LINE__) = Memory::create_lisp_object_cfunction(special); \ | ||||
| create_arguments_from_lambda_list_and_inject(label(params,__LINE__)->value.pair.rest, label(sfun,__LINE__)); \ | create_arguments_from_lambda_list_and_inject(label(params,__LINE__)->value.pair.rest, label(sfun,__LINE__)); \ | ||||
| if_error_log_location_and_return(); \ | |||||
| if_error_log_location_and_return(nullptr); \ | |||||
| label(sfun,__LINE__)->docstring = Memory::create_string(docs); \ | label(sfun,__LINE__)->docstring = Memory::create_string(docs); \ | ||||
| define_symbol(label(sym,__LINE__), label(sfun,__LINE__)); \ | define_symbol(label(sym,__LINE__), label(sfun,__LINE__)); \ | ||||
| label(sfun,__LINE__)->value.cFunction->body = []() -> Lisp_Object* | label(sfun,__LINE__)->value.cFunction->body = []() -> Lisp_Object* | ||||
| @@ -92,11 +92,11 @@ proc print_environment_indent(Environment* env, int indent) -> void { | |||||
| } | } | ||||
| }; | }; | ||||
| if(env == get_root_environment()) { | |||||
| print_indent(indent); | |||||
| printf("[built-ins]-Environment (%lld)\n", (long long)env); | |||||
| return; | |||||
| } | |||||
| // if(env == get_root_environment()) { | |||||
| // print_indent(indent); | |||||
| // printf("[built-ins]-Environment (%lld)\n", (long long)env); | |||||
| // return; | |||||
| // } | |||||
| for_hash_map (env->hm) { | for_hash_map (env->hm) { | ||||
| print_indent(indent); | print_indent(indent); | ||||
| @@ -10,7 +10,7 @@ Lisp_Object* eval_arguments(Lisp_Object*); | |||||
| Lisp_Object* eval_expr(Lisp_Object*); | Lisp_Object* eval_expr(Lisp_Object*); | ||||
| bool is_truthy (Lisp_Object*); | bool is_truthy (Lisp_Object*); | ||||
| int list_length(Lisp_Object*); | int list_length(Lisp_Object*); | ||||
| void load_built_ins_into_environment(); | |||||
| void* load_built_ins_into_environment(); | |||||
| void create_arguments_from_lambda_list_and_inject(Lisp_Object* formal_arguments, Lisp_Object* function); | void create_arguments_from_lambda_list_and_inject(Lisp_Object* formal_arguments, Lisp_Object* function); | ||||
| Lisp_Object* lookup_symbol(Lisp_Object* symbol, Environment*); | Lisp_Object* lookup_symbol(Lisp_Object* symbol, Environment*); | ||||
| @@ -116,7 +116,7 @@ proc unescape_string(char* in) -> int { | |||||
| /* Set the end of string. */ | /* Set the end of string. */ | ||||
| *out = '\0'; | *out = '\0'; | ||||
| return out - in; | |||||
| return (int)(out - in); | |||||
| } | } | ||||
| proc read_entire_file(char* filename) -> char* { | proc read_entire_file(char* filename) -> char* { | ||||
| @@ -456,7 +456,4 @@ proc log_error() -> void { | |||||
| fputs(" in: ", stdout); | fputs(" in: ", stdout); | ||||
| print_call_stack(); | print_call_stack(); | ||||
| puts(console_normal); | puts(console_normal); | ||||
| // HACK(Felix): we should control the stack size in eval_expr not here | |||||
| // Globals::Current_Execution::call_stack.next_index = 0; | |||||
| } | } | ||||
| @@ -1,7 +1,6 @@ | |||||
| #define _CRT_SECURE_NO_WARNINGS | #define _CRT_SECURE_NO_WARNINGS | ||||
| #define _CRT_SECURE_NO_DEPRECATE | #define _CRT_SECURE_NO_DEPRECATE | ||||
| #define _CRTDBG_MAP_ALLOC | |||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| @@ -12,10 +11,8 @@ | |||||
| #include <stdarg.h> | #include <stdarg.h> | ||||
| #include <errno.h> | #include <errno.h> | ||||
| #include <new> | #include <new> | ||||
| // #include <functional> | |||||
| #ifdef _MSC_VER | #ifdef _MSC_VER | ||||
| # include <crtdbg.h> | |||||
| # include <direct.h> | # include <direct.h> | ||||
| # include <windows.h> | # include <windows.h> | ||||
| #else | #else | ||||
| @@ -6,9 +6,6 @@ int main(int argc, char* argv[]) { | |||||
| int res = Slime::run_all_tests(); | int res = Slime::run_all_tests(); | ||||
| Slime::built_in_load(Slime::Memory::create_string("generate-docs.slime")); | Slime::built_in_load(Slime::Memory::create_string("generate-docs.slime")); | ||||
| Slime::Memory::free_everything(); | Slime::Memory::free_everything(); | ||||
| #ifdef _MSC_VER | |||||
| _CrtDumpMemoryLeaks(); | |||||
| #endif | |||||
| return res ? 0 : 1; | return res ? 0 : 1; | ||||
| } | } | ||||
| @@ -28,12 +28,12 @@ int vasprintf(char **strp, const char *fmt, va_list ap) { | |||||
| return -1; | return -1; | ||||
| } | } | ||||
| size_t size = (size_t)len + 1; | size_t size = (size_t)len + 1; | ||||
| char *str = malloc(size); | |||||
| char *str = (char*)malloc(size); | |||||
| if (!str) { | if (!str) { | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| // _vsprintf_s is the "secure" version of vsprintf | // _vsprintf_s is the "secure" version of vsprintf | ||||
| int r = _vsprintf_s(str, len + 1, fmt, ap); | |||||
| int r = vsprintf_s(str, len + 1, fmt, ap); | |||||
| if (r == -1) { | if (r == -1) { | ||||
| free(str); | free(str); | ||||
| return -1; | return -1; | ||||
| @@ -609,9 +609,9 @@ proc run_all_tests() -> bool { | |||||
| try Memory::init(409600); | try Memory::init(409600); | ||||
| printf("-- Util --\n"); | printf("-- Util --\n"); | ||||
| // invoke_test(test_array_lists_adding_and_removing); | |||||
| // invoke_test(test_array_lists_sorting); | |||||
| // invoke_test(test_array_lists_searching); | |||||
| invoke_test(test_array_lists_adding_and_removing); | |||||
| invoke_test(test_array_lists_sorting); | |||||
| invoke_test(test_array_lists_searching); | |||||
| printf("\n -- Parsing --\n"); | printf("\n -- Parsing --\n"); | ||||
| invoke_test(test_parse_atom); | invoke_test(test_parse_atom); | ||||