commit eeeb107

shrub  ·  2026-11-02 15:30:12 +0000 UTC
parent e001bfc
use viewtype for producer
5 files changed,  +22, -16
+1, -1
1@@ -6,7 +6,7 @@ LDLIBS = -L"$(PATSHOME)/ccomp/atslib/lib" -latslib
2 OBJ = main.o scan.o parse.o graph.o
3 
4 monk: $(OBJ)
5-	$(ATSCC) $(ATSFLAGS) -o $@ $(OBJ) $(LDLIBS)
6+	$(ATSCC) $(ATSFLAGS) -o $@ $^ $(LDLIBS)
7 
8 .SUFFIXES: .dats .o
9 .dats.o:
+16, -13
 1@@ -1,15 +1,16 @@
 2 #include "share/atspre_staload.hats"
 3 #define ATS_DYNLOADFLAG 0
 4 
 5+staload      "libats/SATS/dynarray.sats"
 6+staload _  = "libats/DATS/dynarray.dats"
 7+staload      "libats/SATS/hashtbl_linprb.sats"
 8+staload _  = "libats/DATS/hashtbl_linprb.dats"
 9+staload _  = "libats/DATS/hashfun.dats"
10+staload UN = "prelude/SATS/unsafe.sats"
11+
12 staload "graph.sats"
13 staload "types.sats"
14 staload "parse.sats"
15-staload "libats/SATS/dynarray.sats"
16-staload _  = "libats/DATS/dynarray.dats"
17-staload "libats/SATS/hashtbl_linprb.sats"
18-staload _ = "libats/DATS/hashtbl_linprb.dats"
19-staload _ = "libats/DATS/hashfun.dats"
20-staload UN = "prelude/SATS/unsafe.sats"
21 
22 exception GraphErr of ()
23 
24@@ -17,9 +18,9 @@ assume node_id   = usize
25 assume action_id = usize
26 
27 vtypedef thegraph = @{
28-    nodes = dynarray(node),
29+    nodes   = dynarray(node),
30     actions = dynarray(action),
31-    paths = hashtbl(string, node_id)
32+    paths   = hashtbl(string, node_id)
33 }
34 
35 assume graph = thegraph
36@@ -36,6 +37,10 @@ implement mkgraph() =
37 fun node_free(n: node): void = 
38     let 
39         val @{path = p, producer = pr, consumers = c} = n
40+        val () = 
41+            case+ pr of 
42+            | ~None_vt( ) => ()
43+            | ~Some_vt(_) => ()
44     in
45         strptr_free(p);
46         list_vt_free(c)
47@@ -101,7 +106,7 @@ fun mknode(g: &graph, path: Strptr1): node_id =
48         | ~None_vt()   => ( (* the node doesnt exist *)
49             let val newid = dynarray_get_size(g.nodes) (*the id will be the size of the node array *)
50                 val key   = $UN.strptr2string(path) (*borrow key before putting path in the new node*)
51-                val newnode : node = @{path = path, producer = None(), consumers = nil_vt()} 
52+                val newnode : node = @{path = path, producer = None_vt(), consumers = nil_vt()} 
53                 val ()    = dynarray_insert_atend_exn<node>(g.nodes, newnode) 
54                 val prev  = hashtbl_insert_opt<string, node_id>(g.paths, key, newid) 
55             in  
56@@ -129,10 +134,8 @@ fun setprod(g: &graph, nid: node_id, aid: action_id): void =
57         var n: node = dynarray_takeout_at_exn<node>(g.nodes, nid) (*probably slow to takeout and reinsert*)
58         val hasprod = 
59             case+ n.producer of 
60-            | None( ) => false
61-            | Some(_) => true
62-        val () = 
63-            if hasprod then () else n.producer := Some(aid)
64+            | ~None_vt( ) => (n.producer := Some_vt(aid); false)
65+            | @Some_vt(_) => (fold@(n.producer); true)
66         val () = dynarray_insert_at_exn<node>(g.nodes, nid, n)
67     in
68         if hasprod then $raise GraphErr else ()
+2, -2
 1@@ -13,8 +13,8 @@ absvt@ype graph = @{
 2 
 3 vtypedef node = @{
 4     path      = Strptr1,
 5-    producer  = Option(action_id),
 6-    consumers = List0_vt(action_id)
 7+    producer  = Option_vt(action_id),
 8+    consumers = List0_vt (action_id)
 9 }
10 
11 vtypedef action = @{
+1, -0
1@@ -1,5 +1,6 @@
2 #include "share/atspre_staload.hats"
3 #define ATS_DYNLOADFLAG 0
4+
5 staload "scan.sats"
6 staload "parse.sats"
7 
+2, -0
 1@@ -1,8 +1,10 @@
 2 #include "share/atspre_staload.hats"
 3 #define ATS_DYNLOADFLAG 0
 4+
 5 staload "libats/libc/SATS/stdio.sats"
 6 staload "libats/SATS/stringbuf.sats"
 7 staload "libats/DATS/stringbuf.dats"
 8+
 9 staload "scan.sats"
10 
11 exception ScanErr of ()