xo-expression2 xo-procedure2: work on calling primitive for x*y

This commit is contained in:
Roland Conybeare 2026-01-26 13:42:42 -05:00
commit 6acc676d43
16 changed files with 76 additions and 58 deletions

View file

@ -1,3 +1,7 @@
// can regenerate downstream .*pp files with either:
// cmake --build -- xo-procedure2-facet-procedure
// cmake --build -- xo-procedure2-genfacet-all
{
mode: "facet",
// includes in ASyntaxStateMachine.hpp
@ -56,6 +60,7 @@
doc: ["invoke procedure; assume arguments satisfy type system" ],
return_type: "obj<AGCObject>",
args: [
{type: "obj<ARuntimeContext>", name: "rcx"},
{type: "const DArray *", name: "args"},
]
}

View file

@ -19,43 +19,49 @@
namespace xo {
namespace scm {
/** @brief Extract return type and argument types from a function type.
*
* Primary template (undefined) - specializations handle specific cases
namespace detail {
/** @brief Extract return type and argument types from a function type.
*
* Primary template (undefined) - specializations handle specific cases
**/
template <typename Fn>
struct PmFnTraits;
/** specialization for function pointers **/
template <typename R, typename... Args>
struct PmFnTraits<R(*)(obj<ARuntimeContext> rcx, Args...)> {
/** function return type **/
using return_type = R;
/** tuple type for function arguments (except for runtime context) **/
using args_tuple = std::tuple<Args...>;
/** number of arguments (except for runtime context) **/
static constexpr std::size_t n_args = sizeof...(Args);
/** arg_type<i> is the type of the i'th argument to Fn.
* (starting from argument after runtime context)
**/
template <std::size_t I>
using arg_type = std::tuple_element_t<I, args_tuple>;
};
/** specialization for function references **/
template <typename R, typename... Args>
struct PmFnTraits<R(&)(obj<ARuntimeContext>, Args...)> : PmFnTraits<R(*)(obj<ARuntimeContext>, Args...)> {};
/** specialization for plain function types **/
template <typename R, typename... Args>
struct PmFnTraits<R(obj<ARuntimeContext>, Args...)> : PmFnTraits<R(*)(obj<ARuntimeContext>, Args...)> {};
}
/** @brief Schematika primitive with fixed number of arguments
**/
template <typename Fn>
struct FnTraits;
/** specialization for function pointers **/
template <typename R, typename... Args>
struct FnTraits<R(*)(Args...)> {
/** function return type **/
using return_type = R;
/** tuple type for function arguments **/
using args_tuple = std::tuple<Args...>;
/** number of arguments **/
static constexpr std::size_t n_args = sizeof...(Args);
/** arg_type<i> is the type of the i'th argument to Fn **/
template <std::size_t I>
using arg_type = std::tuple_element_t<I, args_tuple>;
};
/** specialization for function references **/
template <typename R, typename... Args>
struct FnTraits<R(&)(Args...)> : FnTraits<R(*)(Args...)> {};
/** specialization for plain function types **/
template <typename R, typename... Args>
struct FnTraits<R(Args...)> : FnTraits<R(*)(Args...)> {};
template <typename Fn>
class Primitive {
public:
using AAllocator = xo::mm::AAllocator;
using AGCObject = xo::mm::AGCObject;
using DArray = xo::scm::DArray;
using Traits = FnTraits<Fn>;
using Traits = detail::PmFnTraits<Fn>;
public:
Primitive(std::string_view name, Fn fn) : name_{name}, fn_{fn} {}
@ -63,14 +69,15 @@ namespace xo {
bool is_nary() const noexcept { return false; }
static constexpr std::int32_t n_args() noexcept { return Traits::n_args; }
obj<AGCObject> apply_nocheck(const DArray * args) {
return _apply_nocheck(args,
obj<AGCObject> apply_nocheck(obj<ARuntimeContext> rcx, const DArray * args) {
return _apply_nocheck(rcx, args,
std::make_index_sequence<Traits::n_args>{});
}
private:
template <std::size_t... Is>
obj<AGCObject> _apply_nocheck(const DArray * args,
obj<AGCObject> _apply_nocheck(obj<ARuntimeContext> rcx,
const DArray * args,
std::index_sequence<Is...>)
{
using xo::facet::FacetRegistry;
@ -80,12 +87,11 @@ namespace xo {
assert(args);
assert(args->size() > 0);
obj<ARuntimeContext> rcx
= FacetRegistry::instance().variant<ARuntimeContext>(args->at(0));
obj<AAllocator> mm = rcx.allocator();
R result
= fn_(GCObjectConversion<typename Traits::template arg_type<Is>>::from_gco(mm, args->at(Is))... );
= fn_(rcx,
GCObjectConversion<typename Traits::template arg_type<Is>>::from_gco(mm, args->at(Is))... );
return GCObjectConversion<R>::to_gco(mm, result);
}

View file

@ -1,3 +1,8 @@
/** @file DPrimitive_gco_2_gco_gco.hpp
*
* @author Roland Conybeare, Jan 2026
**/
#pragma once
#include <xo/gc/GCObject.hpp>
@ -13,3 +18,5 @@ namespace xo {
obj<AGCObject>)>;
}
}
/* end DPrimitive_gco_2_gco_gco.hpp */

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Procedure.json5]
* 2. jinja2 template for facet .hpp file:

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/RuntimeContext.json5]
* 2. jinja2 template for facet .hpp file:

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Procedure.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -56,7 +56,7 @@ public:
// nonconst methods
/** invoke procedure; assume arguments satisfy type system **/
virtual obj<AGCObject> apply_nocheck(Opaque data, const DArray * args) = 0;
virtual obj<AGCObject> apply_nocheck(Opaque data, obj<ARuntimeContext> rcx, const DArray * args) = 0;
///@}
}; /*AProcedure*/

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/RuntimeContext.json5]
* 2. jinja2 template for abstract facet .hpp file:

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Procedure.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -60,7 +60,7 @@ namespace scm {
[[noreturn]] std::int32_t n_args(Copaque) const noexcept override { _fatal(); }
// nonconst methods
[[noreturn]] obj<AGCObject> apply_nocheck(Opaque, const DArray *) override;
[[noreturn]] obj<AGCObject> apply_nocheck(Opaque, obj<ARuntimeContext>, const DArray *) override;
///@}

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IProcedure_DPrimitive_gco_2_gco_gco.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -57,7 +57,7 @@ namespace xo {
// non-const methods
/** invoke procedure; assume arguments satisfy type system **/
static obj<AGCObject> apply_nocheck(DPrimitive_gco_2_gco_gco & self, const DArray * args);
static obj<AGCObject> apply_nocheck(DPrimitive_gco_2_gco_gco & self, obj<ARuntimeContext> rcx, const DArray * args);
///@}
};

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Procedure.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -50,8 +50,8 @@ namespace scm {
}
// non-const methods
obj<AGCObject> apply_nocheck(Opaque data, const DArray * args) override {
return I::apply_nocheck(_dcast(data), args);
obj<AGCObject> apply_nocheck(Opaque data, obj<ARuntimeContext> rcx, const DArray * args) override {
return I::apply_nocheck(_dcast(data), rcx, args);
}
///@}

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/RuntimeContext.json5]
* 2. jinja2 template for abstract facet .hpp file:

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/RuntimeContext.json5]
* 2. jinja2 template for abstract facet .hpp file:

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Procedure.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -56,8 +56,8 @@ public:
}
// non-const methods (still const in router!)
obj<AGCObject> apply_nocheck(const DArray * args) {
return O::iface()->apply_nocheck(O::data(), args);
obj<AGCObject> apply_nocheck(obj<ARuntimeContext> rcx, const DArray * args) {
return O::iface()->apply_nocheck(O::data(), rcx, args);
}
///@}

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/RuntimeContext.json5]
* 2. jinja2 template for abstract facet .hpp file:

View file

@ -35,7 +35,7 @@ IProcedure_Any::_valid
// nonconst methods
auto
IProcedure_Any::apply_nocheck(Opaque, const DArray *) -> obj<AGCObject>
IProcedure_Any::apply_nocheck(Opaque, obj<ARuntimeContext>, const DArray *) -> obj<AGCObject>
{
_fatal();
}

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IProcedure_DPrimitive_gco_2_gco_gco.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -28,9 +28,9 @@ namespace xo {
}
auto
IProcedure_DPrimitive_gco_2_gco_gco::apply_nocheck(DPrimitive_gco_2_gco_gco & self, const DArray * args) -> obj<AGCObject>
IProcedure_DPrimitive_gco_2_gco_gco::apply_nocheck(DPrimitive_gco_2_gco_gco & self, obj<ARuntimeContext> rcx, const DArray * args) -> obj<AGCObject>
{
return self.apply_nocheck(args);
return self.apply_nocheck(rcx, args);
}
} /*namespace scm*/