small optimizaitons

This commit is contained in:
FelixBrendel
2019-11-19 01:51:15 +01:00
parent 2c097fb85a
commit e02db00b86
16 changed files with 668 additions and 670 deletions
+1 -1
Submodule 3rd/ftb updated: 3959dd2fc1...d2133205a7
BIN
View File
Binary file not shown.
+2 -3
View File
@@ -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 ^ /Zi /std:c++latest /Fe%exeName% /W3 /wd4003 /nologo /EHsc
/link /NODEFAULTLIB:libucrt libucrtd.lib
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
+2
View File
@@ -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
+11 -4
View File
@@ -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)
+15 -17
View File
@@ -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 { union value {
Symbol symbol; // used for symbols and keywords 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; Continuation* continuation;
Hash_Map<Lisp_Object*, Lisp_Object*> hashMap; 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*);
+621 -621
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -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;
} }
+2 -2
View File
@@ -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*
+5 -5
View File
@@ -92,11 +92,11 @@ proc print_environment_indent(Environment* env, int indent) -> void {
} }
}; };
if(env == get_root_environment()) { // if(env == get_root_environment()) {
print_indent(indent); // print_indent(indent);
printf("[built-ins]-Environment (%lld)\n", (long long)env); // printf("[built-ins]-Environment (%lld)\n", (long long)env);
return; // return;
} // }
for_hash_map (env->hm) { for_hash_map (env->hm) {
print_indent(indent); print_indent(indent);
+1 -1
View File
@@ -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*);
+1 -4
View File
@@ -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;
} }
-3
View File
@@ -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
-3
View File
@@ -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;
} }
+2 -2
View File
@@ -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;
+3 -3
View File
@@ -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_adding_and_removing);
// invoke_test(test_array_lists_sorting); invoke_test(test_array_lists_sorting);
// invoke_test(test_array_lists_searching); invoke_test(test_array_lists_searching);
printf("\n -- Parsing --\n"); printf("\n -- Parsing --\n");
invoke_test(test_parse_atom); invoke_test(test_parse_atom);