summaryrefslogtreecommitdiff
path: root/src/runtime/c
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2017-01-26 10:17:02 +0000
committerkrasimir <krasimir@chalmers.se>2017-01-26 10:17:02 +0000
commit6af632dd185b176222724cce47a49428f1301752 (patch)
tree2fea848701ca17de3365b5d5621c085de1fbdaa2 /src/runtime/c
parentbe43d5dfdc777995d237e224da7f627426774527 (diff)
added mkMeta and unMeta in the Haskell binding
Diffstat (limited to 'src/runtime/c')
-rw-r--r--src/runtime/c/pgf/expr.c56
-rw-r--r--src/runtime/c/pgf/expr.h15
2 files changed, 71 insertions, 0 deletions
diff --git a/src/runtime/c/pgf/expr.c b/src/runtime/c/pgf/expr.c
index 3c37a4b72..a3c48f32a 100644
--- a/src/runtime/c/pgf/expr.c
+++ b/src/runtime/c/pgf/expr.c
@@ -98,6 +98,46 @@ pgf_expr_apply(PgfApplication* app, GuPool* pool)
}
PgfExpr
+pgf_expr_abs(PgfBindType bind_type, PgfCId id, PgfExpr body, GuPool* pool)
+{
+ return gu_new_variant_i(pool,
+ PGF_EXPR_ABS, PgfExprAbs,
+ .bind_type = bind_type,
+ .id = id,
+ .body = body);
+}
+
+PgfExprAbs*
+pgf_expr_unabs(PgfExpr expr)
+{
+ GuVariantInfo i = gu_variant_open(expr);
+ if (i.tag == PGF_EXPR_ABS) {
+ return (PgfExprAbs*) i.data;
+ }
+
+ return NULL;
+}
+
+PgfExpr
+pgf_expr_meta(int id, GuPool* pool)
+{
+ return gu_new_variant_i(pool,
+ PGF_EXPR_META, PgfExprMeta,
+ .id = id);
+}
+
+PgfExprMeta*
+pgf_expr_unmeta(PgfExpr expr)
+{
+ GuVariantInfo i = gu_variant_open(expr);
+ if (i.tag == PGF_EXPR_META) {
+ return (PgfExprMeta*) i.data;
+ }
+
+ return NULL;
+}
+
+PgfExpr
pgf_expr_string(GuString str, GuPool* pool)
{
PgfLiteral lit;
@@ -143,6 +183,22 @@ pgf_expr_float(double val, GuPool* pool)
lit);
}
+void*
+pgf_expr_unlit(PgfExpr expr, int lit_tag)
+{
+ expr = pgf_expr_unwrap(expr);
+ GuVariantInfo i = gu_variant_open(expr);
+ if (i.tag == PGF_EXPR_LIT) {
+ PgfExprLit* elit = i.data;
+ GuVariantInfo i2 = gu_variant_open(elit->lit);
+ if (i2.tag == lit_tag) {
+ return i2.data;
+ }
+ }
+
+ return NULL;
+}
+
typedef struct PgfExprParser PgfExprParser;
typedef enum {
diff --git a/src/runtime/c/pgf/expr.h b/src/runtime/c/pgf/expr.h
index 763d1ba4f..a2ce6dc42 100644
--- a/src/runtime/c/pgf/expr.h
+++ b/src/runtime/c/pgf/expr.h
@@ -147,6 +147,12 @@ PgfExpr
pgf_expr_apply(PgfApplication*, GuPool* pool);
PgfExpr
+pgf_expr_abs(PgfBindType bind_type, PgfCId id, PgfExpr body, GuPool* pool);
+
+PgfExprAbs*
+pgf_expr_unabs(PgfExpr expr);
+
+PgfExpr
pgf_expr_string(GuString, GuPool* pool);
PgfExpr
@@ -155,6 +161,15 @@ pgf_expr_int(int val, GuPool* pool);
PgfExpr
pgf_expr_float(double val, GuPool* pool);
+void*
+pgf_expr_unlit(PgfExpr expr, int lit_tag);
+
+PgfExpr
+pgf_expr_meta(int id, GuPool* pool);
+
+PgfExprMeta*
+pgf_expr_unmeta(PgfExpr expr);
+
PgfExpr
pgf_read_expr(GuIn* in, GuPool* pool, GuExn* err);