Unlike in Python, I'm taking the approach of evaluating these at function
call time rather than definition time. Assigning things like empty lists/dicts
to default arguments has always been a ridiculous thing in Python, and I don't
want to make that mistake. I'm pretty sure Python only continues to do that
because it was something they didn't want to break for backwards compatibility
reasons even in Python 3.
This required a new approach for handling function arguments.
Methods remain the same: the callee object is on the stack and positioned
to be "argument 0". Non-methods have changed so that "argument 0" is the
first argument, with the function still remaining before that. When a
non-method is called, we track this fact so that we can continue to restore
the stack to the correct height to get rid of the function. This allows
a method decorator to be defined exactly like it would be in Python
def methodDecorator(func):
def wrappedMethod(instance, someOtherArg):
print "Do something with the arg:", someOtherArg
func(instance)
class Foo():
@methodDecorator
def func():
print "I only take an implicit self:", self
let f = Foo()
f.func("but that other arg is needed")