Mercurial Hosting > luan
comparison core/src/luan/impl/LuanCompiler.java @ 670:58ebfec6178b
all luan now compiles
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 12 Apr 2016 01:05:57 -0600 |
parents | 08966099aa6d |
children | d3e5414bdf4c |
comparison
equal
deleted
inserted
replaced
669:e320488819b6 | 670:58ebfec6178b |
---|---|
12 | 12 |
13 public final class LuanCompiler { | 13 public final class LuanCompiler { |
14 private LuanCompiler() {} // never | 14 private LuanCompiler() {} // never |
15 | 15 |
16 public static LuanFunction compile(LuanState luan,String sourceName,String sourceText,LuanTable env,boolean allowExpr) throws LuanException { | 16 public static LuanFunction compile(LuanState luan,String sourceName,String sourceText,LuanTable env,boolean allowExpr) throws LuanException { |
17 LuanParser parser = new LuanParser(sourceName,sourceText,env); | 17 LuanParser parser = new LuanParser(sourceName,sourceText); |
18 parser.addVar( "java", JavaLuan.javaFn ); | 18 parser.addVar( env!=null ? "_ENV" : null ); |
19 parser.addVar( "require", PackageLuan.requireFn ); | 19 parser.addVar( "java" ); |
20 parser.addVar( "require" ); | |
20 Class fnClass = parse(parser,allowExpr); | 21 Class fnClass = parse(parser,allowExpr); |
21 final LuanStateImpl luanImpl = (LuanStateImpl)luan; | 22 final LuanStateImpl luanImpl = (LuanStateImpl)luan; |
23 Closure closure; | |
22 try { | 24 try { |
23 return (LuanFunction)fnClass.getConstructor(LuanStateImpl.class).newInstance(luanImpl); | 25 closure = (Closure)fnClass.getConstructor(LuanState.class).newInstance(luanImpl); |
24 } catch(NoSuchMethodException e) { | 26 } catch(NoSuchMethodException e) { |
25 throw new RuntimeException(e); | 27 throw new RuntimeException(e); |
26 } catch(InstantiationException e) { | 28 } catch(InstantiationException e) { |
27 throw new RuntimeException(e); | 29 throw new RuntimeException(e); |
28 } catch(IllegalAccessException e) { | 30 } catch(IllegalAccessException e) { |
29 throw new RuntimeException(e); | 31 throw new RuntimeException(e); |
30 } catch(InvocationTargetException e) { | 32 } catch(InvocationTargetException e) { |
31 throw new RuntimeException(e); | 33 throw new RuntimeException(e); |
32 } | 34 } |
35 closure.upValues[0].o = env!=null ? env : new LuanTable(); | |
36 closure.upValues[1].o = JavaLuan.javaFn; | |
37 closure.upValues[2].o = PackageLuan.requireFn; | |
38 return closure; | |
33 } | 39 } |
34 | 40 |
35 private static Class parse(LuanParser parser,boolean allowExpr) throws LuanException { | 41 private static Class parse(LuanParser parser,boolean allowExpr) throws LuanException { |
36 try { | 42 try { |
37 if( allowExpr ) { | 43 if( allowExpr ) { |