@@ -48,7 +48,7 @@ simplify tl (DV (Loc i)) = return (SV (Loc i))
48simplify tl (DV (Glob x))
48simplify tl (DV (Glob x))
49 = do ctxt <- ldefs
49 = do ctxt <- ldefs
50 case lookupCtxtExact x ctxt of
50 case lookupCtxtExact x ctxt of
51− [DConstructor _ t 0] -> return $ SCon t x []
51+ Just (DConstructor _ t 0) -> return $ SCon t x []
52 _ -> return $ SV (Glob x)
52 _ -> return $ SV (Glob x)
53simplify tl (DApp tc n args) = do args' <- mapM sVar args
53simplify tl (DApp tc n args) = do args' <- mapM sVar args
54 mkapp (SApp (tl || tc) n) args'
54 mkapp (SApp (tl || tc) n) args'
@@ -90,7 +90,7 @@ simplify tl (DError str) = return $ SError str
90sVar (DV (Glob x))
90sVar (DV (Glob x))
91 = do ctxt <- ldefs
91 = do ctxt <- ldefs
92 case lookupCtxtExact x ctxt of
92 case lookupCtxtExact x ctxt of
93− [DConstructor _ t 0] -> sVar (DC t x [])
93+ Just (DConstructor _ t 0) -> sVar (DC t x [])
94 _ -> return (Glob x, Nothing)
94 _ -> return (Glob x, Nothing)
95sVar (DV x) = return (x, Nothing)
95sVar (DV x) = return (x, Nothing)
96sVar e = do e' <- simplify False e
96sVar e = do e' <- simplify False e
@@ -138,23 +138,23 @@ scopecheck ctxt envTop tm = sc envTop tm where
138 case lookup n (reverse env) of -- most recent first
138 case lookup n (reverse env) of -- most recent first
139 Just i -> do lvar i; return (SV (Loc i))
139 Just i -> do lvar i; return (SV (Loc i))
140 Nothing -> case lookupCtxtExact n ctxt of
140 Nothing -> case lookupCtxtExact n ctxt of
141− [DConstructor _ i ar] ->
141+ Just (DConstructor _ i ar) ->
142 if True -- ar == 0
142 if True -- ar == 0
143 then return (SCon i n [])
143 then return (SCon i n [])
144 else fail $ "Codegen error: Constructor " ++ show n ++
144 else fail $ "Codegen error: Constructor " ++ show n ++
145 " has arity " ++ show ar
145 " has arity " ++ show ar
146− [_] -> return (SV (Glob n))
146+ Just _ -> return (SV (Glob n))
147− [] -> fail $ "Codegen error: No such variable " ++ show n
147+ Nothing -> fail $ "Codegen error: No such variable " ++ show n
148 sc env (SApp tc f args)
148 sc env (SApp tc f args)
149 = do args' <- mapM (scVar env) args
149 = do args' <- mapM (scVar env) args
150 case lookupCtxtExact f ctxt of
150 case lookupCtxtExact f ctxt of
151− [DConstructor n tag ar] ->
151+ Just (DConstructor n tag ar) ->
152 if True -- (ar == length args)
152 if True -- (ar == length args)
153 then return $ SCon tag n args'
153 then return $ SCon tag n args'
154 else fail $ "Codegen error: Constructor " ++ show f ++
154 else fail $ "Codegen error: Constructor " ++ show f ++
155 " has arity " ++ show ar
155 " has arity " ++ show ar
156− [_] -> return $ SApp tc f args'
156+ Just _ -> return $ SApp tc f args'
157− [] -> fail $ "Codegen error: No such variable " ++ show f
157+ Nothing -> fail $ "Codegen error: No such variable " ++ show f
158 sc env (SForeign l ty f args)
158 sc env (SForeign l ty f args)
159 = do args' <- mapM (\ (t, a) -> do a' <- scVar env a
159 = do args' <- mapM (\ (t, a) -> do a' <- scVar env a
160 return (t, a')) args
160 return (t, a')) args
@@ -162,7 +162,7 @@ scopecheck ctxt envTop tm = sc envTop tm where
162 sc env (SCon tag f args)
162 sc env (SCon tag f args)
163 = do args' <- mapM (scVar env) args
163 = do args' <- mapM (scVar env) args
164 case lookupCtxtExact f ctxt of
164 case lookupCtxtExact f ctxt of
165− [DConstructor n tag ar] ->
165+ Just (DConstructor n tag ar) ->
166 if True -- (ar == length args)
166 if True -- (ar == length args)
167 then return $ SCon tag n args'
167 then return $ SCon tag n args'
168 else fail $ "Codegen error: Constructor " ++ show f ++
168 else fail $ "Codegen error: Constructor " ++ show f ++
@@ -199,17 +199,17 @@ scopecheck ctxt envTop tm = sc envTop tm where
199 case lookup n (reverse env) of -- most recent first
199 case lookup n (reverse env) of -- most recent first
200 Just i -> do lvar i; return (Loc i)
200 Just i -> do lvar i; return (Loc i)
201 Nothing -> case lookupCtxtExact n ctxt of
201 Nothing -> case lookupCtxtExact n ctxt of
202− [DConstructor _ i ar] ->
202+ Just (DConstructor _ i ar) ->
203 fail $ "Codegen error : can't pass constructor here"
203 fail $ "Codegen error : can't pass constructor here"
204− [_] -> return (Glob n)
204+ Just _ -> return (Glob n)
205− [] -> fail $ "Codegen error: No such variable " ++ show n ++
205+ Nothing -> fail $ "Codegen error: No such variable " ++ show n ++
206− " in " ++ show tm ++ " " ++ show envTop
206+ " in " ++ show tm ++ " " ++ show envTop
207 scVar _ x = return x
207 scVar _ x = return x
209 scalt env (SConCase _ i n args e)
209 scalt env (SConCase _ i n args e)
210 = do let env' = env ++ zip args [length env..]
210 = do let env' = env ++ zip args [length env..]
211 tag <- case lookupCtxtExact n ctxt of
211 tag <- case lookupCtxtExact n ctxt of
212− [DConstructor _ i ar] ->
212+ Just (DConstructor _ i ar) ->
213 if True -- (length args == ar)
213 if True -- (length args == ar)
214 then return i
214 then return i
215 else fail $ "Codegen error: Constructor " ++ show n ++
215 else fail $ "Codegen error: Constructor " ++ show n ++