This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Android REPL on Kawa - unable to create functions on the fly
- From: Per Bothner <per at bothner dot com>
- To: Helmut Eller <eller dot helmut at gmail dot com>
- Cc: kawa at sources dot redhat dot com
- Date: Sat, 28 Jan 2012 13:27:26 -0800
- Subject: Re: Android REPL on Kawa - unable to create functions on the fly
- References: <33206786.post@talk.nabble.com> <m239b23bt6.fsf@gmail.com>
On 01/26/2012 04:09 AM, Helmut Eller wrote:
Setting gnu.expr.ModuleExp:compilerAvailable makes it possible to
evaluate lambdas.
What do you think of the attached patch?
I'm hoping you don't need to tweak alwaysCompiler or compilerAvalable
any more.
Does comparing System.getProperty("java.vm.name") against "Dalvik"
seem like a reasonable and robust test?
--
--Per Bothner
per@bothner.com http://per.bothner.com/
Index: gnu/expr/ModuleExp.java
===================================================================
--- gnu/expr/ModuleExp.java (revision 7134)
+++ gnu/expr/ModuleExp.java (working copy)
@@ -156,14 +156,34 @@
}
}
- // TODO: This should be false #ifdef Android.
- // The complication is that it needs to be true while building
- // Kawa itself, or generally compiling code *for* Android.
- // I.e. we need to be able to distinguish compile-time and run-time.
- public static boolean compilerAvailable = true;
+ /** @deprecated */
+ public static boolean compilerAvailable = true;
+ /** 1: have compiler; -1: don't have compiler: 0: need to check. */
+ private static int haveCompiler;
+
+ public static synchronized boolean compilerAvailable() {
+ if (haveCompiler == 0) {
+ if (! compilerAvailable)
+ haveCompiler = -1;
+ else if ("Dalvik".equals(System.getProperty("java.vm.name")))
+ haveCompiler = -1;
+ else {
+ try {
+ // Just in case you somehow managed to get this far
+ // while using kawart - i.e. the Kawa "runtime" jar.
+ Class.forName("gnu.expr.TryExp");
+ haveCompiler = 1;
+ } catch (Throwable ex) {
+ haveCompiler = -1;
+ }
+ }
+ }
+ return haveCompiler >= 0;
+ }
+
/** Flag to force compilation, even when not required. */
- public static boolean alwaysCompile = compilerAvailable;
+ public static boolean alwaysCompile = compilerAvailable();
public final static boolean evalModule (Environment env, CallContext ctx,
Compilation comp, URL url,
Index: gnu/expr/Compilation.java
===================================================================
--- gnu/expr/Compilation.java (revision 7134)
+++ gnu/expr/Compilation.java (working copy)
@@ -2383,7 +2383,7 @@
*/
public void mustCompileHere ()
{
- if (! mustCompile && ! ModuleExp.compilerAvailable)
+ if (! mustCompile && ! ModuleExp.compilerAvailable())
error('e', "this expression must be compiled, but compiler is unavailable");
mustCompile = true;
}
@@ -2459,7 +2459,7 @@
{
if (! mustCompile
&& (scope.mustCompile()
- || (ModuleExp.compilerAvailable
+ || (ModuleExp.compilerAvailable()
// We set mustCompile if we see a LambdaExp - not because
// we must but because it is usually desirable.
&& scope instanceof LambdaExp