mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
fix: don't hang on module expansions (#1340)
This commit is contained in:
parent
320bc67bac
commit
499a03e63e
@ -41,6 +41,19 @@ expand eval ctx xobj =
|
||||
Lst _ -> expandList xobj
|
||||
Arr _ -> expandArray xobj
|
||||
Sym _ _ -> expandSymbol xobj
|
||||
-- This case is needed to ensure we expand naked mod names to initers consistently.
|
||||
-- Consider both:
|
||||
-- (width (address &(B 2)))
|
||||
-- (width B)
|
||||
-- The first case is correct code and was handled by expandList. The second case is an error and previously resulted in a loop because
|
||||
-- module expansion wasn't handled in expandSymbol, but handling it there
|
||||
-- by ending the expansion loop breaks init expansion in the first case,
|
||||
-- since expandList calls expand.
|
||||
-- So, we have no choice but to add a case here to cut the recursion and to expand this form consistently in all places.
|
||||
Mod e _ ->
|
||||
let pathToModule = pathToEnv e
|
||||
implicitInit = XObj (Sym (SymPath pathToModule "init") Symbol) (xobjInfo xobj) (xobjTy xobj)
|
||||
in pure (ctx, Right implicitInit)
|
||||
_ -> pure (ctx, Right xobj)
|
||||
where
|
||||
expandList :: XObj -> IO (Context, Either EvalError XObj)
|
||||
|
@ -228,6 +228,8 @@ primitiveRegisterType _ ctx [XObj (Sym (SymPath [] t) _) _ _] =
|
||||
primitiveRegisterTypeWithoutFields ctx t Nothing
|
||||
primitiveRegisterType _ ctx [x] =
|
||||
pure (evalError ctx ("`register-type` takes a symbol, but it got " ++ pretty x) (xobjInfo x))
|
||||
primitiveRegisterType _ ctx [x@(XObj (Sym (SymPath [] _) _) _ _), XObj (Str "") _ _] =
|
||||
pure (evalError ctx ("cannot register type " ++ pretty x ++ " with an empty string override, this will produce invalid C") (xobjInfo x))
|
||||
primitiveRegisterType _ ctx [XObj (Sym (SymPath [] t) _) _ _, XObj (Str override) _ _] =
|
||||
primitiveRegisterTypeWithoutFields ctx t (Just override)
|
||||
primitiveRegisterType _ ctx [x@(XObj (Sym (SymPath [] t) _) _ _), XObj (Str override) _ _, members] =
|
||||
|
Loading…
Reference in New Issue
Block a user