comparison core/src/luan/impl/FnDef.java @ 664:71f8f5075df8

compile FnDef
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 07 Apr 2016 15:11:52 -0600
parents b438a47196bc
children
comparison
equal deleted inserted replaced
663:b438a47196bc 664:71f8f5075df8
1 package luan.impl; 1 package luan.impl;
2 2
3 import luan.LuanException; 3 import luan.LuanException;
4 4
5 5
6 final class FnDef extends CodeImpl implements Expr { 6 public abstract class FnDef extends CodeImpl implements Expr {
7 final Expressions block;
8 final int stackSize; 7 final int stackSize;
9 final int numArgs; 8 final int numArgs;
10 final boolean isVarArg; 9 final boolean isVarArg;
11 final UpValue.Getter[] upValueGetters; 10 final UpValue.Getter[] upValueGetters;
12 11
13 FnDef(Expressions block,int stackSize,int numArgs,boolean isVarArg,UpValue.Getter[] upValueGetters) { 12 public FnDef(int stackSize,int numArgs,boolean isVarArg,UpValue.Getter[] upValueGetters) {
14 this.block = block;
15 this.stackSize = stackSize; 13 this.stackSize = stackSize;
16 this.numArgs = numArgs; 14 this.numArgs = numArgs;
17 this.isVarArg = isVarArg; 15 this.isVarArg = isVarArg;
18 this.upValueGetters = upValueGetters; 16 this.upValueGetters = upValueGetters;
19 // fixReturns(block);
20 } 17 }
21 /* 18
22 private static void fixReturns(Stmt stmt) {
23 if( stmt instanceof ReturnStmt ) {
24 ReturnStmt rs = (ReturnStmt)stmt;
25 rs.throwReturnException = false;
26 } else if( stmt instanceof Block ) {
27 Block b = (Block)stmt;
28 fixReturns( b.stmts[b.stmts.length-1] );
29 } else if( stmt instanceof IfStmt ) {
30 IfStmt is = (IfStmt)stmt;
31 fixReturns( is.thenStmt );
32 fixReturns( is.elseStmt );
33 }
34 }
35 */
36 @Override public Object eval(LuanStateImpl luan) throws LuanException { 19 @Override public Object eval(LuanStateImpl luan) throws LuanException {
37 return new Closure(luan,this); 20 return new Closure(luan,this);
38 } 21 }
39 22
23 public abstract Object run(LuanStateImpl luan) throws LuanException;
40 } 24 }