8
8
9
9
import mx .kenzie .foundation .MethodBuilder ;
10
10
import mx .kenzie .foundation .Type ;
11
- import mx .kenzie .foundation .WriteInstruction ;
12
11
import org .byteskript .skript .api .syntax .SimpleExpression ;
13
12
import org .byteskript .skript .compiler .*;
13
+ import org .byteskript .skript .compiler .structure .Function ;
14
14
import org .byteskript .skript .lang .element .StandardElements ;
15
15
16
16
import java .util .ArrayList ;
17
- import java .util .Arrays ;
18
17
import java .util .List ;
19
18
import java .util .regex .Matcher ;
20
19
@@ -52,13 +51,14 @@ public void compile(Context context, Pattern.Match match) throws Throwable {
52
51
assert method != null ;
53
52
final FunctionDetails details = ((FunctionDetails ) match .meta ());
54
53
assert details != null ;
55
- final Type [] parameters = new Type [details .arguments ];
56
- Arrays .fill (parameters , CommonTypes .OBJECT );
57
54
final Type location = new Type (details .location );
58
- method .writeCode (WriteInstruction .invokeStatic (location , CommonTypes .OBJECT , details .name , parameters ));
55
+ // method.writeCode(WriteInstruction.invokeStatic(location, CommonTypes.OBJECT, details.name, parameters));
56
+
57
+ final Function function = new Function (details .name , location , CommonTypes .OBJECT , details .arguments );
58
+ method .writeCode (function .invoke (context .getType ().internalName ()));
59
59
}
60
60
61
- private record FunctionDetails (String name , int arguments , String location ) {
61
+ private record FunctionDetails (String name , Type [] arguments , String location ) {
62
62
}
63
63
64
64
private Pattern .Match createMatch (String thing , Context context ) {
@@ -68,14 +68,15 @@ private Pattern.Match createMatch(String thing, Context context) {
68
68
final String params = matcher .group ("params" );
69
69
final String location = matcher .group ("location" );
70
70
if (location .contains ("\" " )) return null ;
71
- final int count = getParams (params );
72
- final Matcher dummy = java .util .regex .Pattern .compile (buildDummyPattern (name , count , location )).matcher (thing );
71
+ final Type [] parameters = getParams (params );
72
+ final Matcher dummy = java .util .regex .Pattern .compile (buildDummyPattern (name , parameters .length , location ))
73
+ .matcher (thing );
73
74
dummy .find ();
74
75
final List <Type > types = new ArrayList <>();
75
- for (int i = 0 ; i < count ; i ++) {
76
+ for (int i = 0 ; i < parameters . length ; i ++) {
76
77
types .add (CommonTypes .OBJECT );
77
78
}
78
- return new Pattern .Match (dummy , new FunctionDetails (name , count , location ), types .toArray (new Type [0 ]));
79
+ return new Pattern .Match (dummy , new FunctionDetails (name , parameters , location ), types .toArray (new Type [0 ]));
79
80
}
80
81
81
82
private String buildDummyPattern (String name , int params , String location ) {
@@ -90,16 +91,26 @@ private String buildDummyPattern(String name, int params, String location) {
90
91
return builder .append ("\\ ) from " ).append (location ).toString ();
91
92
}
92
93
93
- private int getParams (String params ) {
94
- if (params .isBlank ()) return 0 ;
94
+ private Type [] getParams (String params ) {
95
+ if (params .isBlank ()) return new Type [ 0 ] ;
95
96
int nest = 0 ;
97
+ final List <Type > types = new ArrayList <>();
96
98
int count = 1 ;
99
+ boolean atomic = false ;
97
100
for (char c : params .toCharArray ()) {
98
101
if (c == '(' ) nest ++;
99
102
else if (c == ')' ) nest --;
100
- else if (c == ',' && nest < 1 ) count ++;
103
+ else if (c == '@' && nest < 1 ) atomic = true ;
104
+ else if (c == ',' && nest < 1 ) {
105
+ count ++;
106
+ if (atomic ) types .add (CommonTypes .ATOMIC );
107
+ else types .add (CommonTypes .OBJECT );
108
+ atomic = false ;
109
+ }
101
110
}
102
- return count ;
111
+ if (atomic ) types .add (CommonTypes .ATOMIC );
112
+ else types .add (CommonTypes .OBJECT );
113
+ return types .toArray (new Type [0 ]);
103
114
}
104
115
105
116
}
0 commit comments