File tree Expand file tree Collapse file tree 2 files changed +11
-16
lines changed Expand file tree Collapse file tree 2 files changed +11
-16
lines changed Original file line number Diff line number Diff line change @@ -28,12 +28,21 @@ public String getArgsName(int index) {
28
28
}
29
29
30
30
@ Override
31
- public Value execute (Value ... args ) {
31
+ public Value execute (Value ... values ) {
32
+ final int size = values .length ;
33
+ if (size != getArgsCount ()) throw new RuntimeException ("Args count mismatch" );
34
+
32
35
try {
36
+ Variables .push ();
37
+ for (int i = 0 ; i < size ; i ++) {
38
+ Variables .set (getArgsName (i ), values [i ]);
39
+ }
33
40
body .execute ();
34
41
return NumberValue .ZERO ;
35
42
} catch (ReturnStatement rt ) {
36
43
return rt .getResult ();
44
+ } finally {
45
+ Variables .pop ();
37
46
}
38
47
}
39
48
Original file line number Diff line number Diff line change @@ -40,21 +40,7 @@ public Value eval() {
40
40
for (int i = 0 ; i < size ; i ++) {
41
41
values [i ] = arguments .get (i ).eval ();
42
42
}
43
-
44
- final Function function = getFunction (name );
45
- if (function instanceof UserDefinedFunction ) {
46
- final UserDefinedFunction userFunction = (UserDefinedFunction ) function ;
47
- if (size != userFunction .getArgsCount ()) throw new RuntimeException ("Args count mismatch" );
48
-
49
- Variables .push ();
50
- for (int i = 0 ; i < size ; i ++) {
51
- Variables .set (userFunction .getArgsName (i ), values [i ]);
52
- }
53
- final Value result = userFunction .execute (values );
54
- Variables .pop ();
55
- return result ;
56
- }
57
- return function .execute (values );
43
+ return getFunction (name ).execute (values );
58
44
}
59
45
60
46
private Function getFunction (String key ) {
You can’t perform that action at this time.
0 commit comments