summaryrefslogtreecommitdiff
path: root/src/runtime/c
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/c')
-rw-r--r--src/runtime/c/pgf/expr.c34
-rw-r--r--src/runtime/c/pgf/expr.h5
2 files changed, 37 insertions, 2 deletions
diff --git a/src/runtime/c/pgf/expr.c b/src/runtime/c/pgf/expr.c
index 105a3db9d..73ed251d1 100644
--- a/src/runtime/c/pgf/expr.c
+++ b/src/runtime/c/pgf/expr.c
@@ -292,6 +292,34 @@ pgf_read_expr(GuReader* rdr, GuPool* pool, GuExn* err)
}
void
+pgf_print_literal(PgfLiteral lit,
+ GuWriter* wtr, GuExn* err)
+{
+ GuVariantInfo ei = gu_variant_open(lit);
+ switch (ei.tag) {
+ case PGF_LITERAL_STR: {
+ PgfLiteralStr* lit = ei.data;
+ gu_putc('"', wtr, err);
+ gu_string_write(lit->val, wtr, err);
+ gu_putc('"', wtr, err);
+ break;
+ }
+ case PGF_LITERAL_INT: {
+ PgfLiteralInt* lit = ei.data;
+ gu_printf(wtr, err, "%d", lit->val);
+ break;
+ }
+ case PGF_LITERAL_FLT: {
+ PgfLiteralFlt* lit = ei.data;
+ gu_printf(wtr, err, "%f", lit->val);
+ break;
+ }
+ default:
+ gu_impossible();
+ }
+}
+
+void
pgf_print_expr(PgfExpr expr, int prec,
GuWriter* wtr, GuExn* err)
{
@@ -316,7 +344,11 @@ pgf_print_expr(PgfExpr expr, int prec,
break;
}
case PGF_EXPR_ABS:
- case PGF_EXPR_LIT:
+ case PGF_EXPR_LIT: {
+ PgfExprLit* lit = ei.data;
+ pgf_print_literal(lit->lit, wtr, err);
+ break;
+ }
case PGF_EXPR_META:
case PGF_EXPR_VAR:
case PGF_EXPR_TYPED:
diff --git a/src/runtime/c/pgf/expr.h b/src/runtime/c/pgf/expr.h
index 65e2d66a9..003102792 100644
--- a/src/runtime/c/pgf/expr.h
+++ b/src/runtime/c/pgf/expr.h
@@ -40,7 +40,7 @@ typedef enum {
} PgfLiteralTag;
typedef struct {
- GuStr val;
+ GuString val;
} PgfLiteralStr;
typedef struct {
@@ -147,6 +147,9 @@ PgfExpr
pgf_read_expr(GuReader* rdr, GuPool* pool, GuExn* err);
void
+pgf_print_literal(PgfLiteral lit, GuWriter* wtr, GuExn* err);
+
+void
pgf_print_expr(PgfExpr expr, int prec, GuWriter* wtr, GuExn* err);
void