@@ -120,7 +120,7 @@ eval ctxt statics genv tm opts = ev True [] tm where
120120 [(Function _ tm, Public)] -> ev True env tm
121121 [(TyDecl nt ty, _)] -> do vty <- ev True env ty
122122 return $ VP nt n vty
123− [(CaseOp inl _ _ [] tree, Public)] ->
123+ [(CaseOp inl _ _ [] tree _ _, Public)] -> -- unoptimised version
124124 if simpl && (not inl)
125125 then liftM (VP Ref n) (ev top env ty)
126126 else do c <- evCase top env [] [] tree
@@ -162,7 +162,7 @@ eval ctxt statics genv tm opts = ev True [] tm where
162162 apply False env f args
163163 | spec = return $ unload env f args
164164 apply top env (VP Ref n ty) args
165− | [(CaseOp inl _ _ ns tree, Public)] <- lookupDefAcc Nothing n atRepl ctxt
165+ | [(CaseOp inl _ _ ns tree _ _, Public)] <- lookupDefAcc Nothing n atRepl ctxt
166166 = -- traceWhen (n == UN ["interp"]) (show (n, args)) $
167167 if simpl && (not inl) then return $ unload env (VP Ref n ty) args
168168 else do c <- evCase top env ns args tree
@@ -309,7 +309,7 @@ eval_hnf ctxt statics genv tm = ev [] tm where
309309 ev env (P Ref n ty) = case lookupDef Nothing n ctxt of
310310 [Function _ t] -> ev env t
311311 [TyDecl nt ty] -> return $ HP nt n ty
312− [CaseOp inl _ _ [] tree] ->
312+ [CaseOp inl _ _ [] tree _ _] ->
313313 do c <- evCase env [] [] tree
314314 case c of
315315 (Nothing, _, _) -> return $ HP Ref n ty
@@ -339,7 +339,7 @@ eval_hnf ctxt statics genv tm = ev [] tm where
339339 app <- apply env sc' as
340340 wknH (-1) app
341341 apply env (HP Ref n ty) args
342− | [CaseOp _ _ _ ns tree] <- lookupDef Nothing n ctxt
342+ | [CaseOp _ _ _ ns tree _ _] <- lookupDef Nothing n ctxt
343343 = do c <- evCase env ns args tree
344344 case c of
345345 (Nothing, _, env') -> return $ unload env' (HP Ref n ty) args
@@ -439,7 +439,9 @@ spec ctxt statics genv tm = error "spec undefined"
439439data Def = Function Type Term
440440 | TyDecl NameType Type
441441 | Operator Type Int ([Value] -> Maybe Value)
442− | CaseOp Bool Type [(Term, Term)] [Name] SC -- Bool for inlineable
442+ | CaseOp Bool Type [(Term, Term)] -- Bool for inlineable
443+ [Name] SC -- Compile time case definition
444+ [Name] SC -- Run time cae definitions
443445{-!
444446deriving instance Binary Def
445447!-}
@@ -448,8 +450,10 @@ instance Show Def where
448450 show (Function ty tm) = "Function: " ++ show (ty, tm)
449451 show (TyDecl nt ty) = "TyDecl: " ++ show nt ++ " " ++ show ty
450452 show (Operator ty _ _) = "Operator: " ++ show ty
451− show (CaseOp _ ty ps ns sc) = "Case: " ++ show ty ++ " " ++ show ps ++ "\n" ++
452− show ns ++ " " ++ show sc
453+ show (CaseOp _ ty ps ns sc ns' sc')
454+ = "Case: " ++ show ty ++ " " ++ show ps ++ "\n" ++
455+ show ns ++ " " ++ show sc ++ "\n" ++
456+ show ns' ++ " " ++ show sc'
453457-- We need this for serialising Def. Fortunately, it never gets used because
454458-- we'll never serialise a primitive operator
455459
@@ -516,13 +520,15 @@ addDatatype (Data n tag ty cons) uctxt
516520 addCons (tag+1) cons (addDef n
517521 (TyDecl (DCon tag (arity ty')) ty, Public) ctxt)
518522
519−addCasedef :: Name -> Bool -> Bool -> [(Term, Term)] -> Type -> Context -> Context
520−addCasedef n alwaysInline tcase ps ty uctxt
523+addCasedef :: Name -> Bool -> Bool -> [(Term, Term)] -> [(Term, Term)] ->
524+ Type -> Context -> Context
525+addCasedef n alwaysInline tcase ps psrt ty uctxt
521526 = let ctxt = definitions uctxt
522527 ps' = ps -- simpl ps in
523− ctxt' = case simpleCase tcase ps' of
524− CaseDef args sc -> let inl = alwaysInline in
525− addDef n (CaseOp inl ty ps args sc,
528+ ctxt' = case (simpleCase tcase ps', simpleCase tcase psrt) of
529+ (CaseDef args sc, CaseDef args' sc') ->
530+ let inl = alwaysInline in
531+ addDef n (CaseOp inl ty ps args sc args' sc',
526532 Public) ctxt in
527533 uctxt { definitions = ctxt' }
528534 where simpl [] = []
@@ -541,7 +547,7 @@ lookupTy root n ctxt
541547 (Function ty _) -> return ty
542548 (TyDecl _ ty) -> return ty
543549 (Operator ty _ _) -> return ty
544− (CaseOp _ ty _ _ _) -> return ty
550+ (CaseOp _ ty _ _ _ _ _) -> return ty
545551
546552isConName :: Maybe [String] -> Name -> Context -> Bool
547553isConName root n ctxt
@@ -557,7 +563,7 @@ lookupP root n ctxt
557563 p <- case def of
558564 (Function ty tm, a) -> return (P Ref n ty, a)
559565 (TyDecl nt ty, a) -> return (P nt n ty, a)
560− (CaseOp _ ty _ _ _, a) -> return (P Ref n ty, a)
566+ (CaseOp _ ty _ _ _ _ _, a) -> return (P Ref n ty, a)
561567 (Operator ty _ _, a) -> return (P Ref n ty, a)
562568 case snd p of
563569 Hidden -> []