suckless: recursive imports, primitive import loop detection

This commit is contained in:
voidlizard 2025-02-04 09:09:43 +03:00
parent 46b02d458f
commit 29c59994e1
1 changed files with 12 additions and 15 deletions

View File

@ -675,12 +675,14 @@ eval' dict0 syn' = handle (handleForm syn') $ do
_ -> throwIO (RuntimeError (mkStr @c $ show $ pretty importsName <> "misteriously disappeared"))
seen <- atomically $ stateTVar imp_ (\e -> (HM.lookup (mkId fn) e, HM.insert (mkId fn) mempty e))
-- liftIO $ print $ pretty "import" <+> pretty fn
unless (isNothing seen) $ throwIO alreadyError
-- TODO: maybe-should-be-error
case seen of
Just{} -> pure nil
Nothing{} -> do
-- FIXME: fancy-error-handling
syn <- liftIO (TIO.readFile fn) <&> parseTop >>= either(error.show) pure
@ -690,15 +692,10 @@ eval' dict0 syn' = handle (handleForm syn') $ do
, what `HS.member` importDecls
]
-- liftIO $ mapM_ (print . pretty) decls
evalTop decls
void $ evalTop decls
pure nil
-- error $ show $ "fucked!" <+> pretty fn
--
ListVal [SymbolVal "define", SymbolVal what, e] -> do
ev <- eval e
bind what ev>> pure nil