From fd9db3b0fab5d6f77bc8c47c222409dabadbbb53 Mon Sep 17 00:00:00 2001 From: FelixBrendel Date: Mon, 6 Apr 2020 09:04:12 +0000 Subject: [PATCH 01/10] Add LICENSE --- LICENSE | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..44186a3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2020, FelixBrendel +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From 4803711f2166501778e2ed731d30f109b99b35c3 Mon Sep 17 00:00:00 2001 From: FelixBrendel Date: Tue, 7 Apr 2020 09:02:09 +0000 Subject: [PATCH 02/10] Add .gitlab-ci.yml --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..658c9ac --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,2 @@ +build_and_run: + script: "build.sh" From d10e7fe3ca76cc081ae07b8510fc1f358621f099 Mon Sep 17 00:00:00 2001 From: FelixBrendel Date: Tue, 7 Apr 2020 09:03:58 +0000 Subject: [PATCH 03/10] Update .gitlab-ci.yml --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 658c9ac..22d6b0f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,2 +1,2 @@ build_and_run: - script: "build.sh" + script: "./build.sh" From 5280fa658691dcb24df6a81f61639410f5288e54 Mon Sep 17 00:00:00 2001 From: FelixBrendel Date: Tue, 7 Apr 2020 09:46:16 +0000 Subject: [PATCH 04/10] Update .gitlab-ci.yml --- .gitlab-ci.yml | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 22d6b0f..c104f84 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,2 +1,40 @@ -build_and_run: - script: "./build.sh" +default: + image: warchantua/dev-essential + artifacts: + paths: + - ./bin/slime + - ./bin/slime_d + expire_in: 1 week + +stages: + - build_debug + - build_release + - test + +build_clang++_d: + stage: build_debug + script: clang++ -D_DEBUG -D_DONT_BREAK_ON_ERRORS src/main.cpp -gfull -gdwarf -o ./bin/slime_d --std=c++17 -I3rd/ + +build_g++_d: + stage: build_debug + script: g++ -D_DEBUG -D_DONT_BREAK_ON_ERRORS src/main.cpp -gfull -gdwarf -o ./bin/slime_d --std=c++17 -I3rd/ + +build_clang++_r: + stage: build_release + script: clang++ -D_DONT_BREAK_ON_ERRORS -O3 src/main.cpp -g -o ./bin/slime --std=c++17 -I3rd/ || exit 1 + +build_g++_r: + stage: build_release + script: g++ -D_DONT_BREAK_ON_ERRORS -O3 src/main.cpp -g -o ./bin/slime --std=c++17 -I3rd/ || exit 1 + +tests_d: + stage: test + script: ./bin/sime_d --run-tests + +tests_r: + stage: test + script: ./bin/sime --run-tests + +valgrind: + stage: test + script: valgrind ./bin/sime --run-tests From ef1f8a496ae757c9fc64ca5280ecd5c0b5b243f8 Mon Sep 17 00:00:00 2001 From: FelixBrendel Date: Tue, 7 Apr 2020 09:53:19 +0000 Subject: [PATCH 05/10] Update .gitlab-ci.yml --- .gitlab-ci.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c104f84..0b73150 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,4 @@ default: - image: warchantua/dev-essential artifacts: paths: - ./bin/slime @@ -12,14 +11,18 @@ stages: - test build_clang++_d: + stage: build_debug - script: clang++ -D_DEBUG -D_DONT_BREAK_ON_ERRORS src/main.cpp -gfull -gdwarf -o ./bin/slime_d --std=c++17 -I3rd/ + script: + - ls ./3rd/ftb + - clang++ -D_DEBUG -D_DONT_BREAK_ON_ERRORS src/main.cpp -gfull -gdwarf -o ./bin/slime_d --std=c++17 -I3rd/ build_g++_d: stage: build_debug - script: g++ -D_DEBUG -D_DONT_BREAK_ON_ERRORS src/main.cpp -gfull -gdwarf -o ./bin/slime_d --std=c++17 -I3rd/ + script: g++ -D_DEBUG -D_DONT_BREAK_ON_ERRORS src/main.cpp -g -o ./bin/slime_d --std=c++17 -I3rd/ build_clang++_r: + image: warchantua/dev-essential stage: build_release script: clang++ -D_DONT_BREAK_ON_ERRORS -O3 src/main.cpp -g -o ./bin/slime --std=c++17 -I3rd/ || exit 1 @@ -36,5 +39,6 @@ tests_r: script: ./bin/sime --run-tests valgrind: + image: warchantua/dev-essential stage: test script: valgrind ./bin/sime --run-tests From 75ab3506f5d18a1ed356ee8343270345b5944ea8 Mon Sep 17 00:00:00 2001 From: FelixBrendel Date: Tue, 7 Apr 2020 09:58:03 +0000 Subject: [PATCH 06/10] Update .gitlab-ci.yml --- .gitlab-ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0b73150..1cd2c53 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,13 +5,16 @@ default: - ./bin/slime_d expire_in: 1 week +variables: + GIT_SUBMODULE_STRATEGY: recursive + stages: - build_debug - build_release - test build_clang++_d: - + image: warchantua/dev-essential stage: build_debug script: - ls ./3rd/ftb From 5ed58a7e4c553042de649188831ae9a2db28790b Mon Sep 17 00:00:00 2001 From: FelixBrendel Date: Tue, 7 Apr 2020 10:06:09 +0000 Subject: [PATCH 07/10] Update .gitlab-ci.yml --- .gitlab-ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1cd2c53..a2dfa56 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,9 +16,7 @@ stages: build_clang++_d: image: warchantua/dev-essential stage: build_debug - script: - - ls ./3rd/ftb - - clang++ -D_DEBUG -D_DONT_BREAK_ON_ERRORS src/main.cpp -gfull -gdwarf -o ./bin/slime_d --std=c++17 -I3rd/ + script: clang++ -D_DEBUG -D_DONT_BREAK_ON_ERRORS src/main.cpp -gfull -gdwarf -o ./bin/slime_d --std=c++17 -I3rd/ build_g++_d: stage: build_debug From a6d631e343066ff8fd57e9ed7e5c33668748f359 Mon Sep 17 00:00:00 2001 From: Felix Brendel Date: Tue, 7 Apr 2020 12:33:53 +0200 Subject: [PATCH 08/10] Pipeline test --- .gitlab-ci.yml | 10 +++++----- src/built_ins.cpp | 6 +++--- src/io.cpp | 2 +- src/libslime.cpp | 1 + src/memory.cpp | 8 ++++++-- src/platform.cpp | 7 +++++++ src/testing.cpp | 4 ++-- 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a2dfa56..ad8990e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,11 +16,11 @@ stages: build_clang++_d: image: warchantua/dev-essential stage: build_debug - script: clang++ -D_DEBUG -D_DONT_BREAK_ON_ERRORS src/main.cpp -gfull -gdwarf -o ./bin/slime_d --std=c++17 -I3rd/ + script: clang++ -D_DEBUG -D_DONT_BREAK_ON_ERRORS src/main.cpp -gfull -gdwarf -o ./bin/slime_d --std=c++17 -I3rd/ build_g++_d: stage: build_debug - script: g++ -D_DEBUG -D_DONT_BREAK_ON_ERRORS src/main.cpp -g -o ./bin/slime_d --std=c++17 -I3rd/ + script: g++ -D_DEBUG -D_DONT_BREAK_ON_ERRORS src/main.cpp -g -o ./bin/slime_d --std=c++17 -I3rd/ build_clang++_r: image: warchantua/dev-essential @@ -33,13 +33,13 @@ build_g++_r: tests_d: stage: test - script: ./bin/sime_d --run-tests + script: ./bin/slime_d --run-tests tests_r: stage: test - script: ./bin/sime --run-tests + script: ./bin/slime --run-tests valgrind: image: warchantua/dev-essential stage: test - script: valgrind ./bin/sime --run-tests + script: valgrind ./bin/slime --run-tests diff --git a/src/built_ins.cpp b/src/built_ins.cpp index 670a426..f010ff9 100644 --- a/src/built_ins.cpp +++ b/src/built_ins.cpp @@ -71,10 +71,10 @@ namespace Slime { proc built_in_load(String file_name) -> Lisp_Object* { profile_with_comment(file_name.data); char* file_content; - path_char fullpath[MAX_PATH]; + path_char fullpath[max_path_len]; #ifdef UNICODE path_char* temp = char_to_path_char(Memory::get_c_str(file_name)); - swprintf(fullpath, MAX_PATH,L"%s", temp); + swprintf(fullpath, max_path_len,L"%s", temp); file_content = read_entire_file(temp); free(temp); #else @@ -89,7 +89,7 @@ namespace Slime { #ifdef UNICODE fullpath[0] = L'\0'; path_char* temp = char_to_path_char(Memory::get_c_str(file_name)); - swprintf(fullpath, MAX_PATH, L"%s%s", it, temp); + swprintf(fullpath, max_path_leno, L"%s%s", it, temp); free(temp); #else fullpath[0] = '\0'; diff --git a/src/io.cpp b/src/io.cpp index 31ccd2b..d6729de 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -356,7 +356,7 @@ namespace Slime { if (abs(node->value.number - (s32)node->value.number) < 0.000001f) asprintf(&temp, "%d", (s32)node->value.number); else - asprintf(&temp, "%f", node->value.number); + asprintf(&temp, "%Lf", node->value.number); return temp; } case (Lisp_Object_Type::Keyword): { diff --git a/src/libslime.cpp b/src/libslime.cpp index bbabed4..4384a99 100644 --- a/src/libslime.cpp +++ b/src/libslime.cpp @@ -17,6 +17,7 @@ # include # include #else +# include # include # include #endif diff --git a/src/memory.cpp b/src/memory.cpp index 54a7b8e..daf4617 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -126,8 +126,12 @@ namespace Slime::Memory { free(value); } - // free the exe dir: - free(Globals::load_path.data[0]); + + // free paths in load path + for (u32 i = 0; i < Globals::load_path.next_index; ++i) { + free(Globals::load_path.data[i]); + } + Globals::load_path.dealloc(); Globals::user_types.dealloc(); Globals::docs.dealloc(); diff --git a/src/platform.cpp b/src/platform.cpp index 0252f40..f882d89 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -1,5 +1,12 @@ namespace Slime { +#ifdef SLIME_WINDOWS + constexpr u32 max_path_len = MAX_PATH; +#else + constexpr u32 max_path_len = PATH_MAX; +#endif + + inline proc get_cwd() -> char* { const u32 buf_size = 2048; char* res = (char*)malloc(buf_size * sizeof(char)); diff --git a/src/testing.cpp b/src/testing.cpp index a98868d..1265746 100644 --- a/src/testing.cpp +++ b/src/testing.cpp @@ -46,13 +46,13 @@ namespace Slime { } \ #define assert_equal_f64(variable, value) \ - if (fabs((f64)variable - (f64)value) > epsilon) { \ + if (fabsl((f64)variable - (f64)value) > epsilon) { \ print_assert_equal_fail(variable, value, f64, "%Lf"); \ return fail; \ } #define assert_not_equal_f64(variable, value) \ - if (fabs((f64)variable - (f64)value) <= epsilon) { \ + if (fabsl((f64)variable - (f64)value) <= epsilon) { \ print_assert_not_equal_fail(variable, value, f64, "L%f"); \ return fail; \ } From 5b1000eb01c2065df34868c9c06b23e66bcf1559 Mon Sep 17 00:00:00 2001 From: Felix Brendel Date: Thu, 9 Apr 2020 18:06:50 +0200 Subject: [PATCH 09/10] valgrind ci errors now on leak --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ad8990e..e7d93a5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -42,4 +42,4 @@ tests_r: valgrind: image: warchantua/dev-essential stage: test - script: valgrind ./bin/slime --run-tests + script: valgrind --error-exitcode=123 -q --track-origins=yes --leak-check=full --show-leak-kinds=all ./bin/slime_d --run-tests From 8d7dfee971ccc0b4bda9e3f66a199529b7c19419 Mon Sep 17 00:00:00 2001 From: Felix Brendel Date: Thu, 9 Apr 2020 20:26:26 +0200 Subject: [PATCH 10/10] fixed memory leaks introduced by continuations --- build.sh | 14 +++++----- src/built_ins.cpp | 4 ++- src/eval.cpp | 3 +++ src/memory.cpp | 68 +++++++++++++++++++++++++++++++++-------------- 4 files changed, 61 insertions(+), 28 deletions(-) diff --git a/build.sh b/build.sh index c6f149c..3bd6c39 100755 --- a/build.sh +++ b/build.sh @@ -18,13 +18,13 @@ time clang++ -D_DEBUG -D_DONT_BREAK_ON_ERRORS \ src/main.cpp -gfull -gdwarf -o ./bin/slime_d --std=c++17 \ -I3rd/ || exit 1 -# echo "" -# echo "--------------------------------" -# echo " compiling fullslime (release) " -# echo "--------------------------------" -# time clang++ -D_DONT_BREAK_ON_ERRORS -O3 \ -# src/main.cpp -g -o ./bin/slime --std=c++17 \ -# -I3rd/ || exit 1 +echo "" +echo "--------------------------------" +echo " compiling fullslime (release) " +echo "--------------------------------" +time clang++ -D_DONT_BREAK_ON_ERRORS -O3 \ + src/main.cpp -g -o ./bin/slime --std=c++17 \ + -I3rd/ || exit 1 echo "" echo "------------------------------" diff --git a/src/built_ins.cpp b/src/built_ins.cpp index f010ff9..f353f54 100644 --- a/src/built_ins.cpp +++ b/src/built_ins.cpp @@ -1319,7 +1319,9 @@ namespace Slime { // example, numbers are not valid symbols. try assert_type(str, Lisp_Object_Type::String); - return Memory::get_symbol(Memory::duplicate_string(str->value.string)); + // TODO(Felix): It was like this: why did we have to copy it? + // return Memory::get_symbol(Memory::duplicate_string(str->value.string)); + return Memory::get_symbol(str->value.string); }; define((concat-strings . strings), "TODO") { profile_with_name("(concat-strings)"); diff --git a/src/eval.cpp b/src/eval.cpp index 37e19a5..fbf7cb0 100644 --- a/src/eval.cpp +++ b/src/eval.cpp @@ -445,6 +445,9 @@ namespace Slime { Globals::Current_Execution.cs.clear(); Globals::Current_Execution.ams.clear(); Globals::Current_Execution.pcs.clear(); + for (auto it: Globals::Current_Execution.nass) { + it.dealloc(); + } Globals::Current_Execution.nass.clear(); Globals::Current_Execution.envi_stack.clear(); Globals::Current_Execution.ats.clear(); diff --git a/src/memory.cpp b/src/memory.cpp index daf4617..115d384 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -100,6 +100,20 @@ namespace Slime::Memory { proc free_everything() -> void { object_memory.for_each([](Lisp_Object* lo){ switch (lo->type) { + case Lisp_Object_Type::Continuation: { + lo->value.continuation->cs.dealloc(); + lo->value.continuation->pcs.dealloc(); + lo->value.continuation->ams.dealloc(); + lo->value.continuation->ats.dealloc(); + lo->value.continuation->mes.dealloc(); + lo->value.continuation->envi_stack.dealloc(); + for (auto it : lo->value.continuation->nass) { + it.dealloc(); + } + lo->value.continuation->nass.dealloc(); + free(lo->value.continuation); + + } break; case Lisp_Object_Type::Function: { lo->value.function->args.positional.symbols.dealloc(); lo->value.function->args.keyword.keywords.dealloc(); @@ -140,6 +154,9 @@ namespace Slime::Memory { Globals::Current_Execution.ams.dealloc(); Globals::Current_Execution.pcs.dealloc(); Globals::Current_Execution.nass.dealloc(); + for (auto it: Globals::Current_Execution.nass) { + it.dealloc(); + } Globals::Current_Execution.ats.dealloc(); Globals::Current_Execution.mes.dealloc(); @@ -278,24 +295,28 @@ namespace Slime::Memory { return node; } + inline proc full_clone_continuation(Continuation* c) -> Continuation* { + Continuation* res = (Continuation*)malloc(sizeof(Continuation)); + res->cs = c->cs.clone(); + res->pcs = c->pcs.clone(); + res->ams = c->ams.clone(); + res->ats = c->ats.clone(); + res->mes = c->mes.clone(); + res->envi_stack = c->envi_stack.clone(); + res->nass = c->nass.clone(); + + for (u32 i = 0; i < res->nass.next_index; ++i) { + res->nass.data[i] = c->nass.data[i].clone(); + } + + return res; + } proc create_lisp_object_continuation() -> Lisp_Object* { - using Globals::Current_Execution; Lisp_Object* node; try node = create_lisp_object(); node->type = Lisp_Object_Type::Continuation; - node->value.continuation = (Continuation*)malloc(sizeof(Continuation)); - node->value.continuation->cs = Current_Execution.cs.clone(); - node->value.continuation->pcs = Current_Execution.pcs.clone(); - node->value.continuation->ams = Current_Execution.ams.clone(); - node->value.continuation->ats = Current_Execution.ats.clone(); - node->value.continuation->mes = Current_Execution.mes.clone(); - node->value.continuation->envi_stack = Current_Execution.envi_stack.clone(); - - node->value.continuation->nass = Current_Execution.nass.clone(); - for (u32 i = 0; i < node->value.continuation->nass.next_index; ++i) { - node->value.continuation->nass.data[i] = node->value.continuation->nass.data[i].clone(); - } + node->value.continuation = full_clone_continuation(&Globals::Current_Execution); return node; } @@ -454,25 +475,32 @@ namespace Slime::Memory { if (n == Memory::nil || n == Memory::t) { return n; } else { - Lisp_Object_Type type = n->type; - if (type == Lisp_Object_Type::Symbol || - type == Lisp_Object_Type::Keyword || - type == Lisp_Object_Type::Function) - { + switch(n->type) { + case Lisp_Object_Type::Symbol: + case Lisp_Object_Type::Keyword: + case Lisp_Object_Type::Function: return n; - } else if (type == Lisp_Object_Type::String) { + case Lisp_Object_Type::String: { Lisp_Object* target; try target = create_lisp_object(); *target = *n; target->value.string = create_string(target->value.string.data); return target; - } else { + } + case Lisp_Object_Type::Continuation: + Lisp_Object* target; + try target = create_lisp_object(); + *target = *n; + target->value.continuation = full_clone_continuation(n->value.continuation); + return target; + default: { Lisp_Object* target; try target = create_lisp_object(); *target = *n; return target; } + } } }