xo-interpreter2 stack: lambda expr -> closure runs in VSM utest
This commit is contained in:
parent
82c82ea332
commit
e219ea0db3
13 changed files with 179 additions and 13 deletions
|
|
@ -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)
|
||||
|
|
|
|||
13
idl/IPrintable_DLocalEnv.json5
Normal file
13
idl/IPrintable_DLocalEnv.json5
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [ "<xo/printable2/Printable.hpp>",
|
||||
"<xo/printable2/detail/IPrintable_Xfer.hpp>" ],
|
||||
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" ],
|
||||
}
|
||||
|
|
@ -58,6 +58,12 @@ namespace xo {
|
|||
std::size_t forward_children(obj<ACollector> gc) noexcept;
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-localenv-printable-facet **/
|
||||
///@{
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const noexcept;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** parent environment (from closure) **/
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -216,6 +216,7 @@ namespace xo {
|
|||
* in execution
|
||||
**/
|
||||
DLocalEnv * local_env_ = nullptr;
|
||||
|
||||
protected: // temporarily, to appease compiler
|
||||
/** environment pointer. Maintains bindings
|
||||
* for global variables.
|
||||
|
|
|
|||
62
include/xo/interpreter2/detail/IPrintable_DLocalEnv.hpp
Normal file
62
include/xo/interpreter2/detail/IPrintable_DLocalEnv.hpp
Normal file
|
|
@ -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 <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DLocalEnv.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DLocalEnv; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DLocalEnv>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DLocalEnv,
|
||||
xo::scm::IPrintable_DLocalEnv>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
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 */
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<APrintable,DLambdaExpr> lambda_pr(const_cast<DLambdaExpr *>(lambda_));
|
||||
obj<APrintable,DLocalEnv> env_pr(const_cast<DLocalEnv *>(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*/
|
||||
|
||||
|
|
|
|||
|
|
@ -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*/
|
||||
|
||||
|
|
|
|||
28
src/interpreter2/IPrintable_DLocalEnv.cpp
Normal file
28
src/interpreter2/IPrintable_DLocalEnv.cpp
Normal file
|
|
@ -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 */
|
||||
|
|
@ -241,10 +241,9 @@ namespace xo {
|
|||
lambda.data(),
|
||||
local_env_);
|
||||
|
||||
this->value_ = obj<AGCObject>(obj<AGCObject,DClosure>(closure));
|
||||
|
||||
// not implemented
|
||||
assert(false);
|
||||
this->value_
|
||||
= obj<AGCObject>(obj<AGCObject,DClosure>(closure));
|
||||
this->pc_ = this->cont_;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include "VsmApplyFrame.hpp"
|
||||
#include "VsmEvalArgsFrame.hpp"
|
||||
#include "Closure.hpp"
|
||||
#include "LocalEnv.hpp"
|
||||
|
||||
#include <xo/printable2/detail/APrintable.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
|
|
@ -37,9 +38,13 @@ namespace xo {
|
|||
FacetRegistry::register_impl<AGCObject, DVsmEvalArgsFrame>();
|
||||
FacetRegistry::register_impl<APrintable, DVsmEvalArgsFrame>();
|
||||
|
||||
FacetRegistry::register_impl<AProcedure, DClosure>();
|
||||
FacetRegistry::register_impl<AGCObject, DClosure>();
|
||||
FacetRegistry::register_impl<APrintable, DClosure>();
|
||||
|
||||
FacetRegistry::register_impl<AGCObject, DLocalEnv>();
|
||||
FacetRegistry::register_impl<APrintable, DLocalEnv>();
|
||||
|
||||
// Procedure
|
||||
// +- Primitive_gco_2_gco_gco
|
||||
// \- Closure
|
||||
|
|
@ -49,6 +54,7 @@ namespace xo {
|
|||
log && log(xtag("DVsmApplyFrame.tseq", typeseq::id<DVsmApplyFrame>()));
|
||||
log && log(xtag("DVsmEvalArgsFrame.tseq", typeseq::id<DVsmEvalArgsFrame>()));
|
||||
log && log(xtag("DClosure.tseq", typeseq::id<DClosure>()));
|
||||
log && log(xtag("DLocalEnv.tseq", typeseq::id<DLocalEnv>()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@
|
|||
**/
|
||||
|
||||
#include <xo/interpreter2/VirtualSchematikaMachine.hpp>
|
||||
#include <xo/object2/DFloat.hpp>
|
||||
#include <xo/object2/number/IGCObject_DFloat.hpp>
|
||||
#include <xo/object2/DInteger.hpp>
|
||||
#include <xo/object2/number/IGCObject_DInteger.hpp>
|
||||
#include <xo/interpreter2/Closure.hpp>
|
||||
#include <xo/object2/Float.hpp>
|
||||
//#include <xo/object2/number/IGCObject_DFloat.hpp>
|
||||
#include <xo/object2/Integer.hpp>
|
||||
//#include <xo/object2/number/IGCObject_DInteger.hpp>
|
||||
|
||||
#ifdef NOT_YET
|
||||
#include <xo/reader2/SchematikaParser.hpp>
|
||||
|
|
@ -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<AGCObject,DFloat>::from(*res.value());
|
||||
auto x = obj<AGCObject,DClosure>::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');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue