@@ -1111,7 +1111,7 @@ sub process_args($qastcomp, @children, $il, $first, :$inv_temp) {
1111
1111
# Return callsite index (which may create it if needed).
1112
1112
return [$ * CODEREFS . get_callsite_idx(@ callsite , @ argnames ), $ arg_array ];
1113
1113
}
1114
- sub process_args_onto_stack ($ qastcomp , @ children , $ il , : $ obj_first ) {
1114
+ sub process_args_onto_stack ($ qastcomp , @ children , $ il , : $ obj_first , : $ inv_first ) {
1115
1115
# Make sure we do positionals before nameds.
1116
1116
my @ pos ;
1117
1117
my @ named ;
@@ -1129,7 +1129,7 @@ sub process_args_onto_stack($qastcomp, @children, $il, :$obj_first) {
1129
1129
my @ argnames ;
1130
1130
my int $ i := 0 ;
1131
1131
while $ i < + @ order {
1132
- my $ arg_res := $ i == 0 && $ obj_first
1132
+ my $ arg_res := $ i == 0 && ( $ obj_first || $ inv_first )
1133
1133
?? $ qastcomp . as_jast(@ order [$ i ], : want($ RT_OBJ ))
1134
1134
!! $ qastcomp . as_jast(@ order [$ i ]);
1135
1135
$ il . append ($ arg_res . jast);
@@ -1146,15 +1146,17 @@ sub process_args_onto_stack($qastcomp, @children, $il, :$obj_first) {
1146
1146
nqp :: push (@ arg_jtypes , jtype($ arg_res . type));
1147
1147
}
1148
1148
1149
- my int $ flags := 0 ;
1150
- if @ order [$ i ]. flat {
1151
- $ flags := @ order [$ i ]. named ?? 24 !! 16 ;
1152
- }
1153
- elsif @ order [$ i ]. named -> $ name {
1154
- $ flags := 8 ;
1155
- nqp :: push (@ argnames , $ name );
1149
+ unless $ i == 0 && $ inv_first {
1150
+ my int $ flags := 0 ;
1151
+ if @ order [$ i ]. flat {
1152
+ $ flags := @ order [$ i ]. named ?? 24 !! 16 ;
1153
+ }
1154
+ elsif @ order [$ i ]. named -> $ name {
1155
+ $ flags := 8 ;
1156
+ nqp :: push (@ argnames , $ name );
1157
+ }
1158
+ nqp :: push (@ callsite , arg_type($ type ) + $ flags );
1156
1159
}
1157
- nqp :: push (@ callsite , arg_type($ type ) + $ flags );
1158
1160
1159
1161
$ i ++ ;
1160
1162
}
@@ -1190,23 +1192,26 @@ QAST::OperationsJAST.add_core_op('call', sub ($qastcomp, $node) {
1190
1192
1191
1193
# Otherwise, it's an indirect call.
1192
1194
else {
1193
- # Compile the thing to invoke.
1195
+ # Ensure we have a thing to invoke.
1194
1196
nqp ::die(" A 'call' node must have a name or at least one child" ) unless + @ ($ node ) >= 1 ;
1195
- my $ invokee := $ qastcomp . as_jast($ node [0 ], : want($ RT_OBJ ));
1196
- $ il . append ($ invokee . jast);
1197
-
1198
- # Process arguments.
1199
- my @ argstuff := process_args($ qastcomp , @ ($ node ), $ il , $ node . name eq " " ?? 1 !! 0 );
1197
+
1198
+ # Proces arguments, making sure first one is an object (since that is
1199
+ # the thing to invoke).
1200
+ my @ argstuff := process_args_onto_stack($ qastcomp , @ ($ node ), $ il , : inv_first);
1200
1201
my $ cs_idx := @ argstuff [0 ];
1201
1202
$ * STACK . spill_to_locals($ il );
1202
-
1203
- # Emit the call.
1204
- $ * STACK . obtain($ il , $ invokee );
1205
- $ il . append (JAST::PushIndex. new ( : value($ cs_idx ) ));
1206
- $ il . append (JAST::Instruction. new ( : op(' aload' ), @ argstuff [1 ] ));
1203
+
1204
+ # Emit the call, using the same thread context trick. The first thing
1205
+ # will be invoked.
1207
1206
$ il . append (JAST::Instruction. new ( : op(' aload_1' ) ));
1208
- $ il . append (JAST::Instruction. new ( : op(' invokestatic' ), $ TYPE_OPS , ' invoke' ,
1209
- ' Void' , $ TYPE_SMO , ' Integer' , " [$ TYPE_OBJ" , $ TYPE_TC ));
1207
+ $ * STACK . obtain($ il , | @ argstuff [1 ]) if @ argstuff [1 ];
1208
+ $ il . append (JAST::InvokeDynamic. new (
1209
+ ' indcall' , ' V' , @ argstuff [2 ],
1210
+ ' org/perl6/nqp/runtime/IndyBootstrap' , ' indcall' ,
1211
+ [
1212
+ JAST::PushIndex. new ( : value($ cs_idx ) )
1213
+ ]
1214
+ ));
1210
1215
}
1211
1216
1212
1217
# Load result onto the stack, unless in void context.
@@ -1234,7 +1239,7 @@ QAST::OperationsJAST.add_core_op('callmethod', -> $qastcomp, $node {
1234
1239
# calling.
1235
1240
if $ node . name ne ' ' {
1236
1241
# Process arguments and force them into locals.
1237
- my @ argstuff := process_args_onto_stack($ qastcomp , @ children , $ il );
1242
+ my @ argstuff := process_args_onto_stack($ qastcomp , @ children , $ il , : obj_first );
1238
1243
my $ cs_idx := @ argstuff [0 ];
1239
1244
$ * STACK . spill_to_locals($ il );
1240
1245
0 commit comments