refactor: + narrower interface for gc pointer forwarding
add AGCObjectVisitor, instead of requiring ACollector.
This commit is contained in:
parent
c3af763383
commit
fdc3054c7c
46 changed files with 187 additions and 165 deletions
|
|
@ -129,27 +129,25 @@ namespace xo {
|
|||
return copy;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DApplyExpr::forward_children(obj<ACollector> gc) noexcept
|
||||
void
|
||||
DApplyExpr::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
|
||||
{
|
||||
typeref_.forward_children(gc);
|
||||
typeref_.visit_gco_children(gc);
|
||||
|
||||
{
|
||||
obj<AGCObject> fn_gco = fn_.to_facet<AGCObject>();
|
||||
gc.forward_inplace(fn_gco.iface(), (void **)&fn_.data_);
|
||||
gc.visit_poly_child(&fn_);
|
||||
//obj<AGCObject> fn_gco = fn_.to_facet<AGCObject>();
|
||||
//gc.forward_inplace(fn_gco.iface(), (void **)&fn_.data_);
|
||||
}
|
||||
|
||||
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_));
|
||||
gc.visit_poly_child(&arg);
|
||||
//obj<AGCObject> arg_gco = arg.to_facet<AGCObject>();
|
||||
//gc.forward_inplace(arg_gco.iface(), (void **)(&arg.data_));
|
||||
}
|
||||
|
||||
return shallow_size();
|
||||
}
|
||||
|
||||
// ----- printable facet -----
|
||||
|
|
|
|||
|
|
@ -83,15 +83,12 @@ namespace xo {
|
|||
return gc.std_move_for(this);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DConstant::forward_children(obj<ACollector> gc) noexcept
|
||||
void
|
||||
DConstant::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
|
||||
{
|
||||
typeref_.forward_children(gc);
|
||||
typeref_.visit_gco_children(gc);
|
||||
|
||||
gc.forward_inplace(&value_);
|
||||
//gc.forward_inplace(value_.iface(), (void **)&(value_.data_));
|
||||
|
||||
return shallow_size();
|
||||
gc.visit_child(&value_);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -90,14 +90,12 @@ namespace xo {
|
|||
return gc.std_move_for(this);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DDefineExpr::forward_children(obj<ACollector> gc) noexcept
|
||||
void
|
||||
DDefineExpr::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
|
||||
{
|
||||
gc.forward_inplace(&lhs_var_);
|
||||
gc.visit_child(&lhs_var_);
|
||||
//gc.forward_inplace(&rhs_); // complicated - need to access via GCObject facet
|
||||
poly_forward_inplace(gc, &rhs_);
|
||||
|
||||
return this->shallow_size();
|
||||
gc.visit_poly_child(&rhs_);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -262,30 +262,22 @@ namespace xo {
|
|||
|
||||
// ----- gcobject facet -----
|
||||
|
||||
std::size_t
|
||||
DGlobalSymtab::shallow_size() const noexcept
|
||||
{
|
||||
return sizeof(DGlobalSymtab);
|
||||
}
|
||||
|
||||
DGlobalSymtab *
|
||||
DGlobalSymtab::shallow_move(obj<ACollector> gc) noexcept
|
||||
{
|
||||
return gc.std_move_for(this);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DGlobalSymtab::forward_children(obj<ACollector> gc) noexcept
|
||||
void
|
||||
DGlobalSymtab::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
|
||||
{
|
||||
// map_ doesn't contain any gc-owned data, can skip
|
||||
|
||||
static_assert(var_map_.is_gc_eligible() == false);
|
||||
static_assert(type_map_.is_gc_eligible() == false);
|
||||
|
||||
gc.forward_inplace(&vars_);
|
||||
gc.forward_inplace(&types_);
|
||||
|
||||
return this->shallow_size();
|
||||
gc.visit_child(&vars_);
|
||||
gc.visit_child(&types_);
|
||||
}
|
||||
|
||||
// ----- printable facet -----
|
||||
|
|
|
|||
|
|
@ -94,26 +94,27 @@ namespace xo {
|
|||
return gc.std_move_for(this);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DIfElseExpr::forward_children(obj<ACollector> gc) noexcept
|
||||
void
|
||||
DIfElseExpr::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
|
||||
{
|
||||
typeref_.forward_children(gc);
|
||||
typeref_.visit_gco_children(gc);
|
||||
|
||||
// GC needs to locate AGCObject iface for each member.
|
||||
{
|
||||
auto gco = test_.to_facet<AGCObject>();
|
||||
gc.forward_inplace(gco.iface(), (void **)&(test_.data_));
|
||||
gc.visit_poly_child(&test_);
|
||||
//auto gco = test_.to_facet<AGCObject>();
|
||||
//gc.forward_inplace(gco.iface(), (void **)&(test_.data_));
|
||||
}
|
||||
{
|
||||
auto gco = when_true_.to_facet<AGCObject>();
|
||||
gc.forward_inplace(gco.iface(), (void **)&(when_true_.data_));
|
||||
gc.visit_poly_child(&when_true_);
|
||||
//auto gco = when_true_.to_facet<AGCObject>();
|
||||
//gc.forward_inplace(gco.iface(), (void **)&(when_true_.data_));
|
||||
}
|
||||
{
|
||||
auto gco = when_false_.to_facet<AGCObject>();
|
||||
gc.forward_inplace(gco.iface(), (void **)&(when_false_.data_));
|
||||
gc.visit_poly_child(&when_false_);
|
||||
//auto gco = when_false_.to_facet<AGCObject>();
|
||||
//gc.forward_inplace(gco.iface(), (void **)&(when_false_.data_));
|
||||
}
|
||||
|
||||
return shallow_size();
|
||||
}
|
||||
|
||||
// ----- printable facet -----
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
namespace xo {
|
||||
using xo::mm::AGCObject;
|
||||
using xo::mm::AGCObjectVisitor;
|
||||
using xo::print::APrintable;
|
||||
using xo::facet::FacetRegistry;
|
||||
using xo::reflect::TypeDescr;
|
||||
|
|
@ -144,36 +145,32 @@ namespace xo {
|
|||
return gc.std_move_for(this);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DLambdaExpr::forward_children(obj<ACollector> gc) noexcept {
|
||||
typeref_.forward_children(gc);
|
||||
void
|
||||
DLambdaExpr::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept {
|
||||
typeref_.visit_gco_children(gc);
|
||||
|
||||
{
|
||||
//gc.forward_inplace(&name_); // doesn't compile for const ptr
|
||||
auto iface = xo::facet::impl_for<AGCObject,DUniqueString>();
|
||||
gc.forward_inplace(&iface, (void **)(&name_));
|
||||
}
|
||||
gc.visit_child(&name_);
|
||||
//{
|
||||
// auto iface = xo::facet::impl_for<AGCObject,DUniqueString>();
|
||||
// gc.forward_inplace(&iface, (void **)(&name_));
|
||||
//}
|
||||
|
||||
// type_name_str_
|
||||
|
||||
{
|
||||
gc.forward_inplace(&local_symtab_);
|
||||
//auto iface = xo::facet::impl_for<AGCObject,DLocalSymtab>();
|
||||
//gc.forward_inplace(&iface, (void **)(&local_symtab_));
|
||||
gc.visit_child(&local_symtab_);
|
||||
//gc.forward_inplace(&local_symtab_);
|
||||
}
|
||||
|
||||
{
|
||||
gc.forward_pivot_inplace(&body_expr_);
|
||||
//auto iface = body_expr_.to_facet<AGCObject>().iface();
|
||||
//gc.forward_inplace(iface, (void **)&(body_expr_.data_));
|
||||
gc.visit_poly_child(&body_expr_);
|
||||
//gc.forward_pivot_inplace(&body_expr_);
|
||||
}
|
||||
|
||||
// xxx free_var_set
|
||||
// xxx captured_var_set
|
||||
// xxx layer_var_map
|
||||
// xxx nested_lambda_map
|
||||
|
||||
return shallow_size();
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -112,26 +112,18 @@ namespace xo {
|
|||
|
||||
// ----- gcobject facet -----
|
||||
|
||||
std::size_t
|
||||
DLocalSymtab::shallow_size() const noexcept
|
||||
{
|
||||
return sizeof(DLocalSymtab);
|
||||
}
|
||||
|
||||
DLocalSymtab *
|
||||
DLocalSymtab::shallow_move(obj<ACollector> gc) noexcept
|
||||
{
|
||||
return gc.std_move_for(this);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DLocalSymtab::forward_children(obj<ACollector> gc) noexcept
|
||||
void
|
||||
DLocalSymtab::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
|
||||
{
|
||||
gc.forward_inplace(&parent_);
|
||||
gc.forward_inplace(&vars_);
|
||||
gc.forward_inplace(&types_);
|
||||
|
||||
return shallow_size();
|
||||
gc.visit_child(&parent_);
|
||||
gc.visit_child(&vars_);
|
||||
gc.visit_child(&types_);
|
||||
}
|
||||
|
||||
// ----- printable facet -----
|
||||
|
|
|
|||
|
|
@ -125,14 +125,12 @@ namespace xo {
|
|||
return gc.std_move_for(this);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DSequenceExpr::forward_children(obj<ACollector> gc) noexcept
|
||||
void
|
||||
DSequenceExpr::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
|
||||
{
|
||||
typeref_.forward_children(gc);
|
||||
typeref_.visit_gco_children(gc);
|
||||
|
||||
gc.forward_inplace(&expr_v_);
|
||||
|
||||
return this->shallow_size();
|
||||
gc.visit_child(&expr_v_);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -52,16 +52,16 @@ namespace xo {
|
|||
return gc.std_move_for(this);
|
||||
}
|
||||
|
||||
size_t
|
||||
DTypename::forward_children(obj<ACollector> gc) noexcept
|
||||
void
|
||||
DTypename::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
|
||||
{
|
||||
gc.forward_inplace(const_cast<DUniqueString**>(&name_));
|
||||
gc.visit_child(&name_);
|
||||
//gc.forward_inplace(const_cast<DUniqueString**>(&name_));
|
||||
{
|
||||
auto e = type_.to_facet<AGCObject>();
|
||||
gc.forward_inplace(e.iface(), (void **)&(type_.data_));
|
||||
gc.visit_poly_child(&type_);
|
||||
//auto e = type_.to_facet<AGCObject>();
|
||||
//gc.forward_inplace(e.iface(), (void **)&(type_.data_));
|
||||
}
|
||||
|
||||
return shallow_size();
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -70,16 +70,14 @@ namespace xo {
|
|||
return gc.std_move_for(this);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DVarRef::forward_children(obj<ACollector> gc) noexcept
|
||||
void
|
||||
DVarRef::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
|
||||
{
|
||||
gc.forward_inplace(&vardef_);
|
||||
gc.visit_child(&vardef_);
|
||||
//auto iface = xo::facet::impl_for<AGCObject,DVariable>();
|
||||
//gc.forward_inplace(&iface, (void **)vardef_.data_);
|
||||
|
||||
// TODO: concept to indicate that no gc pointers in Binding
|
||||
|
||||
return shallow_size();
|
||||
}
|
||||
|
||||
// printable facet
|
||||
|
|
|
|||
|
|
@ -50,12 +50,10 @@ namespace xo {
|
|||
return gc.std_move_for(this);
|
||||
}
|
||||
|
||||
size_t
|
||||
DVariable::forward_children(obj<ACollector> gc) noexcept
|
||||
void
|
||||
DVariable::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
|
||||
{
|
||||
typeref_.forward_children(gc);
|
||||
|
||||
return shallow_size();
|
||||
typeref_.visit_gco_children(gc);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace xo {
|
|||
return self.shallow_move(gc);
|
||||
}
|
||||
auto
|
||||
IGCObject_DApplyExpr::forward_children(DApplyExpr & self, obj<ACollector> gc) noexcept -> void
|
||||
IGCObject_DApplyExpr::visit_gco_children(DApplyExpr & self, obj<AGCObjectVisitor> fn) noexcept -> void
|
||||
{
|
||||
self.forward_children(gc);
|
||||
self.visit_gco_children(fn);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace xo {
|
|||
return self.shallow_move(gc);
|
||||
}
|
||||
auto
|
||||
IGCObject_DConstant::forward_children(DConstant & self, obj<ACollector> gc) noexcept -> void
|
||||
IGCObject_DConstant::visit_gco_children(DConstant & self, obj<AGCObjectVisitor> fn) noexcept -> void
|
||||
{
|
||||
self.forward_children(gc);
|
||||
self.visit_gco_children(fn);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace xo {
|
|||
return self.shallow_move(gc);
|
||||
}
|
||||
auto
|
||||
IGCObject_DDefineExpr::forward_children(DDefineExpr & self, obj<ACollector> gc) noexcept -> void
|
||||
IGCObject_DDefineExpr::visit_gco_children(DDefineExpr & self, obj<AGCObjectVisitor> fn) noexcept -> void
|
||||
{
|
||||
self.forward_children(gc);
|
||||
self.visit_gco_children(fn);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace xo {
|
|||
return self.shallow_move(gc);
|
||||
}
|
||||
auto
|
||||
IGCObject_DGlobalSymtab::forward_children(DGlobalSymtab & self, obj<ACollector> gc) noexcept -> void
|
||||
IGCObject_DGlobalSymtab::visit_gco_children(DGlobalSymtab & self, obj<AGCObjectVisitor> fn) noexcept -> void
|
||||
{
|
||||
self.forward_children(gc);
|
||||
self.visit_gco_children(fn);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace xo {
|
|||
return self.shallow_move(gc);
|
||||
}
|
||||
auto
|
||||
IGCObject_DIfElseExpr::forward_children(DIfElseExpr & self, obj<ACollector> gc) noexcept -> void
|
||||
IGCObject_DIfElseExpr::visit_gco_children(DIfElseExpr & self, obj<AGCObjectVisitor> fn) noexcept -> void
|
||||
{
|
||||
self.forward_children(gc);
|
||||
self.visit_gco_children(fn);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace xo {
|
|||
return self.shallow_move(gc);
|
||||
}
|
||||
auto
|
||||
IGCObject_DLambdaExpr::forward_children(DLambdaExpr & self, obj<ACollector> gc) noexcept -> void
|
||||
IGCObject_DLambdaExpr::visit_gco_children(DLambdaExpr & self, obj<AGCObjectVisitor> fn) noexcept -> void
|
||||
{
|
||||
self.forward_children(gc);
|
||||
self.visit_gco_children(fn);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace xo {
|
|||
return self.shallow_move(gc);
|
||||
}
|
||||
auto
|
||||
IGCObject_DLocalSymtab::forward_children(DLocalSymtab & self, obj<ACollector> gc) noexcept -> void
|
||||
IGCObject_DLocalSymtab::visit_gco_children(DLocalSymtab & self, obj<AGCObjectVisitor> fn) noexcept -> void
|
||||
{
|
||||
self.forward_children(gc);
|
||||
self.visit_gco_children(fn);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace xo {
|
|||
return self.shallow_move(gc);
|
||||
}
|
||||
auto
|
||||
IGCObject_DSequenceExpr::forward_children(DSequenceExpr & self, obj<ACollector> gc) noexcept -> void
|
||||
IGCObject_DSequenceExpr::visit_gco_children(DSequenceExpr & self, obj<AGCObjectVisitor> fn) noexcept -> void
|
||||
{
|
||||
self.forward_children(gc);
|
||||
self.visit_gco_children(fn);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace xo {
|
|||
return self.shallow_move(gc);
|
||||
}
|
||||
auto
|
||||
IGCObject_DTypename::forward_children(DTypename & self, obj<ACollector> gc) noexcept -> void
|
||||
IGCObject_DTypename::visit_gco_children(DTypename & self, obj<AGCObjectVisitor> fn) noexcept -> void
|
||||
{
|
||||
self.forward_children(gc);
|
||||
self.visit_gco_children(fn);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace xo {
|
|||
return self.shallow_move(gc);
|
||||
}
|
||||
auto
|
||||
IGCObject_DVarRef::forward_children(DVarRef & self, obj<ACollector> gc) noexcept -> void
|
||||
IGCObject_DVarRef::visit_gco_children(DVarRef & self, obj<AGCObjectVisitor> fn) noexcept -> void
|
||||
{
|
||||
self.forward_children(gc);
|
||||
self.visit_gco_children(fn);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -102,11 +102,11 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
TypeRef::forward_children(obj<ACollector> gc) noexcept
|
||||
TypeRef::visit_gco_children(obj<AGCObjectVisitor> gc) noexcept
|
||||
{
|
||||
//scope log(XO_DEBUG(true), xtag("type", type_.data()), xtag("type.tseq", type_._typeseq()));
|
||||
|
||||
gc.forward_pivot_inplace(&type_);
|
||||
gc.visit_poly_child(&type_);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace xo {
|
|||
return self.shallow_move(gc);
|
||||
}
|
||||
auto
|
||||
IGCObject_DVariable::forward_children(DVariable & self, obj<ACollector> gc) noexcept -> void
|
||||
IGCObject_DVariable::visit_gco_children(DVariable & self, obj<AGCObjectVisitor> fn) noexcept -> void
|
||||
{
|
||||
self.forward_children(gc);
|
||||
self.visit_gco_children(fn);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue