Mercerenies / gdlisp

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

Splitting Statement Wrappers #3

Closed Mercerenies closed 3 years ago

Mercerenies commented 3 years ago

This is more technical than anything, but it would be nice. Currently, if we have an if statement as the last line of a function as follows

(if 1 2 3)

Then it compiles to a temporary variable

var _if_0 = GDLisp.Nil
if 1:
    _if_0 = 2
else:
    _if_0 = 3
return _if_0

When, really, for things like return (stmt_wrapper::Return) or simple assignment (stmt_wrapper::AssignToExpr), we can simply do the assignment or return in both branches.

if 1:
    return 2
else:
    return 3

So here's my somewhat sizeable proposal. Currently, compile_stmt delegates to compile_expr. What if we got rid of the latter? Then everything calls compile_stmt and more complicated things like function call arguments can pass a special StmtWrapper that understands to generate and use a temporary variable, whereas for simple wrappers, if statements and things can split without the temporary.

Mercerenies commented 3 years ago

With everything that's happened since I first opened this issue, I'm calling this one "won't fix". It adds a ton of complexity and involves a lot of changes to fairly fundamental code. The optimizations in question are not that extreme, and ideally the optimizer could take care of them long-term. Closing.