operations on lists

This commit is contained in:
crumbtoo
2023-11-24 16:03:17 -07:00
parent ec87ed49f8
commit d91043fd63
2 changed files with 9 additions and 0 deletions

View File

@@ -118,6 +118,10 @@ corePrelude = Module (Just ("Prelude", [])) $
twice f x = f (f x); twice f x = f (f x);
fst p = casePair# p k; fst p = casePair# p k;
snd p = casePair# p k1; snd p = casePair# p k1;
head l = caseList# l abort# k;
tail l = caseList# l abort# k1;
_length_cc x xs = (+#) 1 (length xs);
length l = caseList# l 0 length_cc;
|] |]
<> <>
-- primitive constructors need some specialised wiring: -- primitive constructors need some specialised wiring:

View File

@@ -49,6 +49,7 @@ data Prim = ConP Int Int -- ConP Tag Arity
| IntEqP | IntEqP
| CasePairP | CasePairP
| CaseListP | CaseListP
| AbortP
deriving (Show, Eq) deriving (Show, Eq)
instance Pretty Prim where instance Pretty Prim where
@@ -105,6 +106,7 @@ primitives =
, ("if#", IfP) , ("if#", IfP)
, ("casePair#", CasePairP) , ("casePair#", CasePairP)
, ("caseList#", CaseListP) , ("caseList#", CaseListP)
, ("abort#", AbortP)
] ]
instantiate :: Expr -> TiHeap -> [(Name, Addr)] -> (TiHeap, Addr) instantiate :: Expr -> TiHeap -> [(Name, Addr)] -> (TiHeap, Addr)
@@ -335,6 +337,9 @@ step st =
rootAddr = s !! a rootAddr = s !! a
argAddrs = getArgs h s argAddrs = getArgs h s
primStep _ AbortP (TiState s d h g sts) =
error "rl' called abort#!"
dataStep :: Int -> [Addr] -> TiState -> TiState dataStep :: Int -> [Addr] -> TiState -> TiState
dataStep _ _ (TiState [a] (s:d) h g sts) = TiState s d h g sts dataStep _ _ (TiState [a] (s:d) h g sts) = TiState s d h g sts