xo-reader2 stack: top-level lambda w/ apply parses
This commit is contained in:
parent
370e52a149
commit
d869e87516
78 changed files with 1210 additions and 216 deletions
|
|
@ -146,6 +146,44 @@ xo_add_genfacetimpl(
|
|||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-expression-varref
|
||||
FACET_PKG xo_expression2
|
||||
FACET Expression
|
||||
REPR VarRef
|
||||
INPUT idl/IExpression_DVarRef.json5
|
||||
OUTPUT_HPP_DIR include/xo/expression2
|
||||
OUTPUT_IMPL_SUBDIR detail
|
||||
OUTPUT_CPP_DIR src/expression2
|
||||
)
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-gcobject-varref
|
||||
FACET_PKG xo_gc
|
||||
FACET GCObject
|
||||
REPR VarRef
|
||||
INPUT idl/IGCObject_DVarRef.json5
|
||||
OUTPUT_HPP_DIR include/xo/expression2
|
||||
OUTPUT_IMPL_SUBDIR detail
|
||||
OUTPUT_CPP_DIR src/expression2
|
||||
)
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-printable-varref
|
||||
FACET_PKG xo_printable2
|
||||
FACET Printable
|
||||
REPR VarRef
|
||||
INPUT idl/IPrintable_DVarRef.json5
|
||||
OUTPUT_HPP_DIR include/xo/expression2
|
||||
OUTPUT_IMPL_SUBDIR detail
|
||||
OUTPUT_CPP_DIR src/expression2
|
||||
)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-expression-defineexpr
|
||||
|
|
@ -184,6 +222,18 @@ xo_add_genfacetimpl(
|
|||
OUTPUT_CPP_DIR src/expression2
|
||||
)
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-gcobject-applyexpr
|
||||
FACET_PKG xo_gc
|
||||
FACET GCObject
|
||||
REPR ApplyExpr
|
||||
INPUT idl/IGCObject_DApplyExpr.json5
|
||||
OUTPUT_HPP_DIR include/xo/expression2
|
||||
OUTPUT_IMPL_SUBDIR detail
|
||||
OUTPUT_CPP_DIR src/expression2
|
||||
)
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-expression2-facetimpl-printable-applyexpr
|
||||
|
|
|
|||
|
|
@ -67,4 +67,5 @@
|
|||
attributes: [],
|
||||
}
|
||||
],
|
||||
router_facet_explicit_content: [ ],
|
||||
}
|
||||
|
|
|
|||
12
xo-expression2/idl/IExpression_DVarRef.json5
Normal file
12
xo-expression2/idl/IExpression_DVarRef.json5
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [ "\"Expression.hpp\"" ],
|
||||
local_types: [ ],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
facet_idl: "idl/Expression.json5",
|
||||
brief: "provide AExpression interface for DVarRef state",
|
||||
using_doxygen: true,
|
||||
repr: "DVarRef",
|
||||
doc: ["doc for IExpression+DVarRef" ],
|
||||
}
|
||||
15
xo-expression2/idl/IGCObject_DApplyExpr.json5
Normal file
15
xo-expression2/idl/IGCObject_DApplyExpr.json5
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [
|
||||
"<xo/gc/GCObject.hpp>",
|
||||
"<xo/alloc2/Allocator.hpp>"
|
||||
],
|
||||
local_types: [ ],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
facet_idl: "idl/GCObject.json5",
|
||||
brief: "provide AGCObject interface for DApplyExpr",
|
||||
using_doxygen: true,
|
||||
repr: "DApplyExpr",
|
||||
doc: [ "implement AGCObject for DApplyExpr" ],
|
||||
}
|
||||
15
xo-expression2/idl/IGCObject_DVarRef.json5
Normal file
15
xo-expression2/idl/IGCObject_DVarRef.json5
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [
|
||||
"<xo/gc/GCObject.hpp>",
|
||||
"<xo/alloc2/Allocator.hpp>"
|
||||
],
|
||||
local_types: [ ],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
facet_idl: "idl/GCObject.json5",
|
||||
brief: "provide AGCObject interface for DVarRef",
|
||||
using_doxygen: true,
|
||||
repr: "DVarRef",
|
||||
doc: [ "implement AGCObject for DVarRef" ],
|
||||
}
|
||||
13
xo-expression2/idl/IPrintable_DVarRef.json5
Normal file
13
xo-expression2/idl/IPrintable_DVarRef.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 DVarRef",
|
||||
using_doxygen: true,
|
||||
repr: "DVarRef",
|
||||
doc: [ "implement APrintable for DVarRef" ],
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "DApplyExpr.hpp"
|
||||
#include "detail/IExpression_DApplyExpr.hpp"
|
||||
//#include "detail/IGCObject_DApplyExpr.hpp"
|
||||
#include "detail/IGCObject_DApplyExpr.hpp"
|
||||
#include "detail/IPrintable_DApplyExpr.hpp"
|
||||
|
||||
/* end ApplyExpr.hpp */
|
||||
|
|
|
|||
|
|
@ -5,14 +5,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
class Binding {
|
||||
public:
|
||||
static constexpr int32_t s_link_sentinel = -2;
|
||||
static constexpr int32_t s_link_global = -1;
|
||||
static constexpr int32_t c_link_sentinel = -2;
|
||||
static constexpr int32_t c_link_global = -1;
|
||||
|
||||
public:
|
||||
Binding() : i_link_{-2}, j_slot_{-1} {}
|
||||
|
|
@ -21,18 +22,22 @@ namespace xo {
|
|||
|
||||
static Binding null() { return Binding(); }
|
||||
/** global bindings are located by symbol name **/
|
||||
static Binding global() { return Binding(s_link_global, 0); }
|
||||
static Binding global() { return Binding(c_link_global, 0); }
|
||||
static Binding local(int32_t j_slot) { return Binding(0, j_slot); }
|
||||
static Binding relative(int32_t i_link, Binding def);
|
||||
|
||||
bool is_null() const {
|
||||
return (i_link_ == s_link_sentinel) && (j_slot_ == -1);
|
||||
return (i_link_ == c_link_sentinel) && (j_slot_ == -1);
|
||||
}
|
||||
bool is_global() const { return i_link_ == s_link_global; }
|
||||
bool is_global() const { return i_link_ == c_link_global; }
|
||||
bool is_local() const { return (i_link_ == 0) && (j_slot_ >= 0); }
|
||||
|
||||
int32_t i_link() const noexcept { return i_link_; }
|
||||
int32_t j_slot() const noexcept { return j_slot_; }
|
||||
|
||||
/** print human-readable repr to stream @p os **/
|
||||
void print(std::ostream & os) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* >= 0: number of parent links to traverse
|
||||
|
|
@ -40,13 +45,18 @@ namespace xo {
|
|||
* -1: resolve globally
|
||||
* -2: sentinel (binding info not computed)
|
||||
**/
|
||||
int32_t i_link_ = s_link_sentinel;
|
||||
int32_t i_link_ = c_link_sentinel;
|
||||
/** if @ref i_link_ >= 0, frame offset
|
||||
* (in 'variables' not bytes).
|
||||
* ignored if @ref i_link_ is global
|
||||
**/
|
||||
int32_t j_slot_ = -1;
|
||||
};
|
||||
|
||||
inline std::ostream & operator<< (std::ostream & os, Binding x) {
|
||||
x.print(os);
|
||||
return os;
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ namespace xo {
|
|||
**/
|
||||
class DApplyExpr {
|
||||
public:
|
||||
using ACollector = xo::mm::ACollector;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
|
|
@ -81,7 +82,9 @@ namespace xo {
|
|||
/** @defgroup scm-applyexpr-gcobject-facet **/
|
||||
///@{
|
||||
|
||||
// shallow_copy() etc.
|
||||
std::size_t shallow_size() const noexcept;
|
||||
DApplyExpr * shallow_copy(obj<AAllocator> mm) const noexcept;
|
||||
std::size_t forward_children(obj<ACollector> gc) noexcept;
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-applyexpr-printable-facet **/
|
||||
|
|
|
|||
|
|
@ -31,14 +31,14 @@ namespace xo {
|
|||
|
||||
struct Slot {
|
||||
Slot() = default;
|
||||
explicit Slot(const DVariable * var) : var_{var} {}
|
||||
explicit Slot(DVariable * var) : var_{var} {}
|
||||
|
||||
/** variable representing a formal argument.
|
||||
* binding will be correct only within the same layer
|
||||
* as top-level lambda body
|
||||
* (i.e. up to the doorstep of each and every nested lambda)
|
||||
**/
|
||||
const DVariable * var_ = nullptr;
|
||||
DVariable * var_ = nullptr;
|
||||
};
|
||||
|
||||
public:
|
||||
|
|
@ -65,7 +65,7 @@ namespace xo {
|
|||
size_type capacity() const noexcept { return capacity_; }
|
||||
size_type size() const noexcept { return size_; }
|
||||
|
||||
const DVariable * lookup_var(Binding ix) const noexcept {
|
||||
DVariable * lookup_var(Binding ix) noexcept {
|
||||
assert(ix.i_link() == 0);
|
||||
assert(ix.j_slot() < static_cast<int32_t>(size_));
|
||||
|
||||
|
|
|
|||
84
xo-expression2/include/xo/expression2/DVarRef.hpp
Normal file
84
xo-expression2/include/xo/expression2/DVarRef.hpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/** @file DVarRef.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Variable.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
/** @class DVarRef
|
||||
* @brief syntax for a variable reference
|
||||
*
|
||||
* Reference to a known variable possibly
|
||||
* defined in another scope.
|
||||
* For non-local non-global variables,
|
||||
**/
|
||||
class DVarRef {
|
||||
public:
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
using ACollector = xo::mm::ACollector;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
|
||||
public:
|
||||
DVarRef(DVariable * vardef,
|
||||
Binding path);
|
||||
|
||||
/** create instance
|
||||
* @p mm memory allocator
|
||||
* @p vardef variable definition (name, typeref, binding)
|
||||
* @p link number of lexical scope boundaries we must cross
|
||||
* to reach scope containing @p vardef.
|
||||
* Only relevant for non-global vardef
|
||||
**/
|
||||
static DVarRef * make(obj<AAllocator> mm,
|
||||
DVariable * vardef,
|
||||
int32_t link);
|
||||
|
||||
const DUniqueString * name() const;
|
||||
Binding path() const { return path_; }
|
||||
|
||||
/** @defgroup scm-variable-expression-facet **/
|
||||
///@{
|
||||
|
||||
exprtype extype() const noexcept { return exprtype::varref; }
|
||||
TypeRef typeref() const noexcept;
|
||||
TypeDescr valuetype() const noexcept;
|
||||
void assign_valuetype(TypeDescr td) noexcept;
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-variable-gcobject-facet **/
|
||||
///@{
|
||||
|
||||
size_t shallow_size() const noexcept;
|
||||
DVarRef * shallow_copy(obj<AAllocator> mm) const noexcept;
|
||||
size_t forward_children(obj<ACollector> gc) noexcept;
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-variable-printable-facet **/
|
||||
///@{
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** variable definition. Created in the sccope where variable introduced.
|
||||
* Has an associated @ref Binding, but that binding is only correct
|
||||
* around any nested scopes.
|
||||
**/
|
||||
DVariable * vardef_ = nullptr;
|
||||
|
||||
/** at runtime: navigate environemnt via this path to get
|
||||
* runtime memory location for this variable
|
||||
**/
|
||||
Binding path_;
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DVarRef.hpp */
|
||||
13
xo-expression2/include/xo/expression2/VarRef.hpp
Normal file
13
xo-expression2/include/xo/expression2/VarRef.hpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/** @file VarRef.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DVarRef.hpp"
|
||||
#include "detail/IExpression_DVarRef.hpp"
|
||||
#include "detail/IGCObject_DVarRef.hpp"
|
||||
#include "detail/IPrintable_DVarRef.hpp"
|
||||
|
||||
/* end VarRef.hpp */
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
/** @file IExpression_DVarRef.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IExpression_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Expression.hpp"
|
||||
#include "Expression.hpp"
|
||||
#include "DVarRef.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IExpression_DVarRef; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::AExpression,
|
||||
xo::scm::DVarRef>
|
||||
{
|
||||
using ImplType = xo::scm::IExpression_Xfer
|
||||
<xo::scm::DVarRef,
|
||||
xo::scm::IExpression_DVarRef>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IExpression_DVarRef
|
||||
**/
|
||||
class IExpression_DVarRef {
|
||||
public:
|
||||
/** @defgroup scm-expression-dvarref-type-traits **/
|
||||
///@{
|
||||
using TypeDescr = xo::scm::AExpression::TypeDescr;
|
||||
using Copaque = xo::scm::AExpression::Copaque;
|
||||
using Opaque = xo::scm::AExpression::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-expression-dvarref-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** expression type (constant | apply | ..) **/
|
||||
static exprtype extype(const DVarRef & self) noexcept;
|
||||
/** placeholder for type giving possible values for this expression **/
|
||||
static TypeRef typeref(const DVarRef & self) noexcept;
|
||||
/** type giving possible values for this expression. Maybe null before typecheck **/
|
||||
static TypeDescr valuetype(const DVarRef & self) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** assing to valuetype member. Useful when scaffolding expressions **/
|
||||
static void assign_valuetype(DVarRef & self, TypeDescr td) noexcept;
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/** @file IGCObject_DApplyExpr.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DApplyExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DApplyExpr.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GCObject.hpp"
|
||||
#include <xo/gc/GCObject.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include "DApplyExpr.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IGCObject_DApplyExpr; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::AGCObject,
|
||||
xo::scm::DApplyExpr>
|
||||
{
|
||||
using ImplType = xo::mm::IGCObject_Xfer
|
||||
<xo::scm::DApplyExpr,
|
||||
xo::scm::IGCObject_DApplyExpr>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IGCObject_DApplyExpr
|
||||
**/
|
||||
class IGCObject_DApplyExpr {
|
||||
public:
|
||||
/** @defgroup scm-gcobject-dapplyexpr-type-traits **/
|
||||
///@{
|
||||
using size_type = xo::mm::AGCObject::size_type;
|
||||
using AAllocator = xo::mm::AGCObject::AAllocator;
|
||||
using ACollector = xo::mm::AGCObject::ACollector;
|
||||
using Copaque = xo::mm::AGCObject::Copaque;
|
||||
using Opaque = xo::mm::AGCObject::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-gcobject-dapplyexpr-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** memory consumption for this instance **/
|
||||
static size_type shallow_size(const DApplyExpr & self) noexcept;
|
||||
/** copy instance using allocator **/
|
||||
static Opaque shallow_copy(const DApplyExpr & self, obj<AAllocator> mm) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** during GC: forward immdiate children **/
|
||||
static size_type forward_children(DApplyExpr & self, obj<ACollector> gc) noexcept;
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/** @file IGCObject_DVarRef.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GCObject.hpp"
|
||||
#include <xo/gc/GCObject.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include "DVarRef.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IGCObject_DVarRef; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::AGCObject,
|
||||
xo::scm::DVarRef>
|
||||
{
|
||||
using ImplType = xo::mm::IGCObject_Xfer
|
||||
<xo::scm::DVarRef,
|
||||
xo::scm::IGCObject_DVarRef>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IGCObject_DVarRef
|
||||
**/
|
||||
class IGCObject_DVarRef {
|
||||
public:
|
||||
/** @defgroup scm-gcobject-dvarref-type-traits **/
|
||||
///@{
|
||||
using size_type = xo::mm::AGCObject::size_type;
|
||||
using AAllocator = xo::mm::AGCObject::AAllocator;
|
||||
using ACollector = xo::mm::AGCObject::ACollector;
|
||||
using Copaque = xo::mm::AGCObject::Copaque;
|
||||
using Opaque = xo::mm::AGCObject::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-gcobject-dvarref-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** memory consumption for this instance **/
|
||||
static size_type shallow_size(const DVarRef & self) noexcept;
|
||||
/** copy instance using allocator **/
|
||||
static Opaque shallow_copy(const DVarRef & self, obj<AAllocator> mm) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** during GC: forward immdiate children **/
|
||||
static size_type forward_children(DVarRef & self, obj<ACollector> gc) noexcept;
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/** @file IPrintable_DVarRef.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Printable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DVarRef.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DVarRef; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DVarRef>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DVarRef,
|
||||
xo::scm::IPrintable_DVarRef>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DVarRef
|
||||
**/
|
||||
class IPrintable_DVarRef {
|
||||
public:
|
||||
/** @defgroup scm-printable-dvarref-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
using Copaque = xo::print::APrintable::Copaque;
|
||||
using Opaque = xo::print::APrintable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-printable-dvarref-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DVarRef & self, const ppindentinfo & ppii);
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -36,8 +36,10 @@ namespace xo {
|
|||
/** function definition **/
|
||||
lambda,
|
||||
|
||||
/** variable reference **/
|
||||
/** variable definition **/
|
||||
variable,
|
||||
/** variabele reference (possibly non-local) **/
|
||||
varref,
|
||||
/** if-then-else **/
|
||||
ifexpr,
|
||||
/** sequence **/
|
||||
|
|
@ -65,14 +67,16 @@ namespace xo {
|
|||
case exprtype::assign: return "assign";
|
||||
#endif
|
||||
case exprtype::apply: return "apply";
|
||||
#ifdef NOT_YET
|
||||
case exprtype::lambda: return "lambda";
|
||||
case exprtype::variable: return "variable";
|
||||
case exprtype::varref: return "varref";
|
||||
case exprtype::ifexpr: return "if_expr";
|
||||
case exprtype::sequence: return "sequence";
|
||||
#ifdef NOT_YET
|
||||
case exprtype::convert: return "convert";
|
||||
#endif
|
||||
default: break;
|
||||
case exprtype::N: break;
|
||||
//default: break;
|
||||
}
|
||||
|
||||
return "???exprtype???";
|
||||
|
|
|
|||
41
xo-expression2/src/expression2/Binding.cpp
Normal file
41
xo-expression2/src/expression2/Binding.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/** @file Binding.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#include "Binding.hpp"
|
||||
#include <cassert>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
Binding
|
||||
Binding::relative(int32_t i_link, Binding def)
|
||||
{
|
||||
if (def.i_link_ == Binding::c_link_global) {
|
||||
// for globally defined vars, i_link always -1
|
||||
return def;
|
||||
} else if (def.i_link_ >= 0) {
|
||||
return Binding(i_link + def.i_link_, def.j_slot_);
|
||||
} else {
|
||||
assert(false);
|
||||
return Binding();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Binding::print(std::ostream & os) const
|
||||
{
|
||||
if (i_link_ == c_link_global) {
|
||||
os << "{path:global}";
|
||||
} else if (i_link_ == c_link_sentinel) {
|
||||
os << "{path}";
|
||||
} else {
|
||||
os << "{path:" << i_link_ << ":" << j_slot_ << "}";
|
||||
}
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end Binding.cpp */
|
||||
|
|
@ -3,9 +3,12 @@
|
|||
set(SELF_LIB xo_expression2)
|
||||
set(SELF_SRCS
|
||||
init_expression2.cpp
|
||||
expression2_register_facets.cpp
|
||||
expression2_register_types.cpp
|
||||
|
||||
DConstant.cpp
|
||||
DVariable.cpp
|
||||
DVarRef.cpp
|
||||
DDefineExpr.cpp
|
||||
DLambdaExpr.cpp
|
||||
DApplyExpr.cpp
|
||||
|
|
@ -13,6 +16,7 @@ set(SELF_SRCS
|
|||
DSequenceExpr.cpp
|
||||
|
||||
TypeRef.cpp
|
||||
Binding.cpp
|
||||
|
||||
IExpression_Any.cpp
|
||||
|
||||
|
|
@ -24,10 +28,15 @@ set(SELF_SRCS
|
|||
IGCObject_DVariable.cpp
|
||||
IPrintable_DVariable.cpp
|
||||
|
||||
IExpression_DVarRef.cpp
|
||||
IGCObject_DVarRef.cpp
|
||||
IPrintable_DVarRef.cpp
|
||||
|
||||
IExpression_DDefineExpr.cpp
|
||||
IPrintable_DDefineExpr.cpp
|
||||
|
||||
IExpression_DApplyExpr.cpp
|
||||
IGCObject_DApplyExpr.cpp
|
||||
IPrintable_DApplyExpr.cpp
|
||||
|
||||
IExpression_DLambdaExpr.cpp
|
||||
|
|
@ -55,8 +64,6 @@ set(SELF_SRCS
|
|||
IGCObject_DUniqueString.cpp
|
||||
IPrintable_DUniqueString.cpp
|
||||
|
||||
expression2_register_facets.cpp
|
||||
expression2_register_types.cpp
|
||||
)
|
||||
|
||||
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
|
||||
|
|
|
|||
|
|
@ -102,6 +102,48 @@ namespace xo {
|
|||
typeref_.resolve(td);
|
||||
}
|
||||
|
||||
// ----- gcobject facet -----
|
||||
|
||||
std::size_t
|
||||
DApplyExpr::shallow_size() const noexcept {
|
||||
return sizeof(DApplyExpr) + (n_args_ * sizeof(obj<AExpression>));
|
||||
}
|
||||
|
||||
DApplyExpr *
|
||||
DApplyExpr::shallow_copy(obj<AAllocator> mm) const noexcept {
|
||||
DApplyExpr * copy = (DApplyExpr *)mm.alloc_copy((std::byte *)this);
|
||||
|
||||
if (copy) {
|
||||
copy->typeref_ = typeref_;
|
||||
copy->fn_ = fn_;
|
||||
copy->n_args_ = n_args_;
|
||||
|
||||
constexpr auto c_obj_z = sizeof(obj<AExpression>);
|
||||
|
||||
::memcpy((void*)&(copy->args_[0]), (void*)&(args_[0]), n_args_ * c_obj_z);
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DApplyExpr::forward_children(obj<ACollector> gc) noexcept
|
||||
{
|
||||
for (size_type i = 0; i < n_args_; ++i) {
|
||||
obj<AExpression> & arg = args_[i];
|
||||
|
||||
// runtime poly here
|
||||
obj<AGCObject> arg_gco = arg.to_facet<AGCObject>();
|
||||
|
||||
// need the data address within *this
|
||||
gc.forward_inplace(arg_gco.iface(), (void **)(&arg.data_));
|
||||
}
|
||||
|
||||
return shallow_size();
|
||||
}
|
||||
|
||||
// ----- printable facet -----
|
||||
|
||||
bool
|
||||
DApplyExpr::pretty(const ppindentinfo & ppii) const {
|
||||
using xo::print::ppstate;
|
||||
|
|
|
|||
105
xo-expression2/src/expression2/DVarRef.cpp
Normal file
105
xo-expression2/src/expression2/DVarRef.cpp
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/** @file DVarRef.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#include "DVarRef.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AGCObject;
|
||||
using xo::reflect::TypeDescr;
|
||||
|
||||
namespace scm {
|
||||
|
||||
DVarRef::DVarRef(DVariable * vardef,
|
||||
Binding path)
|
||||
: vardef_{vardef},
|
||||
path_{path}
|
||||
{}
|
||||
|
||||
DVarRef *
|
||||
DVarRef::make(obj<AAllocator> mm,
|
||||
DVariable * vardef,
|
||||
int32_t link)
|
||||
{
|
||||
assert(vardef);
|
||||
|
||||
void * mem = mm.alloc_for<DVarRef>();
|
||||
|
||||
return new (mem) DVarRef(vardef,
|
||||
Binding::relative(link,
|
||||
vardef->path()));
|
||||
}
|
||||
|
||||
const DUniqueString *
|
||||
DVarRef::name() const {
|
||||
return vardef_->name();
|
||||
}
|
||||
|
||||
TypeRef
|
||||
DVarRef::typeref() const noexcept {
|
||||
assert(vardef_);
|
||||
|
||||
return vardef_->typeref();
|
||||
}
|
||||
|
||||
TypeDescr
|
||||
DVarRef::valuetype() const noexcept
|
||||
{
|
||||
return this->typeref().td();
|
||||
}
|
||||
|
||||
void
|
||||
DVarRef::assign_valuetype(TypeDescr td) noexcept
|
||||
{
|
||||
assert(vardef_);
|
||||
vardef_->assign_valuetype(td);
|
||||
}
|
||||
|
||||
// gcobject facet
|
||||
|
||||
std::size_t
|
||||
DVarRef::shallow_size() const noexcept
|
||||
{
|
||||
return sizeof(DVarRef);
|
||||
}
|
||||
|
||||
DVarRef *
|
||||
DVarRef::shallow_copy(obj<AAllocator> mm) const noexcept
|
||||
{
|
||||
DVarRef * copy = (DVarRef *)mm.alloc_copy((std::byte *)this);
|
||||
|
||||
if (copy)
|
||||
*copy = *this;
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DVarRef::forward_children(obj<ACollector> gc) noexcept
|
||||
{
|
||||
// TODO: this can be helper in RCollector interface
|
||||
auto iface = xo::facet::impl_for<AGCObject,DVariable>();
|
||||
gc.forward_inplace(&iface, (void **)vardef_);
|
||||
|
||||
// TODO: concept to indicate that no gc pointers in Binding
|
||||
|
||||
return shallow_size();
|
||||
}
|
||||
|
||||
// printable facet
|
||||
|
||||
bool
|
||||
DVarRef::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"DVarRef",
|
||||
refrtag("name", std::string_view(*(this->name()))),
|
||||
refrtag("path", this->path_));
|
||||
}
|
||||
|
||||
}
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DVarRef.cpp */
|
||||
45
xo-expression2/src/expression2/IExpression_DVarRef.cpp
Normal file
45
xo-expression2/src/expression2/IExpression_DVarRef.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/** @file IExpression_DVarRef.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IExpression_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IExpression_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IExpression_DVarRef.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IExpression_DVarRef::extype(const DVarRef & self) noexcept -> exprtype
|
||||
{
|
||||
return self.extype();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DVarRef::typeref(const DVarRef & self) noexcept -> TypeRef
|
||||
{
|
||||
return self.typeref();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DVarRef::valuetype(const DVarRef & self) noexcept -> TypeDescr
|
||||
{
|
||||
return self.valuetype();
|
||||
}
|
||||
|
||||
auto
|
||||
IExpression_DVarRef::assign_valuetype(DVarRef & self, TypeDescr td) noexcept -> void
|
||||
{
|
||||
self.assign_valuetype(td);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IExpression_DVarRef.cpp */
|
||||
39
xo-expression2/src/expression2/IGCObject_DApplyExpr.cpp
Normal file
39
xo-expression2/src/expression2/IGCObject_DApplyExpr.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/** @file IGCObject_DApplyExpr.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DApplyExpr.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DApplyExpr.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IGCObject_DApplyExpr.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IGCObject_DApplyExpr::shallow_size(const DApplyExpr & self) noexcept -> size_type
|
||||
{
|
||||
return self.shallow_size();
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DApplyExpr::shallow_copy(const DApplyExpr & self, obj<AAllocator> mm) noexcept -> Opaque
|
||||
{
|
||||
return self.shallow_copy(mm);
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DApplyExpr::forward_children(DApplyExpr & self, obj<ACollector> gc) noexcept -> size_type
|
||||
{
|
||||
return self.forward_children(gc);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IGCObject_DApplyExpr.cpp */
|
||||
39
xo-expression2/src/expression2/IGCObject_DVarRef.cpp
Normal file
39
xo-expression2/src/expression2/IGCObject_DVarRef.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/** @file IGCObject_DVarRef.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IGCObject_DVarRef.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IGCObject_DVarRef::shallow_size(const DVarRef & self) noexcept -> size_type
|
||||
{
|
||||
return self.shallow_size();
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DVarRef::shallow_copy(const DVarRef & self, obj<AAllocator> mm) noexcept -> Opaque
|
||||
{
|
||||
return self.shallow_copy(mm);
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DVarRef::forward_children(DVarRef & self, obj<ACollector> gc) noexcept -> size_type
|
||||
{
|
||||
return self.forward_children(gc);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IGCObject_DVarRef.cpp */
|
||||
28
xo-expression2/src/expression2/IPrintable_DVarRef.cpp
Normal file
28
xo-expression2/src/expression2/IPrintable_DVarRef.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/** @file IPrintable_DVarRef.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DVarRef.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DVarRef.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IPrintable_DVarRef.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IPrintable_DVarRef::pretty(const DVarRef & self, const ppindentinfo & ppii) -> bool
|
||||
{
|
||||
return self.pretty(ppii);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IPrintable_DVarRef.cpp */
|
||||
|
|
@ -16,13 +16,13 @@
|
|||
#include <xo/expression2/detail/IGCObject_DVariable.hpp>
|
||||
#include <xo/expression2/detail/IPrintable_DVariable.hpp>
|
||||
|
||||
#include <xo/expression2/VarRef.hpp>
|
||||
|
||||
#include <xo/expression2/detail/IExpression_DConstant.hpp>
|
||||
#include <xo/expression2/detail/IGCObject_DConstant.hpp>
|
||||
#include <xo/expression2/detail/IPrintable_DConstant.hpp>
|
||||
|
||||
#include <xo/expression2/detail/IExpression_DApplyExpr.hpp>
|
||||
//#include <xo/expression2/detail/IGCObject_DApplyExpr.hpp>
|
||||
#include <xo/expression2/detail/IPrintable_DApplyExpr.hpp>
|
||||
#include <xo/expression2/ApplyExpr.hpp>
|
||||
|
||||
#include <xo/expression2/detail/IExpression_DLambdaExpr.hpp>
|
||||
//#include <xo/expression2/detail/IGCObject_DLambdaExpr.hpp>
|
||||
|
|
@ -63,6 +63,7 @@ namespace xo {
|
|||
// Expression
|
||||
// +- Constant
|
||||
// +- Variable
|
||||
// +- VarRef
|
||||
// +- DefineExpr
|
||||
// +- ApplyExpr
|
||||
// +- LambdaExpr
|
||||
|
|
@ -77,13 +78,20 @@ namespace xo {
|
|||
FacetRegistry::register_impl<AGCObject, DVariable>();
|
||||
FacetRegistry::register_impl<APrintable, DVariable>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DVarRef>();
|
||||
FacetRegistry::register_impl<AGCObject, DVarRef>();
|
||||
FacetRegistry::register_impl<APrintable, DVarRef>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DDefineExpr>();
|
||||
//FacetRegistry::register_impl<AGCObject, DDefineExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DDefineExpr>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DApplyExpr>();
|
||||
FacetRegistry::register_impl<AGCObject, DApplyExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DApplyExpr>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DLambdaExpr>();
|
||||
//FacetRegistry::register_impl<AGCObject, DLambdaExpr>();
|
||||
FacetRegistry::register_impl<APrintable, DLambdaExpr>();
|
||||
|
||||
FacetRegistry::register_impl<AExpression, DIfElseExpr>();
|
||||
|
|
@ -95,11 +103,13 @@ namespace xo {
|
|||
FacetRegistry::register_impl<APrintable, DSequenceExpr>();
|
||||
|
||||
FacetRegistry::register_impl<ASymbolTable, DLocalSymtab>();
|
||||
//FacetRegistry::register_impl<AGCObject, DLocalSymtab>();
|
||||
FacetRegistry::register_impl<APrintable, DLocalSymtab>();
|
||||
|
||||
log && log(xtag("DUniqueString.tseq", typeseq::id<DUniqueString>()));
|
||||
log && log(xtag("DDefineExpr.tseq", typeseq::id<DDefineExpr>()));
|
||||
log && log(xtag("DVariable.tseq", typeseq::id<DVariable>()));
|
||||
log && log(xtag("DVarRef.tseq", typeseq::id<DVarRef>()));
|
||||
log && log(xtag("DConstant.tseq", typeseq::id<DConstant>()));
|
||||
log && log(xtag("DApplyExpr.tseq", typeseq::id<DApplyExpr>()));
|
||||
log && log(xtag("DLambdaExpr.tseq", typeseq::id<DLambdaExpr>()));
|
||||
|
|
@ -108,7 +118,7 @@ namespace xo {
|
|||
|
||||
log && log(xtag("DLocalSymtab.tseq", typeseq::id<DLocalSymtab>()));
|
||||
|
||||
log && log(xtag("AExpression.tqseq", typeseq::id<AExpression>()));
|
||||
log && log(xtag("AExpression.tseq", typeseq::id<AExpression>()));
|
||||
log && log(xtag("ASymbolTable.tseq", typeseq::id<ASymbolTable>()));
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -57,9 +57,9 @@ public:
|
|||
{% endif %}
|
||||
|
||||
// explicit injected content
|
||||
{% for c in router_facet_explicit_content %}
|
||||
{{c}}
|
||||
{% endif %}
|
||||
{% for content in router_facet_explicit_content %}
|
||||
{{content}}
|
||||
{% endfor %}
|
||||
|
||||
// builtin methods
|
||||
typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); }
|
||||
|
|
|
|||
|
|
@ -76,4 +76,5 @@
|
|||
attributes: [],
|
||||
},
|
||||
],
|
||||
router_facet_explicit_content: [ ],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,12 +120,18 @@ namespace xo {
|
|||
**/
|
||||
void _do_eval_lambda_op();
|
||||
|
||||
/** evaluate a variable expression
|
||||
/** evaluate variable expression (definition)
|
||||
* Require:
|
||||
* - expression in @ref expr_
|
||||
**/
|
||||
void _do_eval_variable_op();
|
||||
|
||||
/** evaluate a variable reference (use after definition)
|
||||
* Require:
|
||||
* - expression in @ref expr_
|
||||
**/
|
||||
void _do_eval_varref_op();
|
||||
|
||||
/** evaluate an apply expression
|
||||
* Require:
|
||||
* - expression in @ref expr_
|
||||
|
|
|
|||
|
|
@ -167,6 +167,9 @@ namespace xo {
|
|||
case exprtype::variable:
|
||||
_do_eval_variable_op();
|
||||
break;
|
||||
case exprtype::varref:
|
||||
_do_eval_varref_op();
|
||||
break;
|
||||
case exprtype::apply:
|
||||
_do_eval_apply_op();
|
||||
break;
|
||||
|
|
@ -210,6 +213,13 @@ namespace xo {
|
|||
assert(false);
|
||||
}
|
||||
|
||||
void
|
||||
VirtualSchematikaMachine::_do_eval_varref_op()
|
||||
{
|
||||
// not implemented
|
||||
assert(false);
|
||||
}
|
||||
|
||||
void
|
||||
VirtualSchematikaMachine::_do_eval_apply_op()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ namespace xo {
|
|||
std::size_t
|
||||
DArray::shallow_size() const noexcept
|
||||
{
|
||||
return sizeof(DArray);
|
||||
return sizeof(DArray) + (capacity_ * sizeof(obj<AGCObject>));
|
||||
}
|
||||
|
||||
DArray *
|
||||
|
|
|
|||
|
|
@ -38,4 +38,5 @@
|
|||
},
|
||||
],
|
||||
nonconst_methods: [],
|
||||
router_facet_explicit_content: [],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,13 +101,15 @@
|
|||
],
|
||||
},
|
||||
{
|
||||
name: "on_parsed_expression_with_semicolon",
|
||||
doc: ["update state machine for incoming parsed expression @p expr followed by semicolon"],
|
||||
name: "on_parsed_expression_with_token",
|
||||
doc: ["update state machine @p p_psm for incoming parsed expression @p expr followed by token @p tk"],
|
||||
return_type: "void",
|
||||
args: [
|
||||
{type: "obj<AExpression>", name: "expr"},
|
||||
{type: "const Token &", name: "tk"},
|
||||
{type: "ParserStateMachine *", name: "p_psm"},
|
||||
],
|
||||
},
|
||||
],
|
||||
router_facet_explicit_content: [ ],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,11 +176,12 @@ namespace xo {
|
|||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax after parsing an expression @p expr
|
||||
* followed by semicolon,
|
||||
* overall parser state in @p p_psm
|
||||
* followed by token @p tk,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
void on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm);
|
||||
void on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-define-printable-facet printable facet methods **/
|
||||
|
|
|
|||
|
|
@ -113,11 +113,12 @@ namespace xo {
|
|||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax after parsing an expression @p expr
|
||||
* followed by semicolon,
|
||||
* followed by token @p tk
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
void on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm);
|
||||
void on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-define-printable-facet printable facet methods **/
|
||||
|
|
|
|||
|
|
@ -120,10 +120,12 @@ namespace xo {
|
|||
void on_parsed_expression(obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on parsed expression @p expr
|
||||
* followed by semicolon from nested ssm.
|
||||
* followed by token @p tk from nested ssm.
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
void on_parsed_expression_with_semicolon(obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
void on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-exprseq-printable-facet printable facet methods **/
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ namespace xo {
|
|||
**/
|
||||
class DIfElseSsm : public DSyntaxStateMachine<DIfElseSsm> {
|
||||
public:
|
||||
using Super = DSyntaxStateMachine<DIfElseExpr>;
|
||||
using Super = DSyntaxStateMachine<DIfElseSsm>;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using DArena = xo::mm::DArena;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
|
|
@ -154,8 +154,9 @@ namespace xo {
|
|||
* followed by semicolon,
|
||||
* with overall parser state in @p p_psm.
|
||||
**/
|
||||
void on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm);
|
||||
void on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-ifelsessm-printable-facet printable facet methods **/
|
||||
|
|
|
|||
|
|
@ -150,8 +150,9 @@ namespace xo {
|
|||
/** update this ssm when nested parser
|
||||
* emits expression @p expr
|
||||
**/
|
||||
void on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm);
|
||||
void on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
#ifdef NOT_YET
|
||||
virtual const char * get_expect_str() const override;
|
||||
|
|
|
|||
|
|
@ -168,8 +168,9 @@ namespace xo {
|
|||
ParserStateMachine * p_psm);
|
||||
void on_rightbrace_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
void on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm);
|
||||
void on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-progressssm-printable-facet printable facet methods **/
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ namespace xo {
|
|||
|
||||
class DSequenceSsm : public DSyntaxStateMachine<DSequenceSsm> {
|
||||
public:
|
||||
using Super = DSyntaxStateMachine<DSequenceSsm>;
|
||||
//using Sequence = xo::scm::Sequence;
|
||||
//using Lambda = xo::scm::Lambda;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
|
|
@ -78,6 +79,13 @@ namespace xo {
|
|||
void on_parsed_expression(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** consume expression @p expr produced by nested ssm followed by token @p tk;
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
void on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-sequencessm-printable-facet printable facet **/
|
||||
///@{
|
||||
|
|
|
|||
|
|
@ -114,8 +114,9 @@ namespace xo {
|
|||
|
||||
/** Default implementation for required SyntaxStateMachine facet method
|
||||
**/
|
||||
void on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm)
|
||||
void on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
// starting with c++23 can use "this auto&& self" instead
|
||||
Derived & self = static_cast<Derived&>(*this);
|
||||
|
|
@ -124,9 +125,10 @@ namespace xo {
|
|||
// since the semicolon isn't relevant to problem with syntax
|
||||
//
|
||||
|
||||
p_psm->illegal_parsed_expression(Derived::ssm_classname(),
|
||||
expr,
|
||||
self.get_expect_str());
|
||||
p_psm->illegal_parsed_expression_with_token(Derived::ssm_classname(),
|
||||
expr,
|
||||
tk,
|
||||
self.get_expect_str());
|
||||
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <xo/expression2/DGlobalSymtab.hpp>
|
||||
#include <xo/expression2/DLocalSymtab.hpp>
|
||||
#include <xo/expression2/DVariable.hpp>
|
||||
#include <xo/expression2/VarRef.hpp>
|
||||
#include <xo/expression2/StringTable.hpp>
|
||||
#include <xo/tokenizer2/Token.hpp>
|
||||
#include <xo/object2/DArray.hpp>
|
||||
|
|
@ -89,8 +90,8 @@ namespace xo {
|
|||
/** get unique (within stringtable) string, beginning with @p prefix **/
|
||||
const DUniqueString * gensym(std::string_view prefix);
|
||||
|
||||
/** get variable defn for @p symbolname, or else nullptr **/
|
||||
Binding lookup_binding(std::string_view symbolname);
|
||||
/** get variable reference for @p symbolname in current context, or else nullptr **/
|
||||
DVarRef * lookup_varref(std::string_view symbolname);
|
||||
|
||||
/** push nested local symtab while parsing the body of a lambda expression;
|
||||
* restore previous symtab at the end of lambda-expression definition.
|
||||
|
|
@ -141,17 +142,6 @@ namespace xo {
|
|||
**/
|
||||
void on_parsed_expression(obj<AExpression> expr);
|
||||
|
||||
/** update state to respond to parsed expression @p expr
|
||||
* (from nested parsing state), with trailing semicolon.
|
||||
*
|
||||
* Need to distinguish cases like:
|
||||
* 6 // ; allowed
|
||||
* f(6 // ) allowed ; forbidden
|
||||
* 6 + // ) forbidden ; forbidden
|
||||
*
|
||||
**/
|
||||
void on_parsed_expression_with_semicolon(obj<AExpression> expr);
|
||||
|
||||
/** update state to respond to parsed expression @p expr
|
||||
* (from nested parsing state), with trailing token @p tk.
|
||||
*
|
||||
|
|
@ -232,6 +222,16 @@ namespace xo {
|
|||
obj<AExpression>,
|
||||
std::string_view expect_str);
|
||||
|
||||
/** report illegal parsed expression @p expr from nested ssm @p ssm_name,
|
||||
* presented with immediately-following input token @p tk
|
||||
* Introducing as placeholder; not clear if this will be reachable
|
||||
* in full parser
|
||||
**/
|
||||
void illegal_parsed_expression_with_token(std::string_view ssm_name,
|
||||
obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
std::string_view expect_str);
|
||||
|
||||
/** report error - no binding for variable @p sym
|
||||
**/
|
||||
void error_unbound_variable(std::string_view ssm_name,
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ public:
|
|||
// const methods
|
||||
/** RTTI: unique id# for actual runtime data representation **/
|
||||
virtual typeseq _typeseq() const noexcept = 0;
|
||||
/** destroy instance @p d; calls c++ dtor only for actual runtime type; does not recover memory **/
|
||||
virtual void _drop(Opaque d) const noexcept = 0;
|
||||
/** identify a type of syntax state machine **/
|
||||
virtual syntaxstatetype ssm_type(Copaque data) const noexcept = 0;
|
||||
/** text describing expected/allowed input to this ssm in current state **/
|
||||
|
|
@ -69,8 +71,8 @@ public:
|
|||
virtual void on_parsed_formal_arglist(Opaque data, DArray * arglist, ParserStateMachine * p_psm) = 0;
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
virtual void on_parsed_expression(Opaque data, obj<AExpression> expr, ParserStateMachine * p_psm) = 0;
|
||||
/** update state machine for incoming parsed expression @p expr followed by semicolon **/
|
||||
virtual void on_parsed_expression_with_semicolon(Opaque data, obj<AExpression> expr, ParserStateMachine * p_psm) = 0;
|
||||
/** update state machine @p p_psm for incoming parsed expression @p expr followed by token @p tk **/
|
||||
virtual void on_parsed_expression_with_token(Opaque data, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) = 0;
|
||||
///@}
|
||||
}; /*ASyntaxStateMachine*/
|
||||
|
||||
|
|
|
|||
|
|
@ -54,8 +54,11 @@ namespace scm {
|
|||
|
||||
// from ASyntaxStateMachine
|
||||
|
||||
// const methods
|
||||
// builtin methods
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
[[noreturn]] void _drop(Opaque) const noexcept override { _fatal(); }
|
||||
|
||||
// const methods
|
||||
[[noreturn]] syntaxstatetype ssm_type(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] std::string_view get_expect_str(Copaque) const noexcept override { _fatal(); }
|
||||
|
||||
|
|
@ -66,7 +69,7 @@ namespace scm {
|
|||
[[noreturn]] void on_parsed_formal(Opaque, const DUniqueString *, TypeDescr, ParserStateMachine *) override;
|
||||
[[noreturn]] void on_parsed_formal_arglist(Opaque, DArray *, ParserStateMachine *) override;
|
||||
[[noreturn]] void on_parsed_expression(Opaque, obj<AExpression>, ParserStateMachine *) override;
|
||||
[[noreturn]] void on_parsed_expression_with_semicolon(Opaque, obj<AExpression>, ParserStateMachine *) override;
|
||||
[[noreturn]] void on_parsed_expression_with_token(Opaque, obj<AExpression>, const Token &, ParserStateMachine *) override;
|
||||
|
||||
///@}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ namespace xo {
|
|||
static void on_parsed_formal_arglist(DDefineSsm & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
static void on_parsed_expression(DDefineSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr followed by semicolon **/
|
||||
static void on_parsed_expression_with_semicolon(DDefineSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine @p p_psm for incoming parsed expression @p expr followed by token @p tk **/
|
||||
static void on_parsed_expression_with_token(DDefineSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ namespace xo {
|
|||
static void on_parsed_formal_arglist(DExpectExprSsm & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
static void on_parsed_expression(DExpectExprSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr followed by semicolon **/
|
||||
static void on_parsed_expression_with_semicolon(DExpectExprSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine @p p_psm for incoming parsed expression @p expr followed by token @p tk **/
|
||||
static void on_parsed_expression_with_token(DExpectExprSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ namespace xo {
|
|||
static void on_parsed_formal_arglist(DExpectFormalArgSsm & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
static void on_parsed_expression(DExpectFormalArgSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr followed by semicolon **/
|
||||
static void on_parsed_expression_with_semicolon(DExpectFormalArgSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine @p p_psm for incoming parsed expression @p expr followed by token @p tk **/
|
||||
static void on_parsed_expression_with_token(DExpectFormalArgSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ namespace xo {
|
|||
static void on_parsed_formal_arglist(DExpectFormalArglistSsm & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
static void on_parsed_expression(DExpectFormalArglistSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr followed by semicolon **/
|
||||
static void on_parsed_expression_with_semicolon(DExpectFormalArglistSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine @p p_psm for incoming parsed expression @p expr followed by token @p tk **/
|
||||
static void on_parsed_expression_with_token(DExpectFormalArglistSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ namespace xo {
|
|||
static void on_parsed_formal_arglist(DExpectSymbolSsm & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
static void on_parsed_expression(DExpectSymbolSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr followed by semicolon **/
|
||||
static void on_parsed_expression_with_semicolon(DExpectSymbolSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine @p p_psm for incoming parsed expression @p expr followed by token @p tk **/
|
||||
static void on_parsed_expression_with_token(DExpectSymbolSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ namespace xo {
|
|||
static void on_parsed_formal_arglist(DExpectTypeSsm & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
static void on_parsed_expression(DExpectTypeSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr followed by semicolon **/
|
||||
static void on_parsed_expression_with_semicolon(DExpectTypeSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine @p p_psm for incoming parsed expression @p expr followed by token @p tk **/
|
||||
static void on_parsed_expression_with_token(DExpectTypeSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ namespace xo {
|
|||
static void on_parsed_formal_arglist(DExprSeqState & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
static void on_parsed_expression(DExprSeqState & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr followed by semicolon **/
|
||||
static void on_parsed_expression_with_semicolon(DExprSeqState & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine @p p_psm for incoming parsed expression @p expr followed by token @p tk **/
|
||||
static void on_parsed_expression_with_token(DExprSeqState & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ namespace xo {
|
|||
static void on_parsed_formal_arglist(DIfElseSsm & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
static void on_parsed_expression(DIfElseSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr followed by semicolon **/
|
||||
static void on_parsed_expression_with_semicolon(DIfElseSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine @p p_psm for incoming parsed expression @p expr followed by token @p tk **/
|
||||
static void on_parsed_expression_with_token(DIfElseSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ namespace xo {
|
|||
static void on_parsed_formal_arglist(DLambdaSsm & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
static void on_parsed_expression(DLambdaSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr followed by semicolon **/
|
||||
static void on_parsed_expression_with_semicolon(DLambdaSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine @p p_psm for incoming parsed expression @p expr followed by token @p tk **/
|
||||
static void on_parsed_expression_with_token(DLambdaSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ namespace xo {
|
|||
static void on_parsed_formal_arglist(DProgressSsm & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
static void on_parsed_expression(DProgressSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr followed by semicolon **/
|
||||
static void on_parsed_expression_with_semicolon(DProgressSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine @p p_psm for incoming parsed expression @p expr followed by token @p tk **/
|
||||
static void on_parsed_expression_with_token(DProgressSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ namespace xo {
|
|||
static void on_parsed_formal_arglist(DSequenceSsm & self, DArray * arglist, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr **/
|
||||
static void on_parsed_expression(DSequenceSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine for incoming parsed expression @p expr followed by semicolon **/
|
||||
static void on_parsed_expression_with_semicolon(DSequenceSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm);
|
||||
/** update state machine @p p_psm for incoming parsed expression @p expr followed by token @p tk **/
|
||||
static void on_parsed_expression_with_token(DSequenceSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm);
|
||||
///@}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -42,8 +42,11 @@ namespace scm {
|
|||
|
||||
// from ASyntaxStateMachine
|
||||
|
||||
// const methods
|
||||
// builtin methods
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
void _drop(Opaque d) const noexcept override { _dcast(d).~DRepr(); }
|
||||
|
||||
// const methods
|
||||
syntaxstatetype ssm_type(Copaque data) const noexcept override {
|
||||
return I::ssm_type(_dcast(data));
|
||||
}
|
||||
|
|
@ -70,8 +73,8 @@ namespace scm {
|
|||
void on_parsed_expression(Opaque data, obj<AExpression> expr, ParserStateMachine * p_psm) override {
|
||||
return I::on_parsed_expression(_dcast(data), expr, p_psm);
|
||||
}
|
||||
void on_parsed_expression_with_semicolon(Opaque data, obj<AExpression> expr, ParserStateMachine * p_psm) override {
|
||||
return I::on_parsed_expression_with_semicolon(_dcast(data), expr, p_psm);
|
||||
void on_parsed_expression_with_token(Opaque data, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) override {
|
||||
return I::on_parsed_expression_with_token(_dcast(data), expr, tk, p_psm);
|
||||
}
|
||||
|
||||
///@}
|
||||
|
|
|
|||
|
|
@ -46,8 +46,13 @@ public:
|
|||
/** @defgroup scm-syntaxstatemachine-router-methods **/
|
||||
///@{
|
||||
|
||||
// const methods
|
||||
// explicit injected content
|
||||
|
||||
// builtin methods
|
||||
typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); }
|
||||
void _drop() const noexcept { O::iface()->_drop(O::data()); }
|
||||
|
||||
// const methods
|
||||
syntaxstatetype ssm_type() const noexcept {
|
||||
return O::iface()->ssm_type(O::data());
|
||||
}
|
||||
|
|
@ -74,8 +79,8 @@ public:
|
|||
void on_parsed_expression(obj<AExpression> expr, ParserStateMachine * p_psm) {
|
||||
return O::iface()->on_parsed_expression(O::data(), expr, p_psm);
|
||||
}
|
||||
void on_parsed_expression_with_semicolon(obj<AExpression> expr, ParserStateMachine * p_psm) {
|
||||
return O::iface()->on_parsed_expression_with_semicolon(O::data(), expr, p_psm);
|
||||
void on_parsed_expression_with_token(obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) {
|
||||
return O::iface()->on_parsed_expression_with_token(O::data(), expr, tk, p_psm);
|
||||
}
|
||||
|
||||
///@}
|
||||
|
|
|
|||
|
|
@ -626,7 +626,7 @@ namespace xo {
|
|||
{
|
||||
if (defstate_ == defexprstatetype::def_6) {
|
||||
p_psm->pop_ssm();
|
||||
p_psm->on_parsed_expression_with_semicolon(def_expr_);
|
||||
p_psm->on_parsed_expression_with_token(def_expr_, tk);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -649,11 +649,28 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
DDefineSsm::on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm)
|
||||
DDefineSsm::on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
this->on_parsed_expression(expr, p_psm);
|
||||
this->on_semicolon_token(Token::semicolon_token(), p_psm);
|
||||
/* must end with semicolon */
|
||||
|
||||
if (tk.tk_type() == tokentype::tk_semicolon) {
|
||||
if (defstate_ == defexprstatetype::def_5)
|
||||
{
|
||||
this->defstate_ = defexprstatetype::def_6;
|
||||
|
||||
def_expr_.data()->assign_rhs(expr);
|
||||
|
||||
// completes this definition syntax
|
||||
this->on_semicolon_token(tk, p_psm);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// error in all other cases
|
||||
Super::on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ namespace xo {
|
|||
|
||||
log && log(xtag("tk", tk));
|
||||
|
||||
const DVariable * var = p_psm->lookup_variable(tk.text());
|
||||
DVarRef * var = p_psm->lookup_varref(tk.text());
|
||||
|
||||
if (!var) {
|
||||
p_psm->error_unbound_variable(ssm_classname(),
|
||||
|
|
@ -210,7 +210,7 @@ namespace xo {
|
|||
//
|
||||
|
||||
DProgressSsm::start(p_psm->parser_alloc(),
|
||||
obj<AExpression,DVariable>(const_cast<DVariable *>(var)),
|
||||
obj<AExpression,DVarRef>(var),
|
||||
p_psm);
|
||||
}
|
||||
|
||||
|
|
@ -388,14 +388,15 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
DExpectExprSsm::on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm)
|
||||
DExpectExprSsm::on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
// expression (reported by nested ProgressSsm)
|
||||
// completes this DExpectExprSsm's assignment
|
||||
|
||||
p_psm->pop_ssm();
|
||||
p_psm->on_parsed_expression_with_semicolon(expr);
|
||||
p_psm->on_parsed_expression_with_token(expr, tk);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -167,7 +167,10 @@ namespace xo {
|
|||
case tokentype::tk_dot:
|
||||
case tokentype::tk_comma:
|
||||
case tokentype::tk_colon:
|
||||
break;
|
||||
case tokentype::tk_semicolon:
|
||||
assert(false);
|
||||
break;
|
||||
case tokentype::tk_doublecolon:
|
||||
case tokentype::tk_singleassign:
|
||||
case tokentype::tk_assign:
|
||||
|
|
@ -396,10 +399,16 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
DExprSeqState::on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm)
|
||||
DExprSeqState::on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->capture_result("DExprSeqState::on_parsed_expression_with_semicolon", expr);
|
||||
if (tk.tk_type() == tokentype::tk_semicolon) {
|
||||
p_psm->capture_result("DExprSeqState::on_parsed_expression_with_token", expr);
|
||||
return;
|
||||
}
|
||||
|
||||
Super::on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -150,13 +150,15 @@ namespace xo {
|
|||
case tokentype::tk_else:
|
||||
this->on_else_token(tk, p_psm);
|
||||
return;
|
||||
case tokentype::tk_semicolon:
|
||||
this->on_semicolon_token(tk, p_psm);
|
||||
return;
|
||||
case tokentype::tk_colon:
|
||||
case tokentype::tk_singleassign:
|
||||
case tokentype::tk_string:
|
||||
case tokentype::tk_f64:
|
||||
case tokentype::tk_i64:
|
||||
case tokentype::tk_bool:
|
||||
case tokentype::tk_semicolon:
|
||||
case tokentype::tk_invalid:
|
||||
case tokentype::tk_leftparen:
|
||||
case tokentype::tk_rightparen:
|
||||
|
|
@ -405,13 +407,25 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
DIfElseSsm::on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm)
|
||||
DIfElseSsm::on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
this->on_parsed_expression(expr, p_psm);
|
||||
this->on_semicolon_token(Token::semicolon_token(), p_psm);
|
||||
// TODO: may consider allowing if-else to terminate on other particular tokens
|
||||
// e.g. ')'
|
||||
|
||||
if ((tk.tk_type() == tokentype::tk_then)
|
||||
|| (tk.tk_type() == tokentype::tk_else)
|
||||
|| (tk.tk_type() == tokentype::tk_semicolon))
|
||||
{
|
||||
this->on_parsed_expression(expr, p_psm);
|
||||
this->on_token(tk, p_psm);
|
||||
return;
|
||||
}
|
||||
|
||||
Super::on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -364,10 +364,11 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
DLambdaSsm::on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm)
|
||||
DLambdaSsm::on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
Super::on_parsed_expression_with_semicolon(expr, p_psm);
|
||||
Super::on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
#ifdef NOT_YET
|
||||
|
|
|
|||
|
|
@ -319,10 +319,7 @@ namespace xo {
|
|||
obj<AExpression> expr = this->assemble_expr(p_psm);
|
||||
|
||||
p_psm->pop_ssm(); // completes self
|
||||
|
||||
// TODO: perhaps need to generalize on_parsed_expression_with_semicolon() ..?
|
||||
p_psm->on_parsed_expression(expr);
|
||||
p_psm->on_token(tk);
|
||||
p_psm->on_parsed_expression_with_token(expr, tk);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -458,25 +455,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
p_psm->pop_ssm();
|
||||
p_psm->on_parsed_expression_with_semicolon(expr);
|
||||
|
||||
/* control here on input like:
|
||||
* (1.234;
|
||||
*
|
||||
* a. '(' sets up stack [lparen_0:expect_rhs_expression]
|
||||
* (see exprstate::on_leftparen())
|
||||
* b. 1.234 pushes (in case operators) [lparen_0:expect_rhs_expression:expr_progress]
|
||||
* (see exprstate::on_f64())
|
||||
* c. semicolon completes expr_progress [lparen_0:expect_rhs_expression]
|
||||
* deliver expresssion to expect_rhs_expression.on_expr_with_semicolon()
|
||||
* (see exprstate::on_expr_with_semicolon())
|
||||
* d. expr_rhs_expression forwards expression to [lparen_0]
|
||||
* e. lparen_0 would advance to [lparen_1], but rejects semicolon
|
||||
*/
|
||||
|
||||
#ifdef OBSOLETE
|
||||
Super::on_token(tk, p_psm);
|
||||
#endif
|
||||
p_psm->on_parsed_expression_with_token(expr, tk);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -489,11 +468,15 @@ namespace xo {
|
|||
|
||||
obj<AExpression> expr = this->assemble_expr(p_psm);
|
||||
|
||||
{
|
||||
if (expr) {
|
||||
obj<APrintable> expr_pr
|
||||
= FacetRegistry::instance().variant<APrintable,AExpression>(expr);
|
||||
= FacetRegistry::instance().try_variant<APrintable,AExpression>(expr);
|
||||
assert(expr_pr);
|
||||
log && log(xtag("expr", expr_pr));
|
||||
} else {
|
||||
// illegal token if assemble failed
|
||||
Super::on_token(tk, p_psm);
|
||||
return;
|
||||
}
|
||||
|
||||
p_psm->pop_ssm();
|
||||
|
|
@ -501,15 +484,19 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
DProgressSsm::on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm)
|
||||
DProgressSsm::on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()),
|
||||
xtag("expr", expr));
|
||||
|
||||
if (op_type_ == optype::invalid) {
|
||||
// e.g. control here on input like
|
||||
// x : = 4 4
|
||||
|
||||
p_psm->illegal_parsed_expression
|
||||
("DProgressSsm::on_parsed_expression_with_semicolon",
|
||||
("DProgressSsm::on_parsed_expression_with_token",
|
||||
expr,
|
||||
this->get_expect_str());
|
||||
return;
|
||||
|
|
@ -521,7 +508,7 @@ namespace xo {
|
|||
|
||||
if (expr2) {
|
||||
p_psm->pop_ssm();
|
||||
p_psm->on_parsed_expression_with_semicolon(expr2);
|
||||
p_psm->on_parsed_expression_with_token(expr2, tk);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -147,10 +147,8 @@ namespace xo {
|
|||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
// TODO: stream inserter that sets up pretty-printing.
|
||||
// Or integrate with indentlog.
|
||||
// Maybe trouble is that indentlog doesn't #include Printable ?
|
||||
//
|
||||
// TODO: switch to printable facet
|
||||
|
||||
log && log(xtag("expr", expr));
|
||||
|
||||
#ifdef NOT_YET
|
||||
|
|
@ -206,8 +204,31 @@ namespace xo {
|
|||
}
|
||||
#endif
|
||||
|
||||
this->seq_expr_->push_back(p_psm->expr_alloc(),
|
||||
expr);
|
||||
this->seq_expr_->push_back(p_psm->expr_alloc(), expr);
|
||||
}
|
||||
|
||||
void
|
||||
DSequenceSsm::on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
if (tk.tk_type() == tokentype::tk_semicolon) {
|
||||
// keep sequence on stack, consuming semicolon
|
||||
|
||||
this->seq_expr_->push_back(p_psm->expr_alloc(),
|
||||
expr);
|
||||
return;
|
||||
} else if (tk.tk_type() == tokentype::tk_rightbrace) {
|
||||
// rightbrace ends sequence
|
||||
|
||||
this->seq_expr_->push_back(p_psm->expr_alloc(), expr);
|
||||
this->on_rightbrace_token(tk, p_psm);
|
||||
return;
|
||||
}
|
||||
|
||||
Super::on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
#ifdef NOT_YET
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ ISyntaxStateMachine_Any::on_parsed_expression(Opaque, obj<AExpression>, ParserSt
|
|||
}
|
||||
|
||||
auto
|
||||
ISyntaxStateMachine_Any::on_parsed_expression_with_semicolon(Opaque, obj<AExpression>, ParserStateMachine *) -> void
|
||||
ISyntaxStateMachine_Any::on_parsed_expression_with_token(Opaque, obj<AExpression>, const Token &, ParserStateMachine *) -> void
|
||||
{
|
||||
_fatal();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ namespace xo {
|
|||
self.on_parsed_expression(expr, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DDefineSsm::on_parsed_expression_with_semicolon(DDefineSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm) -> void
|
||||
ISyntaxStateMachine_DDefineSsm::on_parsed_expression_with_token(DDefineSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_expression_with_semicolon(expr, p_psm);
|
||||
self.on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ namespace xo {
|
|||
self.on_parsed_expression(expr, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DExpectExprSsm::on_parsed_expression_with_semicolon(DExpectExprSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm) -> void
|
||||
ISyntaxStateMachine_DExpectExprSsm::on_parsed_expression_with_token(DExpectExprSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_expression_with_semicolon(expr, p_psm);
|
||||
self.on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ namespace xo {
|
|||
self.on_parsed_expression(expr, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DExpectFormalArgSsm::on_parsed_expression_with_semicolon(DExpectFormalArgSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm) -> void
|
||||
ISyntaxStateMachine_DExpectFormalArgSsm::on_parsed_expression_with_token(DExpectFormalArgSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_expression_with_semicolon(expr, p_psm);
|
||||
self.on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ namespace xo {
|
|||
self.on_parsed_expression(expr, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DExpectFormalArglistSsm::on_parsed_expression_with_semicolon(DExpectFormalArglistSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm) -> void
|
||||
ISyntaxStateMachine_DExpectFormalArglistSsm::on_parsed_expression_with_token(DExpectFormalArglistSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_expression_with_semicolon(expr, p_psm);
|
||||
self.on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ namespace xo {
|
|||
self.on_parsed_expression(expr, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DExpectSymbolSsm::on_parsed_expression_with_semicolon(DExpectSymbolSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm) -> void
|
||||
ISyntaxStateMachine_DExpectSymbolSsm::on_parsed_expression_with_token(DExpectSymbolSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_expression_with_semicolon(expr, p_psm);
|
||||
self.on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ namespace xo {
|
|||
self.on_parsed_expression(expr, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DExpectTypeSsm::on_parsed_expression_with_semicolon(DExpectTypeSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm) -> void
|
||||
ISyntaxStateMachine_DExpectTypeSsm::on_parsed_expression_with_token(DExpectTypeSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_expression_with_semicolon(expr, p_psm);
|
||||
self.on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ namespace xo {
|
|||
self.on_parsed_expression(expr, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DExprSeqState::on_parsed_expression_with_semicolon(DExprSeqState & self, obj<AExpression> expr, ParserStateMachine * p_psm) -> void
|
||||
ISyntaxStateMachine_DExprSeqState::on_parsed_expression_with_token(DExprSeqState & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_expression_with_semicolon(expr, p_psm);
|
||||
self.on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ namespace xo {
|
|||
self.on_parsed_expression(expr, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DIfElseSsm::on_parsed_expression_with_semicolon(DIfElseSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm) -> void
|
||||
ISyntaxStateMachine_DIfElseSsm::on_parsed_expression_with_token(DIfElseSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_expression_with_semicolon(expr, p_psm);
|
||||
self.on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ namespace xo {
|
|||
self.on_parsed_expression(expr, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DLambdaSsm::on_parsed_expression_with_semicolon(DLambdaSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm) -> void
|
||||
ISyntaxStateMachine_DLambdaSsm::on_parsed_expression_with_token(DLambdaSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_expression_with_semicolon(expr, p_psm);
|
||||
self.on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ namespace xo {
|
|||
self.on_parsed_expression(expr, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DProgressSsm::on_parsed_expression_with_semicolon(DProgressSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm) -> void
|
||||
ISyntaxStateMachine_DProgressSsm::on_parsed_expression_with_token(DProgressSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_expression_with_semicolon(expr, p_psm);
|
||||
self.on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ namespace xo {
|
|||
self.on_parsed_expression(expr, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DSequenceSsm::on_parsed_expression_with_semicolon(DSequenceSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm) -> void
|
||||
ISyntaxStateMachine_DSequenceSsm::on_parsed_expression_with_token(DSequenceSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_expression_with_semicolon(expr, p_psm);
|
||||
self.on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -107,38 +107,57 @@ namespace xo {
|
|||
return stringtable_.gensym(str);
|
||||
}
|
||||
|
||||
Binding
|
||||
ParserStateMachine::lookup_binding(std::string_view symbolname)
|
||||
DVarRef *
|
||||
ParserStateMachine::lookup_varref(std::string_view symbolname)
|
||||
{
|
||||
scope log(XO_DEBUG(debug_flag_));
|
||||
|
||||
if (!local_symtab_)
|
||||
return Binding::null();
|
||||
|
||||
const DUniqueString * ustr = stringtable_.lookup(symbolname);
|
||||
|
||||
if (!ustr) {
|
||||
// if not in string table, then can't be a variable either
|
||||
return Binding::null();
|
||||
}
|
||||
|
||||
DLocalSymtab * symtab = local_symtab_;
|
||||
|
||||
// count #of nested scopes to cross, to reach symbol
|
||||
// TODO:
|
||||
// 1. check global symtab
|
||||
// 2. combine local+global symtab into indept struct
|
||||
// 3. move lookup_varref implementation there.
|
||||
//
|
||||
int32_t link_count = 0;
|
||||
|
||||
while (symtab) {
|
||||
Binding b = symtab->lookup_binding(ustr);
|
||||
if (local_symtab_) {
|
||||
const DUniqueString * ustr = stringtable_.lookup(symbolname);
|
||||
|
||||
if (b.is_local()) {
|
||||
assert(b.i_link() == 0);
|
||||
if (ustr) {
|
||||
DLocalSymtab * symtab = local_symtab_;
|
||||
|
||||
return Binding(link_count, b.j_slot());
|
||||
// count #of nested scopes to cross, to reach symbol
|
||||
//
|
||||
int32_t link_count = 0;
|
||||
|
||||
while (symtab) {
|
||||
Binding b = symtab->lookup_binding(ustr);
|
||||
|
||||
if (b.is_local()) {
|
||||
assert(b.i_link() == 0);
|
||||
|
||||
DVariable * vardef = symtab->lookup_var(b);
|
||||
assert(vardef);
|
||||
|
||||
|
||||
/** ascii diagram here
|
||||
**/
|
||||
|
||||
return DVarRef::make(expr_alloc_,
|
||||
vardef,
|
||||
link_count);
|
||||
} else {
|
||||
assert(b.is_null());
|
||||
}
|
||||
|
||||
++link_count;
|
||||
symtab = symtab->parent();
|
||||
}
|
||||
} else {
|
||||
// if we don't already know the symbol,
|
||||
// -> can't be a valid variable reference
|
||||
// (whether global or local)
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
++link_count;
|
||||
symtab = symtab->parent();
|
||||
}
|
||||
|
||||
// TODO: check global symtab also
|
||||
|
|
@ -146,7 +165,7 @@ namespace xo {
|
|||
log.retroactively_enable();
|
||||
log("STUB: check global symtab");
|
||||
|
||||
return Binding::null();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -239,16 +258,6 @@ namespace xo {
|
|||
this->top_ssm().on_parsed_expression(expr, this);
|
||||
}
|
||||
|
||||
void
|
||||
ParserStateMachine::on_parsed_expression_with_semicolon(obj<AExpression> expr)
|
||||
{
|
||||
scope log(XO_DEBUG(debug_flag_), xtag("expr", expr));
|
||||
|
||||
assert(stack_);
|
||||
|
||||
this->top_ssm().on_parsed_expression_with_semicolon(expr, this);
|
||||
}
|
||||
|
||||
void
|
||||
ParserStateMachine::on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk)
|
||||
|
|
@ -257,11 +266,7 @@ namespace xo {
|
|||
|
||||
assert(stack_);
|
||||
|
||||
this->top_ssm().on_parsed_expression(expr, this);
|
||||
|
||||
assert(stack_);
|
||||
|
||||
this->top_ssm().on_token(tk, this);
|
||||
this->top_ssm().on_parsed_expression_with_token(expr, tk, this);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -443,6 +448,39 @@ namespace xo {
|
|||
this->capture_error(ssm_name, errmsg);
|
||||
}
|
||||
|
||||
void
|
||||
ParserStateMachine::illegal_parsed_expression_with_token(std::string_view ssm_name,
|
||||
obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
std::string_view expect_str)
|
||||
{
|
||||
// TODO:
|
||||
// - want to write error message using DArena
|
||||
// - need something like log_streambuf and/or tostr() that's arena-aware
|
||||
|
||||
obj<APrintable> expr_pr
|
||||
= FacetRegistry::instance().variant<APrintable,AExpression>(expr);
|
||||
assert(expr_pr);
|
||||
|
||||
/** TODO
|
||||
* problem here: we have pretty() support for obj<AExpression>,
|
||||
* but not "ordinary printing" support. So expression doesn't get printed
|
||||
**/
|
||||
auto errmsg_string = tostr("Unexpected expression",
|
||||
xtag("expr", expr_pr),
|
||||
xtag("tk", tk),
|
||||
xtag("expecting", expect_str),
|
||||
xtag("ssm", ssm_name),
|
||||
xtag("via", "ParserStateMachine::illegal_parsed_expression"));
|
||||
|
||||
assert(expr_alloc_);
|
||||
|
||||
auto errmsg = DString::from_view(expr_alloc_,
|
||||
std::string_view(errmsg_string));
|
||||
|
||||
this->capture_error(ssm_name, errmsg);
|
||||
}
|
||||
|
||||
void
|
||||
ParserStateMachine::error_unbound_variable(std::string_view ssm_name,
|
||||
std::string_view sym)
|
||||
|
|
|
|||
|
|
@ -976,11 +976,34 @@ namespace xo {
|
|||
REQUIRE(result.is_incomplete());
|
||||
}
|
||||
|
||||
#ifdef NOPE
|
||||
{
|
||||
auto & result = parser.on_token(Token::star_token());
|
||||
|
||||
log && log("after star(*) token:");
|
||||
log && log(xtag("parser", &parser));
|
||||
log && log(xtag("result", result));
|
||||
|
||||
REQUIRE(parser.has_incomplete_expr() == true);
|
||||
REQUIRE(!result.is_error());
|
||||
REQUIRE(result.is_incomplete());
|
||||
}
|
||||
|
||||
{
|
||||
auto & result = parser.on_token(Token::symbol_token("x"));
|
||||
|
||||
log && log("after symbol(x) token:");
|
||||
log && log(xtag("parser", &parser));
|
||||
log && log(xtag("result", result));
|
||||
|
||||
REQUIRE(parser.has_incomplete_expr() == true);
|
||||
REQUIRE(!result.is_error());
|
||||
REQUIRE(result.is_incomplete());
|
||||
}
|
||||
|
||||
{
|
||||
auto & result = parser.on_token(Token::rightbrace_token());
|
||||
|
||||
log && log("after rightbrace token:");
|
||||
log && log("after rightbrace(}) token:");
|
||||
log && log(xtag("parser", &parser));
|
||||
log && log(xtag("result", result));
|
||||
|
||||
|
|
@ -990,11 +1013,6 @@ namespace xo {
|
|||
REQUIRE(result.result_expr());
|
||||
}
|
||||
|
||||
//REQUIRE(result.is_error());
|
||||
//// illegal input on token
|
||||
//REQUIRE(result.error_description());
|
||||
#endif
|
||||
REQUIRE(false);
|
||||
}
|
||||
} /*namespace ut*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue