xo-interpreter2 stack: + dict type + pop more pm types
This commit is contained in:
parent
edd6c50e10
commit
3b448dc02b
15 changed files with 117 additions and 31 deletions
|
|
@ -12,6 +12,7 @@ namespace xo {
|
|||
namespace scm {
|
||||
/** Register primitive-factories **/
|
||||
bool interpreter2_register_primitives(obj<xo::mm::AAllocator> gc,
|
||||
StringTable * stbl,
|
||||
InstallSink sink,
|
||||
InstallFlags flags);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,12 +52,11 @@ namespace xo {
|
|||
|
||||
bool
|
||||
interpreter2_register_primitives(obj<xo::mm::AAllocator> mm,
|
||||
StringTable * stbl,
|
||||
InstallSink sink,
|
||||
InstallFlags flags)
|
||||
{
|
||||
(void)mm;
|
||||
(void)sink;
|
||||
(void)flags;
|
||||
(void)stbl;
|
||||
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ namespace xo {
|
|||
namespace scm {
|
||||
/** Register primitive factories with primitive registry **/
|
||||
bool numeric_register_primitives(obj<xo::mm::AAllocator> mm,
|
||||
StringTable * stbl,
|
||||
InstallSink sink,
|
||||
InstallFlags flags);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,8 +49,11 @@ namespace xo {
|
|||
}
|
||||
|
||||
bool
|
||||
numeric_register_primitives(obj<AAllocator> mm, InstallSink sink, InstallFlags flags)
|
||||
numeric_register_primitives(obj<AAllocator> mm, StringTable * stbl,
|
||||
InstallSink sink, InstallFlags flags)
|
||||
{
|
||||
(void)stbl;
|
||||
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
bool ok = true;
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ namespace xo {
|
|||
* Darray * v = DArray::array(mm, e1, e2, e3);
|
||||
**/
|
||||
template <typename... Args>
|
||||
requires (std::same_as<Args, obj<AGCObject>> && ...)
|
||||
requires (std::convertible_to<Args, obj<AGCObject>> && ...)
|
||||
static DArray * array(obj<AAllocator> mm, Args... args);
|
||||
|
||||
///@}
|
||||
|
|
@ -170,7 +170,7 @@ namespace xo {
|
|||
};
|
||||
|
||||
template <typename... Args>
|
||||
requires (std::same_as<Args, obj<DArray::AGCObject>> && ...)
|
||||
requires (std::convertible_to<Args, obj<DArray::AGCObject>> && ...)
|
||||
DArray *
|
||||
DArray::array(obj<AAllocator> mm, Args... args)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,16 +24,20 @@ namespace xo {
|
|||
|
||||
public:
|
||||
/** create primitive: report current working directory **/
|
||||
static DPrimitive_gco_0 * make_cwd_pm(obj<AAllocator> mm);
|
||||
static DPrimitive_gco_0 * make_cwd_pm(obj<AAllocator> mm,
|
||||
StringTable * stbl);
|
||||
|
||||
/** create primitive: fetch nth element of a sequence **/
|
||||
static DPrimitive_gco_2_gco_gco * make_nth_pm(obj<AAllocator> mm);
|
||||
static DPrimitive_gco_2_gco_gco * make_nth_pm(obj<AAllocator> mm,
|
||||
StringTable * stbl);
|
||||
|
||||
/** create primitive: create cons cell **/
|
||||
static DPrimitive_gco_2_gco_gco * make_cons_pm(obj<AAllocator> mm);
|
||||
static DPrimitive_gco_2_gco_gco * make_cons_pm(obj<AAllocator> mm,
|
||||
StringTable * stbl);
|
||||
|
||||
/** create primitive for creating a dictionary instance **/
|
||||
static DPrimitive_gco_0 * make_dict_make_pm(obj<AAllocator> mm);
|
||||
static DPrimitive_gco_0 * make_dict_make_pm(obj<AAllocator> mm,
|
||||
StringTable * stbl);
|
||||
|
||||
/** create primitive for creating a dictionary instance **/
|
||||
static DPrimitive_gco_2_dict_string * make_dict_lookup_pm(obj<AAllocator> mm);
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ namespace xo {
|
|||
* to InstallSink sink.
|
||||
**/
|
||||
using InstallSource = std::function<bool (obj<AAllocator> mm,
|
||||
StringTable * stbl,
|
||||
InstallSink sink,
|
||||
InstallFlags flags)>;
|
||||
|
||||
|
|
@ -72,9 +73,11 @@ namespace xo {
|
|||
void register_primitives(InstallSource source_fn);
|
||||
|
||||
/** create primitives using memory from @p mm,
|
||||
* with global strings in @p stbl.
|
||||
* delivering each primitive to @p sink.
|
||||
**/
|
||||
bool install_primitives(obj<AAllocator> mm,
|
||||
StringTable * stbl,
|
||||
InstallSink sink,
|
||||
InstallFlags flags);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ namespace xo {
|
|||
namespace scm {
|
||||
/** Register primitive-factories **/
|
||||
bool procedure2_register_primitives(obj<xo::mm::AAllocator> gc,
|
||||
StringTable * stbl,
|
||||
InstallSink sink,
|
||||
InstallFlags flags);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@
|
|||
#include <xo/object2/Sequence.hpp>
|
||||
#include <xo/object2/List.hpp>
|
||||
#include <xo/object2/Integer.hpp>
|
||||
#include <xo/type/FunctionType.hpp>
|
||||
#include <xo/type/ListType.hpp>
|
||||
#include <xo/type/TypeVarRef.hpp>
|
||||
#include <xo/type/AtomicType.hpp>
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/stringtable2/String.hpp>
|
||||
#include <unistd.h> // for getcwd()
|
||||
|
|
@ -35,9 +39,15 @@ namespace xo {
|
|||
}
|
||||
|
||||
DPrimitive_gco_0 *
|
||||
ObjectPrimitives::make_cwd_pm(obj<AAllocator> mm)
|
||||
ObjectPrimitives::make_cwd_pm(obj<AAllocator> mm, StringTable * stbl)
|
||||
{
|
||||
return DPrimitive_gco_0::_make(mm, "cwd", &xfer_cwd);
|
||||
(void)stbl;
|
||||
|
||||
auto str_ty = DAtomicType::make(mm, Metatype::t_str());
|
||||
auto cwd_ty
|
||||
= obj<AType,DFunctionType>(DFunctionType::_make(mm, str_ty));
|
||||
|
||||
return DPrimitive_gco_0::_make(mm, "cwd", cwd_ty, &xfer_cwd);
|
||||
}
|
||||
|
||||
// ----- nth -----
|
||||
|
|
@ -59,9 +69,20 @@ namespace xo {
|
|||
}
|
||||
|
||||
DPrimitive_gco_2_gco_gco *
|
||||
ObjectPrimitives::make_nth_pm(obj<AAllocator> mm)
|
||||
ObjectPrimitives::make_nth_pm(obj<AAllocator> mm, StringTable * stbl)
|
||||
{
|
||||
return DPrimitive_gco_2_gco_gco::_make(mm, "nth", &xfer_nth);
|
||||
auto T_ty = DTypeVarRef::make(mm, stbl->intern("T"));
|
||||
auto list_T_ty = DListType::make(mm, T_ty);
|
||||
auto int_ty = DAtomicType::make(mm, Metatype::t_integer());
|
||||
/** nth_ty: list<T> x int -> T **/
|
||||
auto nth_ty
|
||||
= obj<AType,DFunctionType>
|
||||
(DFunctionType::_make(mm,
|
||||
T_ty,
|
||||
list_T_ty,
|
||||
int_ty));
|
||||
|
||||
return DPrimitive_gco_2_gco_gco::_make(mm, "nth", nth_ty, &xfer_nth);
|
||||
}
|
||||
|
||||
// ----- cons -----
|
||||
|
|
@ -75,17 +96,24 @@ namespace xo {
|
|||
|
||||
auto cdr_list = obj<AGCObject,DList>::from(cdr);
|
||||
|
||||
//auto T = DTypeVarRef::_make(rcx.allocator(), "T");
|
||||
|
||||
return DList::cons(rcx.allocator(),
|
||||
car,
|
||||
cdr_list.data());
|
||||
}
|
||||
|
||||
DPrimitive_gco_2_gco_gco *
|
||||
ObjectPrimitives::make_cons_pm(obj<AAllocator> mm)
|
||||
ObjectPrimitives::make_cons_pm(obj<AAllocator> mm, StringTable * stbl)
|
||||
{
|
||||
return DPrimitive_gco_2_gco_gco::_make(mm, "cons", &xfer_cons);
|
||||
auto T_ty = DTypeVarRef::make(mm, stbl->intern("T"));
|
||||
auto list_T_ty = DListType::make(mm, T_ty);
|
||||
/** cons_ty: T x list<T> -> list<T> **/
|
||||
auto cons_ty
|
||||
= obj<AType,DFunctionType>(DFunctionType::_make(mm,
|
||||
list_T_ty,
|
||||
T_ty,
|
||||
list_T_ty));
|
||||
|
||||
return DPrimitive_gco_2_gco_gco::_make(mm, "cons", cons_ty, &xfer_cons);
|
||||
}
|
||||
|
||||
// ----- dict_make -----
|
||||
|
|
@ -98,9 +126,17 @@ namespace xo {
|
|||
}
|
||||
|
||||
DPrimitive_gco_0 *
|
||||
ObjectPrimitives::make_dict_make_pm(obj<AAllocator> mm)
|
||||
ObjectPrimitives::make_dict_make_pm(obj<AAllocator> mm,
|
||||
StringTable * stbl)
|
||||
{
|
||||
return DPrimitive_gco_0::_make(mm, "dict_make", &xfer_dict_make);
|
||||
(void)stbl;
|
||||
|
||||
// nit: technically better to use empty struct type here
|
||||
auto dict_ty = DAtomicType::make(mm, Metatype::t_dict());
|
||||
auto pm_ty = obj<AType,DFunctionType>(DFunctionType::_make(mm,
|
||||
dict_ty));
|
||||
|
||||
return DPrimitive_gco_0::_make(mm, "dict_make", pm_ty, &xfer_dict_make);
|
||||
}
|
||||
|
||||
// ----- dict_at -----
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ namespace xo {
|
|||
|
||||
bool
|
||||
PrimitiveRegistry::install_primitives(obj<AAllocator> mm,
|
||||
StringTable * stbl,
|
||||
InstallSink sink,
|
||||
InstallFlags flags)
|
||||
{
|
||||
|
|
@ -40,7 +41,7 @@ namespace xo {
|
|||
for (const auto & fn : init_seq_v_) {
|
||||
log && log("do install fn (", i+1, "/", n, ")");
|
||||
|
||||
ok = ok & fn(mm, sink, flags);
|
||||
ok = ok & fn(mm, stbl, sink, flags);
|
||||
++i;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ namespace xo {
|
|||
|
||||
bool
|
||||
procedure2_register_primitives(obj<xo::mm::AAllocator> mm,
|
||||
StringTable * stbl,
|
||||
InstallSink sink,
|
||||
InstallFlags flags)
|
||||
{
|
||||
|
|
@ -61,10 +62,10 @@ namespace xo {
|
|||
|
||||
bool ok = true;
|
||||
|
||||
ok = ok & install_aux(sink, ObjectPrimitives::make_cwd_pm(mm), flags);
|
||||
ok = ok & install_aux(sink, ObjectPrimitives::make_nth_pm(mm), flags);
|
||||
ok = ok & install_aux(sink, ObjectPrimitives::make_cons_pm(mm), flags);
|
||||
ok = ok & install_aux(sink, ObjectPrimitives::make_dict_make_pm(mm), flags);
|
||||
ok = ok & install_aux(sink, ObjectPrimitives::make_cwd_pm(mm, stbl), flags);
|
||||
ok = ok & install_aux(sink, ObjectPrimitives::make_nth_pm(mm, stbl), flags);
|
||||
ok = ok & install_aux(sink, ObjectPrimitives::make_cons_pm(mm, stbl), flags);
|
||||
ok = ok & install_aux(sink, ObjectPrimitives::make_dict_make_pm(mm, stbl), flags);
|
||||
ok = ok & install_aux(sink, ObjectPrimitives::make_dict_lookup_pm(mm), flags);
|
||||
ok = ok & install_aux(sink, ObjectPrimitives::make_dict_upsert_pm(mm), flags);
|
||||
ok = ok & install_aux(sink, ObjectPrimitives::make_fn_n_args_pm(mm), flags);
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ namespace xo {
|
|||
|
||||
PrimitiveRegistry::instance()
|
||||
.install_primitives(mm,
|
||||
&stringtable,
|
||||
sink,
|
||||
pm_install_flags);
|
||||
|
||||
|
|
|
|||
|
|
@ -32,17 +32,27 @@ namespace xo {
|
|||
* for a function with return type @p ret_type and arguments @p args
|
||||
**/
|
||||
template <typename... Args>
|
||||
requires (std::same_as<Args, obj<AType>> && ...)
|
||||
requires (std::convertible_to<Args, obj<AType>> && ...)
|
||||
explicit DFunctionType(obj<AAllocator> mm, obj<AType> ret_type, Args... args);
|
||||
|
||||
/** create instance using memory from @p mm,
|
||||
* for a function with return type @p ret_type and arguments @p args
|
||||
**/
|
||||
template <typename... Args>
|
||||
requires (std::same_as<Args, obj<AType>> && ...)
|
||||
requires (std::convertible_to<Args, obj<AType>> && ...)
|
||||
static DFunctionType * _make(obj<AAllocator> mm,
|
||||
obj<AType> ret_type, Args... args);
|
||||
|
||||
#ifdef NOT_USING
|
||||
/** create instance using memory from @p mm
|
||||
* for function with return type @p ret_type and arguments @p args
|
||||
**/
|
||||
template <typename... Args>
|
||||
requires (std::same_as<Args, obj<AType>> && ...)
|
||||
static obj<AType,DFunctionType> make(obj<AAllocator> mm,
|
||||
obj<AType> ret_type, Args... args);
|
||||
#endif
|
||||
|
||||
///@}
|
||||
/** @defgroup xo-scm-arraytype-type-facet **/
|
||||
///@{
|
||||
|
|
@ -72,14 +82,14 @@ namespace xo {
|
|||
};
|
||||
|
||||
template <typename... Args>
|
||||
requires (std::same_as<Args, obj<AType>> && ...)
|
||||
requires (std::convertible_to<Args, obj<AType>> && ...)
|
||||
DFunctionType::DFunctionType(obj<AAllocator> mm, obj<AType> return_type, Args... args)
|
||||
: return_type_{return_type},
|
||||
arg_types_{DArray::array(mm, args...)}
|
||||
arg_types_{DArray::array(mm, args.template to_facet<AGCObject>()...)}
|
||||
{}
|
||||
|
||||
template <typename... Args>
|
||||
requires (std::same_as<Args, obj<AType>> && ...)
|
||||
requires (std::convertible_to<Args, obj<AType>> && ...)
|
||||
DFunctionType *
|
||||
DFunctionType::_make(obj<AAllocator> mm, obj<AType> ret_type, Args... args)
|
||||
{
|
||||
|
|
@ -88,6 +98,18 @@ namespace xo {
|
|||
return new (mem) DFunctionType(mm, ret_type, args...);
|
||||
}
|
||||
|
||||
#ifdef NOT_USING
|
||||
template <typename... Args>
|
||||
requires (std::same_as<Args, obj<AType>> && ...)
|
||||
obj<AType,DFunctionType>
|
||||
DFunctionType::make(obj<AAllocator> mm, obj<AType> ret_type, Args... args)
|
||||
{
|
||||
void * mem = mm.alloc_for<DFunctionType>();
|
||||
|
||||
return obj<AType,DFunctionType>(_make(mm, ret_type, args...));
|
||||
}
|
||||
#endif
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -39,8 +39,13 @@ namespace xo {
|
|||
t_function,
|
||||
/* struct<a:T,b:U,..> */
|
||||
t_struct,
|
||||
/* dicttionary: like struct, but w/ dynamic key/value pairs */
|
||||
t_dict,
|
||||
|
||||
/* any numeric type: i16|i32|i64|f32|f64 */
|
||||
/** any integer type: i16|i32|i64 **/
|
||||
t_integer,
|
||||
|
||||
/** any numeric type: i16|i32|i64|f32|f64 **/
|
||||
t_numeric,
|
||||
|
||||
/* any type at all */
|
||||
|
|
@ -66,7 +71,9 @@ namespace xo {
|
|||
static Metatype t_array() { return Metatype(code::t_array); }
|
||||
static Metatype t_function() { return Metatype(code::t_function); }
|
||||
static Metatype t_struct() { return Metatype(code::t_struct); }
|
||||
static Metatype t_dict() { return Metatype(code::t_dict); }
|
||||
|
||||
static Metatype t_integer() { return Metatype(code::t_integer); }
|
||||
static Metatype t_numeric() { return Metatype(code::t_numeric); }
|
||||
static Metatype t_any() { return Metatype(code::t_any); }
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ namespace xo {
|
|||
case code::t_array: return "array";
|
||||
case code::t_function: return "function";
|
||||
case code::t_struct: return "struct";
|
||||
case code::t_dict: return "dict";
|
||||
|
||||
case code::t_integer: return "integer";
|
||||
case code::t_numeric: return "numeric";
|
||||
case code::t_any: return "any";
|
||||
}
|
||||
|
|
@ -68,7 +70,11 @@ namespace xo {
|
|||
return false;
|
||||
case code::t_struct:
|
||||
return false;
|
||||
case code::t_dict:
|
||||
return true;
|
||||
|
||||
case code::t_integer:
|
||||
return true;
|
||||
case code::t_numeric:
|
||||
return true;
|
||||
case code::t_any:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue