@@ -1377,6 +1377,7 @@ sub arrange_args(@in) {
1377
1377
my $ call_gen := sub ($ qastcomp , $ op ) {
1378
1378
# Work out what callee is.
1379
1379
my $ callee ;
1380
+ my $ return_type ;
1380
1381
my @ args := $ op . list;
1381
1382
if $ op . name {
1382
1383
$ callee := $ qastcomp . as_mast($ op . op eq ' callstatic'
@@ -1386,6 +1387,9 @@ my $call_gen := sub ($qastcomp, $op) {
1386
1387
elsif + @ args {
1387
1388
@ args := nqp :: clone (@ args );
1388
1389
$ callee := $ qastcomp . as_mast(@ args . shift (), : want($ MVM_reg_obj ));
1390
+ if $ op . op eq ' nativeinvoke' {
1391
+ $ return_type := $ qastcomp . as_mast(@ args . shift (), : want($ MVM_reg_obj ));
1392
+ }
1389
1393
}
1390
1394
else {
1391
1395
nqp ::die(" No name for call and empty children list" );
@@ -1406,6 +1410,9 @@ my $call_gen := sub ($qastcomp, $op) {
1406
1410
1407
1411
# Append the code to evaluate the callee expression
1408
1412
push_ilist(@ ins , $ callee );
1413
+ if $ op . op eq ' nativeinvoke' {
1414
+ push_ilist(@ ins , $ return_type );
1415
+ }
1409
1416
1410
1417
# Process arguments.
1411
1418
for @ args {
@@ -1436,18 +1443,22 @@ my $call_gen := sub ($qastcomp, $op) {
1436
1443
# and allocate a register for it. Probably reuse an arg's or the callee's.
1437
1444
my $ res_reg := $ regalloc . fresh_register($ res_kind );
1438
1445
1446
+ nqp :: unshift (@ arg_regs , $ return_type . result_reg) if $ op . op eq ' nativeinvoke' ;
1447
+
1439
1448
# Generate call.
1440
1449
nqp :: push (@ ins , MAST::Call. new (
1441
1450
: target($ decont_reg ),
1442
1451
: flags(@ arg_flags ),
1443
1452
| @ arg_regs ,
1444
- : result($ res_reg )
1453
+ : result($ res_reg ),
1454
+ : op($ op . op eq ' nativeinvoke' ?? 1 !! 0 ),
1445
1455
));
1446
1456
1447
1457
MAST::InstructionList. new (@ ins , $ res_reg , $ res_kind )
1448
1458
};
1449
1459
QAST ::MASTOperations. add_core_op(' call' , $ call_gen , :! inlinable);
1450
1460
QAST ::MASTOperations. add_core_op(' callstatic' , $ call_gen , :! inlinable);
1461
+ QAST ::MASTOperations. add_core_op(' nativeinvoke' , $ call_gen , :! inlinable);
1451
1462
1452
1463
QAST ::MASTOperations. add_core_op(' callmethod' , -> $ qastcomp , $ op {
1453
1464
my @ args := nqp :: clone ($ op . list);
@@ -2801,7 +2812,7 @@ QAST::MASTOperations.add_core_moarop_mapping('nfarunalt', 'nfarunalt', 0);
2801
2812
2802
2813
# native call ops
2803
2814
QAST ::MASTOperations. add_core_moarop_mapping(' initnativecall' , ' no_op' );
2804
- QAST ::MASTOperations. add_core_moarop_mapping(' buildnativecall' , ' nativecallbuild' , 0 );
2815
+ QAST ::MASTOperations. add_core_moarop_mapping(' buildnativecall' , ' nativecallbuild' );
2805
2816
QAST ::MASTOperations. add_core_moarop_mapping(' nativecallinvoke' , ' nativecallinvoke' );
2806
2817
QAST ::MASTOperations. add_core_op(' nativecall' , -> $ qastcomp , $ op {
2807
2818
proto decont_all(@ args ) {
0 commit comments