summaryrefslogtreecommitdiff
path: root/src/runtime/c
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/c')
-rw-r--r--src/runtime/c/pgf/data.c4
-rw-r--r--src/runtime/c/pgf/data.h11
-rw-r--r--src/runtime/c/pgf/linearize.c10
-rw-r--r--src/runtime/c/pgf/parser.c21
-rw-r--r--src/runtime/c/pgf/parser.h2
-rw-r--r--src/runtime/c/pgf/printer.c2
-rw-r--r--src/runtime/c/pgf/reader.c20
-rw-r--r--src/runtime/c/utils/pgf-translate.c3
8 files changed, 42 insertions, 31 deletions
diff --git a/src/runtime/c/pgf/data.c b/src/runtime/c/pgf/data.c
index 1726518f9..710eeb952 100644
--- a/src/runtime/c/pgf/data.c
+++ b/src/runtime/c/pgf/data.c
@@ -97,7 +97,7 @@ GU_DEFINE_TYPE(
GU_DEFINE_TYPE(
PgfCncCat, struct,
- GU_MEMBER(PgfCncCat, cid, PgfCId),
+ GU_MEMBER(PgfCncCat, abscat, PgfCat),
GU_MEMBER_P(PgfCncCat, cats, PgfCCatIds),
GU_MEMBER(PgfCncCat, n_lins, size_t),
GU_FLEX_MEMBER(PgfCncCat, labels, GuString));
@@ -118,7 +118,7 @@ GU_DEFINE_TYPE(PgfSeqId, typedef, gu_type(PgfSequence));
GU_DEFINE_TYPE(
PgfCncFun, struct,
- GU_MEMBER(PgfCncFun, fun, PgfCId),
+ GU_MEMBER(PgfCncFun, name, PgfCId),
GU_MEMBER(PgfCncFun, n_lins, GuLength),
GU_FLEX_MEMBER(PgfCncFun, lins, PgfSeqId));
diff --git a/src/runtime/c/pgf/data.h b/src/runtime/c/pgf/data.h
index 53df0058c..4a8fc062b 100644
--- a/src/runtime/c/pgf/data.h
+++ b/src/runtime/c/pgf/data.h
@@ -39,6 +39,8 @@ typedef GuSeq PgfCCatSeq;
extern GU_DECLARE_TYPE(PgfCCatSeq, GuSeq);
typedef struct PgfAbstr PgfAbstr;
+extern GU_DECLARE_TYPE(PgfAbstr, struct);
+
typedef struct PgfFunDecl PgfFunDecl;
typedef struct PgfConcr PgfConcr;
@@ -89,7 +91,9 @@ typedef struct PgfEquation PgfEquation;
typedef GuSeq PgfEquations;
typedef PgfEquations PgfEquationsM; // can be null
extern GU_DECLARE_TYPE(PgfEquationsM, GuSeq);
+
typedef struct PgfCat PgfCat;
+extern GU_DECLARE_TYPE(PgfCat, struct);
typedef PgfSequence PgfSeqId; // shared reference
@@ -141,9 +145,9 @@ struct PgfCat {
struct PgfCncCat {
- PgfCId cid;
+ PgfCat *abscat;
PgfCCatIds* cats;
-
+
size_t n_lins;
GuString labels[];
/**< Labels for tuples. All nested tuples, records and tables
@@ -155,7 +159,8 @@ struct PgfCncCat {
};
struct PgfCncFun {
- PgfCId fun; // XXX: resolve to PgfFunDecl*?
+ PgfCId name;
+ PgfFunDecl *absfun;
int funid;
GuLength n_lins;
PgfSeqId lins[];
diff --git a/src/runtime/c/pgf/linearize.c b/src/runtime/c/pgf/linearize.c
index aef966eba..08e182d50 100644
--- a/src/runtime/c/pgf/linearize.c
+++ b/src/runtime/c/pgf/linearize.c
@@ -133,7 +133,7 @@ pgf_lzr_add_infer_entry(
n_args > 0 ? gu_list_index(arg_cats, 0)->fid : -1,
n_args > 1 ? gu_list_index(arg_cats, 1)->fid : -1,
n_args > 2 ? gu_list_index(arg_cats, 2)->fid : -1,
- cat->fid, papply->fun->fun);
+ cat->fid, papply->fun->name);
PgfLinInfers* entries =
gu_map_get(infer_table, &arg_cats, PgfLinInfers*);
if (!entries) {
@@ -161,13 +161,13 @@ pgf_lzr_index(PgfConcr* concr, PgfCCat* ccat, PgfProduction prod,
case PGF_PRODUCTION_APPLY: {
PgfProductionApply* papply = data;
PgfInferMap* infer =
- gu_map_get(concr->fun_indices, &papply->fun->fun,
+ gu_map_get(concr->fun_indices, &papply->fun->name,
PgfInferMap*);
- gu_debug("index: %s -> %d", papply->fun->fun, ccat->fid);
+ gu_debug("index: %s -> %d", papply->fun->name, ccat->fid);
if (!infer) {
infer = gu_map_type_new(PgfInferMap, pool);
gu_map_put(concr->fun_indices,
- &papply->fun->fun, PgfInferMap*, infer);
+ &papply->fun->name, PgfInferMap*, infer);
}
pgf_lzr_add_infer_entry(infer, ccat, papply, pool);
break;
@@ -452,7 +452,7 @@ pgf_lzr_linearize(PgfConcr* concr, PgfCncTree ctree, size_t lin_idx, PgfLinFuncs
PgfCncTreeApp* fapp = cti.data;
PgfCncFun* fun = fapp->fun;
if (fns->expr_apply) {
- fns->expr_apply(fnsp, fun->fun, fapp->n_args);
+ fns->expr_apply(fnsp, fun->name, fapp->n_args);
}
gu_require(lin_idx < fun->n_lins);
PgfSequence seq = fun->lins[lin_idx];
diff --git a/src/runtime/c/pgf/parser.c b/src/runtime/c/pgf/parser.c
index 60b04de33..363f94d24 100644
--- a/src/runtime/c/pgf/parser.c
+++ b/src/runtime/c/pgf/parser.c
@@ -15,7 +15,6 @@ typedef GuList(PgfItemBuf*) PgfItemBufs;
typedef GuBuf PgfCCatBuf;
struct PgfParse {
- PgfAbstr* abstr;
PgfConcr* concr;
PgfItemBuf* agenda;
int max_fid;
@@ -39,7 +38,6 @@ struct PgfExprState {
typedef struct PgfParseResult PgfParseResult;
struct PgfParseResult {
- PgfAbstr* abstr;
PgfConcr* concr;
GuPool *tmp_pool;
GuBuf *pqueue;
@@ -852,11 +850,9 @@ pgf_new_parsing(PgfConcr* concr, PgfLexCallback* callback, int max_fid,
}
static PgfParse*
-pgf_new_parse(PgfAbstr* abstr, PgfConcr* concr,
- int max_fid, GuPool* pool)
+pgf_new_parse(PgfConcr* concr, int max_fid, GuPool* pool)
{
PgfParse* parse = gu_new(PgfParse, pool);
- parse->abstr = abstr;
parse->concr = concr;
parse->agenda = NULL;
parse->max_fid = max_fid;
@@ -969,7 +965,7 @@ pgf_parse_token(PgfParse* parse, PgfToken tok, bool robust, GuPool* pool)
PgfParse* next_parse = NULL;
if (gu_buf_length(agenda) > 0) {
- next_parse = pgf_new_parse(parse->abstr, parse->concr, parse->max_fid, pool);
+ next_parse = pgf_new_parse(parse->concr, parse->max_fid, pool);
next_parse->agenda = agenda;
next_parse->max_fid= parsing->max_fid;
}
@@ -1009,11 +1005,9 @@ pgf_parse_result_from_ccat(PgfParseResult *result, PgfCCat *ccat,
case PGF_PRODUCTION_APPLY: {
PgfProductionApply* papp = pi.data;
- PgfFunDecl *fun_decl =
- gu_map_get(result->abstr->funs, &papp->fun->fun, PgfFunDecl*);
- gu_assert(fun_decl != NULL);
+ gu_assert(papp->fun->absfun != NULL);
- double prob = ps->prob - log(fun_decl->prob);
+ double prob = ps->prob - log(papp->fun->absfun->prob);
PgfExprState *state = gu_new(PgfExprState, result->tmp_pool);
state->prev = ps->state;
@@ -1021,7 +1015,7 @@ pgf_parse_result_from_ccat(PgfParseResult *result, PgfCCat *ccat,
gu_new_variant(PGF_EXPR_FUN,
PgfExprFun,
&state->expr, pool);
- expr_fun->fun = papp->fun->fun;
+ expr_fun->fun = papp->fun->name;
state->args = papp->args;
state->arg_idx = 0;
@@ -1148,7 +1142,6 @@ pgf_parse_result(PgfParse* parse, GuPool* pool)
GuPool *states_pool = gu_new_pool();
PgfParseResult *result =
gu_new_i(pool, PgfParseResult,
- .abstr = parse->abstr,
.concr = parse->concr,
.tmp_pool = states_pool,
.pqueue = gu_new_buf(PgfExprPState, states_pool),
@@ -1168,7 +1161,7 @@ pgf_parse_result(PgfParse* parse, GuPool* pool)
// TODO: s/CId/Cat, add the cid to Cat, make Cat the key to CncCat
PgfParse*
-pgf_parser_parse(PgfAbstr* abstr, PgfConcr* concr, PgfCId cat, size_t lin_idx, GuPool* pool)
+pgf_parser_parse(PgfConcr* concr, PgfCId cat, size_t lin_idx, GuPool* pool)
{
PgfCncCat* cnccat =
gu_map_get(concr->cnccats, &cat, PgfCncCat*);
@@ -1178,7 +1171,7 @@ pgf_parser_parse(PgfAbstr* abstr, PgfConcr* concr, PgfCId cat, size_t lin_idx, G
}
gu_assert(lin_idx < cnccat->n_lins);
- PgfParse* parse = pgf_new_parse(abstr, concr, concr->max_fid, pool);
+ PgfParse* parse = pgf_new_parse(concr, concr->max_fid, pool);
parse->agenda = gu_new_buf(PgfItem*, pool);
PgfItemBuf* conts = gu_new_buf(PgfItem*, pool);
diff --git a/src/runtime/c/pgf/parser.h b/src/runtime/c/pgf/parser.h
index c8b887d21..38ae9f1a4 100644
--- a/src/runtime/c/pgf/parser.h
+++ b/src/runtime/c/pgf/parser.h
@@ -33,7 +33,7 @@ typedef struct PgfParse PgfParse;
/// Begin parsing
PgfParse*
-pgf_parser_parse(PgfAbstr* abstr, PgfConcr* concr, PgfCId cat, size_t lin_idx, GuPool* pool);
+pgf_parser_parse(PgfConcr* concr, PgfCId cat, size_t lin_idx, GuPool* pool);
/**<
* @param parser The parser to use
*
diff --git a/src/runtime/c/pgf/printer.c b/src/runtime/c/pgf/printer.c
index 058375f33..2b1729749 100644
--- a/src/runtime/c/pgf/printer.c
+++ b/src/runtime/c/pgf/printer.c
@@ -178,7 +178,7 @@ pgf_print_cncfun(PgfCncFun *cncfun, PgfSequences *sequences,
}
gu_puts(") [", wtr, err);
- gu_string_write(cncfun->fun, wtr, err);
+ gu_string_write(cncfun->name, wtr, err);
gu_puts("]\n", wtr, err);
}
diff --git a/src/runtime/c/pgf/reader.c b/src/runtime/c/pgf/reader.c
index cfb3c8b7e..f7b6b02be 100644
--- a/src/runtime/c/pgf/reader.c
+++ b/src/runtime/c/pgf/reader.c
@@ -48,6 +48,7 @@ struct PgfReader {
GuPool* opool;
GuPool* tmp_pool;
GuSymTable* symtab;
+ PgfAbstr* curr_abstr;
PgfConcr* curr_concr;
GuMap* curr_lindefs;
PgfContsMap* curr_conts_map; // used temporary for building the bu index for the parser
@@ -619,6 +620,13 @@ pgf_read_to_PgfFunId(GuType* type, PgfReader* rdr, void* to)
*(PgfFunId*) to = gu_list_elems(rdr->curr_concr->cncfuns)[id];
}
+static void
+pgf_read_to_PgfAbstr(GuType* type, PgfReader* rdr, void* to)
+{
+ rdr->curr_abstr = to;
+ pgf_read_to_struct(type, rdr, to);
+}
+
static GU_DEFINE_TYPE(PgfLinDefs, GuIntMap, gu_ptr_type(PgfFunIds),
&gu_null_struct);
typedef PgfCCat PgfCCatData;
@@ -755,6 +763,8 @@ pgf_read_new_PgfConcr(GuType* type, PgfReader* rdr, GuPool* pool,
for (int funid = 0; funid < n_funs; funid++) {
PgfCncFun* cncfun = gu_list_index(concr->cncfuns, funid);
cncfun->funid = funid;
+ cncfun->absfun =
+ gu_map_get(rdr->curr_abstr->funs, &cncfun->name, PgfFunDecl*);
}
return concr;
@@ -764,8 +774,7 @@ static void*
pgf_read_new_PgfCncCat(GuType* type, PgfReader* rdr, GuPool* pool,
size_t* size_out)
{
- PgfCId cid = *(PgfCId*) rdr->curr_key;
- gu_enter("-> cid");
+ gu_enter("->");
(void) (type && size_out);
int first = pgf_read_int(rdr);
@@ -774,7 +783,10 @@ pgf_read_new_PgfCncCat(GuType* type, PgfReader* rdr, GuPool* pool,
PgfCncCat* cnccat =
gu_malloc(pool, sizeof(PgfCncCat)+n_lins*sizeof(GuString));
- cnccat->cid = cid;
+
+ cnccat->abscat =
+ gu_map_get(rdr->curr_abstr->cats, rdr->curr_key, PgfCat*);
+ gu_assert(cnccat->abscat != NULL);
int len = last + 1 - first;
cnccat->cats = gu_new_list(PgfCCatIds, pool, len);
@@ -834,6 +846,7 @@ pgf_read_to_table = GU_TYPETABLE(
PGF_READ_TO(PgfCCat),
PGF_READ_TO(PgfSeqId),
PGF_READ_TO(PgfFunId),
+ PGF_READ_TO(PgfAbstr),
PGF_READ_TO(alias));
#define PGF_READ_NEW_FN(k_, fn_) \
@@ -863,6 +876,7 @@ pgf_new_reader(GuIn* in, GuPool* opool, GuPool* tmp_pool, GuExn* err)
rdr->symtab = gu_new_symtable(opool, tmp_pool);
rdr->err = err;
rdr->in = in;
+ rdr->curr_abstr = NULL;
rdr->curr_concr = NULL;
rdr->curr_lindefs = NULL;
rdr->curr_conts_map = NULL;
diff --git a/src/runtime/c/utils/pgf-translate.c b/src/runtime/c/utils/pgf-translate.c
index f100160bc..5c8e45401 100644
--- a/src/runtime/c/utils/pgf-translate.c
+++ b/src/runtime/c/utils/pgf-translate.c
@@ -33,7 +33,6 @@ int main(int argc, char* argv[]) {
GuString cat;
bool robust_mode;
if (argv[2][0] == '.') {
- printf("%s\n", argv[2]+1);
cat = gu_str_string(argv[2]+1, pool);
robust_mode = true;
} else {
@@ -116,7 +115,7 @@ int main(int argc, char* argv[]) {
// Begin parsing a sentence of the specified category
PgfParse* parse =
- pgf_parser_parse(&pgf->abstract, from_concr, cat, lin_idx, pool);
+ pgf_parser_parse(from_concr, cat, lin_idx, pool);
if (parse == NULL) {
fprintf(stderr, "Couldn't begin parsing\n");
status = EXIT_FAILURE;