@@ -5,17 +5,22 @@ struct DesugaringContext{GraphType} <: AbstractLoweringContext
55 bindings:: Bindings
66 scope_layers:: Vector{ScopeLayer}
77 mod:: Module
8+ expr_compat_mode:: Bool
89end
910
10- function DesugaringContext (ctx)
11+ function DesugaringContext (ctx, expr_compat_mode :: Bool )
1112 graph = ensure_attributes (syntax_graph (ctx),
1213 kind= Kind, syntax_flags= UInt16,
1314 source= SourceAttrType,
1415 value= Any, name_val= String,
1516 scope_type= Symbol, # :hard or :soft
1617 var_id= IdTag,
1718 is_toplevel_thunk= Bool)
18- DesugaringContext (graph, ctx. bindings, ctx. scope_layers, first (ctx. scope_layers). mod)
19+ DesugaringContext (graph,
20+ ctx. bindings,
21+ ctx. scope_layers,
22+ first (ctx. scope_layers). mod,
23+ expr_compat_mode)
1924end
2025
2126# -------------------------------------------------------------------------------
@@ -3246,20 +3251,40 @@ function expand_macro_def(ctx, ex)
32463251 name = sig[1 ]
32473252 args = remove_empty_parameters (children (sig))
32483253 @chk kind (args[end ]) != K " parameters" (args[end ], " macros cannot accept keyword arguments" )
3249- ret = @ast ctx ex [K " function"
3250- [K " call" (sig)
3251- _make_macro_name (ctx, name)
3252- [K " ::"
3253- adopt_scope (@ast (ctx, sig, " __context__" :: K"Identifier" ),
3254- kind (name) == K " ." ? name[1 ] : name)
3255- MacroContext:: K"Value"
3254+ if ctx. expr_compat_mode
3255+ @ast ctx ex [K " function"
3256+ [K " call" (sig)
3257+ _make_macro_name (ctx, name)
3258+ [K " ::"
3259+ adopt_scope (@ast (ctx, sig, " __source__" :: K"Identifier" ),
3260+ kind (name) == K " ." ? name[1 ] : name)
3261+ LineNumberNode:: K"Value"
3262+ ]
3263+ [K " ::"
3264+ adopt_scope (@ast (ctx, sig, " __module__" :: K"Identifier" ),
3265+ kind (name) == K " ." ? name[1 ] : name)
3266+ Module:: K"Value"
3267+ ]
3268+ args[2 : end ]. .. # nospecialize?
32563269 ]
3257- # flisp: We don't mark these @nospecialize because all arguments to
3258- # new macros will be of type SyntaxTree
3259- args[2 : end ]. ..
3270+ ex[2 ]
32603271 ]
3261- ex[2 ]
3262- ]
3272+ else
3273+ @ast ctx ex [K " function"
3274+ [K " call" (sig)
3275+ _make_macro_name (ctx, name)
3276+ [K " ::"
3277+ adopt_scope (@ast (ctx, sig, " __context__" :: K"Identifier" ),
3278+ kind (name) == K " ." ? name[1 ] : name)
3279+ MacroContext:: K"Value"
3280+ ]
3281+ # flisp: We don't mark these @nospecialize because all arguments to
3282+ # new macros will be of type SyntaxTree
3283+ args[2 : end ]. ..
3284+ ]
3285+ ex[2 ]
3286+ ]
3287+ end
32633288end
32643289
32653290# -------------------------------------------------------------------------------
@@ -4515,7 +4540,7 @@ function expand_forms_2(ctx::StatementListCtx, args...)
45154540end
45164541
45174542function expand_forms_2 (ctx:: MacroExpansionContext , ex:: SyntaxTree )
4518- ctx1 = DesugaringContext (ctx)
4543+ ctx1 = DesugaringContext (ctx, ctx . expr_compat_mode )
45194544 ex1 = expand_forms_2 (ctx1, reparent (ctx1, ex))
45204545 ctx1, ex1
45214546end
0 commit comments