@@ -636,52 +636,42 @@ walkExpanded defEnv useEnv divertEnv renameEnv cleanupEnv dim _ isQuoted (List r
636
636
walkExpanded defEnv useEnv divertEnv renameEnv cleanupEnv dim False isQuoted (List $ result ++ [DottedList ls l]) (List ts) apply
637
637
638
638
walkExpanded defEnv useEnv divertEnv renameEnv cleanupEnv dim startOfList inputIsQuoted (List result) (List (Atom aa : ts)) apply = do
639
-
640
639
Atom a <- expandAtom renameEnv (Atom aa)
641
-
640
+ maybeMacro <- findBoundMacro defEnv useEnv a
642
641
-- If a macro is quoted, keep track of it and do not invoke rules below for
643
642
-- procedure abstraction or macro calls
644
643
let isQuoted = inputIsQuoted || (a == " quote" )
645
644
646
- isDefinedAsMacro <- liftIO $ isNamespacedRecBound useEnv macroNamespace a
647
- isDefDefinedAsMacro <- liftIO $ isNamespacedRecBound defEnv macroNamespace a
648
-
649
- -- (currently) unused conditional variables for below test
650
- -- isDiverted <- liftIO $ isRecBound divertEnv a
651
- -- isMacroBound <- liftIO $ isRecBound renameEnv a
652
- -- isLocalRename <- liftIO $ isNamespacedRecBound renameEnv 'r' {-"renamed"-} a
653
-
654
- -- Determine if we should recursively rename an atom
655
- -- This code is a bit of a hack/mess at the moment
656
- if isDefinedAsMacro || isDefDefinedAsMacro
657
- -- if (trace ("walkExp " ++ a ++ " " ++ aa ++ " " ++ (show isDefinedAsMacro) ++ " " ++ (show isDefDefinedAsMacro) ++ " " ++ (show startOfList) ++ " " ++ (show inputIsQuoted) ++ " " ++ (show isQuoted) ++ " ") isDefinedAsMacro || isDefDefinedAsMacro)
658
- -- | | isDiverted
659
- -- || (isMacroBound && not isLocalRename)
660
- -- || not startOfList
661
- || a == aa -- Prevent an infinite loop
662
- -- Preserve keywords encountered in the macro
663
- -- as each of these is really a special form, and renaming them
664
- -- would not work because there is nothing to divert back...
665
- || a == " if"
666
- || a == " let-syntax"
667
- || a == " letrec-syntax"
668
- || a == " define-syntax"
669
- || a == " define"
670
- || a == " set!"
671
- || a == " lambda"
672
- || a == " quote"
673
- || a == " expand"
674
- || a == " string-set!"
675
- || a == " set-car!"
676
- || a == " set-cdr!"
677
- || a == " vector-set!"
678
- || a == " hash-table-set!"
679
- || a == " hash-table-delete!"
680
- then walkExpandedAtom defEnv useEnv divertEnv renameEnv cleanupEnv
681
- dim startOfList inputIsQuoted (List result) a ts isQuoted (isDefinedAsMacro || isDefDefinedAsMacro) apply
682
- else walkExpanded defEnv useEnv divertEnv renameEnv cleanupEnv
683
- dim startOfList inputIsQuoted (List result) (List (Atom a : ts)) apply
684
-
645
+ case maybeMacro of
646
+ Just _ -> walkExpandedAtom defEnv useEnv divertEnv renameEnv cleanupEnv
647
+ dim startOfList inputIsQuoted (List result)
648
+ a ts isQuoted maybeMacro apply
649
+ _ -> do
650
+ -- Determine if we should recursively rename an atom
651
+ -- This code is a bit of a hack/mess at the moment
652
+ if a == aa -- Prevent an infinite loop
653
+ -- Preserve keywords encountered in the macro
654
+ -- as each of these is really a special form, and renaming them
655
+ -- would not work because there is nothing to divert back...
656
+ || a == " if"
657
+ || a == " let-syntax"
658
+ || a == " letrec-syntax"
659
+ || a == " define-syntax"
660
+ || a == " define"
661
+ || a == " set!"
662
+ || a == " lambda"
663
+ || a == " quote"
664
+ || a == " expand"
665
+ || a == " string-set!"
666
+ || a == " set-car!"
667
+ || a == " set-cdr!"
668
+ || a == " vector-set!"
669
+ || a == " hash-table-set!"
670
+ || a == " hash-table-delete!"
671
+ then walkExpandedAtom defEnv useEnv divertEnv renameEnv cleanupEnv
672
+ dim startOfList inputIsQuoted (List result) a ts isQuoted maybeMacro apply
673
+ else walkExpanded defEnv useEnv divertEnv renameEnv cleanupEnv
674
+ dim startOfList inputIsQuoted (List result) (List (Atom a : ts)) apply
685
675
686
676
-- Transform anything else as itself...
687
677
walkExpanded defEnv useEnv divertEnv renameEnv cleanupEnv dim _ isQuoted (List result) (List (t : ts)) apply = do
@@ -709,7 +699,7 @@ walkExpandedAtom :: Env
709
699
-> String
710
700
-> [LispVal ]
711
701
-> Bool -- is Quoted
712
- -> Bool -- is defined as macro
702
+ -> Maybe LispVal -- is defined as macro
713
703
-> (LispVal -> LispVal -> [LispVal ] -> IOThrowsError LispVal ) -- ^ Apply func
714
704
-> IOThrowsError LispVal
715
705
@@ -858,19 +848,8 @@ walkExpandedAtom defEnv useEnv divertEnv renameEnv cleanupEnv dim True _ (List r
858
848
walkExpandedAtom defEnv useEnv divertEnv renameEnv cleanupEnv dim True _ (List result)
859
849
a
860
850
ts
861
- False True apply = do
862
- synUse <- getNamespacedVar' useEnv macroNamespace a
863
- case synUse of
864
- Just syn -> expandSyntax syn
865
- _ -> do
866
- synDef <- getNamespacedVar' defEnv macroNamespace a
867
- case synDef of
868
- Just syn -> expandSyntax syn
869
- _ -> throwError $ Default
870
- " Unexpected error processing a symbol in walkExpandedAtom"
871
- where
872
- expandSyntax syn = do
873
- case syn of
851
+ False (Just syn) apply = do
852
+ case syn of
874
853
--
875
854
-- Note:
876
855
--
@@ -1553,3 +1532,10 @@ isLexicallyDefined outerEnv renameEnv a = do
1553
1532
o <- liftIO $ isBound outerEnv a
1554
1533
r <- liftIO $ isBound renameEnv a
1555
1534
return $ o || r
1535
+
1536
+ findBoundMacro :: Env -> Env -> String -> IOThrowsError (Maybe LispVal )
1537
+ findBoundMacro defEnv useEnv a = do
1538
+ synUse <- getNamespacedVar' useEnv macroNamespace a
1539
+ case synUse of
1540
+ Just syn -> return $ Just syn
1541
+ _ -> getNamespacedVar' defEnv macroNamespace a
0 commit comments