-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
118 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module M | ||
using JuliaLowering: JuliaLowering, @ast, @chk, adopt_scope | ||
using JuliaSyntax | ||
|
||
# Introspection | ||
macro __MODULE__() | ||
__context__.scope_layer.mod | ||
end | ||
|
||
macro __FILE__() | ||
JuliaLowering.filename(__context__.macroname) | ||
end | ||
|
||
macro __LINE__() | ||
JuliaLowering.source_location(__context__.macroname)[1] | ||
end | ||
|
||
module A | ||
another_global = "global in A" | ||
|
||
macro bar(ex) | ||
quote | ||
x = "`x` in @bar" | ||
(x, another_global, $ex) | ||
end | ||
end | ||
end | ||
|
||
someglobal = "global in module M" | ||
|
||
# Macro with local variables | ||
macro foo(ex) | ||
quote | ||
x = "`x` from @foo" | ||
(x, someglobal, A.@bar $ex) | ||
end | ||
end | ||
|
||
macro set_a_global(val) | ||
quote | ||
global a_global = $val | ||
end | ||
end | ||
|
||
macro set_global_in_parent(ex) | ||
e1 = adopt_scope(:(sym_introduced_from_M), __context__) | ||
quote | ||
$e1 = $ex | ||
end | ||
end | ||
|
||
macro baz(ex) | ||
quote | ||
let $ex = 10 | ||
$ex | ||
end | ||
end | ||
end | ||
end |