mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-16 00:09:31 -06:00
the C runtime now supports reading and writing expressions with indexed meta variables. The type checker generates fresh indices
This commit is contained in:
@@ -344,10 +344,18 @@ pgf_expr_parser_term(PgfExprParser* parser)
|
||||
}
|
||||
case PGF_TOKEN_QUESTION: {
|
||||
pgf_expr_parser_token(parser);
|
||||
|
||||
PgfMetaId id = 0;
|
||||
if (parser->token_tag == PGF_TOKEN_INT) {
|
||||
char* str =
|
||||
gu_buf_data(parser->token_value);
|
||||
id = atoi(str);
|
||||
pgf_expr_parser_token(parser);
|
||||
}
|
||||
return gu_new_variant_i(parser->expr_pool,
|
||||
PGF_EXPR_META,
|
||||
PgfExprMeta,
|
||||
0);
|
||||
id);
|
||||
}
|
||||
case PGF_TOKEN_IDENT: {
|
||||
PgfCId id = gu_buf_data(parser->token_value);
|
||||
@@ -1052,9 +1060,13 @@ pgf_print_expr(PgfExpr expr, PgfPrintContext* ctxt, int prec,
|
||||
pgf_print_literal(lit->lit, out, err);
|
||||
break;
|
||||
}
|
||||
case PGF_EXPR_META:
|
||||
case PGF_EXPR_META: {
|
||||
PgfExprMeta* meta = ei.data;
|
||||
gu_putc('?', out, err);
|
||||
if (meta->id > 0)
|
||||
gu_printf(out, err, "%d", meta->id);
|
||||
break;
|
||||
}
|
||||
case PGF_EXPR_FUN: {
|
||||
PgfExprFun* fun = ei.data;
|
||||
pgf_print_cid(fun->fun, out, err);
|
||||
|
||||
@@ -26,6 +26,7 @@ typedef struct {
|
||||
GuExn* exn;
|
||||
GuPool* pool;
|
||||
GuPool* tmp_pool;
|
||||
PgfMetaId meta_id;
|
||||
} PgfTypeChecker;
|
||||
|
||||
static PgfCFType null_cf_type = { .hypos = NULL, .cat = NULL };
|
||||
@@ -259,13 +260,11 @@ pgf_tc_expr(PgfTypeChecker* checker,
|
||||
break;
|
||||
}
|
||||
case PGF_EXPR_META: {
|
||||
PgfExprMeta* emeta = i.data;
|
||||
|
||||
PgfExprMeta* new_emeta =
|
||||
gu_new_variant(PGF_EXPR_META,
|
||||
PgfExprMeta,
|
||||
pe, checker->pool);
|
||||
new_emeta->id = emeta->id;
|
||||
new_emeta->id = checker->meta_id++;
|
||||
break;
|
||||
}
|
||||
case PGF_EXPR_IMPL_ARG: {
|
||||
@@ -538,6 +537,7 @@ pgf_check_expr(PgfPGF* gr, PgfExpr* pe, PgfType* ty,
|
||||
checker->exn = exn;
|
||||
checker->pool = pool;
|
||||
checker->tmp_pool = tmp_pool;
|
||||
checker->meta_id = 1;
|
||||
|
||||
pgf_tc_expr(checker, NULL, pe, pgf_ty2cfty(checker, ty));
|
||||
|
||||
@@ -555,6 +555,7 @@ pgf_infer_expr(PgfPGF* gr, PgfExpr* pe,
|
||||
checker->exn = exn;
|
||||
checker->pool = pool;
|
||||
checker->tmp_pool = tmp_pool;
|
||||
checker->meta_id = 1;
|
||||
|
||||
PgfCFType cf_ty = pgf_inf_expr(checker, NULL, pe);
|
||||
|
||||
@@ -579,6 +580,7 @@ pgf_check_type(PgfPGF* gr, PgfType** pty,
|
||||
checker->exn = exn;
|
||||
checker->pool = pool;
|
||||
checker->tmp_pool = tmp_pool;
|
||||
checker->meta_id = 1;
|
||||
|
||||
pgf_tc_type(checker, pty);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user