File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,19 @@ expand eval ctx xobj =
41
41
Lst _ -> expandList xobj
42
42
Arr _ -> expandArray xobj
43
43
Sym _ _ -> expandSymbol xobj
44
+ -- This case is needed to ensure we expand naked mod names to initers consistently.
45
+ -- Consider both:
46
+ -- (width (address &(B 2)))
47
+ -- (width B)
48
+ -- The first case is correct code and was handled by expandList. The second case is an error and previously resulted in a loop because
49
+ -- module expansion wasn't handled in expandSymbol, but handling it there
50
+ -- by ending the expansion loop breaks init expansion in the first case,
51
+ -- since expandList calls expand.
52
+ -- So, we have no choice but to add a case here to cut the recursion and to expand this form consistently in all places.
53
+ Mod e _ ->
54
+ let pathToModule = pathToEnv e
55
+ implicitInit = XObj (Sym (SymPath pathToModule " init" ) Symbol ) (xobjInfo xobj) (xobjTy xobj)
56
+ in pure (ctx, Right implicitInit)
44
57
_ -> pure (ctx, Right xobj)
45
58
where
46
59
expandList :: XObj -> IO (Context , Either EvalError XObj )
Original file line number Diff line number Diff line change @@ -228,6 +228,8 @@ primitiveRegisterType _ ctx [XObj (Sym (SymPath [] t) _) _ _] =
228
228
primitiveRegisterTypeWithoutFields ctx t Nothing
229
229
primitiveRegisterType _ ctx [x] =
230
230
pure (evalError ctx (" `register-type` takes a symbol, but it got " ++ pretty x) (xobjInfo x))
231
+ primitiveRegisterType _ ctx [x@ (XObj (Sym (SymPath [] _) _) _ _), XObj (Str " " ) _ _] =
232
+ pure (evalError ctx (" cannot register type " ++ pretty x ++ " with an empty string override, this will produce invalid C" ) (xobjInfo x))
231
233
primitiveRegisterType _ ctx [XObj (Sym (SymPath [] t) _) _ _, XObj (Str override) _ _] =
232
234
primitiveRegisterTypeWithoutFields ctx t (Just override)
233
235
primitiveRegisterType _ ctx [x@ (XObj (Sym (SymPath [] t) _) _ _), XObj (Str override) _ _, members] =
You can’t perform that action at this time.
0 commit comments