Mercerenies / gdlisp

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

Macro Call Subversion #42

Open Mercerenies opened 3 years ago

Mercerenies commented 3 years ago

This is mainly targeted at the if / when / unless macros, but in theory it could apply to user-defined macros as well.

The user is going to use if a ton, and I don't want us calling out to GDScript every time. That just slows the compiler to a crawl. if is defined as follows.

(defmacro if (cnd t &opt f)
  `(cond
    (,cnd ,t)
     (#t ,f)))

Here's my proposal. If a macro satisfies all of the following conditions, then it is eligible for call subversion.

  1. The macro body consists of one single statement, which is either a quasiquote or a quote call.
  2. Within the quoted body, all unquotes are of the form (unquote variable-name) where variable-name is the name of an argument to the macro.

In this case, we take the extremely simply macro body and interpret it in Rust using our existing quasiquoting mechanism, avoiding the GDScript macro call altogether.

Mercerenies commented 3 years ago

Also applies to symbol macros after we have #22.