Mercurial Hosting > luan
comparison src/luan/interp/LuanCompiler.java @ 86:6db8f286fa6c
_ENV is per module, not global
git-svn-id: https://luan-java.googlecode.com/svn/trunk@87 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Wed, 27 Feb 2013 08:03:51 +0000 |
parents | 851e356101c1 |
children | 6ca02b188dba |
comparison
equal
deleted
inserted
replaced
85:b2551f00bc51 | 86:6db8f286fa6c |
---|---|
8 import luan.LuanFunction; | 8 import luan.LuanFunction; |
9 import luan.LuanState; | 9 import luan.LuanState; |
10 import luan.LuanException; | 10 import luan.LuanException; |
11 import luan.LuanSource; | 11 import luan.LuanSource; |
12 import luan.LuanElement; | 12 import luan.LuanElement; |
13 import luan.LuanTable; | |
13 | 14 |
14 | 15 |
15 public final class LuanCompiler { | 16 public final class LuanCompiler { |
16 private LuanCompiler() {} // never | 17 private LuanCompiler() {} // never |
17 | 18 |
18 public static LuanFunction compile(LuanState luan,LuanSource src) throws LuanException { | 19 public static LuanFunction compile(LuanState luan,LuanSource src,LuanTable env) throws LuanException { |
19 LuanParser parser = Parboiled.createParser(LuanParser.class); | 20 UpValue.Getter envGetter = env!=null ? new UpValue.ValueGetter(env) : new UpValue.EnvGetter(); |
20 parser.source = src; | 21 LuanParser parser = Parboiled.createParser(LuanParser.class,src,envGetter); |
21 ParsingResult<?> result = new ReportingParseRunner(parser.Target()).run(src.text); | 22 ParsingResult<?> result = new ReportingParseRunner(parser.Target()).run(src.text); |
22 // ParsingResult<?> result = new TracingParseRunner(parser.Target()).run(src); | 23 // ParsingResult<?> result = new TracingParseRunner(parser.Target()).run(src); |
23 if( result.hasErrors() ) | 24 if( result.hasErrors() ) |
24 throw new LuanException( luan, LuanElement.COMPILER, ErrorUtils.printParseErrors(result) ); | 25 throw new LuanException( luan, LuanElement.COMPILER, ErrorUtils.printParseErrors(result) ); |
25 Chunk chunk = (Chunk)result.resultValue; | 26 FnDef fnDef = (FnDef)result.resultValue; |
26 return new Closure((LuanStateImpl)luan,chunk); | 27 return new Closure((LuanStateImpl)luan,fnDef); |
27 } | 28 } |
28 | 29 |
29 public static LuanState newLuanState() { | 30 public static LuanState newLuanState() { |
30 return new LuanStateImpl(); | 31 return new LuanStateImpl(); |
31 } | 32 } |