Mercurial Hosting > luan
comparison src/luan/interp/Closure.java @ 111:2428ecfed375
change LuanFunction.call() from returning Object[] to returning Object, to reduce garbage collection
git-svn-id: https://luan-java.googlecode.com/svn/trunk@112 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 23 May 2014 20:40:05 +0000 |
parents | 6db8f286fa6c |
children | d7be9b3abf1a |
comparison
equal
deleted
inserted
replaced
110:7afa6df829f3 | 111:2428ecfed375 |
---|---|
1 package luan.interp; | 1 package luan.interp; |
2 | 2 |
3 import luan.Luan; | |
3 import luan.LuanFunction; | 4 import luan.LuanFunction; |
4 import luan.LuanState; | 5 import luan.LuanState; |
5 import luan.LuanElement; | 6 import luan.LuanElement; |
6 import luan.LuanException; | 7 import luan.LuanException; |
7 import luan.DeepCloner; | 8 import luan.DeepCloner; |
35 | 36 |
36 UpValue[] upValues() { | 37 UpValue[] upValues() { |
37 return upValues; | 38 return upValues; |
38 } | 39 } |
39 | 40 |
40 public Object[] call(LuanState luan,Object[] args) throws LuanException { | 41 @Override public Object call(LuanState luan,Object[] args) throws LuanException { |
41 return call(this,(LuanStateImpl)luan,args); | 42 return call(this,(LuanStateImpl)luan,args); |
42 } | 43 } |
43 | 44 |
44 private static Object[] call(Closure closure,LuanStateImpl luan,Object[] args) throws LuanException { | 45 private static Object call(Closure closure,LuanStateImpl luan,Object[] args) throws LuanException { |
45 while(true) { | 46 while(true) { |
46 FnDef fnDef = closure.fnDef; | 47 FnDef fnDef = closure.fnDef; |
47 Object[] varArgs = null; | 48 Object[] varArgs = null; |
48 if( fnDef.isVarArg ) { | 49 if( fnDef.isVarArg ) { |
49 if( args.length > fnDef.numArgs ) { | 50 if( args.length > fnDef.numArgs ) { |
58 Object[] stack = luan.newFrame(closure,fnDef.stackSize,varArgs); | 59 Object[] stack = luan.newFrame(closure,fnDef.stackSize,varArgs); |
59 final int n = Math.min(args.length,fnDef.numArgs); | 60 final int n = Math.min(args.length,fnDef.numArgs); |
60 for( int i=0; i<n; i++ ) { | 61 for( int i=0; i<n; i++ ) { |
61 stack[i] = args[i]; | 62 stack[i] = args[i]; |
62 } | 63 } |
63 Object[] returnValues; | 64 Object returnValues; |
64 Closure tailFn; | 65 Closure tailFn; |
65 try { | 66 try { |
66 fnDef.block.eval(luan); | 67 fnDef.block.eval(luan); |
67 } catch(ReturnException e) { | 68 } catch(ReturnException e) { |
68 } finally { | 69 } finally { |
70 closure = luan.tailFn; | 71 closure = luan.tailFn; |
71 luan.popFrame(); | 72 luan.popFrame(); |
72 } | 73 } |
73 if( closure == null ) | 74 if( closure == null ) |
74 return returnValues; | 75 return returnValues; |
75 args = returnValues; | 76 args = Luan.array(returnValues); |
76 } | 77 } |
77 } | 78 } |
78 | 79 |
79 } | 80 } |