annotate core/src/luan/impl/FnCall.java @ 372:f08cefa4594c

start editing manual
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 17 Apr 2015 07:58:20 -0600
parents 3dcb0f9bee82
children d55e873e1f0d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
166
4eaee12f6c65 move luan/interp to impl
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 132
diff changeset
1 package luan.impl;
2
4da26b11d12a start interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
2
48
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
3 import luan.Luan;
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
4 import luan.LuanFunction;
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
5 import luan.LuanException;
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
6 import luan.LuanSource;
2
4da26b11d12a start interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
7
4da26b11d12a start interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
8
40
e3624b7cd603 implement stack trace
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 37
diff changeset
9 final class FnCall extends CodeImpl implements Expressions {
22
1e37f22a34c8 proper tail calls
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 13
diff changeset
10 final Expr fnExpr;
1e37f22a34c8 proper tail calls
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 13
diff changeset
11 final Expressions args;
40
e3624b7cd603 implement stack trace
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 37
diff changeset
12 final String fnName;
2
4da26b11d12a start interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
13
48
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
14 FnCall(LuanSource.Element se,Expr fnExpr,Expressions args) {
40
e3624b7cd603 implement stack trace
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 37
diff changeset
15 super(se);
2
4da26b11d12a start interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
16 this.fnExpr = fnExpr;
4da26b11d12a start interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
17 this.args = args;
40
e3624b7cd603 implement stack trace
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 37
diff changeset
18 this.fnName = fnExpr.se().text();
2
4da26b11d12a start interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
19 }
4da26b11d12a start interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
20
111
2428ecfed375 change LuanFunction.call() from returning Object[] to returning Object, to reduce garbage collection
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
21 @Override public Object eval(LuanStateImpl luan) throws LuanException {
49
8ede219cd111 add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 48
diff changeset
22 return call( luan, fnExpr.eval(luan) );
35
e51906de0f11 implement metatables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 31
diff changeset
23 }
e51906de0f11 implement metatables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 31
diff changeset
24
111
2428ecfed375 change LuanFunction.call() from returning Object[] to returning Object, to reduce garbage collection
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 88
diff changeset
25 private Object call(LuanStateImpl luan,Object o) throws LuanException {
48
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
26 if( o instanceof LuanFunction ) {
64ecb7a3aad7 rename Lua to Luan
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 40
diff changeset
27 LuanFunction fn = (LuanFunction)o;
112
f5af13062b10 fix previous rev
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 111
diff changeset
28 return luan.bit(se).call( fn, fnName, Luan.array(args.eval(luan)) );
35
e51906de0f11 implement metatables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 31
diff changeset
29 }
49
8ede219cd111 add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 48
diff changeset
30 Object h = luan.getHandler("__call",o);
35
e51906de0f11 implement metatables
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 31
diff changeset
31 if( h != null )
49
8ede219cd111 add WebShell
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 48
diff changeset
32 return call(luan,h);
88
6ca02b188dba add LuanBit to clean up code;
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 56
diff changeset
33 throw luan.bit(fnExpr.se()).exception( "attempt to call '"+fnExpr.se().text()+"' (a " + Luan.type(o) + " value)" );
2
4da26b11d12a start interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
34 }
132
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 112
diff changeset
35
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 112
diff changeset
36 @Override public String toString() {
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 112
diff changeset
37 return "(FnCall "+fnName+" "+fnExpr+" "+args+")";
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents: 112
diff changeset
38 }
2
4da26b11d12a start interp
fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
parents:
diff changeset
39 }