xo-interpreter2 stack: work on variable references [WIP]
This commit is contained in:
parent
cbca2b7c6b
commit
73614c3ce4
10 changed files with 238 additions and 0 deletions
11
include/xo/interpreter2/Closure.hpp
Normal file
11
include/xo/interpreter2/Closure.hpp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/** @file Closure.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DClosure.hpp"
|
||||
#include "detail/IProcedure_DClosure.hpp"
|
||||
|
||||
/* end Closure.hpp */
|
||||
|
|
@ -3,8 +3,11 @@
|
|||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LocalEnv.hpp"
|
||||
#include <xo/expression2/LambdaExpr.hpp>
|
||||
#include <xo/procedure2/RuntimeContext.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
|
@ -15,7 +18,10 @@ namespace xo {
|
|||
**/
|
||||
class DClosure {
|
||||
public:
|
||||
using ARuntimeContext = xo::scm::ARuntimeContext;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using AGCObject = xo::mm::AGCObject;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
using size_type = std::int32_t;
|
||||
|
||||
public:
|
||||
|
|
@ -29,11 +35,35 @@ namespace xo {
|
|||
const DLambdaExpr * lm,
|
||||
const DLocalEnv * env);
|
||||
|
||||
/** @defgroup scm-closure-general-methods **/
|
||||
///@{
|
||||
|
||||
const DLambdaExpr * lambda() const noexcept { return lambda_; }
|
||||
const DLocalEnv * env() const noexcept { return env_; }
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-closure-procedure-facet **/
|
||||
///@{
|
||||
|
||||
/** for now, support just fixed-arity procedures **/
|
||||
bool is_nary() const noexcept { return false; }
|
||||
/** number of arguments expected by this procedure (-1 if nary) **/
|
||||
size_type n_args() const noexcept { return lambda_->n_args(); }
|
||||
|
||||
obj<AGCObject> apply_nocheck(obj<ARuntimeContext> rcx, const DArray * args);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-closure-gcobject-facet **/
|
||||
///@{
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-closure-printable-facet **/
|
||||
///@{
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** lambda expression **/
|
||||
const DLambdaExpr * lambda_ = nullptr;
|
||||
|
|
|
|||
67
include/xo/interpreter2/detail/IProcedure_DClosure.hpp
Normal file
67
include/xo/interpreter2/detail/IProcedure_DClosure.hpp
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/** @file IProcedure_DClosure.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IProcedure_DClosure.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IProcedure_DClosure.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Procedure.hpp"
|
||||
#include <xo/procedure2/RuntimeContext.hpp>
|
||||
#include <xo/procedure2/detail/IRuntimeContext_Xfer.hpp>
|
||||
#include <xo/procedure2/Procedure.hpp>
|
||||
#include <xo/procedure2/detail/IProcedure_Xfer.hpp>
|
||||
#include "DClosure.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IProcedure_DClosure; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::AProcedure,
|
||||
xo::scm::DClosure>
|
||||
{
|
||||
using ImplType = xo::scm::IProcedure_Xfer
|
||||
<xo::scm::DClosure,
|
||||
xo::scm::IProcedure_DClosure>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IProcedure_DClosure
|
||||
**/
|
||||
class IProcedure_DClosure {
|
||||
public:
|
||||
/** @defgroup scm-procedure-dclosure-type-traits **/
|
||||
///@{
|
||||
using AGCObject = xo::scm::AProcedure::AGCObject;
|
||||
using Copaque = xo::scm::AProcedure::Copaque;
|
||||
using Opaque = xo::scm::AProcedure::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-procedure-dclosure-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** true iff procedure takes n arguments **/
|
||||
static bool is_nary(const DClosure & self) noexcept;
|
||||
/** number of arguments. -1 for n-ary **/
|
||||
static std::int32_t n_args(const DClosure & self) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** invoke procedure; assume arguments satisfy type system **/
|
||||
static obj<AGCObject> apply_nocheck(DClosure & self, obj<ARuntimeContext> rcx, const DArray * args);
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
Loading…
Add table
Add a link
Reference in a new issue