@@ -105,10 +105,10 @@ eval ctxt statics genv tm opts = ev True [] tm where
106 ev top env (P _ n ty)
106 ev top env (P _ n ty)
107 | Just (Let t v) <- lookup n genv = ev top env v
107 | Just (Let t v) <- lookup n genv = ev top env v
108− ev top env (P Ref n ty) = case lookupDef n ctxt of
108+ ev top env (P Ref n ty) = case lookupDef Nothing n ctxt of
109− Just (Function (Fun _ _ _ v)) -> return v
109+ [Function (Fun _ _ _ v)] -> return v
110− Just (TyDecl nt ty hty) -> return $ VP nt n hty
110+ [TyDecl nt ty hty] -> return $ VP nt n hty
111− Just (CaseOp inl _ _ [] tree) ->
111+ [CaseOp inl _ _ [] tree] ->
112 if simpl && (not inl)
112 if simpl && (not inl)
113 then liftM (VP Ref n) (ev top env ty)
113 then liftM (VP Ref n) (ev top env ty)
114 else do c <- evCase top env [] [] tree
114 else do c <- evCase top env [] [] tree
@@ -149,14 +149,14 @@ eval ctxt statics genv tm opts = ev True [] tm where
149 apply False env f args
149 apply False env f args
150 | spec = return $ unload env f args
150 | spec = return $ unload env f args
151 apply top env (VP Ref n ty) args
151 apply top env (VP Ref n ty) args
152− | Just (CaseOp inl _ _ ns tree) <- lookupDef n ctxt
152+ | [CaseOp inl _ _ ns tree] <- lookupDef Nothing n ctxt
153 = -- traceWhen (n == UN ["interp"]) (show (n, args)) $
153 = -- traceWhen (n == UN ["interp"]) (show (n, args)) $
154 if simpl && (not inl) then return $ unload env (VP Ref n ty) args
154 if simpl && (not inl) then return $ unload env (VP Ref n ty) args
155 else do c <- evCase top env ns args tree
155 else do c <- evCase top env ns args tree
156 case c of
156 case c of
157 (Nothing, _) -> return $ unload env (VP Ref n ty) args
157 (Nothing, _) -> return $ unload env (VP Ref n ty) args
158 (Just v, rest) -> evApply top env rest v
158 (Just v, rest) -> evApply top env rest v
159− | Just (Operator _ i op) <- lookupDef n ctxt
159+ | [Operator _ i op] <- lookupDef Nothing n ctxt
160 = if (i <= length args)
160 = if (i <= length args)
161 then case op (take i args) of
161 then case op (take i args) of
162 Nothing -> return $ unload env (VP Ref n ty) args
162 Nothing -> return $ unload env (VP Ref n ty) args
@@ -292,10 +292,10 @@ eval_hnf ctxt statics genv tm = ev [] tm where
292 ev :: [HNF] -> TT Name -> Eval HNF
292 ev :: [HNF] -> TT Name -> Eval HNF
293 ev env (P _ n ty)
293 ev env (P _ n ty)
294 | Just (Let t v) <- lookup n genv = ev env v
294 | Just (Let t v) <- lookup n genv = ev env v
295− ev env (P Ref n ty) = case lookupDef n ctxt of
295+ ev env (P Ref n ty) = case lookupDef Nothing n ctxt of
296− Just (Function (Fun _ _ t _)) -> ev env t
296+ [Function (Fun _ _ t _)] -> ev env t
297− Just (TyDecl nt ty hty) -> return $ HP nt n ty
297+ [TyDecl nt ty hty] -> return $ HP nt n ty
298− Just (CaseOp inl _ _ [] tree) ->
298+ [CaseOp inl _ _ [] tree] ->
299 do c <- evCase env [] [] tree
299 do c <- evCase env [] [] tree
300 case c of
300 case c of
301 (Nothing, _, _) -> return $ HP Ref n ty
301 (Nothing, _, _) -> return $ HP Ref n ty
@@ -325,7 +325,7 @@ eval_hnf ctxt statics genv tm = ev [] tm where
325 app <- apply env sc' as
325 app <- apply env sc' as
326 wknH (-1) app
326 wknH (-1) app
327 apply env (HP Ref n ty) args
327 apply env (HP Ref n ty) args
328− | Just (CaseOp _ _ _ ns tree) <- lookupDef n ctxt
328+ | [CaseOp _ _ _ ns tree] <- lookupDef Nothing n ctxt
329 = do c <- evCase env ns args tree
329 = do c <- evCase env ns args tree
330 case c of
330 case c of
331 (Nothing, _, env') -> return $ unload env' (HP Ref n ty) args
331 (Nothing, _, env') -> return $ unload env' (HP Ref n ty) args
@@ -494,29 +494,30 @@ addOperator n ty a op uctxt
494 ctxt' = addDef n (Operator ty a op) ctxt in
494 ctxt' = addDef n (Operator ty a op) ctxt in
495 uctxt { definitions = ctxt' }
495 uctxt { definitions = ctxt' }
497−lookupTy :: Name -> Context -> Maybe Type
497+lookupTy :: Maybe Name -> Name -> Context -> [Type]
498−lookupTy n ctxt = do def <- lookupCtxt n (definitions ctxt)
499+ = do def <- lookupCtxt root n (definitions ctxt)
499 case def of
500 case def of
500 (Function (Fun ty _ _ _)) -> return ty
501 (Function (Fun ty _ _ _)) -> return ty
501 (TyDecl _ ty _) -> return ty
502 (TyDecl _ ty _) -> return ty
502 (Operator ty _ _) -> return ty
503 (Operator ty _ _) -> return ty
503 (CaseOp _ ty _ _ _) -> return ty
504 (CaseOp _ ty _ _ _) -> return ty
505−lookupP :: Name -> Context -> Maybe Term
506+lookupP :: Maybe Name -> Name -> Context -> [Term]
506−lookupP n ctxt
507+lookupP root n ctxt
507− = do def <- lookupCtxt n (definitions ctxt)
508+ = do def <- lookupCtxt root n (definitions ctxt)
508 case def of
509 case def of
509 (Function (Fun ty _ tm _)) -> return (P Ref n ty)
510 (Function (Fun ty _ tm _)) -> return (P Ref n ty)
510 (TyDecl nt ty hty) -> return (P nt n ty)
511 (TyDecl nt ty hty) -> return (P nt n ty)
511 (CaseOp _ ty _ _ _) -> return (P Ref n ty)
512 (CaseOp _ ty _ _ _) -> return (P Ref n ty)
512 (Operator ty _ _) -> return (P Ref n ty)
513 (Operator ty _ _) -> return (P Ref n ty)
514−lookupDef :: Name -> Context -> Maybe Def
515+lookupDef :: Maybe Name -> Name -> Context -> [Def]
515−lookupDef n ctxt = lookupCtxt n (definitions ctxt)
516+lookupDef root n ctxt = lookupCtxt root n (definitions ctxt)
517−lookupVal :: Name -> Context -> Maybe Value
518+lookupVal :: Maybe Name -> Name -> Context -> [Value]
518−lookupVal n ctxt
519+lookupVal root n ctxt
519− = do def <- lookupCtxt n (definitions ctxt)
520+ = do def <- lookupCtxt root n (definitions ctxt)
520 case def of
521 case def of
521 (Function (Fun _ _ _ htm)) -> return htm
522 (Function (Fun _ _ _ htm)) -> return htm
522 (TyDecl nt ty hty) -> return (VP nt n hty)
523 (TyDecl nt ty hty) -> return (VP nt n hty)