diff options
author | Camil Staps | 2016-07-01 09:11:02 +0200 |
---|---|---|
committer | Camil Staps | 2016-07-01 09:11:02 +0200 |
commit | 55e6cadc298beda9d079d99147b3cb0f50ce25ec (patch) | |
tree | dd28e78845843d2dff7d2b3daa2b60f5520e8b7e | |
parent | Fixes (diff) |
Printing
-rw-r--r-- | AStack.dcl | 3 | ||||
-rw-r--r-- | AStack.icl | 2 | ||||
-rw-r--r-- | BStack.dcl | 5 | ||||
-rw-r--r-- | BStack.icl | 7 | ||||
-rw-r--r-- | CStack.dcl | 3 | ||||
-rw-r--r-- | CStack.icl | 2 | ||||
-rw-r--r-- | Def.dcl | 3 | ||||
-rw-r--r-- | Descriptors.dcl | 14 | ||||
-rw-r--r-- | Descriptors.icl | 25 | ||||
-rw-r--r-- | GraphStore.dcl | 16 | ||||
-rw-r--r-- | GraphStore.icl | 34 | ||||
-rw-r--r-- | IO.dcl | 14 | ||||
-rw-r--r-- | IO.icl | 27 | ||||
-rw-r--r-- | Misc.dcl | 5 | ||||
-rw-r--r-- | Misc.icl | 11 |
15 files changed, 125 insertions, 46 deletions
@@ -1,11 +1,14 @@ definition module ABC.AStack +from StdOverloaded import class toString from ABC.Def import ::NodeId, ::NrArgs :: ASrc :== Int :: ADst :== Int :: AStack (:== [NodeId]) +instance toString AStack + as_get :: ASrc AStack -> NodeId as_init :: AStack as_popn :: NrArgs AStack -> AStack @@ -7,6 +7,8 @@ import ABC.Misc :: AStack :== [NodeId] +instance toString AStack where toString xs = "[" <++ (",", xs) <+ "]" + as_get :: ASrc AStack -> NodeId as_get _ [] = abortn "as_get: index too large" as_get 0 [n:_] = n @@ -1,17 +1,20 @@ definition module ABC.BStack -from StdOverloaded import class == +from StdOverloaded import class ==, class toString from ABC.Def import ::NrArgs :: Basic = Int Int | Bool Bool instance == Basic +instance toString Basic :: BSrc :== Int :: BDst :== Int :: BStack (:== [Basic]) +instance toString BStack + bs_copy :: BSrc BStack -> BStack bs_get :: BSrc BStack -> Basic bs_getB :: BSrc BStack -> Bool @@ -11,8 +11,15 @@ where (==) (Int m) (Int n) = m == n (==) _ _ = False +instance toString Basic +where + toString (Bool b) = toString b + toString (Int i) = toString i + :: BStack :== [Basic] +instance toString BStack where toString xs = "[" <++ (",", xs) <+ "]" + bs_copy :: BSrc BStack -> BStack bs_copy i s = [bs_get i s:s] @@ -1,11 +1,14 @@ definition module ABC.CStack +from StdOverloaded import class toString from ABC.Def import ::InstrId :: CSrc :== Int :: CDst :== Int :: CStack (:== [InstrId]) +instance toString CStack + cs_init :: CStack cs_get :: CSrc CStack -> InstrId cs_popn :: CSrc CStack -> CStack @@ -7,6 +7,8 @@ import ABC.Misc :: CStack :== [InstrId] +instance toString CStack where toString xs = "[" <++ (",", xs) <+ "]" + cs_init :: CStack cs_init = [] @@ -3,8 +3,7 @@ definition module ABC.Def from ABC.AStack import ::AStack from ABC.BStack import ::BStack from ABC.CStack import ::CStack -from ABC.GraphStore import ::GraphStore -from ABC.Descriptors import ::DescStore +from ABC.GraphStore import ::GraphStore, ::DescStore from ABC.Program import ::ProgramStore from ABC.IO import ::IO diff --git a/Descriptors.dcl b/Descriptors.dcl deleted file mode 100644 index 7c0dad6..0000000 --- a/Descriptors.dcl +++ /dev/null @@ -1,14 +0,0 @@ -definition module ABC.Descriptors - -from ABC.Def import ::Arity, ::InstrId, ::Name, ::APEntry, ::DescId - -:: Desc = Desc APEntry Arity Name - -d_ap_entry :: Desc -> InstrId -d_arity :: Desc -> Arity -d_name :: Desc -> String - -:: DescStore (:== [Desc]) - -ds_get :: DescId DescStore -> Desc -ds_init :: [Desc] -> DescStore diff --git a/Descriptors.icl b/Descriptors.icl deleted file mode 100644 index 5874136..0000000 --- a/Descriptors.icl +++ /dev/null @@ -1,25 +0,0 @@ -implementation module ABC.Descriptors - -import StdEnv - -import ABC.Machine -import ABC.Misc - -d_ap_entry :: Desc -> InstrId -d_ap_entry (Desc e _ _) = e - -d_arity :: Desc -> Arity -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 -ds_get _ [] = abortn "ds_get: index too large" -ds_get i [_:s] = ds_get (i-1) s - -ds_init :: [Desc] -> DescStore -ds_init ds = ds diff --git a/GraphStore.dcl b/GraphStore.dcl index 5095a78..108a77e 100644 --- a/GraphStore.dcl +++ b/GraphStore.dcl @@ -1,10 +1,24 @@ definition module ABC.GraphStore -from ABC.Def import ::NodeId +from StdOverloaded import class toString +from ABC.Def import ::Arity, ::InstrId, ::Name, ::APEntry, ::DescId, ::NodeId from ABC.Nodes import ::Node +:: Desc = Desc APEntry Arity Name + +d_ap_entry :: Desc -> InstrId +d_arity :: Desc -> Arity +d_name :: Desc -> String + +:: DescStore (:== [Desc]) + +ds_get :: DescId DescStore -> Desc +ds_init :: [Desc] -> DescStore + :: GraphStore +show_graphstore :: GraphStore DescStore -> String + gs_get :: NodeId GraphStore -> Node gs_init :: GraphStore gs_newnode :: GraphStore -> (GraphStore, NodeId) diff --git a/GraphStore.icl b/GraphStore.icl index 3d966c0..6f2a2e0 100644 --- a/GraphStore.icl +++ b/GraphStore.icl @@ -5,11 +5,43 @@ import StdEnv import ABC.Machine import ABC.Misc +STORE_SIZE :== 1000 + +d_ap_entry :: Desc -> InstrId +d_ap_entry (Desc e _ _) = e + +d_arity :: Desc -> Arity +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 +ds_get _ [] = abortn "ds_get: index too large" +ds_get i [_:s] = ds_get (i-1) s + +ds_init :: [Desc] -> DescStore +ds_init ds = ds + :: GraphStore = { nodes :: [Node] , free :: Int } -STORE_SIZE :== 1000 +show_graphstore :: GraphStore DescStore -> String +show_graphstore {nodes,free} ds = show_nds (free+1) nodes ds +where + show_nds :: Int [Node] [Desc] -> String + show_nds i [] ds = "" + show_nds i [n:ns] ds + = i <+ " : " <+ show_nd n ds <+ "\n" <+ show_nds (i+1) ns ds + + show_nd :: Node [Desc] -> String + show_nd (Basic _ e b) _ = e <+ " " <+ b + show_nd (Node d e a) ds = d_name (ds_get d ds) <+ " " <+ e <+ " " <+ a + show_nd Empty _ = "Empty" gs_get :: NodeId GraphStore -> Node gs_get i {nodes} = get i nodes @@ -1,3 +1,15 @@ definition module ABC.IO -:: IO +from StdOverloaded import class toString + +from ABC.Nodes import ::Node +from ABC.GraphStore import ::Desc +from ABC.Def import ::State + +:: IO (:== [Char]) + +io_init :: IO +io_print :: a IO -> IO | toString a + +show_node :: Node Desc -> String +instance toString State @@ -1,3 +1,28 @@ implementation module ABC.IO -:: IO = IO +import StdEnv + +import ABC.Machine +import ABC.Misc + +:: IO :== [Char] + +io_init :: IO +io_init = [] + +io_print :: a IO -> IO | toString a +io_print x io = io ++ fromString (toString x) + +show_node :: Node Desc -> String +show_node (Basic _ _ b) _ = toString b +show_node (Node _ _ _) (Desc _ _ n) = n + +instance toString State +where + toString {astack,bstack,cstack,graphstore,descstore,pc,program,io} + = "output : " <+ io <+ "\n" <+ + "pc : " <+ pc <+ "\n" <+ + "A-stack : " <+ astack <+ "\n" <+ + "B-stack : " <+ bstack <+ "\n" <+ + "C-stack : " <+ cstack <+ "\n" <+ + "Graph :\n" <+ show_graphstore graphstore descstore @@ -1,3 +1,8 @@ definition module ABC.Misc +from StdOverloaded import class toString + abortn :: String -> a + +(<+) infixl 5 :: a b -> String | toString a & toString b +(<++) infixl 5 :: a (g, [b]) -> String | toString a & toString b & toString g @@ -4,3 +4,14 @@ import StdEnv abortn :: String -> a abortn s = abort (s +++ "\n") + +(<+) infixl 5 :: a b -> String | toString a & toString b +(<+) a b = toString a +++ toString b + +(<++) infixl 5 :: a (g, [b]) -> String | toString a & toString b & toString g +(<++) a (g,xs) = a <+ printersperse g xs + +printersperse :: a [b] -> String | toString a & toString b +printersperse g [] = "" +printersperse g [x] = toString x +printersperse g [x:xs] = x <+ g <++ (g, xs) |