diff --git a/src/runtime/c/pgf/expr.cxx b/src/runtime/c/pgf/expr.cxx index 104ea1fb6..b8ea42fc6 100644 --- a/src/runtime/c/pgf/expr.cxx +++ b/src/runtime/c/pgf/expr.cxx @@ -1,7 +1,9 @@ #include "pgf/data.h" PGF_INTERNAL -uintptr_t pgf_unmarshall_literal(PgfUnmarshaller *u, PgfLiteral l) +PgfDBMarshaller db_marshaller; + +uintptr_t PgfDBMarshaller::match_lit(PgfUnmarshaller *u, uintptr_t l) { switch (ref::get_tag(l)) { case PgfLiteralInt::tag: { @@ -18,21 +20,20 @@ uintptr_t pgf_unmarshall_literal(PgfUnmarshaller *u, PgfLiteral l) } } -PGF_INTERNAL -uintptr_t pgf_unmarshall_expr(PgfUnmarshaller *u, PgfExpr e) +uintptr_t PgfDBMarshaller::match_expr(PgfUnmarshaller *u, uintptr_t e) { switch (ref::get_tag(e)) { case PgfExprAbs::tag: { auto eabs = ref::untagged(e); - uintptr_t body = pgf_unmarshall_expr(u,eabs->body); + uintptr_t body = match_expr(u,eabs->body); uintptr_t res = u->eabs(eabs->bind_type,&eabs->name,body); u->free_ref(body); return res; } case PgfExprApp::tag: { auto eapp = ref::untagged(e); - uintptr_t fun = pgf_unmarshall_expr(u,eapp->fun); - uintptr_t arg = pgf_unmarshall_expr(u,eapp->arg); + uintptr_t fun = match_expr(u,eapp->fun); + uintptr_t arg = match_expr(u,eapp->arg); uintptr_t res = u->eapp(fun,arg); u->free_ref(arg); u->free_ref(fun); @@ -40,7 +41,7 @@ uintptr_t pgf_unmarshall_expr(PgfUnmarshaller *u, PgfExpr e) } case PgfExprLit::tag: { auto elit = ref::untagged(e); - uintptr_t lit = pgf_unmarshall_literal(u,elit->lit); + uintptr_t lit = match_lit(u,elit->lit); uintptr_t res = u->elit(lit); u->free_ref(lit); return res; @@ -56,8 +57,8 @@ uintptr_t pgf_unmarshall_expr(PgfUnmarshaller *u, PgfExpr e) } case PgfExprTyped::tag: { auto etyped = ref::untagged(e); - uintptr_t expr = pgf_unmarshall_expr(u,etyped->expr); - uintptr_t type = pgf_unmarshall_type(u,etyped->type); + uintptr_t expr = match_expr(u,etyped->expr); + uintptr_t type = match_type(u,(uintptr_t) &(*etyped->type)); uintptr_t res = u->etyped(expr,type); u->free_ref(type); u->free_ref(expr); @@ -65,7 +66,7 @@ uintptr_t pgf_unmarshall_expr(PgfUnmarshaller *u, PgfExpr e) } case PgfExprImplArg::tag: { auto eimpl = ref::untagged(e); - uintptr_t expr = pgf_unmarshall_expr(u,eimpl->expr); + uintptr_t expr = match_expr(u,eimpl->expr); uintptr_t res = u->eimplarg(expr); u->free_ref(expr); return res; @@ -76,20 +77,22 @@ uintptr_t pgf_unmarshall_expr(PgfUnmarshaller *u, PgfExpr e) } PGF_INTERNAL -uintptr_t pgf_unmarshall_type(PgfUnmarshaller *u, PgfType *tp) +uintptr_t PgfDBMarshaller::match_type(PgfUnmarshaller *u, uintptr_t ty) { + PgfType *tp = (PgfType *) ty; + PgfTypeHypo *hypos = (PgfTypeHypo *) alloca(tp->hypos->len * sizeof(PgfTypeHypo)); for (size_t i = 0; i < tp->hypos->len; i++) { hypos[i].bind_type = tp->hypos->data[i].bind_type; hypos[i].cid = &(*tp->hypos->data[i].cid); - hypos[i].type = pgf_unmarshall_type(u, tp->hypos->data[i].type); + hypos[i].type = match_type(u, (uintptr_t) &(*tp->hypos->data[i].type)); } uintptr_t *exprs = (uintptr_t *) alloca(tp->exprs->len * sizeof(uintptr_t)); for (size_t i = 0; i < tp->exprs->len; i++) { - exprs[i] = pgf_unmarshall_expr(u, tp->exprs->data[i]); + exprs[i] = match_expr(u, tp->exprs->data[i]); } uintptr_t res = u->dtyp(tp->hypos->len, hypos, diff --git a/src/runtime/c/pgf/expr.h b/src/runtime/c/pgf/expr.h index bfcfeb143..39064e8db 100644 --- a/src/runtime/c/pgf/expr.h +++ b/src/runtime/c/pgf/expr.h @@ -99,14 +99,13 @@ typedef struct { PgfExpr expr; } PgfExprProb; -PGF_INTERNAL_DECL -uintptr_t pgf_unmarshall_literal(PgfUnmarshaller *u, PgfLiteral l); +struct PgfDBMarshaller : public PgfMarshaller { + virtual uintptr_t match_lit(PgfUnmarshaller *u, uintptr_t l); + virtual uintptr_t match_expr(PgfUnmarshaller *u, uintptr_t e); + virtual uintptr_t match_type(PgfUnmarshaller *u, uintptr_t tp); +}; -PGF_INTERNAL_DECL -uintptr_t pgf_unmarshall_expr(PgfUnmarshaller *u, PgfExpr e); - -PGF_INTERNAL_DECL -uintptr_t pgf_unmarshall_type(PgfUnmarshaller *u, PgfType *tp); +extern PGF_INTERNAL_DECL PgfDBMarshaller db_marshaller; typedef struct PgfBind { PgfBindType bind_type; diff --git a/src/runtime/c/pgf/pgf.cxx b/src/runtime/c/pgf/pgf.cxx index a68541b4f..4e245d2c6 100644 --- a/src/runtime/c/pgf/pgf.cxx +++ b/src/runtime/c/pgf/pgf.cxx @@ -217,7 +217,7 @@ PgfTypeHypo *pgf_category_context(PgfPGF *pgf, PgfText *catname, size_t *n_hypos for (size_t i = 0; i < abscat->context->len; i++) { hypos[i].bind_type = abscat->context->data[i].bind_type; hypos[i].cid = textdup(abscat->context->data[i].cid); - hypos[i].type = pgf_unmarshall_type(u, abscat->context->data[i].type); + hypos[i].type = db_marshaller.match_type(u, (uintptr_t) &(*abscat->context->data[i].type)); } *n_hypos = abscat->context->len; @@ -283,7 +283,7 @@ uintptr_t pgf_function_type(PgfPGF *pgf, PgfText *funname, PgfUnmarshaller *u) if (absfun == 0) return 0; - return pgf_unmarshall_type(u, absfun->type); + return db_marshaller.match_type(u, (uintptr_t) &(*absfun->type)); } PGF_API