feat: refactor method_call benchmark to use inheritance and fix constructor binding

Refactor the method_call benchmark across Lua, Python, Ruby, and Wren to use proper inheritance with super calls instead of direct state manipulation. This ensures all languages benchmark super method invocations consistently.

Fix a bug in the Wren compiler where constructors weren't being bound correctly by extracting method binding logic into a dedicated `bindMethod` function that properly handles both instance and static methods against the class object.

Optimize if-statement compilation by restructuring jump instruction emission to eliminate unnecessary CODE_JUMP instructions when no else branch exists, reducing bytecode size for conditional blocks.

Update the superclass constructor test to verify inherited field access through super constructor chains, confirming correct field initialization across multiple inheritance levels.
This commit is contained in:
Bob Nystrom
2013-12-18 15:37:41 +00:00
parent e26afd7de3
commit 7ac04b9e3d
7 changed files with 62 additions and 61 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ NthToggle = Toggle:new()
function NthToggle:activate ()
self.counter = self.counter + 1
if self.counter >= self.count_max then
self.state = not self.state
Toggle.activate(self)
self.counter = 0
end
return self
+2 -2
View File
@@ -4,7 +4,7 @@
import sys
import time
class Toggle:
class Toggle(object):
def __init__(self, start_state):
self.bool = start_state
def value(self):
@@ -21,7 +21,7 @@ class NthToggle(Toggle):
def activate(self):
self.counter += 1
if (self.counter >= self.count_max):
self.bool = not self.bool
super(NthToggle, self).activate()
self.counter = 0
return(self)
+1 -1
View File
@@ -29,7 +29,7 @@ class NthToggle < Toggle
def activate
@counter += 1
if @counter >= @count_max
@bool = !@bool
super
@counter = 0
end
self
+2 -31
View File
@@ -10,36 +10,8 @@ class Toggle {
}
}
class NthToggle {
this new(startState, maxCounter) {
_state = startState
_countMax = maxCounter
_count = 0
}
value { return _state }
activate {
_count = _count + 1
if (_count >= _countMax) {
_state = !_state
_count = 0
}
return this
}
}
// TODO: The follow the other examples, we should be using inheritance here.
// Since Wren doesn't currently support inherited fields or calling superclass
// constructors, it doesn't. It probably won't make a huge perf difference,
// but it should be fixed when possible to be:
/*
class NthToggle is Toggle {
this new(startState, maxCounter) {
// TODO: Need to distinguish superclass method calls from superclass
// constructor calls.
super.new(startState)
this new(startState, maxCounter) super.new(startState) {
_countMax = maxCounter
_count = 0
}
@@ -47,14 +19,13 @@ class NthToggle is Toggle {
activate {
_count = _count + 1
if (_count >= _countMax) {
_state = !_state
super.activate
_count = 0
}
return this
}
}
*/
var start = OS.clock
var n = 1000000