feat: add numParams tracking and arity-checked fn.call variants for extra/missing args

Add `numParams` field to `ObjFn` and `Compiler` structs to track expected parameter count. Refactor `parameterList` to return count and store it in compiler. Modify `endCompiler` to pass `numParams` to `wrenNewFunction`. Replace single `fn_call` native with 17 arity-specific `fn_call0` through `fn_call16` natives that validate argument count against `fn->numParams` via `callFunction` helper, returning error on missing args. Remove stale TODO comment in VM interpreter. Add test files `call_extra_arguments.wren` and `call_missing_arguments.wren`.
This commit is contained in:
Bob Nystrom
2014-02-04 17:34:05 +00:00
parent dbf0131776
commit 86015f4e48
7 changed files with 102 additions and 43 deletions
+16
View File
@@ -0,0 +1,16 @@
var f0 = fn IO.print("zero")
var f1 = fn(a) IO.print("one " + a)
var f2 = fn(a, b) IO.print("two " + a + " " + b)
var f3 = fn(a, b, c) IO.print("three " + a + " " + b + " " + c)
f0.call("a") // expect: zero
f0.call("a", "b") // expect: zero
f1.call("a", "b") // expect: one a
f1.call("a", "b", "c") // expect: one a
f2.call("a", "b", "c") // expect: two a b
f2.call("a", "b", "c", "d") // expect: two a b
f3.call("a", "b", "c", "d") // expect: three a b c
f3.call("a", "b", "c", "d", "e") // expect: three a b c
@@ -0,0 +1,2 @@
var f2 = fn(a, b) IO.print(a + b)
f2.call("a") // expect runtime error: Function expects more arguments.