Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make define-macro macro that outputs JS functions #102

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Gozala
Copy link
Collaborator

@Gozala Gozala commented May 22, 2014

This is work in progress patch. With this extension following code will produce output below it:

(define-macro unless  
  [condition form]
  (list 'if condition nil form ))


(unless weekend? (alarm "8:00"))
(function () {
    var unless = exports.unless = function unless(condition, form) {
            return list(symbol(void 0, 'if'), condition, void 0, form);
        };
    this['user.wisp$unless'] = unless;
    return unless;
})();
isWeekend ? void 0 : alarm('8:00');

Only visible difference is that macro will actually compile to a JS function. This is a step towards implementing macro imports. Now what's left is to extend analyzer (or maybe compiler) so that :require forms from ns will actually be required during compilation. That way macros from those modules will actually be installed. In addition macro expander will have to be modified slightly so that it will look up macros not only in it's own hash map but rather where define-macro installs them: this['user.wisp$unless']. Finally namespace info will have to be preserved on symbols so that in the code (unless weekend? (alarm "8:00")) unless could be mapped back to either local unless or imported one like my.macros/unless which is necessary to properly resolve macros.

@vendethiel
Copy link

That could actually make macro debug much easier too, right ?

@Gozala
Copy link
Collaborator Author

Gozala commented May 22, 2014

That could actually make macro debug much easier too, right ?

I'm not sure it will be make a big difference since most of the time compilation will happen ahead of time, although it may make testing of macros little easier.

@Gozala
Copy link
Collaborator Author

Gozala commented May 22, 2014

Namespace fixes mentioned earlier have being worked on under #103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants