aboutsummaryrefslogtreecommitdiff
path: root/GraphStore.icl
diff options
context:
space:
mode:
authorCamil Staps2016-07-01 09:11:02 +0200
committerCamil Staps2016-07-01 09:11:02 +0200
commit55e6cadc298beda9d079d99147b3cb0f50ce25ec (patch)
treedd28e78845843d2dff7d2b3daa2b60f5520e8b7e /GraphStore.icl
parentFixes (diff)
Printing
Diffstat (limited to 'GraphStore.icl')
-rw-r--r--GraphStore.icl34
1 files changed, 33 insertions, 1 deletions
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