Mercurial Hosting > luan
comparison core/src/luan/impl/FnDef.java @ 171:3dcb0f9bee82
add core component
git-svn-id: https://luan-java.googlecode.com/svn/trunk@172 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Sun, 22 Jun 2014 05:41:22 +0000 |
parents | src/luan/impl/FnDef.java@4eaee12f6c65 |
children | 24ede40ee0aa |
comparison
equal
deleted
inserted
replaced
170:7c792a328a83 | 171:3dcb0f9bee82 |
---|---|
1 package luan.impl; | |
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 } |