Mercurial Hosting > luan
comparison src/luan/interp/Chunk.java @ 21:c93d8c781853
add functions
git-svn-id: https://luan-java.googlecode.com/svn/trunk@22 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Tue, 04 Dec 2012 09:16:03 +0000 |
parents | 09d41f7490a8 |
children | 2446c1755d9b |
comparison
equal
deleted
inserted
replaced
20:d85510d92eee | 21:c93d8c781853 |
---|---|
1 package luan.interp; | 1 package luan.interp; |
2 | 2 |
3 import luan.LuaState; | 3 import luan.LuaState; |
4 import luan.LuaException; | 4 import luan.LuaException; |
5 import luan.LuaClosure; | |
5 | 6 |
6 | 7 |
7 final class Chunk implements Stmt { | 8 public final class Chunk implements Expr { |
8 private final Stmt block; | 9 public final Stmt block; |
9 private final int stackSize; | 10 public final int stackSize; |
11 public final int numArgs; | |
10 | 12 |
11 Chunk(Stmt block,int stackSize) { | 13 Chunk(Stmt block,int stackSize,int numArgs) { |
12 this.block = block; | 14 this.block = block; |
13 this.stackSize = stackSize; | 15 this.stackSize = stackSize; |
14 } | 16 this.numArgs = numArgs; |
15 | 17 Stmt stmt = block; |
16 @Override public void eval(LuaState lua) throws LuaException { | 18 while( stmt instanceof Block ) { |
17 lua.newStack(stackSize); | 19 Block b = (Block)stmt; |
18 try { | 20 if( b.stmts.length==0 ) |
19 block.eval(lua); | 21 break; |
20 } finally { | 22 stmt = b.stmts[b.stmts.length-1]; |
21 lua.popStack(); | 23 } |
24 if( stmt instanceof ReturnStmt ) { | |
25 ReturnStmt rs = (ReturnStmt)stmt; | |
26 rs.throwReturnException = false; | |
22 } | 27 } |
23 } | 28 } |
24 | 29 |
30 public LuaClosure newClosure(LuaState lua) { | |
31 return new LuaClosure(this,lua); | |
32 } | |
33 | |
34 @Override public Object eval(LuaState lua) { | |
35 return newClosure(lua); | |
36 } | |
37 | |
25 } | 38 } |