Skip to content

Commit dd3f8a7

Browse files
committed
Apply suggestions from code review
1 parent 4abba47 commit dd3f8a7

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/desugaring.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3251,21 +3251,21 @@ function expand_macro_def(ctx, ex)
32513251
name = sig[1]
32523252
args = remove_empty_parameters(children(sig))
32533253
@chk kind(args[end]) != K"parameters" (args[end], "macros cannot accept keyword arguments")
3254+
scope_ref = kind(name) == K"." ? name[1] : name
32543255
if ctx.expr_compat_mode
32553256
@ast ctx ex [K"function"
32563257
[K"call"(sig)
32573258
_make_macro_name(ctx, name)
32583259
[K"::"
3259-
adopt_scope(@ast(ctx, sig, "__source__"::K"Identifier"),
3260-
kind(name) == K"." ? name[1] : name)
3260+
# TODO: should we be adopting the scope of the K"macro" expression itself?
3261+
adopt_scope(@ast(ctx, sig, "__source__"::K"Identifier"), scope_ref)
32613262
LineNumberNode::K"Value"
32623263
]
32633264
[K"::"
3264-
adopt_scope(@ast(ctx, sig, "__module__"::K"Identifier"),
3265-
kind(name) == K"." ? name[1] : name)
3265+
adopt_scope(@ast(ctx, sig, "__module__"::K"Identifier"), scope_ref)
32663266
Module::K"Value"
32673267
]
3268-
args[2:end]... # nospecialize?
3268+
map(e->_apply_nospecialize(ctx, e), args[2:end])...
32693269
]
32703270
ex[2]
32713271
]
@@ -3274,8 +3274,7 @@ function expand_macro_def(ctx, ex)
32743274
[K"call"(sig)
32753275
_make_macro_name(ctx, name)
32763276
[K"::"
3277-
adopt_scope(@ast(ctx, sig, "__context__"::K"Identifier"),
3278-
kind(name) == K"." ? name[1] : name)
3277+
adopt_scope(@ast(ctx, sig, "__context__"::K"Identifier"), scope_ref)
32793278
MacroContext::K"Value"
32803279
]
32813280
# flisp: We don't mark these @nospecialize because all arguments to
@@ -4509,7 +4508,12 @@ function expand_forms_2(ctx::DesugaringContext, ex::SyntaxTree, docs=nothing)
45094508
eval ::K"Value"
45104509
ctx.mod ::K"Value"
45114510
[K"inert" ex]
4512-
ctx.expr_compat_mode ::K"Bool"
4511+
[K"parameters"
4512+
[K"="
4513+
"expr_compat_mode"::K"Identifier"
4514+
ctx.expr_compat_mode::K"Bool"
4515+
]
4516+
]
45134517
]
45144518
]
45154519
elseif k == K"vect"

src/eval.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,12 @@ end
344344

345345
#-------------------------------------------------------------------------------
346346
# Our version of eval takes our own data structures
347-
function Core.eval(mod::Module, ex::SyntaxTree, expr_compat_mode::Bool=false)
347+
function Core.eval(mod::Module, ex::SyntaxTree; expr_compat_mode::Bool=false)
348348
k = kind(ex)
349349
if k == K"toplevel"
350350
x = nothing
351351
for e in children(ex)
352-
x = eval(mod, e, expr_compat_mode)
352+
x = eval(mod, e; expr_compat_mode)
353353
end
354354
return x
355355
end

src/macro_expansion.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function expand_quote(ctx, ex)
6868
# (ex, @HERE) ?
6969
@ast ctx ex [K"call"
7070
interpolate_ast::K"Value"
71-
ctx.expr_compat_mode ? Expr::K"Value" : SyntaxTree::K"Value"
71+
(ctx.expr_compat_mode ? Expr : SyntaxTree)::K"Value"
7272
[K"inert" ex]
7373
unquoted...
7474
]

src/runtime.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ function interpolate_ast(::Type{SyntaxTree}, ex, values...)
109109
end
110110

111111
function interpolate_ast(::Type{Expr}, ex, values...)
112+
# TODO: Adjust `_interpolated_value` to ensure that incoming `Expr` data
113+
# structures are treated as AST in Expr compat mode, rather than `K"Value"`?
114+
# Or convert `ex` to `Expr` early during lowering and implement
115+
# `interpolate_ast` for `Expr`?
112116
Expr(interpolate_ast(SyntaxTree, ex, values...))
113117
end
114118

@@ -175,7 +179,7 @@ function eval_module(parentmod, modname, expr_compat_mode, body)
175179
name = Symbol(modname)
176180
eval(parentmod, :(
177181
baremodule $name
178-
$eval($name, $body, $expr_compat_mode)
182+
$eval($name, $body; expr_compat_mode=$expr_compat_mode)
179183
end
180184
))
181185
end

0 commit comments

Comments
 (0)