-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement compiletime.code with a macro #8859
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
Implement compiletime.code with a macro #8859
Conversation
3dbbcf0
to
6d772ed
Compare
Now, the implemetation is simpler with macros.
6d772ed
to
b6995d5
Compare
Note that I changed the printer. Now it shows the actual code rather than a simplified view of it. I am considering adding an alternative that would print the actual source code of the parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* ``` | ||
* | ||
* @note only by-name arguments will be displayed as "code". | ||
* Other values may display unintutively. | ||
*/ | ||
inline def (self: => StringContext) code (args: => Any*): String = ??? | ||
transparent inline def (inline self: StringContext) code (inline args: Any*): String = ${ codeExpr('self, 'args) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not clear to me why we need transparent
, given that the result type is always String
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is because we want this to return a string literal that can be constant folded with other string literals. Also, the error
method used the type of the string know the value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intrinsic implementation was also transparent, but we forgot to mark the definition as such.
Now, the implementation is simpler with macros. At the time we did not have pattern matching on quoted code.