From 700aa80415afd51f26c9839845bd3ebdb423eaf3 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Mon, 6 Jun 2022 00:41:57 +0900 Subject: [PATCH 01/24] Add new profile topic `count_instruction_fetch` Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/machine.hpp | 5 +++++ include/meevax/kernel/profiler.hpp | 7 ++++++- src/kernel/profiler.cpp | 16 ++++++++++++++++ 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dae72dcc3..56b86c39e 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.40.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.41.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.40_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.41_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.40 +Meevax Lisp System, version 0.4.41 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 12fd0b492..4fc37cdb2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.40 +0.4.41 diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index 7543211f0..3ff99de38 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -338,6 +338,11 @@ inline namespace kernel << faint("; d = ") << d << "\n" << std::endl; } + if constexpr (profiler::count_instruction_fetch) + { + current_profiler().instruction_fetchs[car(c).template as()]++; + } + switch (car(c).template as()) { case mnemonic::load_absolute: /* ----------------------------------------- diff --git a/include/meevax/kernel/profiler.hpp b/include/meevax/kernel/profiler.hpp index e03e6a71f..610d11a81 100644 --- a/include/meevax/kernel/profiler.hpp +++ b/include/meevax/kernel/profiler.hpp @@ -20,16 +20,21 @@ #include #include +#include + namespace meevax { inline namespace kernel { struct profiler { - static constexpr auto count_allocations = false; + static constexpr auto count_allocations = false; + static constexpr auto count_instruction_fetch = true; std::unordered_map allocation_counts; + std::unordered_map instruction_fetchs; + ~profiler(); }; diff --git a/src/kernel/profiler.cpp b/src/kernel/profiler.cpp index 0d53fda6d..5dc0c3e86 100644 --- a/src/kernel/profiler.cpp +++ b/src/kernel/profiler.cpp @@ -52,6 +52,22 @@ inline namespace kernel | echo \"TYPENAME\tALLOCATION COUNT\n$(cat -)\" \ | column -t -s'\t'"); } + + if (auto ss = std::stringstream(); not std::empty(instruction_fetchs)) + { + for (auto&& [mnemonic, count] : instruction_fetchs) + { + ss << mnemonic << "\t" << count << "\n"; + } + + sh("echo \"" + ss.str() + "\" | sed 's/meevax::kernel:://g' \ + | sort --field-separator='\t' \ + --key=2 \ + --numeric-sort \ + --reverse \ + | echo \"MNEMONIC\tFETCH COUNT\n$(cat -)\" \ + | column -t -s'\t'"); + } } auto current_profiler() -> profiler & From c2ebea2a74fb828a8425d4b97eeed5fb48eb9c9c Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Tue, 7 Jun 2022 05:05:10 +0900 Subject: [PATCH 02/24] Cleanup syntax `if` Signed-off-by: yamacir-kit --- README.md | 6 +-- VERSION | 2 +- include/meevax/kernel/machine.hpp | 69 +++++++++++++------------------ 3 files changed, 33 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 56b86c39e..a509532eb 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.41.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.42.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.41_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.42_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.41 +Meevax Lisp System, version 0.4.42 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 4fc37cdb2..7db6fa787 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.41 +0.4.42 diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index 3ff99de38..8f9bc3aca 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -375,10 +375,6 @@ inline namespace kernel * * ------------------------------------------------------------------- */ s = cons(cadr(c).template as().load(e), s); - if (car(s).template is()) - { - std::cout << "; warning: " << cadr(c) << " is unbound." << std::endl; - } c = cddr(c); goto decode; @@ -902,54 +898,47 @@ inline namespace kernel { if (current_context & context::tail) { - auto consequent = - compile(context::tail, - current_environment, - cadr(current_expression), - current_scope, - list(make(mnemonic::return_))); - - auto alternate = - cddr(current_expression) - ? compile(context::tail, - current_environment, - caddr(current_expression), - current_scope, - list(make(mnemonic::return_))) - : list(make(mnemonic::load_constant), unspecified_object, - make(mnemonic::return_)); + assert(lexical_cast(current_continuation) == "(return)"); return compile(context::none, current_environment, car(current_expression), // current_scope, - cons(make(mnemonic::tail_select), consequent, alternate, - cdr(current_continuation))); + list(make(mnemonic::tail_select), + compile(context::tail, + current_environment, + cadr(current_expression), + current_scope, + current_continuation), + cddr(current_expression) + ? compile(context::tail, + current_environment, + caddr(current_expression), + current_scope, + current_continuation) + : list(make(mnemonic::load_constant), unspecified_object, + make(mnemonic::return_)))); } else { - auto consequent = - compile(context::none, - current_environment, - cadr(current_expression), - current_scope, - list(make(mnemonic::join))); - - auto alternate = - cddr(current_expression) - ? compile(context::none, - current_environment, - caddr(current_expression), - current_scope, - list(make(mnemonic::join))) - : list(make(mnemonic::load_constant), unspecified_object, - make(mnemonic::join)); - return compile(context::none, current_environment, car(current_expression), // current_scope, - cons(make(mnemonic::select), consequent, alternate, + cons(make(mnemonic::select), + compile(context::none, + current_environment, + cadr(current_expression), + current_scope, + list(make(mnemonic::join))), + cddr(current_expression) + ? compile(context::none, + current_environment, + caddr(current_expression), + current_scope, + list(make(mnemonic::join))) + : list(make(mnemonic::load_constant), unspecified_object, + make(mnemonic::join)), current_continuation)); } } From cb347f3000552b203d0877a511ef54ba6055508e Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Thu, 9 Jun 2022 00:31:29 +0900 Subject: [PATCH 03/24] Simplify struct `context` Signed-off-by: yamacir-kit --- README.md | 6 +- VERSION | 2 +- include/meevax/kernel/context.hpp | 22 +++--- include/meevax/kernel/machine.hpp | 121 ++++++++++++------------------ include/meevax/kernel/syntax.hpp | 2 +- src/kernel/environment.cpp | 2 +- test/transformer.ss | 2 +- 7 files changed, 63 insertions(+), 94 deletions(-) diff --git a/README.md b/README.md index a509532eb..618caba87 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.42.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.43.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.42_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.43_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.42 +Meevax Lisp System, version 0.4.43 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 7db6fa787..3d08009d9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.42 +0.4.43 diff --git a/include/meevax/kernel/context.hpp b/include/meevax/kernel/context.hpp index 98c633a42..3f1391372 100644 --- a/include/meevax/kernel/context.hpp +++ b/include/meevax/kernel/context.hpp @@ -23,23 +23,19 @@ inline namespace kernel { struct context { - enum value_type + bool is_outermost = false; + bool is_tail = false; + + auto mark_outermost_as(bool value) noexcept -> auto & { - none, - outermost = (1 << 0), - tail = (1 << 1), - size, + is_outermost = value; + return *this; } - const value; - - template - constexpr context(T const value) noexcept - : value { static_cast(value) } - {} - constexpr operator value_type() const noexcept + auto mark_tail_as(bool value) noexcept -> auto & { - return value; + is_tail = value; + return *this; } }; } // namespace kernel diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index 8f9bc3aca..8d86dac61 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -183,8 +183,8 @@ inline namespace kernel * * ---------------------------------------------------------------------- */ static auto compile( - context const current_context, - environment & current_environment, + context current_context, + environment & current_environment, const_reference current_expression, const_reference current_scope = unit, const_reference current_continuation = list(make(mnemonic::stop))) -> lvalue @@ -253,7 +253,7 @@ inline namespace kernel { assert(id.as().load().is_also()); - return compile(context::none, + return compile(current_context, current_environment, id.as().load().as().expand(current_expression, current_environment.fork(current_scope)), current_scope, @@ -269,7 +269,7 @@ inline namespace kernel } else if (applicant.is_also()) { - return compile(context::none, + return compile(context(), current_environment, applicant.as().expand(current_expression, current_environment.fork(current_scope)), @@ -313,15 +313,15 @@ inline namespace kernel * * ------------------------------------------------------------------ */ { - return operand(context::none, + return operand(context(), current_environment, cdr(current_expression), current_scope, - compile(context::none, + compile(context(), current_environment, car(current_expression), current_scope, - cons(make(current_context & context::tail ? mnemonic::tail_call : mnemonic::call), + cons(make(current_context.is_tail ? mnemonic::tail_call : mnemonic::call), current_continuation))); } } @@ -483,7 +483,7 @@ inline namespace kernel e = cons(unit, e); // dummy environment std::swap(c.as(), - body(context::none, + body(context(), static_cast(*this), cadr(c).template as().expression(), cadr(c).template as().scope(), @@ -505,14 +505,14 @@ inline namespace kernel for (let const& transformer_spec : transformer_specs) { - expander.as().execute(compile(context::outermost, + expander.as().execute(compile(context().mark_outermost_as(true), expander.as(), cons(make("define-syntax", define_syntax), transformer_spec), cadr(c).template as().scope())); } std::swap(c.as(), - machine::body(context::outermost, + machine::body(context().mark_outermost_as(true), expander.as(), body, cadr(c).template as().scope(), @@ -758,7 +758,7 @@ inline namespace kernel { let const& id = current_environment.identify(car(current_expression), current_scope); - return compile(context::none, + return compile(context(), current_environment, cadr(current_expression), current_scope, @@ -819,7 +819,7 @@ inline namespace kernel */ if (cdr(current_expression).is()) // is tail-sequence { - return compile(current_context | context::tail, + return compile(current_context.mark_tail_as(true), current_environment, car(current_expression), current_scope, @@ -896,22 +896,22 @@ inline namespace kernel * * ----------------------------------------------------------------------- */ { - if (current_context & context::tail) + if (current_context.is_tail) { assert(lexical_cast(current_continuation) == "(return)"); - return compile(context::none, + return compile(context(), current_environment, car(current_expression), // current_scope, list(make(mnemonic::tail_select), - compile(context::tail, + compile(current_context, current_environment, cadr(current_expression), current_scope, current_continuation), cddr(current_expression) - ? compile(context::tail, + ? compile(current_context, current_environment, caddr(current_expression), current_scope, @@ -921,18 +921,18 @@ inline namespace kernel } else { - return compile(context::none, + return compile(context(), current_environment, car(current_expression), // current_scope, cons(make(mnemonic::select), - compile(context::none, + compile(context(), current_environment, cadr(current_expression), current_scope, list(make(mnemonic::join))), cddr(current_expression) - ? compile(context::none, + ? compile(context(), current_environment, caddr(current_expression), current_scope, @@ -945,11 +945,11 @@ inline namespace kernel static SYNTAX(cons_) { - return compile(context::none, + return compile(context(), current_environment, cadr(current_expression), current_scope, - compile(context::none, + compile(context(), current_environment, car(current_expression), current_scope, @@ -981,11 +981,11 @@ inline namespace kernel * * ----------------------------------------------------------------------- */ { - if (current_scope.is() or (current_context & context::outermost)) + if (current_scope.is() or current_context.is_outermost) { if (car(current_expression).is()) // (define (f . ) ) { - return compile(context::none, + return compile(context(), current_environment, cons(make("lambda", lambda), cdar(current_expression), cdr(current_expression)), current_scope, @@ -994,7 +994,7 @@ inline namespace kernel } else // (define x ...) { - return compile(context::none, + return compile(context(), current_environment, cdr(current_expression) ? cadr(current_expression) : unspecified_object, current_scope, @@ -1062,7 +1062,7 @@ inline namespace kernel * * ----------------------------------------------------------------------- */ { - return compile(context::none, + return compile(context(), current_environment, cdr(current_expression) ? cadr(current_expression) : undefined, current_scope, @@ -1126,7 +1126,7 @@ inline namespace kernel auto make_keyword = [&](let const& binding) { return make(car(binding), - compile(context::outermost, + compile(context(), current_environment, cadr(binding), current_scope)); @@ -1207,11 +1207,11 @@ inline namespace kernel auto const& [variables, inits] = unzip2(car(current_expression)); return cons(make(mnemonic::dummy), - operand(context::none, + operand(context(), current_environment, inits, cons(variables, current_scope), - lambda(context::none, + lambda(current_context, current_environment, cons(variables, cdr(current_expression)), // ( ) current_scope, @@ -1262,11 +1262,11 @@ inline namespace kernel { if (current_expression.is()) { - return operand(context::none, + return operand(context(), current_environment, cdr(current_expression), current_scope, - compile(context::none, + compile(context(), current_environment, car(current_expression), current_scope, @@ -1275,7 +1275,7 @@ inline namespace kernel } else { - return compile(context::none, + return compile(context(), current_environment, current_expression, current_scope, @@ -1309,53 +1309,26 @@ inline namespace kernel * * ---------------------------------------------------------------------- */ { - if (current_context & context::outermost) + if (cdr(current_expression).is()) // is tail sequence { - if (cdr(current_expression).is()) - { - return compile(current_context, - current_environment, - car(current_expression), - current_scope, - current_continuation); - } - else - { - return compile(context::outermost, - current_environment, - car(current_expression), - current_scope, - cons(make(mnemonic::drop), - begin(context::outermost, - current_environment, - cdr(current_expression), - current_scope, - current_continuation))); - } + return compile(current_context, + current_environment, + car(current_expression), + current_scope, + current_continuation); } else { - if (cdr(current_expression).is()) // is tail sequence - { - return compile(current_context, - current_environment, - car(current_expression), - current_scope, - current_continuation); - } - else - { - return compile(context::none, - current_environment, - car(current_expression), // head expression - current_scope, - cons(make(mnemonic::drop), // pop result of head expression - begin(context::none, - current_environment, - cdr(current_expression), // rest expressions - current_scope, - current_continuation))); - } + return compile(current_context.mark_tail_as(false), + current_environment, + car(current_expression), // head expression + current_scope, + cons(make(mnemonic::drop), // pop result of head expression + begin(current_context, + current_environment, + cdr(current_expression), // rest expressions + current_scope, + current_continuation))); } } }; diff --git a/include/meevax/kernel/syntax.hpp b/include/meevax/kernel/syntax.hpp index 11b99e8a3..d18713421 100644 --- a/include/meevax/kernel/syntax.hpp +++ b/include/meevax/kernel/syntax.hpp @@ -23,7 +23,7 @@ #define SYNTAX(NAME) \ auto NAME( \ - [[maybe_unused]] context const current_context, \ + [[maybe_unused]] context current_context, \ [[maybe_unused]] environment & current_environment, \ [[maybe_unused]] const_reference current_expression, \ [[maybe_unused]] const_reference current_scope, \ diff --git a/src/kernel/environment.cpp b/src/kernel/environment.cpp index 600e3fdf4..95abd7373 100644 --- a/src/kernel/environment.cpp +++ b/src/kernel/environment.cpp @@ -131,7 +131,7 @@ inline namespace kernel { auto dump = std::make_tuple(std::exchange(s, unit), std::exchange(e, unit), - std::exchange(c, compile(context::none, *this, expression, scope())), + std::exchange(c, compile(context(), *this, expression, scope())), std::exchange(d, unit)); if (debug) diff --git a/test/transformer.ss b/test/transformer.ss index 0b8e0e827..0a68ee9e9 100644 --- a/test/transformer.ss +++ b/test/transformer.ss @@ -32,7 +32,7 @@ (check (cons x y) => (2 . 1)) -; ; ------------------------------------------------------------------------------ +; ------------------------------------------------------------------------------ (define-syntax swap! (sc-macro-transformer From 65f84efc5a0cbf96639b893dda36707c6c606d29 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Thu, 9 Jun 2022 03:55:17 +0900 Subject: [PATCH 04/24] Fix syntax `let-syntax` to generate code via syntax `lambda` Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/machine.hpp | 32 +++++++++++++++---------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 618caba87..fd00cbd29 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.43.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.44.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.43_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.44_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.43 +Meevax Lisp System, version 0.4.44 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 3d08009d9..f12386c3e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.43 +0.4.44 diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index 8d86dac61..072cb50e7 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -468,28 +468,28 @@ inline namespace kernel * s e (%let-syntax . c) d => s e c' d * * ------------------------------------------------------------------- */ - [&]() + [this]() { - for (let const& keyword_ : car(cadr(c).template as().scope())) + auto && [current_expression, current_scope] = unpair(cadr(c)); + + for (let const& keyword_ : car(current_scope)) { let & binding = keyword_.as().load(); - let const& f = environment(static_cast(*this)).execute(binding); - - binding = make(f, fork(cdr(cadr(c).template as().scope()))); + binding = make(environment(static_cast(*this)).execute(binding), + fork(cdr(current_scope))); } - }(); - - e = cons(unit, e); // dummy environment - - std::swap(c.as(), - body(context(), - static_cast(*this), - cadr(c).template as().expression(), - cadr(c).template as().scope(), - cddr(c) - ).template as()); + std::swap(c.as(), + compile(context(), + static_cast(*this), + cons(cons(make("lambda", lambda), + car(current_scope), // + current_expression), // + car(current_scope)), + cdr(current_scope), + cddr(c)).template as()); + }(); goto decode; case mnemonic::letrec_syntax: /* ----------------------------------------- From 9a891041cf2376965e71a12ddd13755e97a6fd8c Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Fri, 10 Jun 2022 23:12:14 +0900 Subject: [PATCH 05/24] Fix syntax `letrec-syntax` to generate code via syntax `lambda` Signed-off-by: yamacir-kit --- README.md | 6 ++--- VERSION | 2 +- include/meevax/kernel/machine.hpp | 44 +++++++++++++++++-------------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index fd00cbd29..7affa40b3 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.44.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.45.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.44_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.45_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.44 +Meevax Lisp System, version 0.4.45 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index f12386c3e..a2af767cd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.44 +0.4.45 diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index 072cb50e7..07816a6e8 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -482,13 +482,13 @@ inline namespace kernel std::swap(c.as(), compile(context(), - static_cast(*this), - cons(cons(make("lambda", lambda), - car(current_scope), // - current_expression), // - car(current_scope)), - cdr(current_scope), - cddr(c)).template as()); + static_cast(*this), + cons(cons(make("lambda", lambda), + car(current_scope), // + current_expression), // + car(current_scope)), + cdr(current_scope), + cddr(c)).template as()); }(); goto decode; @@ -497,27 +497,31 @@ inline namespace kernel * s e (%letrec-syntax . c) d => s e c' d * * ------------------------------------------------------------------- */ - [&]() // DIRTY HACK!!! + [this]() // DIRTY HACK!!! { - let const expander = fork(cadr(c).template as().scope()); + auto && [current_expression, current_scope] = unpair(cadr(c)); + + auto && [transformer_specs, body] = unpair(current_expression); - auto const [transformer_specs, body] = unpair(cadr(c).template as().expression()); + let const syntactic_environment = fork(current_scope); for (let const& transformer_spec : transformer_specs) { - expander.as().execute(compile(context().mark_outermost_as(true), - expander.as(), - cons(make("define-syntax", define_syntax), transformer_spec), - cadr(c).template as().scope())); + let const c = compile(context().mark_outermost_as(true), + syntactic_environment.as(), + cons(make("define-syntax", define_syntax), transformer_spec), + current_scope); + + syntactic_environment.as().execute(c); } std::swap(c.as(), - machine::body(context().mark_outermost_as(true), - expander.as(), - body, - cadr(c).template as().scope(), - cddr(c) - ).template as()); + compile(context().mark_outermost_as(true), + syntactic_environment.as(), + cons(cons(make("lambda", lambda), unit, body), unit), // (let () ) + current_scope, + cddr(c) + ).template as()); }(); goto decode; From b480424ddfc9da7beed533eac891b91f12d9bcba Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Fri, 10 Jun 2022 23:27:46 +0900 Subject: [PATCH 06/24] Fix macroexpand to pass compilation context correctly Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/machine.hpp | 2 +- include/meevax/kernel/profiler.hpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7affa40b3..7fa0ec73f 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.45.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.46.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.45_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.46_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.45 +Meevax Lisp System, version 0.4.46 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index a2af767cd..19cc27710 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.45 +0.4.46 diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index 07816a6e8..32d6d9f89 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -269,7 +269,7 @@ inline namespace kernel } else if (applicant.is_also()) { - return compile(context(), + return compile(current_context, current_environment, applicant.as().expand(current_expression, current_environment.fork(current_scope)), diff --git a/include/meevax/kernel/profiler.hpp b/include/meevax/kernel/profiler.hpp index 610d11a81..f7a1f40f2 100644 --- a/include/meevax/kernel/profiler.hpp +++ b/include/meevax/kernel/profiler.hpp @@ -29,7 +29,7 @@ inline namespace kernel struct profiler { static constexpr auto count_allocations = false; - static constexpr auto count_instruction_fetch = true; + static constexpr auto count_instruction_fetch = false; std::unordered_map allocation_counts; From e22890e86c8db06e03be1dbf3a52f67e932f6fbf Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 01:36:35 +0900 Subject: [PATCH 07/24] Remove compile context `is_outermost` Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/context.hpp | 17 +++-------------- include/meevax/kernel/machine.hpp | 10 +++++----- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 7fa0ec73f..5c72b50e0 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.46.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.47.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.46_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.47_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.46 +Meevax Lisp System, version 0.4.47 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 19cc27710..90ebc3240 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.46 +0.4.47 diff --git a/include/meevax/kernel/context.hpp b/include/meevax/kernel/context.hpp index 3f1391372..0ee2d9540 100644 --- a/include/meevax/kernel/context.hpp +++ b/include/meevax/kernel/context.hpp @@ -23,21 +23,10 @@ inline namespace kernel { struct context { - bool is_outermost = false; - bool is_tail = false; - - auto mark_outermost_as(bool value) noexcept -> auto & - { - is_outermost = value; - return *this; - } - - auto mark_tail_as(bool value) noexcept -> auto & - { - is_tail = value; - return *this; - } + bool is_tail = false; }; + + constexpr auto in_a_tail_context = context { true }; } // namespace kernel } // namespace meevax diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index 32d6d9f89..ce9a4f7be 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -507,7 +507,7 @@ inline namespace kernel for (let const& transformer_spec : transformer_specs) { - let const c = compile(context().mark_outermost_as(true), + let const c = compile(context(), syntactic_environment.as(), cons(make("define-syntax", define_syntax), transformer_spec), current_scope); @@ -516,7 +516,7 @@ inline namespace kernel } std::swap(c.as(), - compile(context().mark_outermost_as(true), + compile(context(), syntactic_environment.as(), cons(cons(make("lambda", lambda), unit, body), unit), // (let () ) current_scope, @@ -823,7 +823,7 @@ inline namespace kernel */ if (cdr(current_expression).is()) // is tail-sequence { - return compile(current_context.mark_tail_as(true), + return compile(in_a_tail_context, current_environment, car(current_expression), current_scope, @@ -985,7 +985,7 @@ inline namespace kernel * * ----------------------------------------------------------------------- */ { - if (current_scope.is() or current_context.is_outermost) + if (current_scope.is()) { if (car(current_expression).is()) // (define (f . ) ) { @@ -1323,7 +1323,7 @@ inline namespace kernel } else { - return compile(current_context.mark_tail_as(false), + return compile(context(), current_environment, car(current_expression), // head expression current_scope, From f3883dbce8f9db0defaf99973362e4034dd0d746 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 02:18:55 +0900 Subject: [PATCH 08/24] Replace `boolean` with native `bool` Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- basis/r4rs-essential.ss | 4 ++-- include/meevax/kernel/boolean.hpp | 18 ------------------ include/meevax/memory/nan_boxing_pointer.hpp | 11 ++++++++++- src/kernel/boolean.cpp | 11 +++-------- src/kernel/library.cpp | 2 +- test/environment.cpp | 4 +--- 8 files changed, 21 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 5c72b50e0..9c29be739 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.47.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.48.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.47_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.48_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.47 +Meevax Lisp System, version 0.4.48 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 90ebc3240..6083bc1cb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.47 +0.4.48 diff --git a/basis/r4rs-essential.ss b/basis/r4rs-essential.ss index 2dfbc860a..92ea6560d 100644 --- a/basis/r4rs-essential.ss +++ b/basis/r4rs-essential.ss @@ -221,8 +221,8 @@ (if x #f #t)) (define (boolean? x) - (or (eqv? x #t) - (eqv? x #f))) + (or (eq? x #t) + (eq? x #f))) (define (equal? x y) (if (and (pair? x) diff --git a/include/meevax/kernel/boolean.hpp b/include/meevax/kernel/boolean.hpp index 798df6273..75d4829f3 100644 --- a/include/meevax/kernel/boolean.hpp +++ b/include/meevax/kernel/boolean.hpp @@ -23,24 +23,6 @@ namespace meevax { inline namespace kernel { - struct boolean - { - using value_type = bool; - - const value_type value; - - constexpr boolean(value_type const value) - : value { value } - {} - - constexpr operator value_type() const noexcept - { - return value; - } - }; - - auto operator <<(std::ostream &, boolean const&) -> std::ostream &; - let extern const t; let extern const f; diff --git a/include/meevax/memory/nan_boxing_pointer.hpp b/include/meevax/memory/nan_boxing_pointer.hpp index e47a8f34d..87c723db4 100644 --- a/include/meevax/memory/nan_boxing_pointer.hpp +++ b/include/meevax/memory/nan_boxing_pointer.hpp @@ -18,6 +18,7 @@ #define INCLUDED_MEEVAX_MEMORY_NAN_BOXING_POINTER_HPP #include +#include #include #include #include @@ -193,7 +194,15 @@ inline namespace memory { #define DEFINE(TYPE) \ case signature_##TYPE: \ - return os << yellow(as()) + if constexpr (std::is_same_v) \ + { \ + return os << std::boolalpha << yellow('#', as()); \ + } \ + else \ + { \ + return os << yellow(as()); \ + } \ + static_assert(true) DEFINE(pointer); DEFINE(T_0b010); diff --git a/src/kernel/boolean.cpp b/src/kernel/boolean.cpp index 31de59fdc..ca7a53f33 100644 --- a/src/kernel/boolean.cpp +++ b/src/kernel/boolean.cpp @@ -21,17 +21,12 @@ namespace meevax { inline namespace kernel { - auto operator <<(std::ostream & os, boolean const& datum) -> std::ostream & - { - return os << cyan("#", std::boolalpha, datum.value); - } - - let const t = make(true); - let const f = make(false); + let const t = make(true); + let const f = make(false); auto select(const_reference x) -> bool { - return not eq(x, f) or not eqv(x, f); + return not eq(x, f); } } // namespace kernel } // namespace meevax diff --git a/src/kernel/library.cpp b/src/kernel/library.cpp index 5bc1a4e94..7ff756f0f 100644 --- a/src/kernel/library.cpp +++ b/src/kernel/library.cpp @@ -1084,7 +1084,7 @@ inline namespace kernel throw exit_status::success; case 1: - if (let const& x = car(xs); x.is()) + if (let const& x = car(xs); x.is()) { throw select(x) ? exit_status::success : exit_status::failure; } diff --git a/test/environment.cpp b/test/environment.cpp index ceb52a956..51f35388f 100644 --- a/test/environment.cpp +++ b/test/environment.cpp @@ -7,7 +7,7 @@ auto main() -> int { using namespace meevax; - const auto specials_count = 12; + const auto specials_count = 10; { assert(standard_error.is()); assert(standard_input.is()); @@ -16,8 +16,6 @@ auto main() -> int assert(e1.is()); assert(eof_object.is()); assert(eos_object.is()); - assert(f.is()); - assert(t.is()); assert(undefined.is()); assert(unspecified_object.is()); assert(interaction_environment().is()); From 58157de63b36b1416b7e5ef16fdfe597d66b5883 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 11:21:44 +0900 Subject: [PATCH 09/24] Remove unused type `eos` Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/miscellaneous.hpp | 7 ------- src/kernel/miscellaneous.cpp | 7 ------- test/environment.cpp | 3 +-- 5 files changed, 5 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 9c29be739..84416702d 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.48.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.49.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.48_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.49_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.48 +Meevax Lisp System, version 0.4.49 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 6083bc1cb..d1a6c6313 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.48 +0.4.49 diff --git a/include/meevax/kernel/miscellaneous.hpp b/include/meevax/kernel/miscellaneous.hpp index 34754bdb7..77c9cfad0 100644 --- a/include/meevax/kernel/miscellaneous.hpp +++ b/include/meevax/kernel/miscellaneous.hpp @@ -29,13 +29,6 @@ inline namespace kernel let extern const eof_object; auto operator <<(std::ostream &, eof const&) -> std::ostream &; - - struct eos - {}; - - let extern const eos_object; - - auto operator <<(std::ostream &, eos const&) -> std::ostream &; } // namespace kernel } // namespace meevax diff --git a/src/kernel/miscellaneous.cpp b/src/kernel/miscellaneous.cpp index e9f189474..8a59d763a 100644 --- a/src/kernel/miscellaneous.cpp +++ b/src/kernel/miscellaneous.cpp @@ -26,12 +26,5 @@ inline namespace kernel { return os << magenta("#,(") << green("eof-object") << magenta(")"); } - - let const eos_object = make(); - - auto operator <<(std::ostream & os, eos const&) -> std::ostream & - { - return os << magenta("#,(") << green("eos-object") << magenta(")"); - } } // namespace kernel } // namespace meevax diff --git a/test/environment.cpp b/test/environment.cpp index 51f35388f..48bd547bd 100644 --- a/test/environment.cpp +++ b/test/environment.cpp @@ -7,7 +7,7 @@ auto main() -> int { using namespace meevax; - const auto specials_count = 10; + const auto specials_count = 9; { assert(standard_error.is()); assert(standard_input.is()); @@ -15,7 +15,6 @@ auto main() -> int assert(e0.is()); assert(e1.is()); assert(eof_object.is()); - assert(eos_object.is()); assert(undefined.is()); assert(unspecified_object.is()); assert(interaction_environment().is()); From dfbcf404402cdd8e664629adc4d5ebdf3080964c Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 11:53:50 +0900 Subject: [PATCH 10/24] Remove struct `option` Signed-off-by: yamacir-kit --- README.md | 6 ++-- VERSION | 2 +- include/meevax/kernel/machine.hpp | 5 ++-- include/meevax/kernel/option.hpp | 47 ------------------------------- src/kernel/environment.cpp | 2 +- 5 files changed, 7 insertions(+), 55 deletions(-) delete mode 100644 include/meevax/kernel/option.hpp diff --git a/README.md b/README.md index 84416702d..246280a1b 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.49.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.50.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.49_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.50_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.49 +Meevax Lisp System, version 0.4.50 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index d1a6c6313..6aed7c397 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.49 +0.4.50 diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index ce9a4f7be..856cfb14d 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -23,7 +23,6 @@ #include #include #include -#include #include namespace meevax @@ -326,11 +325,11 @@ inline namespace kernel } } - template + template inline auto execute() -> lvalue { decode: - if constexpr (Option & option::trace) + if constexpr (trace) { std::cerr << faint("; s = ") << s << "\n" << faint("; e = ") << e << "\n" diff --git a/include/meevax/kernel/option.hpp b/include/meevax/kernel/option.hpp deleted file mode 100644 index a48b6a7d7..000000000 --- a/include/meevax/kernel/option.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright 2018-2022 Tatsuya Yamasaki. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -#ifndef INCLUDED_MEEVAX_KERNEL_OPTION_HPP -#define INCLUDED_MEEVAX_KERNEL_OPTION_HPP - -namespace meevax -{ -inline namespace kernel -{ - struct option - { - enum value_type - { - none, - trace = (1 << 0), - size, - } - const value; - - template - constexpr option(T const value) noexcept - : value { static_cast(value) } - {} - - constexpr operator value_type() const noexcept - { - return value; - } - }; -} // namespace kernel -} // namespace meevax - -#endif // INCLUDED_MEEVAX_KERNEL_OPTION_HPP diff --git a/src/kernel/environment.cpp b/src/kernel/environment.cpp index 95abd7373..adc88dea6 100644 --- a/src/kernel/environment.cpp +++ b/src/kernel/environment.cpp @@ -154,7 +154,7 @@ inline namespace kernel { if (trace) { - return machine::execute(); + return machine::execute(); } else { From b3d3611a3456da9ca5ecde42afd660ad8c135298 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 13:36:11 +0900 Subject: [PATCH 11/24] Update `configurator::display_version` to be static Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 15 ++++++++------- include/meevax/kernel/machine.hpp | 8 +++++--- include/meevax/kernel/writer.hpp | 6 +++--- include/meevax/utility/module.hpp | 8 ++++++++ src/kernel/environment.cpp | 9 +-------- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 246280a1b..2850bc3ab 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.50.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.51.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.50_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.51_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.50 +Meevax Lisp System, version 0.4.51 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 6aed7c397..e1a99a982 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.50 +0.4.51 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index 35ebc1759..f3e883855 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -35,9 +35,10 @@ inline namespace kernel IMPORT(environment, evaluate, NIL); IMPORT(environment, load, NIL); - IMPORT(environment, print, const); IMPORT(environment, read, NIL); + USING_STATIC(environment, print); + template using dispatcher = std::unordered_map; @@ -46,11 +47,11 @@ inline namespace kernel const dispatcher long_options, long_options_with_arguments; public: - bool batch = false; - bool debug = false; - bool interactive = false; - bool trace = false; - bool verbose = false; + static inline auto batch = false; + static inline auto debug = false; + static inline auto interactive = false; + static inline auto trace = false; + static inline auto verbose = false; explicit configurator() : short_options @@ -249,7 +250,7 @@ inline namespace kernel }(); } - auto display_version() const -> void + static auto display_version() -> void { print("Meevax Lisp ", version()); } diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index 856cfb14d..a00662782 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -29,15 +29,17 @@ namespace meevax { inline namespace kernel { - template + template class machine // TR-SECD machine. { - friend environment; + friend Environment; machine() {} - IMPORT(environment, fork, const); + IMPORT(Environment, fork, const); + + using environment = Environment; protected: let s, // stack (holding intermediate results and return address) diff --git a/include/meevax/kernel/writer.hpp b/include/meevax/kernel/writer.hpp index 5baecdc38..677fe3313 100644 --- a/include/meevax/kernel/writer.hpp +++ b/include/meevax/kernel/writer.hpp @@ -33,19 +33,19 @@ inline namespace kernel public: template - auto write(std::ostream & os, Ts&&... xs) const -> std::ostream & + static auto write(std::ostream & os, Ts&&... xs) -> std::ostream & { return (os << ... << xs); } template - auto write(const_reference x, Ts&&... xs) const -> decltype(auto) + static auto write(const_reference x, Ts&&... xs) -> decltype(auto) { return write(x.as(), std::forward(xs)...); } template - auto print(Ts&&... xs) const -> decltype(auto) + static auto print(Ts&&... xs) -> decltype(auto) { return write(standard_output, std::forward(xs)..., '\n'); } diff --git a/include/meevax/utility/module.hpp b/include/meevax/utility/module.hpp index 6df353ad8..fea3b9c6c 100644 --- a/include/meevax/utility/module.hpp +++ b/include/meevax/utility/module.hpp @@ -30,4 +30,12 @@ static_assert(true) #define EXPORT(M, SYMBOL) using M::SYMBOL +#define USING_STATIC(TYPE, FUNCTION) \ +template \ +static auto FUNCTION(Ts&&... xs) -> decltype(auto) \ +{ \ + return TYPE::FUNCTION(std::forward(xs)...); \ +} \ +static_assert(true) + #endif // INCLUDED_MEEVAX_UTILITY_MODULE_HPP diff --git a/src/kernel/environment.cpp b/src/kernel/environment.cpp index adc88dea6..0afbb46b0 100644 --- a/src/kernel/environment.cpp +++ b/src/kernel/environment.cpp @@ -152,14 +152,7 @@ inline namespace kernel auto environment::execute() -> lvalue { - if (trace) - { - return machine::execute(); - } - else - { - return machine::execute(); - } + return trace ? machine::execute() : machine::execute(); } auto environment::execute(const_reference code) -> lvalue From 4d7d8ed8751fda638f7007d000fa2a74d9bfbddd Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 13:48:35 +0900 Subject: [PATCH 12/24] Update `configurator::short_options` to be static Signed-off-by: yamacir-kit --- README.md | 6 +-- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 58 +++++++++++++------------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 2850bc3ab..ad2227afe 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.51.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.52.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.51_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.52_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.51 +Meevax Lisp System, version 0.4.52 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index e1a99a982..e32a889bd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.51 +0.4.52 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index f3e883855..49d6a8b56 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -42,7 +42,7 @@ inline namespace kernel template using dispatcher = std::unordered_map; - const dispatcher short_options, short_options_with_arguments; + const dispatcher short_options_with_arguments; const dispatcher long_options, long_options_with_arguments; @@ -53,38 +53,38 @@ inline namespace kernel static inline auto trace = false; static inline auto verbose = false; - explicit configurator() - : short_options - { - std::make_pair('b', [this](auto&&...) - { - return make(batch = true); - }), + static inline const dispatcher short_options + { + std::make_pair('b', [](auto&&...) + { + return make(batch = true); + }), - std::make_pair('d', [this](auto&&...) - { - return make(debug = true); - }), + std::make_pair('d', [](auto&&...) + { + return make(debug = true); + }), - std::make_pair('h', [this](auto&&...) -> lvalue - { - display_help(); - throw exit_status::success; - }), + std::make_pair('h', [](auto&&...) -> lvalue + { + configurator::display_help(); + throw exit_status::success; + }), - std::make_pair('i', [this](auto&&...) - { - return make(interactive = true); - }), + std::make_pair('i', [](auto&&...) + { + return make(interactive = true); + }), - std::make_pair('v', [this](auto&&...) -> lvalue - { - display_version(); - throw exit_status::success; - }), - } + std::make_pair('v', [](auto&&...) -> lvalue + { + configurator::display_version(); + throw exit_status::success; + }), + }; - , short_options_with_arguments + explicit configurator() + : short_options_with_arguments { std::make_pair('e', [this](const_reference x, auto&&...) { @@ -255,7 +255,7 @@ inline namespace kernel print("Meevax Lisp ", version()); } - auto display_help() const -> void + static auto display_help() -> void { display_version(); print(); From 813e76de7ae3647fbf374453f0822f3ef129b597 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 13:53:42 +0900 Subject: [PATCH 13/24] Fix configurator to be compilable with Clang Signed-off-by: yamacir-kit --- README.md | 6 ++-- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 50 +++++++++++++------------- script/install.sh | 2 +- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index ad2227afe..1cf8ac82d 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.52.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.53.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.52_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.53_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.52 +Meevax Lisp System, version 0.4.53 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index e32a889bd..7e7344150 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.52 +0.4.53 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index 49d6a8b56..c4fca8099 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -53,6 +53,31 @@ inline namespace kernel static inline auto trace = false; static inline auto verbose = false; + static auto display_version() -> void + { + print("Meevax Lisp ", version()); + } + + static auto display_help() -> void + { + display_version(); + print(); + print("Usage: meevax [OPTION...] [FILE...]"); + print(); + print("Options:"); + print(" -b, --batch Suppress any system output."); + print(" -d, --debug Display detailed informations for developers."); + print(" -e, --evaluate=STRING Read and evaluate given STRING at configuration step."); + print(" -h, --help Display this help text and exit."); + print(" -i, --interactive Take over control of root environment."); + print(" -l, --load=FILENAME Same as -e '(load FILENAME)'"); + print(" -t, --trace Display stacks of virtual machine for each steps."); + print(" -v, --version Display version information and exit."); + print(" --verbose Display detailed informations."); + print(" -w, --write=OBJECT Same as -e '(write OBJECT)'"); + } + + private: static inline const dispatcher short_options { std::make_pair('b', [](auto&&...) @@ -83,6 +108,7 @@ inline namespace kernel }), }; + public: explicit configurator() : short_options_with_arguments { @@ -249,30 +275,6 @@ inline namespace kernel return unspecified_object; }(); } - - static auto display_version() -> void - { - print("Meevax Lisp ", version()); - } - - static auto display_help() -> void - { - display_version(); - print(); - print("Usage: meevax [OPTION...] [FILE...]"); - print(); - print("Options:"); - print(" -b, --batch Suppress any system output."); - print(" -d, --debug Display detailed informations for developers."); - print(" -e, --evaluate=STRING Read and evaluate given STRING at configuration step."); - print(" -h, --help Display this help text and exit."); - print(" -i, --interactive Take over control of root environment."); - print(" -l, --load=FILENAME Same as -e '(load FILENAME)'"); - print(" -t, --trace Display stacks of virtual machine for each steps."); - print(" -v, --version Display version information and exit."); - print(" --verbose Display detailed informations."); - print(" -w, --write=OBJECT Same as -e '(write OBJECT)'"); - } }; } // namespace kernel } // namespace meevax diff --git a/script/install.sh b/script/install.sh index 713204d58..8d3c9489e 100755 --- a/script/install.sh +++ b/script/install.sh @@ -5,7 +5,7 @@ root="$(git rev-parse --show-toplevel)" make() { rm -rf "$2" - cmake -B "$2" -S "$(dirname "$2")" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ + cmake -B "$2" -S "$(dirname "$2")" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ cmake --build "$2" --target "$1" } From f25d78ad2ccd2198b61463d5c2acac4d8cff4554 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 14:08:45 +0900 Subject: [PATCH 14/24] Update `configurator::long_options` to be static Signed-off-by: yamacir-kit --- README.md | 6 +- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 82 +++++++++++++------------- include/meevax/kernel/writer.hpp | 10 ++-- script/install.sh | 2 +- 5 files changed, 51 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 1cf8ac82d..b2774edfb 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.53.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.54.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.53_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.54_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.53 +Meevax Lisp System, version 0.4.54 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 7e7344150..183c2e41b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.53 +0.4.54 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index c4fca8099..60df5788e 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -44,7 +44,7 @@ inline namespace kernel const dispatcher short_options_with_arguments; - const dispatcher long_options, long_options_with_arguments; + const dispatcher long_options_with_arguments; public: static inline auto batch = false; @@ -108,6 +108,46 @@ inline namespace kernel }), }; + static inline const dispatcher long_options + { + std::make_pair("batch", [](auto&&...) + { + return make(batch = true); + }), + + std::make_pair("debug", [](auto&&...) + { + return make(debug = true); + }), + + std::make_pair("help", [](auto&&...) -> lvalue + { + display_help(); + throw exit_status::success; + }), + + std::make_pair("interactive", [](auto&&...) + { + return make(interactive = true); + }), + + std::make_pair("trace", [](auto&&...) + { + return make(trace = true); + }), + + std::make_pair("verbose", [](auto&&...) + { + return make(verbose = true); + }), + + std::make_pair("version", [](auto&&...) -> lvalue + { + display_version(); + throw exit_status::success; + }), + }; + public: explicit configurator() : short_options_with_arguments @@ -128,46 +168,6 @@ inline namespace kernel }), } - , long_options - { - std::make_pair("batch", [this](auto&&...) - { - return make(batch = true); - }), - - std::make_pair("debug", [this](auto&&...) - { - return make(debug = true); - }), - - std::make_pair("help", [this](auto&&...) -> lvalue - { - display_help(); - throw exit_status::success; - }), - - std::make_pair("interactive", [this](auto&&...) - { - return make(interactive = true); - }), - - std::make_pair("trace", [this](auto&&...) - { - return make(trace = true); - }), - - std::make_pair("verbose", [this](auto&&...) - { - return make(verbose = true); - }), - - std::make_pair("version", [this](auto&&...) -> lvalue - { - display_version(); - throw exit_status::success; - }), - } - , long_options_with_arguments { std::make_pair("evaluate", [this](const_reference x, auto&&...) diff --git a/include/meevax/kernel/writer.hpp b/include/meevax/kernel/writer.hpp index 677fe3313..ed1efa393 100644 --- a/include/meevax/kernel/writer.hpp +++ b/include/meevax/kernel/writer.hpp @@ -51,20 +51,20 @@ inline namespace kernel } public: - auto null_port() const -> const_reference + static auto null_port() -> const_reference { let static port = make("/dev/null"); return port; } - auto verbose_port() const -> const_reference + static auto verbose_port() -> const_reference { - return static_cast(*this).verbose ? standard_output : null_port(); + return Environment::verbose ? standard_output : null_port(); } - auto debug_port() const -> const_reference + static auto debug_port() -> const_reference { - return static_cast(*this).debug ? standard_error : null_port(); + return Environment::debug ? standard_error : null_port(); } }; } // namespace kernel diff --git a/script/install.sh b/script/install.sh index 8d3c9489e..713204d58 100755 --- a/script/install.sh +++ b/script/install.sh @@ -5,7 +5,7 @@ root="$(git rev-parse --show-toplevel)" make() { rm -rf "$2" - cmake -B "$2" -S "$(dirname "$2")" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ + cmake -B "$2" -S "$(dirname "$2")" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ cmake --build "$2" --target "$1" } From d9ca5bb3242330fcfc5e0a29efb44c7884e2c605 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 14:31:47 +0900 Subject: [PATCH 15/24] Move free function `interaction_environment` into new header `interaction_environment.hpp` Signed-off-by: yamacir-kit --- README.md | 6 ++-- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 6 ++-- include/meevax/kernel/environment.hpp | 10 +++---- .../meevax/kernel/interaction_environment.hpp | 30 +++++++++++++++++++ include/meevax/kernel/library.hpp | 2 -- src/kernel/interaction_environment.cpp | 30 +++++++++++++++++++ src/kernel/library.cpp | 7 +---- src/main.cpp | 1 + test/environment.cpp | 1 + 10 files changed, 76 insertions(+), 19 deletions(-) create mode 100644 include/meevax/kernel/interaction_environment.hpp create mode 100644 src/kernel/interaction_environment.cpp diff --git a/README.md b/README.md index b2774edfb..bde300f2e 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.54.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.55.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.54_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.55_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.54 +Meevax Lisp System, version 0.4.55 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 183c2e41b..0313ed8e9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.54 +0.4.55 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index 60df5788e..a8e620dd7 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -152,9 +153,10 @@ inline namespace kernel explicit configurator() : short_options_with_arguments { - std::make_pair('e', [this](const_reference x, auto&&...) + std::make_pair('e', [](const_reference x, auto&&...) { - return print(evaluate(x)), unspecified_object; + print(interaction_environment().as().evaluate(x)); + return unspecified_object; }), std::make_pair('l', [this](const_reference x, auto&&...) diff --git a/include/meevax/kernel/environment.hpp b/include/meevax/kernel/environment.hpp index f57e8ab41..8c7ee5d37 100644 --- a/include/meevax/kernel/environment.hpp +++ b/include/meevax/kernel/environment.hpp @@ -55,11 +55,11 @@ inline namespace kernel { (import(xs), ...); - define("set-batch!", [this](let const& xs, auto&&...) { return batch = select(car(xs)); }); - define("set-debug!", [this](let const& xs, auto&&...) { return debug = select(car(xs)); }); - define("set-interactive!", [this](let const& xs, auto&&...) { return interactive = select(car(xs)); }); - define("set-trace!", [this](let const& xs, auto&&...) { return trace = select(car(xs)); }); - define("set-verbose!", [this](let const& xs, auto&&...) { return verbose = select(car(xs)); }); + // define("set-batch!", [this](let const& xs, auto&&...) { return batch = select(car(xs)); }); + // define("set-debug!", [this](let const& xs, auto&&...) { return debug = select(car(xs)); }); + // define("set-interactive!", [this](let const& xs, auto&&...) { return interactive = select(car(xs)); }); + // define("set-trace!", [this](let const& xs, auto&&...) { return trace = select(car(xs)); }); + // define("set-verbose!", [this](let const& xs, auto&&...) { return verbose = select(car(xs)); }); } auto operator [](const_reference) -> const_reference; diff --git a/include/meevax/kernel/interaction_environment.hpp b/include/meevax/kernel/interaction_environment.hpp new file mode 100644 index 000000000..cec72e3df --- /dev/null +++ b/include/meevax/kernel/interaction_environment.hpp @@ -0,0 +1,30 @@ +/* + Copyright 2018-2022 Tatsuya Yamasaki. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef INCLUDED_MEEVAX_KERNEL_INTERACTION_ENVIRONMENT_HPP +#define INCLUDED_MEEVAX_KERNEL_INTERACTION_ENVIRONMENT_HPP + +#include + +namespace meevax +{ +inline namespace kernel +{ + auto interaction_environment() -> const_reference; +} // namespace kernel +} // namespace meevax + +#endif // INCLUDED_MEEVAX_KERNEL_INTERACTION_ENVIRONMENT_HPP diff --git a/include/meevax/kernel/library.hpp b/include/meevax/kernel/library.hpp index 45a455887..5c2919261 100644 --- a/include/meevax/kernel/library.hpp +++ b/include/meevax/kernel/library.hpp @@ -24,8 +24,6 @@ namespace meevax { inline namespace kernel { - auto interaction_environment() -> const_reference; - struct library : public environment { std::vector export_specs; diff --git a/src/kernel/interaction_environment.cpp b/src/kernel/interaction_environment.cpp new file mode 100644 index 000000000..34a79151a --- /dev/null +++ b/src/kernel/interaction_environment.cpp @@ -0,0 +1,30 @@ +/* + Copyright 2018-2022 Tatsuya Yamasaki. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include +#include + +namespace meevax +{ +inline namespace kernel +{ + auto interaction_environment() -> const_reference + { + let static const interaction_environment = make(); + return interaction_environment; + } +} // namespace kernel +} // namespace meevax diff --git a/src/kernel/library.cpp b/src/kernel/library.cpp index 7ff756f0f..a21b278eb 100644 --- a/src/kernel/library.cpp +++ b/src/kernel/library.cpp @@ -15,18 +15,13 @@ */ #include +#include #include namespace meevax { inline namespace kernel { - auto interaction_environment() -> const_reference - { - let static const interaction_environment = make(); - return interaction_environment; - } - library::library(syntax_library_t) { define("begin", machine::begin); diff --git a/src/main.cpp b/src/main.cpp index c065cde12..0aca95e72 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,7 @@ limitations under the License. */ +#include #include #include diff --git a/test/environment.cpp b/test/environment.cpp index 48bd547bd..e37e87981 100644 --- a/test/environment.cpp +++ b/test/environment.cpp @@ -1,6 +1,7 @@ #undef NDEBUG #include +#include #include auto main() -> int From e2201363a8319a515faeb5467b185c256a222f99 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 14:43:45 +0900 Subject: [PATCH 16/24] Update `configurator::short_options_with_arguments` to be static Signed-off-by: yamacir-kit --- README.md | 6 ++-- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 43 +++++++++++++------------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index bde300f2e..d90d45e29 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.55.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.56.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.55_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.56_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.55 +Meevax Lisp System, version 0.4.56 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 0313ed8e9..319405ebd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.55 +0.4.56 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index a8e620dd7..81ce30aad 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -43,8 +43,6 @@ inline namespace kernel template using dispatcher = std::unordered_map; - const dispatcher short_options_with_arguments; - const dispatcher long_options_with_arguments; public: @@ -109,6 +107,26 @@ inline namespace kernel }), }; + static inline const dispatcher short_options_with_arguments + { + std::make_pair('e', [](const_reference x, auto&&...) + { + print(interaction_environment().as().evaluate(x)); + return unspecified_object; + }), + + std::make_pair('l', [](const_reference x, auto&&...) + { + return interaction_environment().as().load(x.as_const()); + }), + + std::make_pair('w', [](const_reference x, auto&&...) + { + print(x); + return unspecified_object; + }), + }; + static inline const dispatcher long_options { std::make_pair("batch", [](auto&&...) @@ -151,26 +169,7 @@ inline namespace kernel public: explicit configurator() - : short_options_with_arguments - { - std::make_pair('e', [](const_reference x, auto&&...) - { - print(interaction_environment().as().evaluate(x)); - return unspecified_object; - }), - - std::make_pair('l', [this](const_reference x, auto&&...) - { - return load(x.as_const()); - }), - - std::make_pair('w', [this](const_reference x, auto&&...) - { - return print(x), unspecified_object; - }), - } - - , long_options_with_arguments + : long_options_with_arguments { std::make_pair("evaluate", [this](const_reference x, auto&&...) { From 01efeb03801c5a9b06de7bcc92cd0be170b4ce13 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 14:52:31 +0900 Subject: [PATCH 17/24] Update `configurator::long_options_with_arguments` to be static Signed-off-by: yamacir-kit --- README.md | 6 ++-- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 41 +++++++++++++------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index d90d45e29..7e462a423 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.56.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.57.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.56_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.57_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.56 +Meevax Lisp System, version 0.4.57 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 319405ebd..b0da4c03b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.56 +0.4.57 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index 81ce30aad..bbfb073bc 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -34,6 +34,9 @@ inline namespace kernel { friend environment; + explicit configurator() + {} + IMPORT(environment, evaluate, NIL); IMPORT(environment, load, NIL); IMPORT(environment, read, NIL); @@ -43,8 +46,6 @@ inline namespace kernel template using dispatcher = std::unordered_map; - const dispatcher long_options_with_arguments; - public: static inline auto batch = false; static inline auto debug = false; @@ -167,27 +168,27 @@ inline namespace kernel }), }; - public: - explicit configurator() - : long_options_with_arguments - { - std::make_pair("evaluate", [this](const_reference x, auto&&...) - { - return print(evaluate(x)), unspecified_object; - }), + static inline const dispatcher long_options_with_arguments + { + std::make_pair("evaluate", [](const_reference x, auto&&...) + { + print(interaction_environment().as().evaluate(x)); + return unspecified_object; + }), - std::make_pair("load", [this](const_reference x, auto&&...) - { - return load(x.as_const()); - }), + std::make_pair("load", [](const_reference x, auto&&...) + { + return interaction_environment().as().load(x.as_const()); + }), - std::make_pair("write", [this](const_reference x, auto&&...) - { - return print(x), unspecified_object; - }), - } - {} + std::make_pair("write", [](const_reference x, auto&&...) + { + print(x); + return unspecified_object; + }), + }; + public: auto configure(const int argc, char const* const* const argv) { return configure({ argv + 1, argv + argc }); From 62ab16c9756d1dec10a83c75be96f38997b060d4 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 15:38:54 +0900 Subject: [PATCH 18/24] Lipsticks Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 17 ++++++++--------- src/kernel/environment.cpp | 5 ----- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7e462a423..320de8e91 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.57.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.58.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.57_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.58_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.57 +Meevax Lisp System, version 0.4.58 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index b0da4c03b..f96de0bf2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.57 +0.4.58 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index bbfb073bc..6d58d3de6 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -49,7 +49,7 @@ inline namespace kernel public: static inline auto batch = false; static inline auto debug = false; - static inline auto interactive = false; + static inline auto interactive = true; static inline auto trace = false; static inline auto verbose = false; @@ -198,11 +198,7 @@ inline namespace kernel { static std::regex const pattern { R"(--(\w[-\w]+)(=(.*))?|-([\w]+))" }; - if (std::empty(args)) - { - interactive = true; - } - else for (auto current_option = std::begin(args); current_option != std::end(args); ++current_option) [&]() + for (auto current_option = std::begin(args); current_option != std::end(args); ++current_option) [&]() { std::smatch analysis {}; @@ -214,7 +210,7 @@ inline namespace kernel // std::cout << header("") << "analysis[3] = " << analysis[3] << std::endl; // std::cout << header("") << "analysis[4] = " << analysis[4] << std::endl; - if (auto const current_short_options = analysis.str(4); not current_short_options.empty()) + if (auto const& current_short_options = analysis.str(4); not current_short_options.empty()) { for (auto current_short_option = std::cbegin(current_short_options); current_short_option != std::cend(current_short_options); ++current_short_option) { @@ -239,7 +235,8 @@ inline namespace kernel } else { - throw error(make(cat, "unknown short-option -", *current_short_option)); + throw error(make("unknown short-option"), + make(*current_short_option)); } } } @@ -266,11 +263,13 @@ inline namespace kernel } else { - throw error(make(cat, "unknown long-option: ", *current_option)); + throw error(make("unknown long-option"), + make(*current_option)); } } else { + interactive = false; return load(*current_option); } diff --git a/src/kernel/environment.cpp b/src/kernel/environment.cpp index 0afbb46b0..e6697b516 100644 --- a/src/kernel/environment.cpp +++ b/src/kernel/environment.cpp @@ -90,11 +90,6 @@ inline namespace kernel define(binding.as().symbol(), binding.as().load()); } - - if (interactive) - { - print(faint("; ", length(bindings), " identifiers imported.")); - } } auto environment::define(const_reference name, const_reference value) -> void From 3d4f5f645d78a09a41e106e82203c4dd8808356c Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sun, 12 Jun 2022 17:46:54 +0900 Subject: [PATCH 19/24] Fix constexpr declaration Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/object.hpp | 4 ++-- include/meevax/memory/nan_boxing_pointer.hpp | 20 ++++++++++---------- src/kernel/library.cpp | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 320de8e91..72bba3ebb 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.58.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.59.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.58_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.59_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.58 +Meevax Lisp System, version 0.4.59 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index f96de0bf2..b7c7a484a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.58 +0.4.59 diff --git a/include/meevax/kernel/object.hpp b/include/meevax/kernel/object.hpp index 44dbfcc0a..958698de4 100644 --- a/include/meevax/kernel/object.hpp +++ b/include/meevax/kernel/object.hpp @@ -50,13 +50,13 @@ inline namespace kernel }; template - constexpr auto make(Ts&&... xs) + auto make(Ts&&... xs) { return lvalue::allocate(std::forward(xs)...); // NOTE: This leaks memory if exception thrown from T's constructor. } template - constexpr auto make(T&& x) + auto make(T&& x) { return lvalue::allocate::type>(std::forward(x)); } diff --git a/include/meevax/memory/nan_boxing_pointer.hpp b/include/meevax/memory/nan_boxing_pointer.hpp index 87c723db4..99436d382 100644 --- a/include/meevax/memory/nan_boxing_pointer.hpp +++ b/include/meevax/memory/nan_boxing_pointer.hpp @@ -72,12 +72,12 @@ inline namespace memory auto operator =(nan_boxing_pointer const&) -> nan_boxing_pointer & = default; - constexpr nan_boxing_pointer(std::nullptr_t = nullptr) + nan_boxing_pointer(std::nullptr_t = nullptr) : nan_boxing_pointer { static_cast(nullptr) } {} #define DEFINE(TYPE) \ - constexpr nan_boxing_pointer(TYPE const& value) noexcept \ + nan_boxing_pointer(TYPE const& value) noexcept \ : data { reinterpret_cast( \ signature_##TYPE | bit_cast>(value)) } \ {} \ @@ -109,17 +109,17 @@ inline namespace memory #undef DEFINE - constexpr auto operator ->() const + auto operator ->() const { return get(); } - constexpr auto operator *() const -> decltype(auto) + auto operator *() const -> decltype(auto) { return *get(); } - constexpr explicit operator bool() const noexcept + explicit operator bool() const noexcept { return get() != nullptr; } @@ -139,17 +139,17 @@ inline namespace memory } } - constexpr auto dereferenceable() const noexcept + auto dereferenceable() const noexcept { return signature() == signature_pointer; } - constexpr auto equivalent_to(nan_boxing_pointer const& nbp) const noexcept + auto equivalent_to(nan_boxing_pointer const& nbp) const noexcept { return data == nbp.data; } - constexpr auto get() const noexcept -> pointer + auto get() const noexcept -> pointer { return dereferenceable() ? reinterpret_cast(reinterpret_cast(data) & mask_payload) : nullptr; } @@ -160,12 +160,12 @@ inline namespace memory return type() == typeid(typename std::decay::type); } - constexpr auto signature() const noexcept + auto signature() const noexcept { return reinterpret_cast(data) & mask_signature; } - constexpr auto type() const noexcept -> decltype(auto) + auto type() const noexcept -> decltype(auto) { switch (signature()) { diff --git a/src/kernel/library.cpp b/src/kernel/library.cpp index a21b278eb..aff410047 100644 --- a/src/kernel/library.cpp +++ b/src/kernel/library.cpp @@ -968,7 +968,7 @@ inline namespace kernel library::library(write_library_t) { - define("%write-simple", [this](let const& xs) + define("%write-simple", [](let const& xs) { write(cadr(xs), car(xs)); return unspecified_object; From 1b2899d791d29989d6d95d126ad1dcb8a0c9c749 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Mon, 13 Jun 2022 01:52:16 +0900 Subject: [PATCH 20/24] Update `environment::evaluate` to not to dump registors Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/machine.hpp | 20 ++++++++++++++++---- src/kernel/environment.cpp | 20 ++++++++++++-------- src/kernel/identity.cpp | 2 +- src/kernel/syntax.cpp | 2 +- 6 files changed, 34 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 72bba3ebb..9d5472e7d 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.59.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.60.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.59_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.60_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.59 +Meevax Lisp System, version 0.4.60 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index b7c7a484a..de41f35ea 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.59 +0.4.60 diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index a00662782..f86aa2896 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -471,16 +471,23 @@ inline namespace kernel * ------------------------------------------------------------------- */ [this]() { - auto && [current_expression, current_scope] = unpair(cadr(c)); + auto [current_expression, current_scope] = unpair(cadr(c)); + + let const syntactic_environment = fork(cdr(current_scope)); + + let const c_ = c; for (let const& keyword_ : car(current_scope)) { let & binding = keyword_.as().load(); - binding = make(environment(static_cast(*this)).execute(binding), - fork(cdr(current_scope))); + c = binding; + + binding = make(execute(), syntactic_environment); } + c = c_; + std::swap(c.as(), compile(context(), static_cast(*this), @@ -699,8 +706,13 @@ inline namespace kernel return [this]() { assert(cdr(s).template is()); + assert(cdr(c).template is()); + let const x = car(s); - s = unit; + + s = cdr(s); + c = cdr(c); + return x; }(); } diff --git a/src/kernel/environment.cpp b/src/kernel/environment.cpp index e6697b516..0f73e3b4a 100644 --- a/src/kernel/environment.cpp +++ b/src/kernel/environment.cpp @@ -33,6 +33,8 @@ inline namespace kernel auto environment::apply(const_reference f, const_reference xs) -> lvalue { + assert(f.is() or f.is() or f.is()); + auto dump = std::make_tuple(std::exchange(s, list(f, xs)), std::exchange(e, unit), std::exchange(c, list(make(mnemonic::call), @@ -124,10 +126,12 @@ inline namespace kernel } else { - auto dump = std::make_tuple(std::exchange(s, unit), - std::exchange(e, unit), - std::exchange(c, compile(context(), *this, expression, scope())), - std::exchange(d, unit)); + assert(s.is()); + assert(e.is()); + assert(c.is()); + assert(d.is()); + + c = compile(context(), *this, expression, scope()); if (debug) { @@ -136,10 +140,10 @@ inline namespace kernel let const result = execute(); - s = std::get<0>(dump); - e = std::get<1>(dump); - c = std::get<2>(dump); - d = std::get<3>(dump); + assert(s.is()); + assert(e.is()); + assert(c.is()); + assert(d.is()); return result; } diff --git a/src/kernel/identity.cpp b/src/kernel/identity.cpp index a824472bf..fcde5f6e2 100644 --- a/src/kernel/identity.cpp +++ b/src/kernel/identity.cpp @@ -31,7 +31,7 @@ inline namespace kernel auto identity::symbol() const -> const_reference { - assert(first.is()); + assert(first.is_also()); return first; } diff --git a/src/kernel/syntax.cpp b/src/kernel/syntax.cpp index 2c3e9464b..6b9f7a763 100644 --- a/src/kernel/syntax.cpp +++ b/src/kernel/syntax.cpp @@ -22,7 +22,7 @@ inline namespace kernel { syntax::syntax(std::string const& name, function_type const& compile) : description { name } - , compile { compile } + , compile { compile } {} auto operator <<(std::ostream & os, syntax const& datum) -> std::ostream & From 842c4e07cce2106855c70697ff1c8bb35b19515a Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Mon, 13 Jun 2022 03:58:11 +0900 Subject: [PATCH 21/24] Add experimental optimization for `load-constant` Signed-off-by: yamacir-kit --- README.md | 6 +-- VERSION | 2 +- include/meevax/kernel/machine.hpp | 84 +++++++++++++++++++++++++++++++ src/kernel/environment.cpp | 2 + 4 files changed, 90 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9d5472e7d..362a571b2 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.60.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.61.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.60_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.61_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.60 +Meevax Lisp System, version 0.4.61 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index de41f35ea..45976791b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.60 +0.4.61 diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index f86aa2896..56dab65d6 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -752,6 +752,90 @@ inline namespace kernel return variable.is() ? variable.as().identify_with_offset(scope) : f; } + static auto optimize(const_reference c) -> lvalue + { + if (not c.is()) + { + return c; + } + else switch (car(c).template as()) + { + case mnemonic::call: + case mnemonic::cons: + case mnemonic::drop: + case mnemonic::dummy: + case mnemonic::join: + case mnemonic::letrec: + case mnemonic::return_: + case mnemonic::stop: + case mnemonic::tail_call: + return cons(car(c), + optimize(cdr(c))); + + case mnemonic::define: + case mnemonic::define_syntax: + case mnemonic::let_syntax: + case mnemonic::letrec_syntax: + case mnemonic::load_absolute: + case mnemonic::load_relative: + case mnemonic::load_variadic: + case mnemonic::store_absolute: + case mnemonic::store_relative: + case mnemonic::store_variadic: + return cons(car(c), + cadr(c), + optimize(cddr(c))); + + case mnemonic::load_closure: + case mnemonic::load_continuation: + return cons(car(c), + optimize(cadr(c)), + optimize(cddr(c))); + + case mnemonic::select: + case mnemonic::tail_select: + return cons(car(c), + optimize(cadr(c)), + optimize(caddr(c)), + optimize(cdddr(c))); + + + case mnemonic::load_constant: /* ----------------------------------------- + * + * (load-constant x + * load-constant y + * cons + * ...) + * + * => (load-constant (x . y) + * ...) + * + * --------------------------------------------------------------------- */ + if (5 <= length(c) and + list_ref(c, 0).is() and + list_ref(c, 0).as() == mnemonic::load_constant and + list_ref(c, 2).is() and + list_ref(c, 2).as() == mnemonic::load_constant and + list_ref(c, 4).is() and + list_ref(c, 4).as() == mnemonic::cons) + { + return optimize(cons(list_ref(c, 0), cons(list_ref(c, 3), + list_ref(c, 1)), + optimize(list_tail(c, 5)))); + } + else + { + return cons(car(c), cadr(c), + optimize(cddr(c))); + } + + default: + assert(false); + return c; + } + } + + [[deprecated]] inline auto reset() -> void { s = unit; diff --git a/src/kernel/environment.cpp b/src/kernel/environment.cpp index 0f73e3b4a..60b22e459 100644 --- a/src/kernel/environment.cpp +++ b/src/kernel/environment.cpp @@ -133,6 +133,8 @@ inline namespace kernel c = compile(context(), *this, expression, scope()); + c = optimize(c); + if (debug) { disassemble(debug_port().as(), c); From 66536229efa8594b95f3a31e10d55f121478ea21 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Tue, 14 Jun 2022 01:56:53 +0900 Subject: [PATCH 22/24] Update `optimize` to reuse given code Signed-off-by: yamacir-kit --- README.md | 6 +-- VERSION | 2 +- include/meevax/kernel/machine.hpp | 68 ++++++++++++++++++++++++------- 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 362a571b2..e9670df89 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.61.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.62.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.61_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.62_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.61 +Meevax Lisp System, version 0.4.62 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 45976791b..73de7f980 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.61 +0.4.62 diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index 56dab65d6..8f94be28c 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -769,8 +769,17 @@ inline namespace kernel case mnemonic::return_: case mnemonic::stop: case mnemonic::tail_call: - return cons(car(c), - optimize(cdr(c))); + return [&]() + { + if (let const& continuation = optimize(cdr(c)); continuation == cdr(c)) + { + return c; + } + else + { + return cons(car(c), continuation); + } + }(); case mnemonic::define: case mnemonic::define_syntax: @@ -782,22 +791,50 @@ inline namespace kernel case mnemonic::store_absolute: case mnemonic::store_relative: case mnemonic::store_variadic: - return cons(car(c), - cadr(c), - optimize(cddr(c))); + return [&]() + { + if (let const& continuation = optimize(cddr(c)); continuation == cddr(c)) + { + return c; + } + else + { + return cons(car(c), cadr(c), continuation); + } + }(); case mnemonic::load_closure: case mnemonic::load_continuation: - return cons(car(c), - optimize(cadr(c)), - optimize(cddr(c))); + return [&]() + { + if (let const& branch = optimize(cadr(c)), + continuation = optimize(cddr(c)); + branch == cadr(c) and continuation == cddr(c)) + { + return c; + } + else + { + return cons(car(c), branch, continuation); + } + }(); case mnemonic::select: case mnemonic::tail_select: - return cons(car(c), - optimize(cadr(c)), - optimize(caddr(c)), - optimize(cdddr(c))); + return [&]() + { + if (let const& consequent = optimize(cadr(c)), + alternate = optimize(caddr(c)), + continuation = optimize(cdddr(c)); + consequent == cadr(c) and alternate == caddr(c) and continuation == cdddr(c)) + { + return c; + } + else + { + return cons(car(c), consequent, alternate, continuation); + } + }(); case mnemonic::load_constant: /* ----------------------------------------- @@ -823,10 +860,13 @@ inline namespace kernel list_ref(c, 1)), optimize(list_tail(c, 5)))); } + else if (let const& continuation = optimize(cddr(c)); continuation == cddr(c)) + { + return c; + } else { - return cons(car(c), cadr(c), - optimize(cddr(c))); + return cons(car(c), cadr(c), continuation); } default: From 4879c442b3b9b4cf6007a526311eaade1db000e9 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Tue, 14 Jun 2022 02:43:41 +0900 Subject: [PATCH 23/24] Add new struct `optimizer` Signed-off-by: yamacir-kit --- README.md | 6 +- VERSION | 2 +- include/meevax/kernel/environment.hpp | 8 +- include/meevax/kernel/machine.hpp | 123 ------------------- include/meevax/kernel/optimizer.hpp | 168 ++++++++++++++++++++++++++ 5 files changed, 177 insertions(+), 130 deletions(-) create mode 100644 include/meevax/kernel/optimizer.hpp diff --git a/README.md b/README.md index e9670df89..4b608ef44 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.62.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.63.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.62_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.63_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.62 +Meevax Lisp System, version 0.4.63 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 73de7f980..6c75a3792 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.62 +0.4.63 diff --git a/include/meevax/kernel/environment.hpp b/include/meevax/kernel/environment.hpp index 8c7ee5d37..70142d36d 100644 --- a/include/meevax/kernel/environment.hpp +++ b/include/meevax/kernel/environment.hpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -28,9 +29,10 @@ inline namespace kernel { class environment : public virtual pair , public configurator - , public machine - , public reader - , public writer + , public machine + , public optimizer + , public reader + , public writer { using pair::pair; diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index 8f94be28c..600cfcc4e 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -752,129 +752,6 @@ inline namespace kernel return variable.is() ? variable.as().identify_with_offset(scope) : f; } - static auto optimize(const_reference c) -> lvalue - { - if (not c.is()) - { - return c; - } - else switch (car(c).template as()) - { - case mnemonic::call: - case mnemonic::cons: - case mnemonic::drop: - case mnemonic::dummy: - case mnemonic::join: - case mnemonic::letrec: - case mnemonic::return_: - case mnemonic::stop: - case mnemonic::tail_call: - return [&]() - { - if (let const& continuation = optimize(cdr(c)); continuation == cdr(c)) - { - return c; - } - else - { - return cons(car(c), continuation); - } - }(); - - case mnemonic::define: - case mnemonic::define_syntax: - case mnemonic::let_syntax: - case mnemonic::letrec_syntax: - case mnemonic::load_absolute: - case mnemonic::load_relative: - case mnemonic::load_variadic: - case mnemonic::store_absolute: - case mnemonic::store_relative: - case mnemonic::store_variadic: - return [&]() - { - if (let const& continuation = optimize(cddr(c)); continuation == cddr(c)) - { - return c; - } - else - { - return cons(car(c), cadr(c), continuation); - } - }(); - - case mnemonic::load_closure: - case mnemonic::load_continuation: - return [&]() - { - if (let const& branch = optimize(cadr(c)), - continuation = optimize(cddr(c)); - branch == cadr(c) and continuation == cddr(c)) - { - return c; - } - else - { - return cons(car(c), branch, continuation); - } - }(); - - case mnemonic::select: - case mnemonic::tail_select: - return [&]() - { - if (let const& consequent = optimize(cadr(c)), - alternate = optimize(caddr(c)), - continuation = optimize(cdddr(c)); - consequent == cadr(c) and alternate == caddr(c) and continuation == cdddr(c)) - { - return c; - } - else - { - return cons(car(c), consequent, alternate, continuation); - } - }(); - - - case mnemonic::load_constant: /* ----------------------------------------- - * - * (load-constant x - * load-constant y - * cons - * ...) - * - * => (load-constant (x . y) - * ...) - * - * --------------------------------------------------------------------- */ - if (5 <= length(c) and - list_ref(c, 0).is() and - list_ref(c, 0).as() == mnemonic::load_constant and - list_ref(c, 2).is() and - list_ref(c, 2).as() == mnemonic::load_constant and - list_ref(c, 4).is() and - list_ref(c, 4).as() == mnemonic::cons) - { - return optimize(cons(list_ref(c, 0), cons(list_ref(c, 3), - list_ref(c, 1)), - optimize(list_tail(c, 5)))); - } - else if (let const& continuation = optimize(cddr(c)); continuation == cddr(c)) - { - return c; - } - else - { - return cons(car(c), cadr(c), continuation); - } - - default: - assert(false); - return c; - } - } - [[deprecated]] inline auto reset() -> void { diff --git a/include/meevax/kernel/optimizer.hpp b/include/meevax/kernel/optimizer.hpp new file mode 100644 index 000000000..f10466acb --- /dev/null +++ b/include/meevax/kernel/optimizer.hpp @@ -0,0 +1,168 @@ +/* + Copyright 2018-2022 Tatsuya Yamasaki. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef INCLUDED_MEEVAX_KERNEL_OPTIMIZER_HPP +#define INCLUDED_MEEVAX_KERNEL_OPTIMIZER_HPP + +#include + +namespace meevax +{ +inline namespace kernel +{ + struct optimizer + { + static inline auto fmerge_constants = true; + + static auto merge_constants(const_reference c) -> lvalue + { + if (not c.is()) + { + return c; + } + else switch (car(c).template as()) + { + case mnemonic::call: + case mnemonic::cons: + case mnemonic::drop: + case mnemonic::dummy: + case mnemonic::join: + case mnemonic::letrec: + case mnemonic::return_: + case mnemonic::stop: + case mnemonic::tail_call: + return [&]() + { + if (let const& continuation = merge_constants(cdr(c)); continuation == cdr(c)) + { + return c; + } + else + { + return cons(car(c), continuation); + } + }(); + + case mnemonic::define: + case mnemonic::define_syntax: + case mnemonic::let_syntax: + case mnemonic::letrec_syntax: + case mnemonic::load_absolute: + case mnemonic::load_relative: + case mnemonic::load_variadic: + case mnemonic::store_absolute: + case mnemonic::store_relative: + case mnemonic::store_variadic: + return [&]() + { + if (let const& continuation = merge_constants(cddr(c)); continuation == cddr(c)) + { + return c; + } + else + { + return cons(car(c), cadr(c), continuation); + } + }(); + + case mnemonic::load_closure: + case mnemonic::load_continuation: + return [&]() + { + if (let const& branch = merge_constants(cadr(c)), + continuation = merge_constants(cddr(c)); + branch == cadr(c) and continuation == cddr(c)) + { + return c; + } + else + { + return cons(car(c), branch, continuation); + } + }(); + + case mnemonic::select: + case mnemonic::tail_select: + return [&]() + { + if (let const& consequent = merge_constants(cadr(c)), + alternate = merge_constants(caddr(c)), + continuation = merge_constants(cdddr(c)); + consequent == cadr(c) and alternate == caddr(c) and continuation == cdddr(c)) + { + return c; + } + else + { + return cons(car(c), consequent, alternate, continuation); + } + }(); + + + case mnemonic::load_constant: /* ----------------------------------------- + * + * (load-constant x + * load-constant y + * cons + * ...) + * + * => (load-constant (x . y) + * ...) + * + * --------------------------------------------------------------------- */ + if (5 <= length(c) and + list_ref(c, 0).is() and + list_ref(c, 0).as() == mnemonic::load_constant and + list_ref(c, 2).is() and + list_ref(c, 2).as() == mnemonic::load_constant and + list_ref(c, 4).is() and + list_ref(c, 4).as() == mnemonic::cons) + { + return merge_constants(cons(list_ref(c, 0), cons(list_ref(c, 3), + list_ref(c, 1)), + merge_constants(list_tail(c, 5)))); + } + else if (let const& continuation = merge_constants(cddr(c)); continuation == cddr(c)) + { + return c; + } + else + { + return cons(car(c), cadr(c), continuation); + } + + default: + assert(false); + return c; + } + } + + static auto optimize(const_reference c) + { + let code = c; + + if (fmerge_constants) + { + code = merge_constants(code); + } + + return code; + } + }; +} // namespace kernel +} // namespace meevax + +#endif // INCLUDED_MEEVAX_KERNEL_OPTIMIZER_HPP From 9af5e561a259a9b3b46ebfbf2b852ca7783fe885 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Tue, 14 Jun 2022 03:03:10 +0900 Subject: [PATCH 24/24] Simplify instruction `tail_call` Signed-off-by: yamacir-kit --- README.md | 6 ++-- VERSION | 2 +- include/meevax/kernel/machine.hpp | 49 ++++++++----------------------- 3 files changed, 16 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 4b608ef44..a9e0bbf9f 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.63.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.64.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.63_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.64_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.63 +Meevax Lisp System, version 0.4.64 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 6c75a3792..96b9b226d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.63 +0.4.64 diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index 600cfcc4e..afddfdad7 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -533,66 +533,40 @@ inline namespace kernel }(); goto decode; - case mnemonic::call: + case mnemonic::tail_call: if (let const& callee = car(s); callee.is()) /* --------------- * - * ( xs . s) e (%call . c) d => () (xs . e') c' (s e c . d) + * ( xs . s) e (%tail-call . c) d => () (xs . e') c' d * * where = (c' . e') * * ------------------------------------------------------------------- */ { - d = cons(cddr(s), e, cdr(c), d); c = callee.as().c(); e = cons(cadr(s), callee.as().e()); s = unit; + goto decode; } - else if (callee.is_also()) /* ------------------------------- - * - * ( xs . s) e (%call . c) d => (x . s) e c d - * - * where x = procedure(xs) - * - * ------------------------------------------------------------------- */ - { - s = cons(callee.as().call(cadr(s)), cddr(s)); - c = cdr(c); - } - else if (callee.is()) /* --------------------------------- - * - * ( xs . s) e (%call . c) d => (xs . s') e' c' d' - * - * where = (s' e' c' . 'd) - * - * ------------------------------------------------------------------- */ - { - s = cons(caadr(s), callee.as().s()); - e = callee.as().e(); - c = callee.as().c(); - d = callee.as().d(); - } - else - { - throw error(make("not applicable"), callee); - } - goto decode; + [[fallthrough]]; // This is inefficient because the type check occurs twice, but currently the performance difference caused by this is too small. - case mnemonic::tail_call: + case mnemonic::call: if (let const& callee = car(s); callee.is()) /* --------------- * - * ( xs . s) e (%tail-call . c) d => () (xs . e') c' d + * ( xs . s) e (%call . c) d => () (xs . e') c' (s e c . d) * * where = (c' . e') * * ------------------------------------------------------------------- */ { + d = cons(cddr(s), e, cdr(c), d); c = callee.as().c(); e = cons(cadr(s), callee.as().e()); s = unit; + goto decode; } else if (callee.is_also()) /* ------------------------------- * - * ( xs . s) e (%tail-call . c) d => (x . s) e c d + * ( xs . s) e (%call . c) d => (x . s) e c d * * where x = procedure(xs) * @@ -600,10 +574,11 @@ inline namespace kernel { s = cons(callee.as().call(cadr(s)), cddr(s)); c = cdr(c); + goto decode; } else if (callee.is()) /* --------------------------------- * - * ( xs . s) e (%tail-call . c) d => (xs . s') e' c' d' + * ( xs . s) e (%call . c) d => (xs . s') e' c' d' * * where = (s' e' c' . 'd) * @@ -613,12 +588,12 @@ inline namespace kernel e = callee.as().e(); c = callee.as().c(); d = callee.as().d(); + goto decode; } else { throw error(make("not applicable"), callee); } - goto decode; case mnemonic::dummy: /* ------------------------------------------------- *