From 9f9b23d0dddd3b61e4289cfbcf08241deddc65de Mon Sep 17 00:00:00 2001 From: krasimir Date: Thu, 19 Nov 2015 13:18:19 +0000 Subject: added mkInt and mkFloat in the Haskell binding to make it easy to create literal expressions --- src/runtime/c/pgf/expr.c | 30 ++++++++++++++++++++++++++++++ src/runtime/c/pgf/expr.h | 6 ++++++ 2 files changed, 36 insertions(+) (limited to 'src/runtime/c/pgf') diff --git a/src/runtime/c/pgf/expr.c b/src/runtime/c/pgf/expr.c index 3482e0b11..d579027aa 100644 --- a/src/runtime/c/pgf/expr.c +++ b/src/runtime/c/pgf/expr.c @@ -112,6 +112,36 @@ pgf_expr_string(GuString str, GuPool* pool) lit); } +PgfExpr +pgf_expr_int(int val, GuPool* pool) +{ + PgfLiteral lit; + PgfLiteralInt* plit = + gu_new_variant(PGF_LITERAL_INT, + PgfLiteralInt, + &lit, pool); + plit->val = val; + return gu_new_variant_i(pool, + PGF_EXPR_LIT, + PgfExprLit, + lit); +} + +PgfExpr +pgf_expr_float(double val, GuPool* pool) +{ + PgfLiteral lit; + PgfLiteralFlt* plit = + gu_new_variant(PGF_LITERAL_FLT, + PgfLiteralFlt, + &lit, pool); + plit->val = val; + return gu_new_variant_i(pool, + PGF_EXPR_LIT, + PgfExprLit, + lit); +} + typedef struct PgfExprParser PgfExprParser; typedef enum { diff --git a/src/runtime/c/pgf/expr.h b/src/runtime/c/pgf/expr.h index 23aa971f0..2e76bf21d 100644 --- a/src/runtime/c/pgf/expr.h +++ b/src/runtime/c/pgf/expr.h @@ -149,6 +149,12 @@ pgf_expr_apply(PgfApplication*, GuPool* pool); PgfExpr pgf_expr_string(GuString, GuPool* pool); +PgfExpr +pgf_expr_int(int val, GuPool* pool); + +PgfExpr +pgf_expr_float(double val, GuPool* pool); + PgfExpr pgf_read_expr(GuIn* in, GuPool* pool, GuExn* err); -- cgit v1.2.3