Skip to content

Commit

Permalink
SCLang: Too many args passed to certain 'inline' methods
Browse files Browse the repository at this point in the history
When the compile/parser see a method with only a single call, or a call to `super.something`, it 'inlines' it.

For these methods, all the users arguments were being passed through, regardless of how many were declared in the function signature.

This commit checks this, and removes any excess args from the stack.

Closes #1087
  • Loading branch information
JordanHendersonMusic committed May 9, 2024
1 parent 96c4fc5 commit ffe7f32
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lang/LangSource/PyrInterpreter3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2980,6 +2980,10 @@ HOT void Interpret(VMGlobals* g) {
for (m = 0, mmax = methraw->numargs - numArgsPushed; m < mmax; ++m)
slotCopy(++sp, ++qslot);
numArgsPushed = methraw->numargs;
} else if (methraw->varargs == 0 && numArgsPushed > methraw->numargs) {
const auto num_slots_to_chop = numArgsPushed - methraw->numargs;
sp -= num_slots_to_chop;
numArgsPushed = methraw->numargs;
}
selector = slotRawSymbol(&meth->selectors);
goto msg_lookup;
Expand All @@ -2992,6 +2996,10 @@ HOT void Interpret(VMGlobals* g) {
for (m = 0, mmax = methraw->numargs - numArgsPushed; m < mmax; ++m)
slotCopy(++sp, ++qslot);
numArgsPushed = methraw->numargs;
} else if (methraw->varargs == 0 && numArgsPushed > methraw->numargs){
const auto num_slots_to_chop = numArgsPushed - methraw->numargs;
sp -= num_slots_to_chop;
numArgsPushed = methraw->numargs;
}
selector = slotRawSymbol(&meth->selectors);
classobj = slotRawSymbol(&slotRawClass(&meth->ownerclass)->superclass)->u.classobj;
Expand All @@ -3006,6 +3014,11 @@ HOT void Interpret(VMGlobals* g) {
slotCopy(++sp, ++qslot);
numArgsPushed = methraw->numargs;
}
else if (methraw->varargs == 0 && numArgsPushed > methraw->numargs) {
const auto num_slots_to_chop = numArgsPushed - methraw->numargs;
sp -= num_slots_to_chop;
numArgsPushed = methraw->numargs;
}
selector = slotRawSymbol(&meth->selectors);
index = methraw->specialIndex;
slotCopy(slot, &slotRawObject(slot)->slots[index]);
Expand All @@ -3023,6 +3036,11 @@ HOT void Interpret(VMGlobals* g) {
slotCopy(++sp, ++qslot);
numArgsPushed = methraw->numargs;
}
else if (methraw->varargs == 0 && numArgsPushed > methraw->numargs) {
const auto num_slots_to_chop = numArgsPushed - methraw->numargs;
sp -= num_slots_to_chop;
numArgsPushed = methraw->numargs;
}
selector = slotRawSymbol(&meth->selectors);
slotCopy(slot, &g->classvars->slots[methraw->specialIndex]);

Expand Down
12 changes: 12 additions & 0 deletions testsuite/classlibrary/TestCorrectArgCount.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
TestCorrectArgCountObj {
var <a, <b, <c;
*new {|a| ^super.newCopyArgs(a) }
}
TestCorrectArgCount : UnitTest {
test_correct_arg {
var o = TestCorrectArgCountObj(\a, \b, \c);
this.assertEquals(o.a, \a);
this.assertEquals(o.b, nil);
this.assertEquals(o.c, nil);
}
}

0 comments on commit ffe7f32

Please sign in to comment.