Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
[submodule "ecl"]
path = ecl
url = git://git.code.sf.net/p/ecls/ecl
[submodule "slime"]
path = slime
url = git://common-lisp.net/projects/mirror/slime.git
[submodule "lisp-packages/cl-opengl"]
path = lisp-packages/cl-opengl
url = git://github.com/ageneau/cl-opengl.git
Expand All @@ -23,3 +20,7 @@
[submodule "libatomic_ops"]
path = libatomic_ops
url = https://github.com/ivmai/libatomic_ops.git
[submodule "slime"]
path = slime
url = https://github.com/slime/slime.git

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ update-modules:
git submodule update

patch-ecl:
cd ecl && git clean -dxf && git checkout HEAD . && for i in ../patches/ecl/*.patch; do patch -p1 < $$i; done
cd ecl && git clean -dxf && git checkout master . && for i in ../patches/ecl/*.patch; do patch -p1 < $$i; done
cp config.sub config.guess ecl/src/
cp config.sub config.guess ecl/src/gmp/
chmod +x ecl/src/config.* ecl/src/gmp/config.*
Expand Down
2 changes: 1 addition & 1 deletion android/HelloEcl/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package="org.lisp.ecl"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<uses-sdk android:minSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="@string/app_name"
android:debuggable="true">
Expand Down
18 changes: 10 additions & 8 deletions android/HelloEcl/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ endif
ECL_HOME := ../../local-install/$(PLATFORM)
ECL_VER := $(shell basename $(ECL_HOME)/lib/ecl-* |cut -d "-" -f2)

LOCAL_MODULE := hello-ecl
LOCAL_PATH := $(BASE_PATH)
LOCAL_SRC_FILES := hello-ecl.c ecl_boot.c
LOCAL_CFLAGS += -I$(ECL_HOME)/include
LOCAL_CFLAGS += -g -Wall -DANDROID
LOCAL_LDLIBS := -L$(ECL_HOME)/lib -lecl -lgmp -L$(ECL_HOME)/lib/ecl-$(ECL_VER) -lasdf -lsockets -lsb-bsd-sockets -lserve-event -lecl-help -lecl-cdb -lgc -latomic_ops
LOCAL_LDLIBS += -llog
LOCAL_MODULE := ecl_android
LOCAL_PATH := $(BASE_PATH)
LOCAL_SRC_FILES := org_lisp_ecl_EmbeddedCommonLisp.c ecl_boot.c
LOCAL_CFLAGS += -I$(ECL_HOME)/include
LOCAL_CFLAGS += -g -Wall -DANDROID
LOCAL_LDLIBS := -L$(ECL_HOME)/lib
LOCAL_LDLIBS += -L$(ECL_HOME)/lib/ecl-$(ECL_VER)
LOCAL_LDLIBS += -lecl -lasdf -lgmp -lsockets -llog
LOCAL_LDLIBS += -lsb-bsd-sockets -lserve-event -lecl-help
LOCAL_LDLIBS += -lecl-cdb -lgc -latomic_ops

include $(BUILD_SHARED_LIBRARY)

64 changes: 0 additions & 64 deletions android/HelloEcl/jni/hello-ecl.c

This file was deleted.

134 changes: 134 additions & 0 deletions android/HelloEcl/jni/org_lisp_ecl_EmbeddedCommonLisp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#include <assert.h>

#if ANDROID
#include <android/log.h>
#endif

#include <string.h>
#include <jni.h>
#include <pthread.h>
#include <stdio.h>

#include <ecl/ecl.h>
#include "ecl_boot.h"

#if ANDROID
#define ECL_TAG "ecl-native"
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, ECL_TAG, __VA_ARGS__))
#define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, ECL_TAG, __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, ECL_TAG, __VA_ARGS__))
#define LOGV(...) ((void)__android_log_print(ANDROID_LOG_VERBOSE, ECL_TAG, __VA_ARGS__))
#else
#define LOGI(...)
#define LOGW(...)
#define LOGE(...)
#endif

#define jni_ecl_read_from_string(x) si_string_to_object(1, x)

/*
* Class: org_lisp_ecl_EmbeddedCommonLisp
* Method: start
* Signature: ()V
*/
JNIEXPORT void JNICALL
Java_org_lisp_ecl_EmbeddedCommonLisp_start(JNIEnv *env, jobject this,
jstring path) {

const char *lisp_dir = (*env)->GetStringUTFChars(env, path, NULL);
LOGI("ECL starting: *default-pathname-defaults* to: %s\n", lisp_dir);
ecl_boot(lisp_dir);
LOGI("ECL started.");
};

/* This was fun to make UTF8 work across Java-C-Lisp boundaries.
-evrim, 2014. */
cl_object java_string_to_ecl_string(JNIEnv *env, jstring str) {
const jchar *txt = (*env)->GetStringChars(env, str, NULL);
jsize len = (*env)->GetStringLength(env, str);
cl_object ecl_txt = ecl_alloc_simple_extended_string(len);
cl_index i;

for (i=0;i<len;i++) {
ecl_txt->string.self[i] = txt[i];
};

(*env)->ReleaseStringChars(env, str, txt);

return ecl_txt;
}


jstring ecl_object_to_java_string(JNIEnv *env, cl_object o) {
jstring ret;
if (ECL_EXTENDED_STRING_P(o)) {
LOGI("ecl->java extended string of fillp: %d, dim: %d",
o->string.fillp,
o->string.dim);

jsize len = o->string.fillp;
jchar *arr = malloc(sizeof(jchar)*(len+1));
cl_index i;
for (i=0; i<len; i++) {
arr[i] = o->string.self[i];
}
arr[len] = 0;
ret = (*env)->NewString(env, arr, len);
free(arr);
} else if (ECL_STRINGP(o)) {
LOGI("ecl->java base string of len %d: %s",
o->base_string.dim,
o->base_string.self);

ret = (*env)->NewStringUTF(env,
(const char*)o->base_string.self);
} else {
LOGI("ecl->java not a string, coercing");
return ecl_object_to_java_string(env, cl_princ_to_string(o));
}

return ret;
}

/*
* Class: org_lisp_ecl_EmbeddedCommonLisp
* Method: exec
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL
Java_org_lisp_ecl_EmbeddedCommonLisp_exec(JNIEnv *env, jobject this, jstring str) {
jstring ret;
cl_object txt = java_string_to_ecl_string(env, str);
cl_object result = si_safe_eval(3, jni_ecl_read_from_string(txt), Cnil, OBJNULL);

if (result) {
ret = ecl_object_to_java_string(env, result);
} else {
ret = (*env)->NewStringUTF(env, "ERROR in eval");
}

return ret;
};

#undef jni_ecl_read_from_string

/*
* Class: org_lisp_ecl_EmbeddedCommonLisp
* Method: exec_
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL
Java_org_lisp_ecl_EmbeddedCommonLisp_exec_(JNIEnv *env, jobject this, jstring str) {
jstring ret;
const char *cmd = (*env)->GetStringUTFChars(env, str, NULL);
cl_object result = si_safe_eval(3, c_string_to_object(cmd),
Cnil, OBJNULL);

if (result) {
cl_object out = si_coerce_to_base_string(cl_princ_to_string(result));
ret = (*env)->NewStringUTF(env, (const char*) out->base_string.self);
} else {
ret = (*env)->NewStringUTF(env, "ERROR in eval");
}
return ret;
};
37 changes: 37 additions & 0 deletions android/HelloEcl/jni/org_lisp_ecl_EmbeddedCommonLisp.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions android/HelloEcl/src/org/lisp/ecl/EmbeddedCommonLisp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.lisp.ecl;

import android.util.Log;

public class EmbeddedCommonLisp {
private static String TAG = "EmbeddedCommonLisp";

public void start() {
start(System.getenv("user.dir"));
}
public native void start(String path);
public native String exec(String string);
// public native String botExec(String string);

static {
System.loadLibrary("ecl_android");
Log.w(TAG,"Done loading library");
}
}
Loading