diff --git a/src/runtime/c/pgf/generator.cxx b/src/runtime/c/pgf/generator.cxx index 4dc8d211d..0e864b0b8 100644 --- a/src/runtime/c/pgf/generator.cxx +++ b/src/runtime/c/pgf/generator.cxx @@ -2,16 +2,86 @@ #include "data.h" #include "generator.h" +PgfExpr PgfGenerator::eabs(PgfBindType btype, PgfText *name, PgfExpr body) +{ + body = m->match_expr(this, body); + return u->eabs(btype, name, body); +} + +PgfExpr PgfGenerator::eapp(PgfExpr fun, PgfExpr arg) +{ + fun = m->match_expr(this, fun); + arg = m->match_expr(this, arg); + return u->eapp(fun, arg); +} + +PgfExpr PgfGenerator::elit(PgfLiteral lit) +{ + lit = m->match_lit(this, lit); + return u->elit(lit); +} + +PgfExpr PgfGenerator::emeta(PgfMetaId meta) +{ + return u->emeta(meta); +} + +PgfExpr PgfGenerator::efun(PgfText *name) +{ + return u->efun(name); +} + +PgfExpr PgfGenerator::evar(int index) +{ + return u->evar(index); +} + +PgfExpr PgfGenerator::etyped(PgfExpr expr, PgfType typ) +{ + expr = m->match_expr(this, expr); + typ = m->match_type(u, typ); + return u->etyped(expr, typ); +} + +PgfExpr PgfGenerator::eimplarg(PgfExpr expr) +{ + expr = m->match_expr(this, expr); + return u->eimplarg(expr); +} + +PgfLiteral PgfGenerator::lint(size_t size, uintmax_t *v) +{ + return u->lint(size,v); +} + +PgfLiteral PgfGenerator::lflt(double v) +{ + return u->lflt(v); +} + +PgfLiteral PgfGenerator::lstr(PgfText *v) +{ + return u->lstr(v); +} + +PgfType PgfGenerator::dtyp(size_t n_hypos, PgfTypeHypo *hypos, + PgfText *cat, + size_t n_exprs, PgfExpr *exprs) +{ + return u->dtyp(n_hypos, hypos, cat, n_exprs, exprs); +} + +void PgfGenerator::free_ref(object o) +{ + u->free_ref(o); +} PgfRandomGenerator::PgfRandomGenerator(ref pgf, size_t depth, uint64_t *seed, PgfMarshaller *m, PgfUnmarshaller *u) + : PgfGenerator(pgf,depth,m,u) { - this->pgf = pgf; - this->depth = depth; this->seed = seed; - this->m = m; - this->u = u; this->prob = 0; this->scope = NULL; this->scope_len = 0; @@ -21,68 +91,6 @@ PgfRandomGenerator::~PgfRandomGenerator() { } -PgfExpr PgfRandomGenerator::eabs(PgfBindType btype, PgfText *name, PgfExpr body) -{ - body = m->match_expr(this, body); - return u->eabs(btype, name, body); -} - -PgfExpr PgfRandomGenerator::eapp(PgfExpr fun, PgfExpr arg) -{ - fun = m->match_expr(this, fun); - arg = m->match_expr(this, arg); - return u->eapp(fun, arg); -} - -PgfExpr PgfRandomGenerator::elit(PgfLiteral lit) -{ - lit = m->match_lit(this, lit); - return u->elit(lit); -} - -PgfExpr PgfRandomGenerator::emeta(PgfMetaId meta) -{ - return 0; -} - -PgfExpr PgfRandomGenerator::efun(PgfText *name) -{ - return u->efun(name); -} - -PgfExpr PgfRandomGenerator::evar(int index) -{ - return u->evar(index); -} - -PgfExpr PgfRandomGenerator::etyped(PgfExpr expr, PgfType typ) -{ - expr = m->match_expr(this, expr); - typ = m->match_type(u, typ); - return u->etyped(expr, typ); -} - -PgfExpr PgfRandomGenerator::eimplarg(PgfExpr expr) -{ - expr = m->match_expr(this, expr); - return u->eimplarg(expr); -} - -PgfLiteral PgfRandomGenerator::lint(size_t size, uintmax_t *v) -{ - return u->lint(size,v); -} - -PgfLiteral PgfRandomGenerator::lflt(double v) -{ - return u->lflt(v); -} - -PgfLiteral PgfRandomGenerator::lstr(PgfText *v) -{ - return u->lstr(v); -} - class PGF_INTERNAL_DECL PgfVarGenerator : public PgfDBUnmarshaller { size_t index; @@ -160,11 +168,11 @@ again: { PgfVarGenerator v_gen(this, index, cat, n_exprs, exprs); expr = m->match_type(&v_gen, sc->type); if (expr != 0) { - if (rand() < Scope::VAR_PROB) { - prob += -log(Scope::VAR_PROB); + if (rand() < VAR_PROB) { + prob += -log(VAR_PROB); break; } else { - prob += -log(1-Scope::VAR_PROB); + prob += -log(1-VAR_PROB); if (var_expr != 0) u->free_ref(var_expr); var_expr = expr; @@ -200,7 +208,7 @@ again: { ref fun = probspace_random(pgf->abstract.funs_by_cat, cat, rand_value); if (fun == 0) { if (var_expr != 0) { - prob += -log(Scope::VAR_PROB/(1-Scope::VAR_PROB)); + prob += -log(VAR_PROB/(1-VAR_PROB)); expr = var_expr; } } else { @@ -239,11 +247,6 @@ again: { return expr; } -void PgfRandomGenerator::free_ref(object x) -{ - u->free_ref(x); -} - PgfExpr PgfRandomGenerator::descend(PgfExpr expr, size_t n_hypos, PgfTypeHypo *hypos) { @@ -278,70 +281,12 @@ PgfExpr PgfRandomGenerator::descend(PgfExpr expr, PgfExhaustiveGenerator::PgfExhaustiveGenerator(ref pgf, size_t depth, PgfMarshaller *m, PgfUnmarshaller *u) + : PgfGenerator(pgf,depth,m,u) { - this->pgf = pgf; - this->depth = depth; - this->m = m; - this->u = u; this->top_res = NULL; this->top_res_index = 0; } -PgfExpr PgfExhaustiveGenerator::eabs(PgfBindType btype, PgfText *name, PgfExpr body) -{ - return 0; -} - -PgfExpr PgfExhaustiveGenerator::eapp(PgfExpr fun, PgfExpr arg) -{ - return 0; -} - -PgfExpr PgfExhaustiveGenerator::elit(PgfLiteral lit) -{ - return 0; -} - -PgfExpr PgfExhaustiveGenerator::emeta(PgfMetaId meta) -{ - return 0; -} - -PgfExpr PgfExhaustiveGenerator::efun(PgfText *name) -{ - return 0; -} - -PgfExpr PgfExhaustiveGenerator::evar(int index) -{ - return 0; -} - -PgfExpr PgfExhaustiveGenerator::etyped(PgfExpr expr, PgfType typ) -{ - return 0; -} - -PgfExpr PgfExhaustiveGenerator::eimplarg(PgfExpr expr) -{ - return 0; -} - -PgfLiteral PgfExhaustiveGenerator::lint(size_t size, uintmax_t *v) -{ - return 0; -} - -PgfLiteral PgfExhaustiveGenerator::lflt(double v) -{ - return 0; -} - -PgfLiteral PgfExhaustiveGenerator::lstr(PgfText *v) -{ - return 0; -} - void PgfExhaustiveGenerator::push_left_states(PgfProbspace space, PgfText *cat, Result *res, prob_t outside_prob) { while (space != 0) { @@ -384,12 +329,12 @@ PgfType PgfExhaustiveGenerator::dtyp(size_t n_hypos, PgfTypeHypo *hypos, } top_res = res; - predict_literal(g.first, res, u); + predict_literal(g.first, res); push_left_states(pgf->abstract.funs_by_cat, cat, top_res, 0); return 0; } -void PgfExhaustiveGenerator::predict_literal(ref cat, Result *res, PgfUnmarshaller *u) +void PgfExhaustiveGenerator::predict_literal(ref cat, Result *res) { PgfExpr expr; if (strcmp(cat->text, "Int") == 0) { @@ -416,14 +361,10 @@ void PgfExhaustiveGenerator::predict_literal(ref cat, Result *res, PgfU res->exprs.push_back(std::pair(expr,0)); for (State1 *state : res->states) { - state->combine(this,res->scope,expr,0,u); + state->combine(this,res->scope,expr,0); } } -void PgfExhaustiveGenerator::free_ref(object x) -{ -} - void PgfExhaustiveGenerator::State::free_refs(PgfUnmarshaller *u) { } @@ -444,14 +385,14 @@ void PgfExhaustiveGenerator::State::release(State *state, PgfUnmarshaller *u) delete state; } -bool PgfExhaustiveGenerator::State0::process(PgfExhaustiveGenerator *gen, PgfUnmarshaller *u) +bool PgfExhaustiveGenerator::State0::process(PgfExhaustiveGenerator *gen) { ref fun = space->value.fun; prob_t outside_prob = this->prob-fun->prob; gen->push_left_states(space->right, &(*space->value.cat), res, outside_prob); - PgfExpr expr = u->efun(&fun->name); + PgfExpr expr = gen->u->efun(&fun->name); res->ref_count++; @@ -462,17 +403,17 @@ bool PgfExhaustiveGenerator::State0::process(PgfExhaustiveGenerator *gen, PgfUnm state->n_args = 0; state->expr = expr; - if (state->process(gen, u)) { - State::release(state,u); + if (state->process(gen)) { + State::release(state,gen->u); } return true; } -bool PgfExhaustiveGenerator::State1::process(PgfExhaustiveGenerator *gen, PgfUnmarshaller *u) +bool PgfExhaustiveGenerator::State1::process(PgfExhaustiveGenerator *gen) { if (n_args >= type->hypos->len) { - complete(gen, u); + complete(gen); return true; } @@ -524,13 +465,13 @@ again: { if (textcmp(&type->name, g.first) == 0) { State1 *var_state = new State1(); var_state->res = arg_res; - var_state->prob = outside_prob - log(Scope::VAR_PROB); + var_state->prob = outside_prob - log(VAR_PROB); var_state->type = type; var_state->n_args = 0; - var_state->expr = u->evar(index); + var_state->expr = gen->u->evar(index); gen->queue.push(var_state); - outside_prob += -log(1-Scope::VAR_PROB); + outside_prob += -log(1-VAR_PROB); } index++; @@ -538,13 +479,13 @@ again: { } // predict literals - gen->predict_literal(g.first, arg_res, u); + gen->predict_literal(g.first, arg_res); // predict global functions gen->push_left_states(gen->pgf->abstract.funs_by_cat, g.first, arg_res, outside_prob); } else { for (std::pair p : arg_res->exprs) { - this->combine(gen,arg_res->scope,p.first,p.second,u); + this->combine(gen,arg_res->scope,p.first,p.second); } } @@ -552,15 +493,14 @@ again: { } void PgfExhaustiveGenerator::State1::combine(PgfExhaustiveGenerator *gen, - Scope *scope, PgfExpr expr, prob_t prob, - PgfUnmarshaller *u) + Scope *scope, PgfExpr expr, prob_t prob) { Scope *s = scope; while (s != res->scope) { - PgfExpr abs = u->eabs(s->bind_type, &s->var, expr); + PgfExpr abs = gen->u->eabs(s->bind_type, &s->var, expr); if (s != scope) { // if expr is a lambda created in the previous iteration - u->free_ref(expr); + gen->u->free_ref(expr); } expr = abs; s = s->next; @@ -569,19 +509,19 @@ void PgfExhaustiveGenerator::State1::combine(PgfExhaustiveGenerator *gen, PgfBindType bind_type = vector_elem(type->hypos, n_args)->bind_type; if (bind_type == PGF_BIND_TYPE_IMPLICIT) { - PgfExpr implarg = u->eimplarg(expr); + PgfExpr implarg = gen->u->eimplarg(expr); if (scope != res->scope) { // if expr is a lambda created in the previous loop - u->free_ref(expr); + gen->u->free_ref(expr); } expr = implarg; } - PgfExpr app = u->eapp(this->expr, expr); + PgfExpr app = gen->u->eapp(this->expr, expr); if (bind_type == PGF_BIND_TYPE_IMPLICIT || scope != res->scope) { // if expr is either a lambda or an implicit argument - u->free_ref(expr); + gen->u->free_ref(expr); } res->ref_count++; @@ -595,7 +535,7 @@ void PgfExhaustiveGenerator::State1::combine(PgfExhaustiveGenerator *gen, gen->queue.push(app_state); } -void PgfExhaustiveGenerator::State1::complete(PgfExhaustiveGenerator *gen, PgfUnmarshaller *u) +void PgfExhaustiveGenerator::State1::complete(PgfExhaustiveGenerator *gen) { prob_t outside_prob; if (res == gen->top_res) @@ -606,7 +546,7 @@ void PgfExhaustiveGenerator::State1::complete(PgfExhaustiveGenerator *gen, PgfUn prob_t inside_prob = prob-outside_prob; res->exprs.push_back(std::pair(expr,inside_prob)); for (State1 *state : res->states) { - state->combine(gen,res->scope,expr,inside_prob,u); + state->combine(gen,res->scope,expr,inside_prob); } } @@ -615,7 +555,7 @@ void PgfExhaustiveGenerator::State1::free_refs(PgfUnmarshaller *u) u->free_ref(expr); } -PgfExpr PgfExhaustiveGenerator::fetch(PgfDB *db, PgfUnmarshaller *u, prob_t *prob) +PgfExpr PgfExhaustiveGenerator::fetch(PgfDB *db, prob_t *prob) { DB_scope scope(db, READER_SCOPE); @@ -634,13 +574,13 @@ PgfExpr PgfExhaustiveGenerator::fetch(PgfDB *db, PgfUnmarshaller *u, prob_t *pro State *state = queue.top(); queue.pop(); - if (state->process(this, u)) { + if (state->process(this)) { State::release(state, u); } } } -void PgfExhaustiveGenerator::free_refs(PgfUnmarshaller *u) +PgfExhaustiveGenerator::~PgfExhaustiveGenerator() { while (!queue.empty()) { State *state = queue.top(); queue.pop(); @@ -653,10 +593,7 @@ void PgfExhaustiveGenerator::free_refs(PgfUnmarshaller *u) free_ref(j.first); } } -} -PgfExhaustiveGenerator::~PgfExhaustiveGenerator() -{ while (!scopes.empty()) { Scope *scope = scopes.back(); scopes.pop_back(); delete scope; diff --git a/src/runtime/c/pgf/generator.h b/src/runtime/c/pgf/generator.h index 64c737860..fb01aa95d 100644 --- a/src/runtime/c/pgf/generator.h +++ b/src/runtime/c/pgf/generator.h @@ -1,42 +1,37 @@ #ifndef GENERATOR_H #define GENERATOR_H -struct PGF_INTERNAL_DECL Scope { +class PGF_INTERNAL_DECL PgfGenerator : public PgfUnmarshaller +{ +protected: constexpr static prob_t VAR_PROB = 0.1; - Scope *next; - PgfType type; - PgfMarshaller *m; - PgfBindType bind_type; - PgfText var; -}; + struct Scope { + + Scope *next; + PgfType type; + PgfMarshaller *m; + PgfBindType bind_type; + PgfText var; + }; -class PGF_INTERNAL_DECL PgfRandomGenerator : public PgfUnmarshaller -{ ref pgf; size_t depth; - uint64_t *seed; - prob_t prob; PgfMarshaller *m; PgfInternalMarshaller i_m; PgfUnmarshaller *u; - Scope *scope; - size_t scope_len; - - prob_t rand() { - *seed = *seed * 1103515245 + 12345; - return (prob_t)((*seed/65536) % 32768)/32768; + PgfGenerator(ref pgf, + size_t depth, + PgfMarshaller *m, PgfUnmarshaller *u) + { + this->pgf = pgf; + this->depth = depth; + this->m = m; + this->u = u; } public: - PgfRandomGenerator(ref pgf, size_t depth, uint64_t *seed, - PgfMarshaller *m, PgfUnmarshaller *u); - prob_t getProb() { return prob; } - ~PgfRandomGenerator(); - - PgfExpr descend(PgfExpr expr, size_t n_hypos, PgfTypeHypo *hypos); - virtual PgfExpr eabs(PgfBindType btype, PgfText *name, PgfExpr body); virtual PgfExpr eapp(PgfExpr fun, PgfExpr arg); virtual PgfExpr elit(PgfLiteral lit); @@ -54,29 +49,50 @@ public: virtual void free_ref(object x); }; -class PGF_INTERNAL_DECL PgfExhaustiveGenerator : public PgfUnmarshaller, public PgfExprEnum +class PGF_INTERNAL_DECL PgfRandomGenerator : public PgfGenerator +{ + uint64_t *seed; + prob_t prob; + + Scope *scope; + size_t scope_len; + + prob_t rand() { + *seed = *seed * 1103515245 + 12345; + return (prob_t)((*seed/65536) % 32768)/32768; + } + +public: + PgfRandomGenerator(ref pgf, size_t depth, uint64_t *seed, + PgfMarshaller *m, PgfUnmarshaller *u); + prob_t getProb() { return prob; } + ~PgfRandomGenerator(); + + PgfExpr descend(PgfExpr expr, size_t n_hypos, PgfTypeHypo *hypos); + + virtual PgfType dtyp(size_t n_hypos, PgfTypeHypo *hypos, + PgfText *cat, + size_t n_exprs, PgfExpr *exprs); +}; + +class PGF_INTERNAL_DECL PgfExhaustiveGenerator : public PgfGenerator, public PgfExprEnum { struct Result; - ref pgf; - size_t depth; - PgfMarshaller *m; - PgfUnmarshaller *u; - PgfInternalMarshaller i_m; Result *top_res; size_t top_res_index; struct State { Result *res; prob_t prob; - virtual bool process(PgfExhaustiveGenerator *gen, PgfUnmarshaller *u) = 0; + virtual bool process(PgfExhaustiveGenerator *gen) = 0; virtual void free_refs(PgfUnmarshaller *u); static void release(State *state, PgfUnmarshaller *u); }; struct State0 : State { PgfProbspace space; - virtual bool process(PgfExhaustiveGenerator *gen, PgfUnmarshaller *u); + virtual bool process(PgfExhaustiveGenerator *gen); }; struct State1 : State { @@ -84,12 +100,11 @@ class PGF_INTERNAL_DECL PgfExhaustiveGenerator : public PgfUnmarshaller, public size_t n_args; PgfExpr expr; - virtual bool process(PgfExhaustiveGenerator *gen, PgfUnmarshaller *u); + virtual bool process(PgfExhaustiveGenerator *gen); virtual void free_refs(PgfUnmarshaller *u); void combine(PgfExhaustiveGenerator *gen, - Scope *scope, PgfExpr expr, prob_t prob, - PgfUnmarshaller *u); - void complete(PgfExhaustiveGenerator *gen, PgfUnmarshaller *u); + Scope *scope, PgfExpr expr, prob_t prob); + void complete(PgfExhaustiveGenerator *gen); }; typedef std::pair,Scope*> Goal; @@ -125,7 +140,7 @@ class PGF_INTERNAL_DECL PgfExhaustiveGenerator : public PgfUnmarshaller, public std::priority_queue, CompareState> queue; std::vector scopes; - void predict_literal(ref cat, Result *res, PgfUnmarshaller *u); + void predict_literal(ref cat, Result *res); void push_left_states(PgfProbspace space, PgfText *cat, Result *res, prob_t outside_prob); public: @@ -133,24 +148,11 @@ public: PgfMarshaller *m, PgfUnmarshaller *u); virtual ~PgfExhaustiveGenerator(); - virtual PgfExpr eabs(PgfBindType btype, PgfText *name, PgfExpr body); - virtual PgfExpr eapp(PgfExpr fun, PgfExpr arg); - virtual PgfExpr elit(PgfLiteral lit); - virtual PgfExpr emeta(PgfMetaId meta); - virtual PgfExpr efun(PgfText *name); - virtual PgfExpr evar(int index); - virtual PgfExpr etyped(PgfExpr expr, PgfType typ); - virtual PgfExpr eimplarg(PgfExpr expr); - virtual PgfLiteral lint(size_t size, uintmax_t *v); - virtual PgfLiteral lflt(double v); - virtual PgfLiteral lstr(PgfText *v); virtual PgfType dtyp(size_t n_hypos, PgfTypeHypo *hypos, PgfText *cat, size_t n_exprs, PgfExpr *exprs); - virtual void free_ref(object x); - virtual PgfExpr fetch(PgfDB *db, PgfUnmarshaller *u, prob_t *prob); - virtual void free_refs(PgfUnmarshaller *u); + virtual PgfExpr fetch(PgfDB *db, prob_t *prob); }; #endif diff --git a/src/runtime/c/pgf/parser.cxx b/src/runtime/c/pgf/parser.cxx index 7a21a46f1..2f5f3236c 100644 --- a/src/runtime/c/pgf/parser.cxx +++ b/src/runtime/c/pgf/parser.cxx @@ -666,7 +666,8 @@ void PgfParser::Production::trace(PgfParser::Choice *res) { #endif } -PgfParser::PgfParser(ref concr, ref start, PgfText *sentence, PgfMarshaller *m) +PgfParser::PgfParser(ref concr, ref start, PgfText *sentence, + PgfMarshaller *m, PgfUnmarshaller *u) { this->concr = concr; this->start = start; @@ -675,6 +676,7 @@ PgfParser::PgfParser(ref concr, ref start, PgfText *se this->before = NULL; this->after = NULL; this->m = m; + this->u = u; } void PgfParser::space(PgfTextSpot *start, PgfTextSpot *end, PgfExn* err) @@ -769,7 +771,7 @@ void PgfParser::prepare() before = after; } -PgfExpr PgfParser::fetch(PgfDB *db, PgfUnmarshaller *u, prob_t *prob) +PgfExpr PgfParser::fetch(PgfDB *db, prob_t *prob) { DB_scope scope(db, READER_SCOPE); @@ -794,10 +796,6 @@ PgfExpr PgfParser::fetch(PgfDB *db, PgfUnmarshaller *u, prob_t *prob) return 0; } -void PgfParser::free_refs(PgfUnmarshaller *u) -{ -} - PgfParser::~PgfParser() { free(sentence); diff --git a/src/runtime/c/pgf/parser.h b/src/runtime/c/pgf/parser.h index 91b9af572..8adc93b03 100644 --- a/src/runtime/c/pgf/parser.h +++ b/src/runtime/c/pgf/parser.h @@ -3,7 +3,7 @@ class PGF_INTERNAL_DECL PgfParser : public PgfPhraseScanner, public PgfExprEnum { public: - PgfParser(ref concr, ref start, PgfText *sentence, PgfMarshaller *m); + PgfParser(ref concr, ref start, PgfText *sentence, PgfMarshaller *m, PgfUnmarshaller *u); void space(PgfTextSpot *start, PgfTextSpot *end, PgfExn* err); void start_matches(PgfTextSpot *end, PgfExn* err); @@ -11,9 +11,8 @@ public: void end_matches(PgfTextSpot *end, PgfExn* err); void prepare(); - PgfExpr fetch(PgfDB *db, PgfUnmarshaller *u, prob_t *prob); + PgfExpr fetch(PgfDB *db, prob_t *prob); - virtual void free_refs(PgfUnmarshaller *u); virtual ~PgfParser(); private: @@ -54,6 +53,7 @@ private: State *before, *after; PgfMarshaller *m; + PgfUnmarshaller *u; }; #endif diff --git a/src/runtime/c/pgf/pgf.cxx b/src/runtime/c/pgf/pgf.cxx index 2cf1f1f43..16fc140d0 100644 --- a/src/runtime/c/pgf/pgf.cxx +++ b/src/runtime/c/pgf/pgf.cxx @@ -2635,7 +2635,7 @@ struct PGF_INTERNAL_DECL PgfLincatUnmarshaller : PgfUnmarshaller { PGF_API PgfExprEnum *pgf_parse(PgfDB *db, PgfConcrRevision revision, - PgfType ty, PgfMarshaller *m, + PgfType ty, PgfMarshaller *m, PgfUnmarshaller *u, PgfText *sentence, PgfExn * err) { @@ -2646,12 +2646,12 @@ PgfExprEnum *pgf_parse(PgfDB *db, PgfConcrRevision revision, bool case_sensitive = pgf_is_case_sensitive(concr); - PgfLincatUnmarshaller u(concr); - m->match_type(&u, ty); - if (u.lincat == 0) + PgfLincatUnmarshaller lincat_u(concr); + m->match_type(&lincat_u, ty); + if (lincat_u.lincat == 0) return 0; - PgfParser *parser = new PgfParser(concr, u.lincat, sentence, m); + PgfParser *parser = new PgfParser(concr, lincat_u.lincat, sentence, m, u); phrasetable_lookup_cohorts(concr->phrasetable, sentence, case_sensitive, parser, err); @@ -2663,9 +2663,8 @@ PgfExprEnum *pgf_parse(PgfDB *db, PgfConcrRevision revision, } PGF_API -void pgf_free_expr_enum(PgfUnmarshaller *u, PgfExprEnum *en) +void pgf_free_expr_enum(PgfExprEnum *en) { - en->free_refs(u); delete en; } diff --git a/src/runtime/c/pgf/pgf.h b/src/runtime/c/pgf/pgf.h index 204649c57..a358411e0 100644 --- a/src/runtime/c/pgf/pgf.h +++ b/src/runtime/c/pgf/pgf.h @@ -526,15 +526,14 @@ PgfExpr pgf_generate_random_from #ifdef __cplusplus struct PgfExprEnum { - virtual PgfExpr fetch(PgfDB *db, PgfUnmarshaller *u, prob_t *prob)=0; - virtual void free_refs(PgfUnmarshaller *u)=0; + virtual PgfExpr fetch(PgfDB *db, prob_t *prob)=0; virtual ~PgfExprEnum() {}; }; #else typedef struct PgfExprEnum PgfExprEnum; typedef struct PgfExprEnumVtbl PgfExprEnumVtbl; struct PgfExprEnumVtbl { - PgfExpr (*fetch)(PgfExprEnum *this, PgfDB *db, PgfUnmarshaller *u, prob_t *prob); + PgfExpr (*fetch)(PgfExprEnum *this, PgfDB *db, prob_t *prob); }; struct PgfExprEnum { PgfExprEnumVtbl *vtbl; @@ -784,12 +783,12 @@ void pgf_bracketed_linearize_all(PgfDB *db, PgfConcrRevision revision, PGF_API_DECL PgfExprEnum *pgf_parse(PgfDB *db, PgfConcrRevision revision, - PgfType ty, PgfMarshaller *m, + PgfType ty, PgfMarshaller *m, PgfUnmarshaller *u, PgfText *sentence, PgfExn * err); PGF_API_DECL -void pgf_free_expr_enum(PgfUnmarshaller *u, PgfExprEnum *en); +void pgf_free_expr_enum(PgfExprEnum *en); PGF_API_DECL PgfText *pgf_get_printname(PgfDB *db, PgfConcrRevision revision, diff --git a/src/runtime/haskell/PGF2.hsc b/src/runtime/haskell/PGF2.hsc index 4b4cbcf84..0edb87fd7 100644 --- a/src/runtime/haskell/PGF2.hsc +++ b/src/runtime/haskell/PGF2.hsc @@ -702,14 +702,14 @@ parse c ty sent = return (ParseOk exprs) enumerateExprs c_db c_enum_ptr = do - c_enum <- newForeignPtrEnv pgf_free_expr_enum unmarshaller c_enum_ptr + c_enum <- newForeignPtr pgf_free_expr_enum c_enum_ptr c_fetch <- (#peek PgfExprEnumVtbl, fetch) =<< (#peek PgfExprEnum, vtbl) c_enum_ptr unsafeInterleaveIO (fetchLazy c_fetch c_enum) where fetchLazy c_fetch c_enum = withForeignPtr c_enum $ \c_enum_ptr -> alloca $ \p_prob -> do - c_expr <- callFetch c_fetch c_enum_ptr c_db unmarshaller p_prob + c_expr <- callFetch c_fetch c_enum_ptr c_db p_prob if c_expr == castPtrToStablePtr nullPtr then do return [] else do expr <- deRefStablePtr c_expr diff --git a/src/runtime/haskell/PGF2/FFI.hsc b/src/runtime/haskell/PGF2/FFI.hsc index fc606e20d..9c20a0bf8 100644 --- a/src/runtime/haskell/PGF2/FFI.hsc +++ b/src/runtime/haskell/PGF2/FFI.hsc @@ -269,9 +269,9 @@ foreign import ccall pgf_align_words :: Ptr PgfDB -> Ptr Concr -> StablePtr Expr foreign import ccall pgf_parse :: Ptr PgfDB -> Ptr Concr -> StablePtr Type -> Ptr PgfMarshaller -> Ptr PgfText -> Ptr PgfExn -> IO (Ptr PgfExprEnum) -foreign import ccall "dynamic" callFetch :: Dynamic (Ptr PgfExprEnum -> Ptr PgfDB -> Ptr PgfUnmarshaller -> Ptr (#type prob_t) -> IO (StablePtr Expr)) +foreign import ccall "dynamic" callFetch :: Dynamic (Ptr PgfExprEnum -> Ptr PgfDB -> Ptr (#type prob_t) -> IO (StablePtr Expr)) -foreign import ccall "&pgf_free_expr_enum" pgf_free_expr_enum :: FunPtr (Ptr PgfUnmarshaller -> Ptr PgfExprEnum -> IO ()) +foreign import ccall "&pgf_free_expr_enum" pgf_free_expr_enum :: FunPtr (Ptr PgfExprEnum -> IO ()) foreign import ccall "wrapper" wrapSymbol0 :: Wrapper (Ptr PgfLinearizationOutputIface -> IO ())