feat: add optimized field load/store instructions for direct method access
Introduce CODE_LOAD_FIELD_THIS and CODE_STORE_FIELD_THIS opcodes that bypass receiver stack operations when field access occurs directly within a method body. Refactor field() compiler to emit these faster instructions when compiler->methodName is set, and extract loadThis() helper to correctly resolve 'this' in nested functions. Update VM interpreter with dedicated dispatch cases that read receiver from frame->stackStart instead of popping, and add debug disassembly support. Add test cases for field closure capture and nested class field isolation, removing related TODO comments.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
class Foo {
|
||||
new { _field = "Foo field" }
|
||||
|
||||
closeOverGet {
|
||||
return fn { return _field }
|
||||
}
|
||||
|
||||
closeOverSet {
|
||||
return fn { _field = "new value" }
|
||||
}
|
||||
}
|
||||
|
||||
var foo = new Foo
|
||||
IO.write(foo.closeOverGet.call) // expect: Foo field
|
||||
foo.closeOverSet.call
|
||||
IO.write(foo.closeOverGet.call) // expect: new value
|
||||
@@ -6,6 +6,7 @@ class Foo {
|
||||
_d = d
|
||||
_e = e
|
||||
}
|
||||
|
||||
write {
|
||||
IO.write(_a)
|
||||
IO.write(_b)
|
||||
@@ -23,7 +24,3 @@ foo.write
|
||||
// expect: 3
|
||||
// expect: 4
|
||||
// expect: 5
|
||||
|
||||
// TODO: Trying to get or set a field outside of a class.
|
||||
// TODO: Fields in nested classes.
|
||||
// TODO: Closing over fields.
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
class Outer {
|
||||
method {
|
||||
_field = "outer"
|
||||
IO.write(_field) // expect: outer
|
||||
|
||||
class Inner {
|
||||
method {
|
||||
_field = "inner"
|
||||
IO.write(_field) // expect: inner
|
||||
}
|
||||
}
|
||||
|
||||
(new Inner).method
|
||||
IO.write(_field) // expect: outer
|
||||
}
|
||||
}
|
||||
|
||||
(new Outer).method
|
||||
Reference in New Issue
Block a user