diff options
-rw-r--r-- | .gitignore | 10 | ||||
-rw-r--r-- | AStack.dcl | 32 | ||||
-rw-r--r-- | AStack.icl | 35 | ||||
-rw-r--r-- | BStack.dcl | 9 | ||||
-rw-r--r-- | BStack.icl | 20 | ||||
-rw-r--r-- | CStack.icl | 3 | ||||
-rw-r--r-- | Def.dcl | 1 | ||||
-rw-r--r-- | Descriptors.dcl | 2 | ||||
-rw-r--r-- | Descriptors.icl | 1 | ||||
-rw-r--r-- | GraphStore.icl | 7 | ||||
-rw-r--r-- | IO.dcl | 3 | ||||
-rw-r--r-- | IO.icl | 3 | ||||
-rw-r--r-- | Machine.icl | 1 | ||||
-rw-r--r-- | Nodes.dcl | 3 | ||||
-rw-r--r-- | Nodes.icl | 12 | ||||
-rw-r--r-- | Program.dcl | 2 |
16 files changed, 92 insertions, 52 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..73deb1e --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Executables +*.exe +*.out + +# Directory used to store object files, abc files and assembly files +Clean System Files/ + +# iTasks environment extra data +*-data/ +sapl/ @@ -1,37 +1,15 @@ -implementation module ABC.AStack +definition module ABC.AStack -import StdEnv +from ABC.Def import ::NodeId, ::NrArgs -import ABC.Def +:: ASrc :== Int +:: ADst :== Int +:: AStack (:== [NodeId]) 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] @@ -1,15 +1,40 @@ -definition module ABC.AStack +implementation module ABC.AStack -from ABC.Def import ::NodeId, ::NrArgs +import StdEnv -:: ASrc :== Int -:: ADst :== Int -:: AStack (:== [NodeId]) +import ABC.Def +import ABC.Misc + +:: AStack :== [NodeId] 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 ++ s + 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] @@ -1,8 +1,13 @@ definition module ABC.BStack +from StdOverloaded import class == +from ABC.Def import ::NrArgs + :: Basic = Int Int | Bool Bool +instance == Basic + :: BSrc :== Int :: BDst :== Int :: BStack (:== [Basic]) @@ -13,10 +18,10 @@ bs_getB :: BSrc BStack -> Bool bs_getI :: BSrc BStack -> Int bs_init :: BStack bs_popn :: NrArgs BStack -> BStack -bs_push :: Dynamic BStack -> BStack +bs_push :: Basic BStack -> BStack bs_pushB :: Bool BStack -> BStack bs_pushI :: Int BStack -> BStack -bs_update :: BDst Dynamic BStack -> BStack +bs_update :: BDst Basic BStack -> BStack bs_addI :: BStack -> BStack bs_decI :: BStack -> BStack bs_incI :: BStack -> BStack @@ -5,6 +5,14 @@ import StdEnv import ABC.Def import ABC.Misc +instance == Basic +where + (==) (Bool b) (Bool c) = b == c + (==) (Int m) (Int n) = m == n + (==) _ _ = False + +:: BStack :== [Basic] + bs_copy :: BSrc BStack -> BStack bs_copy i s = [bs_get i s:s] @@ -31,16 +39,16 @@ 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 :: Basic BStack -> BStack bs_push d s = [d:s] bs_pushB :: Bool BStack -> BStack -bs_pushB b s = [dynamic b:s] +bs_pushB b s = [Bool b:s] bs_pushI :: Int BStack -> BStack -bs_pushI i s = [dynamic i:s] +bs_pushI i s = [Int i:s] -bs_update :: BDst Dynamic BStack -> BStack +bs_update :: BDst Basic 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] @@ -80,9 +88,9 @@ 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 [Int m:Int n:s] = bs_pushI (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 [Int m:Int n:s] = bs_pushI (m - n) s bs_subI _ = abortn "bs_subI: no integers" @@ -3,6 +3,9 @@ implementation module ABC.CStack import StdEnv import ABC.Def +import ABC.Misc + +:: CStack :== [InstrId] cs_init :: CStack cs_init = [] @@ -24,6 +24,7 @@ from ABC.IO import ::IO :: DescId :== Int :: InstrId :== Int :: Name :== String +:: Arity :== Int :: Instruction :== State -> State diff --git a/Descriptors.dcl b/Descriptors.dcl index b2dcce4..7c0dad6 100644 --- a/Descriptors.dcl +++ b/Descriptors.dcl @@ -1,6 +1,6 @@ definition module ABC.Descriptors -from ABC.Def import ::Arity, ::InstrId +from ABC.Def import ::Arity, ::InstrId, ::Name, ::APEntry, ::DescId :: Desc = Desc APEntry Arity Name diff --git a/Descriptors.icl b/Descriptors.icl index 11ec8ea..5874136 100644 --- a/Descriptors.icl +++ b/Descriptors.icl @@ -14,6 +14,7 @@ d_arity (Desc _ a _) = a d_name :: Desc -> String d_name (Desc _ _ n) = n +:: DescStore :== [Desc] ds_get :: DescId DescStore -> Desc ds_get 0 [d:_] = d diff --git a/GraphStore.icl b/GraphStore.icl index e7f0be6..3d966c0 100644 --- a/GraphStore.icl +++ b/GraphStore.icl @@ -3,6 +3,7 @@ implementation module ABC.GraphStore import StdEnv import ABC.Machine +import ABC.Misc :: GraphStore = { nodes :: [Node] , free :: Int @@ -16,13 +17,13 @@ where get :: NodeId [Node] -> Node get 0 [n:_] = n get _ [] = abortn "gs_get: index too large" - get i [_:s] = gs_get (i-1) s + get i [_:s] = get (i-1) s gs_init :: GraphStore gs_init = {nodes=[], free=STORE_SIZE} gs_newnode :: GraphStore -> (GraphStore, NodeId) -gs_newnode {free=:0} = abortn "gs_newnode: graph store is full" +gs_newnode {free=0} = abortn "gs_newnode: graph store is full" gs_newnode {nodes,free} = ({nodes=[Empty:nodes], free=free-1}, free) gs_update :: NodeId (Node -> Node) GraphStore -> GraphStore @@ -34,4 +35,4 @@ where update :: Int [Node] (Node -> Node) -> [Node] update 0 [n:s] f = [f n:s] - update i [n:s] f = [n:update (i-1) f s] + update i [n:s] f = [n:update (i-1) s f] @@ -0,0 +1,3 @@ +definition module ABC.IO + +:: IO @@ -0,0 +1,3 @@ +implementation module ABC.IO + +:: IO = IO diff --git a/Machine.icl b/Machine.icl new file mode 100644 index 0000000..ab1acb4 --- /dev/null +++ b/Machine.icl @@ -0,0 +1 @@ +implementation module ABC.Machine @@ -1,6 +1,7 @@ definition module ABC.Nodes -from ABC.Def import ::ArgNr, ::Arity, ::NodeId, ::InstrId +from ABC.Def import ::ArgNr, ::Arity, ::NodeId, ::InstrId, ::Args, ::DescId, ::NrArgs +from ABC.BStack import ::Basic :: Node = Node DescId InstrId Args | Basic DescId InstrId Basic @@ -2,7 +2,7 @@ implementation module ABC.Nodes import StdEnv -import ABC.Def +import ABC.Machine import ABC.Misc n_arg :: Node ArgNr Arity -> NodeId @@ -12,9 +12,9 @@ n_arg n i a n_args :: Node Arity -> [NodeId] n_args (Node _ _ args) a -| a = length args = args -| otherwise = abortn "n_args: incorrect arity" -n_args _ _ = abortn "n_args: no arguments in node" +| a == length args = args +| otherwise = abortn "n_args: incorrect arity" +n_args _ _ = abortn "n_args: no arguments in node" n_arity :: Node -> Arity n_arity (Basic _ _ _) = 0 @@ -60,7 +60,7 @@ n_eq_symbol (Basic i1 _ b1) (Basic i2 _ b2) = i1 == i2 && b1 == b2 n_eq_symbol _ _ = False n_fill :: DescId InstrId Args Node -> Node -n_fill d i a _ = Node d e a +n_fill d i a _ = Node d i a n_fillB :: DescId InstrId Bool Node -> Node n_fillB d e b _ = Basic d e (Bool b) @@ -73,5 +73,5 @@ n_nargs n i a = take i (n_args n a) n_setentry :: InstrId Node -> Node n_setentry e (Node d _ a) = Node d e a -n_setentry e (Basic d _ b) = Bsaic d e b +n_setentry e (Basic d _ b) = Basic d e b n_setentry _ Empty = abortn "n_setentry: Empty node" diff --git a/Program.dcl b/Program.dcl index 31b61d7..ffdf948 100644 --- a/Program.dcl +++ b/Program.dcl @@ -1,6 +1,6 @@ definition module ABC.Program -from ABC.Def import ::InstrId, ::Instruction +from ABC.Def import ::InstrId, ::Instruction, ::State pc_init :: InstrId pc_next :: InstrId -> InstrId |