fix: count subscript parameters in wrenMakeCallHandle for bracket signatures

Add missing loop to count underscore parameters in subscript operator signatures
starting with '['. Previously only counted parameters in parenthesized signatures,
causing incorrect arity for methods like `[_,_]` and `[_,_]=(_)`. Also adds
validation assertions for null and empty signatures, and extends test coverage
with unary, binary, subscript, and subscript-set operator call handles.
This commit is contained in:
Bob Nystrom
2016-05-04 13:29:44 +00:00
parent 1c08148cc8
commit d717f0f174
3 changed files with 66 additions and 4 deletions
+32 -1
View File
@@ -13,7 +13,11 @@ void callRunTests(WrenVM* vm)
WrenValue* zero = wrenMakeCallHandle(vm, "zero()");
WrenValue* one = wrenMakeCallHandle(vm, "one(_)");
WrenValue* two = wrenMakeCallHandle(vm, "two(_,_)");
WrenValue* unary = wrenMakeCallHandle(vm, "-");
WrenValue* binary = wrenMakeCallHandle(vm, "-(_)");
WrenValue* subscript = wrenMakeCallHandle(vm, "[_,_]");
WrenValue* subscriptSet = wrenMakeCallHandle(vm, "[_,_]=(_)");
// Different arity.
wrenEnsureSlots(vm, 1);
wrenSetSlotValue(vm, 0, callClass);
@@ -34,6 +38,29 @@ void callRunTests(WrenVM* vm)
wrenSetSlotDouble(vm, 2, 2.0);
wrenCall(vm, two);
// Operators.
wrenEnsureSlots(vm, 1);
wrenSetSlotValue(vm, 0, callClass);
wrenCall(vm, unary);
wrenEnsureSlots(vm, 2);
wrenSetSlotValue(vm, 0, callClass);
wrenSetSlotDouble(vm, 1, 1.0);
wrenCall(vm, binary);
wrenEnsureSlots(vm, 3);
wrenSetSlotValue(vm, 0, callClass);
wrenSetSlotDouble(vm, 1, 1.0);
wrenSetSlotDouble(vm, 2, 2.0);
wrenCall(vm, subscript);
wrenEnsureSlots(vm, 4);
wrenSetSlotValue(vm, 0, callClass);
wrenSetSlotDouble(vm, 1, 1.0);
wrenSetSlotDouble(vm, 2, 2.0);
wrenSetSlotDouble(vm, 3, 3.0);
wrenCall(vm, subscriptSet);
// Returning a value.
WrenValue* getValue = wrenMakeCallHandle(vm, "getValue()");
wrenEnsureSlots(vm, 1);
@@ -89,4 +116,8 @@ void callRunTests(WrenVM* vm)
wrenReleaseValue(vm, two);
wrenReleaseValue(vm, getValue);
wrenReleaseValue(vm, value);
wrenReleaseValue(vm, unary);
wrenReleaseValue(vm, binary);
wrenReleaseValue(vm, subscript);
wrenReleaseValue(vm, subscriptSet);
}
+20
View File
@@ -21,12 +21,32 @@ class Call {
}
static getValue() { ["a", "b"] }
static - {
System.print("unary")
}
static -(arg) {
System.print("binary %(arg)")
}
static [one, two] {
System.print("subscript %(one) %(two)")
}
static [one, two]=(three) {
System.print("subscript set %(one) %(two) %(three)")
}
}
// expect: noParams
// expect: zero
// expect: one 1
// expect: two 1 2
// expect: unary
// expect: binary 1
// expect: subscript 1 2
// expect: subscript set 1 2 3
// expect: two true false
// expect: two 1.2 3.4