diff options
-rw-r--r-- | AStack.dcl | 37 | ||||
-rw-r--r-- | AStack.icl | 15 | ||||
-rw-r--r-- | BStack.dcl | 30 | ||||
-rw-r--r-- | BStack.icl | 88 | ||||
-rw-r--r-- | CStack.dcl | 12 | ||||
-rw-r--r-- | CStack.icl | 21 | ||||
-rw-r--r-- | Def.dcl | 5 | ||||
-rw-r--r-- | Def.icl | 1 | ||||
-rw-r--r-- | Misc.dcl | 3 | ||||
-rw-r--r-- | Misc.icl | 6 |
10 files changed, 218 insertions, 0 deletions
diff --git a/AStack.dcl b/AStack.dcl new file mode 100644 index 0000000..2812842 --- /dev/null +++ b/AStack.dcl @@ -0,0 +1,37 @@ +implementation module ABC.AStack + +import StdEnv + +import ABC.Def + +as_get :: ASrc AStack -> NodeId +as_get _ [] = abortn "as_get: index too large" +as_get 0 [n:_] = n +as_get i [_:s] = as_get (i-1) s + +as_init :: AStack +as_init = [] + +as_popn :: NrArgs AStack -> AStack +as_popn 0 s = s +as_popn _ [] = abortn "as_popn: popping too many elements" +as_popn i [_:s] = as_popn (i-1) s + +as_push :: NodeId AStack -> AStack +as_push n s = [n:s] + +as_pushn :: [NodeId] AStack -> AStack +as_pushn is s = is ++ ns + +as_topn :: NrArgs AStack -> [NodeId] +as_topn i s = topn [] i s +where + topn :: [NodeId] NrArgs AStack -> [NodeId] + topn ns 0 _ = ns + topn _ i [] = abortn "as_topn: taking too many elements" + topn ns i [n:s] = topn (ns ++ [n]) (i-1) s + +as_update :: ADst NodeId AStack -> AStack +as_update 0 n [_:s] = [n:s] +as_update _ _ [] = abortn "as_update: index too large" +as_update i n [m:s] = [m:as_update (i-1) n s] diff --git a/AStack.icl b/AStack.icl new file mode 100644 index 0000000..799892f --- /dev/null +++ b/AStack.icl @@ -0,0 +1,15 @@ +definition module ABC.AStack + +from ABC.Def import ::NodeId, ::NrArgs + +:: ASrc :== Int +:: ADst :== Int +:: AStack (:== [NodeId]) + +as_get :: ASrc AStack -> NodeId +as_init :: AStack +as_popn :: NrArgs AStack -> AStack +as_push :: NodeId AStack -> AStack +as_pushn :: [NodeId] AStack -> AStack +as_topn :: NrArgs AStack -> [NodeId] +as_update :: ADst NodeId AStack -> AStack diff --git a/BStack.dcl b/BStack.dcl new file mode 100644 index 0000000..4f5bbfa --- /dev/null +++ b/BStack.dcl @@ -0,0 +1,30 @@ +definition module ABC.BStack + +:: Basic = Int Int + | Bool Bool + +:: BSrc :== Int +:: BDst :== Int +:: BStack (:== [Basic]) + +bs_copy :: BSrc BStack -> BStack +bs_get :: BSrc BStack -> Basic +bs_getB :: BSrc BStack -> Bool +bs_getI :: BSrc BStack -> Int +bs_init :: BStack +bs_popn :: NrArgs BStack -> BStack +bs_push :: Dynamic BStack -> BStack +bs_pushB :: Bool BStack -> BStack +bs_pushI :: Int BStack -> BStack +bs_update :: BDst Dynamic BStack -> BStack +bs_addI :: BStack -> BStack +bs_decI :: BStack -> BStack +bs_incI :: BStack -> BStack +bs_eqB :: BStack -> BStack +bs_eqI :: BStack -> BStack +bs_eqBi :: Bool BSrc BStack -> BStack +bs_eqIi :: Int BSrc BStack -> BStack +bs_gtI :: BStack -> BStack +bs_ltI :: BStack -> BStack +bs_mulI :: BStack -> BStack +bs_subI :: BStack -> BStack diff --git a/BStack.icl b/BStack.icl new file mode 100644 index 0000000..aa96551 --- /dev/null +++ b/BStack.icl @@ -0,0 +1,88 @@ +implementation module ABC.BStack + +import StdEnv + +import ABC.Def +import ABC.Misc + +bs_copy :: BSrc BStack -> BStack +bs_copy i s = [bs_get i s:s] + +bs_get :: BSrc BStack -> Basic +bs_get _ [] = abortn "bs_get: index too large" +bs_get 0 [b:s] = b +bs_get i [_:s] = bs_get (i-1) s + +bs_getB :: BSrc BStack -> Bool +bs_getB i s = case bs_get i s of + (Bool b) = b + _ = abortn "bs_getB on non-Bool value\n" + +bs_getI :: BSrc BStack -> Int +bs_getI i s = case bs_get i s of + (Int i) = i + _ = abortn "bs_getI on non-Int value\n" + +bs_init :: BStack +bs_init = [] + +bs_popn :: NrArgs BStack -> BStack +bs_popn 0 s = s +bs_popn _ [] = abortn "bs_popn: popping too many elements" +bs_popn i [_:s] = bs_popn (i-1) s + +bs_push :: Dynamic BStack -> BStack +bs_push d s = [d:s] + +bs_pushB :: Bool BStack -> BStack +bs_pushB b s = [dynamic b:s] + +bs_pushI :: Int BStack -> BStack +bs_pushI i s = [dynamic i:s] + +bs_update :: BDst Dynamic BStack -> BStack +bs_update 0 d [_:s] = [d:s] +bs_update _ _ [] = abortn "bs_update: index too large" +bs_update i d [e:s] = [e:bs_update (i-1) d s] + +bs_addI :: BStack -> BStack +bs_addI [Int m:Int n:s] = bs_pushI (m+n) s +bs_addI _ = abortn "bs_addI: no integers" + +bs_decI :: BStack -> BStack +bs_decI [Int n:s] = bs_pushI (n-1) s +bs_decI _ = abortn "bs_decI: no integer" + +bs_incI :: BStack -> BStack +bs_incI [Int n:s] = bs_pushI (n+1) s +bs_incI _ = abortn "bs_incI: no integer" + +bs_eqB :: BStack -> BStack +bs_eqB [Bool b:Bool c:s] = bs_pushB (b == c) s +bs_eqB _ = abortn "bs_eqB: no booleans" + +bs_eqI :: BStack -> BStack +bs_eqI [Int m:Int n:s] = bs_pushB (m == n) s +bs_eqI _ = abortn "bs_eqI: no integers" + +bs_eqBi :: Bool BSrc BStack -> BStack +bs_eqBi b i s = bs_pushB (bs_getB i s == b) s + +bs_eqIi :: Int BSrc BStack -> BStack +bs_eqIi n i s = bs_pushB (bs_getI i s == n) s + +bs_gtI :: BStack -> BStack +bs_gtI [Int m:Int n:s] = bs_pushB (m > n) s +bs_gtI _ = abortn "bs_gtI: no integers" + +bs_ltI :: BStack -> BStack +bs_ltI [Int m:Int n:s] = bs_pushB (m < n) s +bs_ltI _ = abortn "bs_ltI: no integers" + +bs_mulI :: BStack -> BStack +bs_mulI [Int m:Int n:s] = bs_pushB (m * n) s +bs_mulI _ = abortn "bs_mulI: no integers" + +bs_subI :: BStack -> BStack +bs_subI [Int m:Int n:s] = bs_pushB (m - n) s +bs_subI _ = abortn "bs_subI: no integers" diff --git a/CStack.dcl b/CStack.dcl new file mode 100644 index 0000000..8aa6824 --- /dev/null +++ b/CStack.dcl @@ -0,0 +1,12 @@ +definition module ABC.CStack + +from ABC.Def import ::InstrId + +:: CSrc :== Int +:: CDst :== Int +:: CStack (:== [InstrId]) + +cs_init :: CStack +cs_get :: CSrc CStack -> InstrId +cs_popn :: CSrc CStack -> CStack +cs_push :: InstrId CStack -> CStack diff --git a/CStack.icl b/CStack.icl new file mode 100644 index 0000000..f549c4f --- /dev/null +++ b/CStack.icl @@ -0,0 +1,21 @@ +implementation module ABC.CStack + +import StdEnv + +import ABC.Def + +cs_init :: CStack +cs_init = [] + +cs_get :: CSrc CStack -> InstrId +cs_get _ [] = abortn "cs_get: index too large" +cs_get 0 [i:_] = i +cs_get i [_:s] = cs_get (i-1) s + +cs_popn :: CSrc CStack -> CStack +cs_popn 0 s = s +cs_popn _ [] = abortn "cs_popn: popping too many elements" +cs_popn i [_:s] = cs_popn (i-1) s + +cs_push :: InstrId CStack -> CStack +cs_push i s = [i:s] @@ -0,0 +1,5 @@ +definition module ABC.Def + +:: NodeId :== Int +:: NrArgs :== Int +:: InstrId :== Int @@ -0,0 +1 @@ +implementation module ABC.Def diff --git a/Misc.dcl b/Misc.dcl new file mode 100644 index 0000000..acd5117 --- /dev/null +++ b/Misc.dcl @@ -0,0 +1,3 @@ +definition module ABC.Misc + +abortn :: String -> a diff --git a/Misc.icl b/Misc.icl new file mode 100644 index 0000000..034ce9d --- /dev/null +++ b/Misc.icl @@ -0,0 +1,6 @@ +implementation module ABC.Misc + +import StdEnv + +abortn :: String -> a +abortn s = abort (s +++ "\n") |