From 3147e164536ab6d5221302f09ccab627638f84be Mon Sep 17 00:00:00 2001 From: "kr.angelov" Date: Tue, 28 May 2013 12:59:19 +0000 Subject: an initial skeleton for building a Java binding to the C runtime --- src/runtime/java/jpgf.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/runtime/java/jpgf.c (limited to 'src/runtime/java/jpgf.c') diff --git a/src/runtime/java/jpgf.c b/src/runtime/java/jpgf.c new file mode 100644 index 000000000..4796e32dd --- /dev/null +++ b/src/runtime/java/jpgf.c @@ -0,0 +1,31 @@ +#include +#include +#include "org_grammaticalframework_PGF.h" + +JNIEXPORT jobject JNICALL +Java_org_grammaticalframework_PGF_readPGF(JNIEnv *env, jclass cls, jstring s) +{ + const char *fpath = (*env)->GetStringUTFChars(env, s, 0); + + GuPool* pool = gu_new_pool(); + GuPool* tmp_pool = gu_local_pool(); + + // Create an exception frame that catches all errors. + GuExn* err = gu_new_exn(NULL, gu_kind(type), tmp_pool); + + // Read the PGF grammar. + PgfPGF* pgf = pgf_read(fpath, pool, err); + if (!gu_ok(err)) { + gu_pool_free(pool); + gu_pool_free(tmp_pool); + return NULL; + } + + gu_pool_free(tmp_pool); + + (*env)->ReleaseStringUTFChars(env, s, fpath); + + jmethodID constrId = (*env)->GetMethodID(env, cls, "", "(II)V"); + + return (*env)->NewObject(env, cls, constrId, (int) pool, (int) pgf); +} -- cgit v1.2.3