First stab at format args and a working println macro #141
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces the necessary plumbing to implement the Rune equivalent of Rust's
println!
macro.This will eventually be pulled and made into re-usable code so that it can be re-used with other macros that wants to use format specifications (
assert!
,assert_eq!
, etc...).The macro is implemented like the following:
#[builtin] template!("Hello ", a)
(instead oftemplate { "Hello ", a }
, which required a special keyword.#[builtin] format_spec!(value, type = debug)
(if debug).The
#[builtin]
attribute changes naming resolution for macros to look for compiler built-in macros. These are macros which expand internally toBuiltInMacro
variants, and the macro AST is assigned the appropriate ID so that it can look up the implementation during assembly. It also acts as a sentinel which nukes the compilation in case we forget to expand it. I.e. all attributes need to be consumed one way or another, and if we fail to expand the internal macros, they won't be and compilation will fail.This allows us to use and implement internal macros which can do some special things. In this case, an expansion of
format_spec!
results in using the newly introducedFormatSpec
instruction to build the newly introducedFormatSpec
object, which has a few tricks up its sleeve when combined withconcat-strings
.Ultimately this means that the following macro invocation:
Is expanded to:
Or... the following instructions:
Currently only the following format specifications are supported:
{}
).{2}
).{foo}
).{foo:?}
).Also note that only a limited subset of types are supported through string-concat right now. And the implementation needs to be cleaned up A LOT.