@@ -1322,6 +1322,32 @@ def _special_form_ast(ctx: CompilerContext,
1322
1322
raise CompilerException ("Special form identified, but not handled" ) from None
1323
1323
1324
1324
1325
+ def _resolve_macro_sym (ctx : CompilerContext , form : sym .Symbol ) -> Optional [Var ]:
1326
+ """Determine if a Basilisp symbol refers to a macro and, if so, return the
1327
+ Var it points to.
1328
+
1329
+ If the symbol cannot be resolved or does not refer to a macro, then this
1330
+ function will return None. _sym_ast will generate the AST for a standard
1331
+ function call."""
1332
+ if form .ns is not None :
1333
+ if form .ns == _BUILTINS_NS :
1334
+ return None
1335
+ elif form .ns == ctx .current_ns .name :
1336
+ return ctx .current_ns .find (sym .symbol (form .name ))
1337
+ ns_sym = sym .symbol (form .ns )
1338
+ if ns_sym in ctx .current_ns .imports :
1339
+ # We still import Basilisp code, so we'll want to check if
1340
+ # the symbol is referring to a Basilisp Var
1341
+ return Var .find (form )
1342
+ elif ns_sym in ctx .current_ns .aliases :
1343
+ aliased_ns = ctx .current_ns .get_alias (ns_sym )
1344
+ if aliased_ns :
1345
+ return Var .find (sym .symbol (form .name , ns = aliased_ns .name ))
1346
+ return None
1347
+
1348
+ return ctx .current_ns .find (form )
1349
+
1350
+
1325
1351
def _list_ast (ctx : CompilerContext , form : llist .List ) -> ASTStream :
1326
1352
"""Generate a stream of Python AST nodes for a source code list.
1327
1353
@@ -1359,12 +1385,7 @@ def _list_ast(ctx: CompilerContext, form: llist.List) -> ASTStream:
1359
1385
1360
1386
# Macros are immediately evaluated so the modified form can be compiled
1361
1387
if isinstance (first , sym .Symbol ):
1362
- if first .ns is not None :
1363
- v = Var .find (first )
1364
- else :
1365
- ns_sym = sym .symbol (first .name , ns = ctx .current_ns .name )
1366
- v = Var .find (ns_sym )
1367
-
1388
+ v = _resolve_macro_sym (ctx , first )
1368
1389
if v is not None and _is_macro (v ):
1369
1390
try :
1370
1391
# Call the macro as (f &form & rest)
0 commit comments