1
1
package com .annimon .ownlang .parser .ast ;
2
2
3
3
import com .annimon .ownlang .lib .Function ;
4
+ import com .annimon .ownlang .lib .FunctionValue ;
4
5
import com .annimon .ownlang .lib .Functions ;
6
+ import static com .annimon .ownlang .lib .Functions .isExists ;
5
7
import com .annimon .ownlang .lib .UserDefinedFunction ;
6
8
import com .annimon .ownlang .lib .Value ;
7
9
import com .annimon .ownlang .lib .Variables ;
@@ -39,7 +41,7 @@ public Value eval() {
39
41
values [i ] = arguments .get (i ).eval ();
40
42
}
41
43
42
- final Function function = Functions . get (name );
44
+ final Function function = getFunction (name );
43
45
if (function instanceof UserDefinedFunction ) {
44
46
final UserDefinedFunction userFunction = (UserDefinedFunction ) function ;
45
47
if (size != userFunction .getArgsCount ()) throw new RuntimeException ("Args count mismatch" );
@@ -55,6 +57,15 @@ public Value eval() {
55
57
return function .execute (values );
56
58
}
57
59
60
+ private Function getFunction (String key ) {
61
+ if (Functions .isExists (key )) return Functions .get (key );
62
+ if (Variables .isExists (key )) {
63
+ final Value value = Variables .get (key );
64
+ if (value instanceof FunctionValue ) return ((FunctionValue )value ).getValue ();
65
+ }
66
+ throw new RuntimeException ("Unknown function " + key );
67
+ }
68
+
58
69
@ Override
59
70
public void accept (Visitor visitor ) {
60
71
visitor .visit (this );
0 commit comments