diff --git a/src/runtime/java/jpgf.c b/src/runtime/java/jpgf.c index 026bd9a48..84b2ebb4e 100644 --- a/src/runtime/java/jpgf.c +++ b/src/runtime/java/jpgf.c @@ -1226,6 +1226,46 @@ Java_org_grammaticalframework_pgf_Expr_initStringLit(JNIEnv* env, jclass clazz, return expr; } +JNIEXPORT jlong JNICALL +Java_org_grammaticalframework_pgf_Expr_initIntLit(JNIEnv* env, jclass clazz, jint jd, jlong jpool) +{ + GuPool* pool = l2p(jpool); + PgfExpr expr; + + PgfExprLit* e = + gu_new_variant(PGF_EXPR_LIT, + PgfExprLit, + &expr, pool); + + PgfLiteralInt* nlit = + gu_new_variant(PGF_LITERAL_INT, + PgfLiteralInt, + &e->lit, pool); + nlit->val = jd; + + return expr; +} + +JNIEXPORT jlong JNICALL +Java_org_grammaticalframework_pgf_Expr_initFloatLit(JNIEnv* env, jclass clazz, jdouble jf, jlong jpool) +{ + GuPool* pool = l2p(jpool); + PgfExpr expr; + + PgfExprLit* e = + gu_new_variant(PGF_EXPR_LIT, + PgfExprLit, + &expr, pool); + + PgfLiteralFlt* flit = + gu_new_variant(PGF_LITERAL_FLT, + PgfLiteralFlt, + &e->lit, pool); + flit->val = jf; + + return expr; +} + JNIEXPORT jlong JNICALL Java_org_grammaticalframework_pgf_Expr_initApp__Lorg_grammaticalframework_pgf_Expr_2_3Lorg_grammaticalframework_pgf_Expr_2J (JNIEnv* env, jclass clazz, jobject jfun, jobjectArray args, jlong jpool) diff --git a/src/runtime/java/org/grammaticalframework/pgf/Expr.java b/src/runtime/java/org/grammaticalframework/pgf/Expr.java index 6541db140..2c6882203 100644 --- a/src/runtime/java/org/grammaticalframework/pgf/Expr.java +++ b/src/runtime/java/org/grammaticalframework/pgf/Expr.java @@ -31,6 +31,20 @@ public class Expr implements Serializable { this.ref = initStringLit(s, pool.ref); } + /** Constructs an expression which represents an integer literal */ + public Expr(int d) { + this.pool = new Pool(); + this.master = null; + this.ref = initIntLit(d, pool.ref); + } + + /** Constructs an expression which represents a floating point literal */ + public Expr(double f) { + this.pool = new Pool(); + this.master = null; + this.ref = initFloatLit(f, pool.ref); + } + /** Constructs an expression which is a function application * @param fun The name of the top-level function. * @param args the arguments for the function. @@ -85,6 +99,8 @@ public class Expr implements Serializable { private static native String showExpr(long ref); private static native long initStringLit(String s, long pool); + private static native long initIntLit(int d, long pool); + private static native long initFloatLit(double f, long pool); private static native long initApp(Expr fun, Expr[] args, long pool); private static native long initApp(String fun, Expr[] args, long pool);