Mercerenies / gdlisp

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

`yield*` macro #25

Closed Mercerenies closed 3 years ago

Mercerenies commented 3 years ago

A yield* macro that yields from whatever function you call until the function terminates. We could compile it something like (rough example below)

(yield* (foo))

to

(let ((result (foo)))
  (while (and (instance? result GDScriptFunctionState) (result:is_valid))
    (yield)
    (setq result (result:resume)))
  result)

which would (barring weirdness with and requiring the while intermediate form right now) compile to basically

var result = foo()
while result is GDScriptFunctionState and result.is_valid():
    yield()
    result = result.resume()
return result
Mercerenies commented 3 years ago

Closed as of 9867fe7. There's some some room to optimize the resulting GDScript, as it is definitely more complicated than the proposed GDScript above, but the GDLisp expansion is identical.