@@ -214,15 +214,29 @@ compile env (List [Atom "expand", _body]) copts = do
214
214
val <- Language.Scheme.Macro. expand env False _body Language.Scheme.Core. apply
215
215
compileScalar (" return $ " ++ astToHaskellStr val) copts
216
216
217
- compile env (List (Atom " let-syntax" : List _bindings : _body)) copts = do
217
+ compile env (List (Atom " let-syntax" : List _bindings : _body)) copts@ ( CompileOptions tfnc uvar uargs nfnc) = do
218
218
-- TODO: check if let-syntax has been rebound?
219
219
bodyEnv <- liftIO $ extendEnv env []
220
220
_ <- Language.Scheme.Macro. loadMacros env bodyEnv Nothing False _bindings
221
221
-- Expand whole body as a single continuous macro, to ensure hygiene
222
222
expanded <- Language.Scheme.Macro. expand bodyEnv False (List _body) Language.Scheme.Core. apply
223
- case expanded of
224
- List e -> compile bodyEnv (List $ Atom " begin" : e) copts
225
- e -> compile bodyEnv e copts
223
+
224
+ -- TODO: should be able to consolidate with the one from macroEval
225
+ -- also, need to use for the other 'expand' call below
226
+ vars <- Language.Scheme.Macro. getDivertedVars bodyEnv
227
+ case vars of
228
+ [] -> func bodyEnv expanded copts
229
+ _ -> do
230
+ Atom symNext <- _gensym " afterDivert"
231
+ diverted <- compileDivertedVars symNext bodyEnv vars copts
232
+ rest <- func bodyEnv expanded $ CompileOptions symNext uvar uargs nfnc
233
+ return $ [diverted] ++ rest
234
+
235
+ where
236
+ func bodyEnv' expanded' copts' = do
237
+ case expanded' of
238
+ List e -> compile bodyEnv' (List $ Atom " begin" : e) copts'
239
+ e -> compile bodyEnv' e copts'
226
240
227
241
compile env (List (Atom " letrec-syntax" : List _bindings : _body)) copts = do
228
242
-- TODO: check if let-syntax has been rebound?
@@ -649,19 +663,14 @@ mfunc env lisp func copts@(CompileOptions tfnc uvar uargs nfnc) = do
649
663
650
664
transformed <- Language.Scheme.Macro. macroEval env lisp Language.Scheme.Core. apply
651
665
652
- -- TESTING
653
- -- TODO: need to refactor this into a common function, and use it here as well
654
- -- as for expand below. Also, it would be nice if all the details for
655
- -- "diverted" could be contained in the macro module
656
- List tmp <- getNamespacedVar env " " " diverted"
657
- case tmp of
666
+ vars <- Language.Scheme.Macro. getDivertedVars env
667
+ case vars of
658
668
[] -> func env transformed copts
659
- _ -> do -- TODO: call a function to process diverted vars
660
- Atom symNext <- _gensym " afterDivert"
661
- diverted <- compileDivertedVars symNext env tmp copts
662
- rest <- func env transformed $ CompileOptions symNext uvar uargs nfnc -- copts
663
- return $ [diverted] ++ rest
664
- -- END
669
+ _ -> do
670
+ Atom symNext <- _gensym " afterDivert"
671
+ diverted <- compileDivertedVars symNext env vars copts
672
+ rest <- func env transformed $ CompileOptions symNext uvar uargs nfnc
673
+ return $ [diverted] ++ rest
665
674
666
675
-- | Take a list of variables diverted into env at compile time, and
667
676
-- divert them into the env at runtime
0 commit comments