Mercerenies / gdlisp

Lisp on the Godot platform
GNU General Public License v3.0
146 stars 1 forks source link

Super Calls #16

Closed Mercerenies closed 2 years ago

Mercerenies commented 3 years ago

Calling superclass methods. I might suggest the literal word super being reserved for this purpose

(super:foo)

Constructors will need to be special-cased, as the constructor super call must appear first (like in Java). We don't even handle constructor super calls in the gdscript syntax tree right now, so that will need to be implemented too.

Mercerenies commented 2 years ago

Constructor super calls which appear at the beginning of the constructor have already been handled, as per acf44c2. That leaves a handful of cases left to consider.

As an example of the last case, the following code

(defclass Foo ()
  (defn foo () (lambda () (super)))

should compile to something like (simplifying the lambda expansion for the purposes of brevity)

class Lambda:
    var _self
    func _init(_self):
        self._self = _self
    func call_func():
        self._self._super_foo()

class Foo(Reference):
    func foo():
        return Lambda.new(self)
    func _super_foo():
        return .foo()
Mercerenies commented 2 years ago

Implemented fully as of 4baee4e.