xo-interpreter2 stack: + dict type + pop more pm types
This commit is contained in:
parent
0e12e2644e
commit
ba6754b378
6 changed files with 65 additions and 19 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue