diff --git a/CMakeLists.txt b/CMakeLists.txt index b0b3c63a..7bda6388 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,6 +127,18 @@ xo_add_genfacetimpl( OUTPUT_CPP_DIR src/interpreter2 ) +# note: manual target; generated code committed to git +xo_add_genfacetimpl( + TARGET xo-interpreter2-facetimpl-printable-localenv + FACET_PKG xo_printable2 + FACET Printable + REPR LocalEnv + INPUT idl/IPrintable_DLocalEnv.json5 + OUTPUT_HPP_DIR include/xo/interpreter2 + OUTPUT_IMPL_SUBDIR detail + OUTPUT_CPP_DIR src/interpreter2 +) + # ---------------------------------------------------------------- xo_add_genfacet_all(xo-interpreter2-genfacet-all) diff --git a/idl/IPrintable_DLocalEnv.json5 b/idl/IPrintable_DLocalEnv.json5 new file mode 100644 index 00000000..0302834d --- /dev/null +++ b/idl/IPrintable_DLocalEnv.json5 @@ -0,0 +1,13 @@ +{ + mode: "implementation", + includes: [ "", + "" ], + local_types: [ ], + namespace1: "xo", + namespace2: "scm", + facet_idl: "idl/Printable.json5", + brief: "provide APrintable interface for DLocalEnv", + using_doxygen: true, + repr: "DLocalEnv", + doc: [ "implement APrintable for DLocalEnv" ], +} diff --git a/include/xo/interpreter2/DLocalEnv.hpp b/include/xo/interpreter2/DLocalEnv.hpp index 5563fb3a..234db71f 100644 --- a/include/xo/interpreter2/DLocalEnv.hpp +++ b/include/xo/interpreter2/DLocalEnv.hpp @@ -58,6 +58,12 @@ namespace xo { std::size_t forward_children(obj gc) noexcept; ///@} + /** @defgroup scm-localenv-printable-facet **/ + ///@{ + + bool pretty(const ppindentinfo & ppii) const noexcept; + + ///@} private: /** parent environment (from closure) **/ diff --git a/include/xo/interpreter2/LocalEnv.hpp b/include/xo/interpreter2/LocalEnv.hpp index a709e006..8955e35d 100644 --- a/include/xo/interpreter2/LocalEnv.hpp +++ b/include/xo/interpreter2/LocalEnv.hpp @@ -7,6 +7,6 @@ #include "DLocalEnv.hpp" #include "detail/IGCObject_DLocalEnv.hpp" -//#include "detail/IPrintable_DLocalEnv.hpp" +#include "detail/IPrintable_DLocalEnv.hpp" /* end LocalEnv.hpp */ diff --git a/include/xo/interpreter2/VirtualSchematikaMachine.hpp b/include/xo/interpreter2/VirtualSchematikaMachine.hpp index 1aebed2c..f28c5bef 100644 --- a/include/xo/interpreter2/VirtualSchematikaMachine.hpp +++ b/include/xo/interpreter2/VirtualSchematikaMachine.hpp @@ -216,6 +216,7 @@ namespace xo { * in execution **/ DLocalEnv * local_env_ = nullptr; + protected: // temporarily, to appease compiler /** environment pointer. Maintains bindings * for global variables. diff --git a/include/xo/interpreter2/detail/IPrintable_DLocalEnv.hpp b/include/xo/interpreter2/detail/IPrintable_DLocalEnv.hpp new file mode 100644 index 00000000..c0ddb7f8 --- /dev/null +++ b/include/xo/interpreter2/detail/IPrintable_DLocalEnv.hpp @@ -0,0 +1,62 @@ +/** @file IPrintable_DLocalEnv.hpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DLocalEnv.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_repr.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DLocalEnv.json5] + **/ + +#pragma once + +#include "Printable.hpp" +#include +#include +#include "DLocalEnv.hpp" + +namespace xo { namespace scm { class IPrintable_DLocalEnv; } } + +namespace xo { + namespace facet { + template <> + struct FacetImplementation + { + using ImplType = xo::print::IPrintable_Xfer + ; + }; + } +} + +namespace xo { + namespace scm { + /** @class IPrintable_DLocalEnv + **/ + class IPrintable_DLocalEnv { + public: + /** @defgroup scm-printable-dlocalenv-type-traits **/ + ///@{ + using ppindentinfo = xo::print::APrintable::ppindentinfo; + using Copaque = xo::print::APrintable::Copaque; + using Opaque = xo::print::APrintable::Opaque; + ///@} + /** @defgroup scm-printable-dlocalenv-methods **/ + ///@{ + // const methods + /** Pretty-printing support for this object. +See [xo-indentlog/xo/indentlog/pretty.hpp] **/ + static bool pretty(const DLocalEnv & self, const ppindentinfo & ppii); + + // non-const methods + ///@} + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end */ \ No newline at end of file diff --git a/src/interpreter2/CMakeLists.txt b/src/interpreter2/CMakeLists.txt index e7493775..373f6138 100644 --- a/src/interpreter2/CMakeLists.txt +++ b/src/interpreter2/CMakeLists.txt @@ -17,10 +17,12 @@ set(SELF_SRCS IPrintable_DVsmApplyFrame.cpp DClosure.cpp - IGCObject_DClosure.cpp IProcedure_DClosure.cpp + IGCObject_DClosure.cpp + IPrintable_DClosure.cpp IGCObject_DLocalEnv.cpp + IPrintable_DLocalEnv.cpp DLocalEnv.cpp VsmInstr.cpp diff --git a/src/interpreter2/DClosure.cpp b/src/interpreter2/DClosure.cpp index b1868950..d1baa172 100644 --- a/src/interpreter2/DClosure.cpp +++ b/src/interpreter2/DClosure.cpp @@ -10,6 +10,7 @@ namespace xo { using xo::mm::AGCObject; + using xo::print::APrintable; namespace scm { @@ -69,6 +70,24 @@ namespace xo { return shallow_size(); } + // ----- printable facet ----- + + bool + DClosure::pretty(const ppindentinfo & ppii) const + { + obj lambda_pr(const_cast(lambda_)); + obj env_pr(const_cast(env_)); + + bool lambda_present = lambda_pr; + bool env_present = env_pr; + + return ppii.pps()->pretty_struct + (ppii, + "DClosure", + refrtag("lambda", lambda_pr, lambda_present), + refrtag("env", env_pr, env_present)); + } + } /*namespace scm*/ } /*namespace xo*/ diff --git a/src/interpreter2/DLocalEnv.cpp b/src/interpreter2/DLocalEnv.cpp index 9ba65085..9ee0911a 100644 --- a/src/interpreter2/DLocalEnv.cpp +++ b/src/interpreter2/DLocalEnv.cpp @@ -121,6 +121,22 @@ namespace xo { return shallow_size(); } + // ----- printable facet ----- + + bool + DLocalEnv::pretty(const ppindentinfo & ppii) const noexcept + { + // print local bindings, perhaps + // symtab_ + // args_ + + return ppii.pps()->pretty_struct + (ppii, + "DLocalEnv", + refrtag("n_args", args_->size()) + ); + } + } /*namespace scm*/ } /*namespace xo*/ diff --git a/src/interpreter2/IPrintable_DLocalEnv.cpp b/src/interpreter2/IPrintable_DLocalEnv.cpp new file mode 100644 index 00000000..bf701cb6 --- /dev/null +++ b/src/interpreter2/IPrintable_DLocalEnv.cpp @@ -0,0 +1,28 @@ +/** @file IPrintable_DLocalEnv.cpp + * + * Generated automagically from ingredients: + * 1. code generator: + * [xo-facet/codegen/genfacet] + * arguments: + * --input [idl/IPrintable_DLocalEnv.json5] + * 2. jinja2 template for abstract facet .hpp file: + * [iface_facet_any.hpp.j2] + * 3. idl for facet methods + * [idl/IPrintable_DLocalEnv.json5] +**/ + +#include "detail/IPrintable_DLocalEnv.hpp" + +namespace xo { + namespace scm { + auto + IPrintable_DLocalEnv::pretty(const DLocalEnv & self, const ppindentinfo & ppii) -> bool + { + return self.pretty(ppii); + } + + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end IPrintable_DLocalEnv.cpp */ diff --git a/src/interpreter2/VirtualSchematikaMachine.cpp b/src/interpreter2/VirtualSchematikaMachine.cpp index bfd5e09f..c62a723f 100644 --- a/src/interpreter2/VirtualSchematikaMachine.cpp +++ b/src/interpreter2/VirtualSchematikaMachine.cpp @@ -241,10 +241,9 @@ namespace xo { lambda.data(), local_env_); - this->value_ = obj(obj(closure)); - - // not implemented - assert(false); + this->value_ + = obj(obj(closure)); + this->pc_ = this->cont_; } void diff --git a/src/interpreter2/interpreter2_register_facets.cpp b/src/interpreter2/interpreter2_register_facets.cpp index 1953bf1d..22757a48 100644 --- a/src/interpreter2/interpreter2_register_facets.cpp +++ b/src/interpreter2/interpreter2_register_facets.cpp @@ -8,6 +8,7 @@ #include "VsmApplyFrame.hpp" #include "VsmEvalArgsFrame.hpp" #include "Closure.hpp" +#include "LocalEnv.hpp" #include #include @@ -37,9 +38,13 @@ namespace xo { FacetRegistry::register_impl(); FacetRegistry::register_impl(); + FacetRegistry::register_impl(); FacetRegistry::register_impl(); FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + // Procedure // +- Primitive_gco_2_gco_gco // \- Closure @@ -49,6 +54,7 @@ namespace xo { log && log(xtag("DVsmApplyFrame.tseq", typeseq::id())); log && log(xtag("DVsmEvalArgsFrame.tseq", typeseq::id())); log && log(xtag("DClosure.tseq", typeseq::id())); + log && log(xtag("DLocalEnv.tseq", typeseq::id())); return true; } diff --git a/utest/VirtualSchematikaMachine.test.cpp b/utest/VirtualSchematikaMachine.test.cpp index 90805af7..ee4ca351 100644 --- a/utest/VirtualSchematikaMachine.test.cpp +++ b/utest/VirtualSchematikaMachine.test.cpp @@ -4,10 +4,11 @@ **/ #include -#include -#include -#include -#include +#include +#include +//#include +#include +//#include #ifdef NOT_YET #include @@ -28,6 +29,7 @@ namespace xo { using xo::scm::VirtualSchematikaMachine; using xo::scm::VsmConfig; using xo::scm::VsmResultExt; + using xo::scm::DClosure; using xo::scm::DFloat; using xo::scm::DInteger; using xo::mm::AGCObject; @@ -196,17 +198,17 @@ namespace xo { bool eof_flag = false; vsm.begin_interactive_session(); - VsmResultExt res = vsm.read_eval_print(span_type::from_cstr("lambda (x : i64) -> i64 { x * x; };"), eof_flag); + VsmResultExt res = vsm.read_eval_print(span_type::from_cstr("lambda (x : i64) -> i64 { x * x; }"), eof_flag); REQUIRE(res.is_value()); REQUIRE(res.value()); log && log(xtag("res.tseq", res.value()->_typeseq())); - auto x = obj::from(*res.value()); + auto x = obj::from(*res.value()); REQUIRE(x); - REQUIRE(x.data()->value() == 1.570796325); + //REQUIRE(x.data()->value() == 1.570796325); REQUIRE(res.remaining_.size() == 1); REQUIRE(*res.remaining_.lo() == '\n');