GitHub

@@ -1642,7 +1642,7 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)

16421642

{

16431643

mrb_sym sym = name ? name : nsym(tree->cdr->car);

16441644

int skip = 0;

1645-

int n = 0, nk = 0, st = 0, noop = 0, blk = 0;

1645+

int n = 0, nk = 0, noop = 0, blk = 0, sp_save = cursp();

1646164616471647

codegen(s, tree->car, VAL); /* receiver */

16481648

if (safe) {

@@ -1653,9 +1653,8 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)

16531653

tree = tree->cdr->cdr->car;

16541654

if (tree) {

16551655

if (tree->car) { /* positional arguments */

1656-

st = n = gen_values(s, tree->car, VAL, sp?1:0, 14);

1656+

n = gen_values(s, tree->car, VAL, sp?1:0, 14);

16571657

if (n < 0) { /* variable length */

1658-

st = 1; /* one stack element */

16591658

noop = 1; /* not operator */

16601659

n = 15;

16611660

push();

@@ -1664,12 +1663,22 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)

16641663

if (tree->cdr->car) { /* keyword arguments */

16651664

noop = 1;

16661665

nk = gen_hash(s, tree->cdr->car->cdr, VAL, 14);

1667-

if (nk < 0) {st++; nk = 15;}

1668-

else st += 2*nk;

1666+

if (nk < 0) nk = 15;

16691667

}

16701668

}

16711669

if (sp) { /* last argument pushed (attr=, []=) */

1670+

/* pack keyword arguments */

1671+

if (nk > 0 && nk < 15) {

1672+

pop_n(nk*2);

1673+

genop_2(s, OP_HASH, cursp(), nk);

1674+

push();

1675+

}

16721676

if (n == CALL_MAXARGS) {

1677+

if (nk > 0) {

1678+

pop(); pop();

1679+

genop_2(s, OP_ARYPUSH, cursp(), 1);

1680+

push();

1681+

}

16731682

gen_move(s, cursp(), sp, 0);

16741683

pop();

16751684

genop_2(s, OP_ARYPUSH, cursp(), 1);

@@ -1678,8 +1687,10 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)

16781687

else {

16791688

gen_move(s, cursp(), sp, 0);

16801689

push();

1681-

n++; st++;

1690+

if (nk > 0) n++;

1691+

n++;

16821692

}

1693+

nk = 0;

16831694

}

16841695

if (tree && tree->cdr && tree->cdr->cdr) {

16851696

codegen(s, tree->cdr->cdr, VAL);

@@ -1688,7 +1699,7 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)

16881699

blk = 1;

16891700

}

16901701

push();pop();

1691-

pop_n(st+1);

1702+

s->sp = sp_save;

16921703

if (!noop && sym == MRB_OPSYM_2(s->mrb, add) && n == 1) {

16931704

gen_addsub(s, OP_ADD, cursp());

16941705

}

Read the original on github.com ↗