diff --git a/src/runtime/c/pgf/generator.cxx b/src/runtime/c/pgf/generator.cxx index 0a6254db6..4dc8d211d 100644 --- a/src/runtime/c/pgf/generator.cxx +++ b/src/runtime/c/pgf/generator.cxx @@ -282,55 +282,9 @@ PgfExhaustiveGenerator::PgfExhaustiveGenerator(ref pgf, this->pgf = pgf; this->depth = depth; this->m = m; + this->u = u; this->top_res = NULL; this->top_res_index = 0; - - PgfText *text_Int = string2text("Int"); - ref cat_Int = - namespace_lookup(pgf->abstract.cats, text_Int); - free(text_Int); - if (cat_Int != 0) { - uintmax_t value = 999; - PgfLiteral lint = u->lint(1,&value); - PgfExpr expr = u->elit(lint); - u->free_ref(lint); - Goal g(ref::from_ptr(&cat_Int->name),NULL); - Result *res = new Result(); - res->exprs.push_back(std::pair(expr,0)); - results[g] = res; - } - - PgfText *text_Float = string2text("Float"); - ref cat_Float = - namespace_lookup(pgf->abstract.cats, text_Float); - free(text_Float); - if (cat_Float != 0) { - PgfLiteral lflt = u->lflt(3.14); - PgfExpr expr = u->elit(lflt); - u->free_ref(lflt); - Goal g(ref::from_ptr(&cat_Float->name),NULL); - Result *res = new Result(); - res->exprs.push_back(std::pair(expr,0)); - results[g] = res; - } - - PgfText *text_String = string2text("String"); - ref cat_String = - namespace_lookup(pgf->abstract.cats, text_String); - free(text_String); - if (cat_String != 0) { - PgfText *value = (PgfText *) alloca(sizeof(PgfText)+4); - value->size = 3; - strcpy(value->text, "Foo"); - - PgfLiteral lstr = u->lstr(value); - PgfExpr expr = u->elit(lstr); - u->free_ref(lstr); - Goal g(ref::from_ptr(&cat_String->name),NULL); - Result *res = new Result(); - res->exprs.push_back(std::pair(expr,0)); - results[g] = res; - } } PgfExpr PgfExhaustiveGenerator::eabs(PgfBindType btype, PgfText *name, PgfExpr body) @@ -430,10 +384,42 @@ PgfType PgfExhaustiveGenerator::dtyp(size_t n_hypos, PgfTypeHypo *hypos, } top_res = res; + predict_literal(g.first, res, u); push_left_states(pgf->abstract.funs_by_cat, cat, top_res, 0); return 0; } +void PgfExhaustiveGenerator::predict_literal(ref cat, Result *res, PgfUnmarshaller *u) +{ + PgfExpr expr; + if (strcmp(cat->text, "Int") == 0) { + uintmax_t value = 999; + PgfLiteral lint = u->lint(1,&value); + expr = u->elit(lint); + u->free_ref(lint); + } else if (strcmp(cat->text, "Float") == 0) { + PgfLiteral lflt = u->lflt(3.14); + expr = u->elit(lflt); + u->free_ref(lflt); + } else if (strcmp(cat->text, "String") == 0) { + PgfText *value = (PgfText *) alloca(sizeof(PgfText)+4); + value->size = 3; + strcpy(value->text, "Foo"); + + PgfLiteral lstr = u->lstr(value); + expr = u->elit(lstr); + u->free_ref(lstr); + } else { + return; + } + + res->exprs.push_back(std::pair(expr,0)); + + for (State1 *state : res->states) { + state->combine(this,res->scope,expr,0,u); + } +} + void PgfExhaustiveGenerator::free_ref(object x) { } @@ -551,6 +537,9 @@ again: { s = s->next; } + // predict literals + gen->predict_literal(g.first, arg_res, u); + // predict global functions gen->push_left_states(gen->pgf->abstract.funs_by_cat, g.first, arg_res, outside_prob); } else { diff --git a/src/runtime/c/pgf/generator.h b/src/runtime/c/pgf/generator.h index 728e3d09a..64c737860 100644 --- a/src/runtime/c/pgf/generator.h +++ b/src/runtime/c/pgf/generator.h @@ -61,6 +61,7 @@ class PGF_INTERNAL_DECL PgfExhaustiveGenerator : public PgfUnmarshaller, public ref pgf; size_t depth; PgfMarshaller *m; + PgfUnmarshaller *u; PgfInternalMarshaller i_m; Result *top_res; size_t top_res_index; @@ -124,6 +125,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 push_left_states(PgfProbspace space, PgfText *cat, Result *res, prob_t outside_prob); public: