comparison src/luan/interp/FnDef.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 src/luan/interp/Chunk.java@8ede219cd111
children
comparison
equal deleted inserted replaced
85:b2551f00bc51 86:6db8f286fa6c
1 package luan.interp;
2
3 import luan.LuanException;
4 import luan.LuanSource;
5
6
7 final class FnDef extends CodeImpl implements Expr {
8 final Stmt block;
9 final int stackSize;
10 final int numArgs;
11 final boolean isVarArg;
12 final UpValue.Getter[] upValueGetters;
13
14 FnDef(LuanSource.Element se,Stmt block,int stackSize,int numArgs,boolean isVarArg,UpValue.Getter[] upValueGetters) {
15 super(se);
16 this.block = block;
17 this.stackSize = stackSize;
18 this.numArgs = numArgs;
19 this.isVarArg = isVarArg;
20 this.upValueGetters = upValueGetters;
21 fixReturns(block);
22 }
23
24 private static void fixReturns(Stmt stmt) {
25 if( stmt instanceof ReturnStmt ) {
26 ReturnStmt rs = (ReturnStmt)stmt;
27 rs.throwReturnException = false;
28 } else if( stmt instanceof Block ) {
29 Block b = (Block)stmt;
30 fixReturns( b.stmts[b.stmts.length-1] );
31 } else if( stmt instanceof IfStmt ) {
32 IfStmt is = (IfStmt)stmt;
33 fixReturns( is.thenStmt );
34 fixReturns( is.elseStmt );
35 }
36 }
37
38 @Override public Object eval(LuanStateImpl luan) throws LuanException {
39 return new Closure(luan,this);
40 }
41
42 }