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

Add S06 macros #261

Open
rurban opened this Issue Mar 14, 2017 · 9 comments

Comments

2 participants
@rurban
Member

rurban commented Mar 14, 2017

Use the existing perl6 S06 synopsis and testcases. "In the absence of
a signature to the contrary, a macro is called as if it were a method
on the current match object returned from the grammar rule being
reduced; that is, all the current parse information is available by
treating $self as if it were a $/ object. Macros may return
either a string to be reparsed, or a syntax tree that needs no further
parsing."

Change the syntax a little bit to harmonize with perl5:

{{{ }}} => `` for unquote splicing.

Expand the ast inside the backticks at compile-time as a subprocess
would be expanded with its result. Use qx() for subprocesses instead.

macro infix:<name> () => macro 'name' :infix ()

I.e. Allow optional single-quoted names for non-identifiers, such as '!!' :postfix.
Use perl5 attributes as perl6 operator overloaders to tell macros if they have
non-standard position: infix, prefix, postfix, circumfix, postcircumfix.

Don't support the quasi attributes :ast/:lang/:unquote, other than :COMPILING.
Support the COMPILING:: pseudo-package for namespace clarification, but not the import syntax COMPILING<$x>. The fullname is good and magic enough.

See the feature/gh261-macros branch.

@rurban rurban changed the title from Add S06 macro to Add S06 macros Mar 14, 2017

@vendethiel

This comment has been minimized.

Show comment
Hide comment
@vendethiel

vendethiel Mar 14, 2017

Contributor

There are a lot of questions stemming from this document. How do you do hygiene? I seem to remember you're a CL enthusiast(?) so you might not bother, but CL needs to execute code to know even how to parse what's coming next. I'm interested in your take on this.

Stuff like macro f() { quasi { my $c = 1; } }; f(); say $c; (or really, adding anything to the scope) is something @masak and everyone else working on 007 have talked a lot about, often in the #6macros freenode channel.

Contributor

vendethiel commented Mar 14, 2017

There are a lot of questions stemming from this document. How do you do hygiene? I seem to remember you're a CL enthusiast(?) so you might not bother, but CL needs to execute code to know even how to parse what's coming next. I'm interested in your take on this.

Stuff like macro f() { quasi { my $c = 1; } }; f(); say $c; (or really, adding anything to the scope) is something @masak and everyone else working on 007 have talked a lot about, often in the #6macros freenode channel.

@rurban

This comment has been minimized.

Show comment
Hide comment
@rurban

rurban Mar 14, 2017

Member

Hygiene is hard with this non-hygienic syntax. For proper hygiene you would need pattern matching as in scheme. But the existing tests should pass.
I'll push the branch soon.

Member

rurban commented Mar 14, 2017

Hygiene is hard with this non-hygienic syntax. For proper hygiene you would need pattern matching as in scheme. But the existing tests should pass.
I'll push the branch soon.

@vendethiel

This comment has been minimized.

Show comment
Hide comment
@vendethiel

vendethiel Mar 14, 2017

Contributor

Okay, so I'm even more interested to see how you'd generate identifiers. Waiting for the branch push. Thanks.

Contributor

vendethiel commented Mar 14, 2017

Okay, so I'm even more interested to see how you'd generate identifiers. Waiting for the branch push. Thanks.

rurban added a commit that referenced this issue Mar 14, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261
@rurban

This comment has been minimized.

Show comment
Hide comment
@rurban

rurban Mar 14, 2017

Member

Just the tests yet, to get the syntax right.
Lexicals are hygienic as they are referred to by index, not by name. So they don't need gensym.

Member

rurban commented Mar 14, 2017

Just the tests yet, to get the syntax right.
Lexicals are hygienic as they are referred to by index, not by name. So they don't need gensym.

@vendethiel

This comment has been minimized.

Show comment
Hide comment
@vendethiel

vendethiel Mar 14, 2017

Contributor

Okay, so you don't plan to make possible to break hygiene, or do you intend to make COMPILING work for this purpose? (it seems the test file is still somewhat rough, since #todo rakudo are still present)

Contributor

vendethiel commented Mar 14, 2017

Okay, so you don't plan to make possible to break hygiene, or do you intend to make COMPILING work for this purpose? (it seems the test file is still somewhat rough, since #todo rakudo are still present)

@rurban

This comment has been minimized.

Show comment
Hide comment
@rurban

rurban Mar 14, 2017

Member

COMPILING sounds easiest. But I'll wait for the perl6 decisions. I just want to implement the already working parts, sans the generally unliked {{{ syntax.
Hygiene is relative with such lexicals as looking up the variable by name will not really work. Similar to the inliner, which needs to create copies with the same name. GCC adds hidden .1 suffices to such copies. Basically macro is very similar to inlining. I'll use the inlining functions in the compiler.

Member

rurban commented Mar 14, 2017

COMPILING sounds easiest. But I'll wait for the perl6 decisions. I just want to implement the already working parts, sans the generally unliked {{{ syntax.
Hygiene is relative with such lexicals as looking up the variable by name will not really work. Similar to the inliner, which needs to create copies with the same name. GCC adds hidden .1 suffices to such copies. Basically macro is very similar to inlining. I'll use the inlining functions in the compiler.

@rurban

This comment has been minimized.

Show comment
Hide comment
@rurban

rurban Mar 14, 2017

Member

re compile-time `` syntax vs '{{{ }}}':
I prefer this syntax and proposed it to Larry some years ago.

  • it resembles the lisp `, quasi/backtick syntax
  • it is semantically similar to qx()/'``' as result of expansion in a subprocess.
  • it is already supported by the syntax highlighter.
  • qx() is still usable within macros, so there's no conflict.
Member

rurban commented Mar 14, 2017

re compile-time `` syntax vs '{{{ }}}':
I prefer this syntax and proposed it to Larry some years ago.

  • it resembles the lisp `, quasi/backtick syntax
  • it is semantically similar to qx()/'``' as result of expansion in a subprocess.
  • it is already supported by the syntax highlighter.
  • qx() is still usable within macros, so there's no conflict.
@vendethiel

This comment has been minimized.

Show comment
Hide comment
@vendethiel

vendethiel Mar 14, 2017

Contributor

That's down to bikeshedding, but we sometimes ago talked about ` being somewhat a sigil, so quasi { `{$ast} } would be used. It's backwards with lisp's quote, and I don't think perl 5/6 needs multi-level unquotes (as opposed to Lisp's infamous `(fn1 `(fn2 ,',var)))

Contributor

vendethiel commented Mar 14, 2017

That's down to bikeshedding, but we sometimes ago talked about ` being somewhat a sigil, so quasi { `{$ast} } would be used. It's backwards with lisp's quote, and I don't think perl 5/6 needs multi-level unquotes (as opposed to Lisp's infamous `(fn1 `(fn2 ,',var)))

@rurban

This comment has been minimized.

Show comment
Hide comment
@rurban

rurban Mar 14, 2017

Member

yes, it's pure bikeshedding. multi-level quote/unquote is still possible though. question is who wants to write such unreadable code. we will see. (Note to myself: eventually track parser/compiler recursion depth, max 500)
object systems need hygienic macros desperately.

Member

rurban commented Mar 14, 2017

yes, it's pure bikeshedding. multi-level quote/unquote is still possible though. question is who wants to write such unreadable code. we will see. (Note to myself: eventually track parser/compiler recursion depth, max 500)
object systems need hygienic macros desperately.

rurban added a commit that referenced this issue Mar 15, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Mar 15, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Mar 15, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Mar 17, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Mar 19, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Mar 20, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Mar 20, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Mar 24, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Mar 24, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Mar 24, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Mar 25, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

@rurban rurban added the enhancement label Mar 26, 2017

@rurban rurban self-assigned this Mar 26, 2017

rurban added a commit that referenced this issue Mar 30, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Mar 30, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Mar 31, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Apr 16, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Apr 17, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Apr 28, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Apr 29, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Apr 29, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Apr 30, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Apr 30, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue May 1, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue May 2, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue May 2, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue May 2, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue May 4, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue May 4, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Oct 14, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Oct 21, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Oct 21, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Oct 22, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Oct 27, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Nov 1, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Nov 2, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 3, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 7, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 13, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 13, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

@rurban rurban added this to In progress in cperl Dec 16, 2017

rurban added a commit that referenced this issue Dec 16, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 18, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 18, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 18, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 19, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 20, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 20, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 20, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 21, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 21, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 22, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 23, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 23, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 24, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 26, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 26, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Dec 27, 2017

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Jan 6, 2018

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Jan 9, 2018

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Jan 16, 2018

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Feb 4, 2018

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Sep 1, 2018

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Sep 1, 2018

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Sep 2, 2018

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Sep 6, 2018

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Sep 14, 2018

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Sep 16, 2018

add t/comp/macro.t
from roast/S06-macros tests.
See #261

rurban added a commit that referenced this issue Sep 18, 2018

add t/comp/macro.t
from roast/S06-macros tests.
See #261
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment