refactor: rename symbols to methods and defineName to declareVariable in compiler and VM
Rename the `SymbolTable symbols` field in `VM` struct to `methods` to clarify its purpose for method dispatch, and update all references across `vm.c`, `vm.h`, `primitives.c`, and `compiler.c`. Rename `defineName` to `declareVariable` to better reflect its actual behavior of declaring a variable without defining it. Remove the unused `internSymbol` helper function. Add `clearSymbolTable(&vm->globalSymbols)` to `freeVM` to fix a memory leak. Update `dumpCode` signature to take `VM*` and `ObjFn*` instead of `ObjBlock*`, and display method names via `getSymbolName`. Add `stackStart` field to `CallFrame` replacing `locals` for clearer semantics. Introduce `test/method_arity.wren` to validate method dispatch with up to 10 parameters.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
class Foo {
|
||||
method { 0 }
|
||||
method(a) { a }
|
||||
method(a, b) { a + b }
|
||||
method(a, b, c) { a + b + c }
|
||||
method(a, b, c, d) { a + b + c + d }
|
||||
method(a, b, c, d, e) { a + b + c + d + e }
|
||||
method(a, b, c, d, e, f) { a + b + c + d + e + f }
|
||||
method(a, b, c, d, e, f, g) { a + b + c + d + e + f + g }
|
||||
method(a, b, c, d, e, f, g, h) { a + b + c + d + e + f + g + h }
|
||||
method(a, b, c, d, e, f, g, h, i) { a + b + c + d + e + f + g + h + i }
|
||||
method(a, b, c, d, e, f, g, h, i, j) { a + b + c + d + e + f + g + h + i + j }
|
||||
}
|
||||
|
||||
var foo = Foo.new
|
||||
io.write(foo.method) // expect: 0
|
||||
io.write(foo.method(1)) // expect: 1
|
||||
io.write(foo.method(1, 2)) // expect: 3
|
||||
io.write(foo.method(1, 2, 3)) // expect: 6
|
||||
io.write(foo.method(1, 2, 3, 4)) // expect: 10
|
||||
io.write(foo.method(1, 2, 3, 4, 5)) // expect: 15
|
||||
io.write(foo.method(1, 2, 3, 4, 5, 6)) // expect: 21
|
||||
io.write(foo.method(1, 2, 3, 4, 5, 6, 7)) // expect: 28
|
||||
io.write(foo.method(1, 2, 3, 4, 5, 6, 7, 8)) // expect: 36
|
||||
io.write(foo.method(1, 2, 3, 4, 5, 6, 7, 8, 9)) // expect: 45
|
||||
io.write(foo.method(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) // expect: 55
|
||||
Reference in New Issue
Block a user