-
Notifications
You must be signed in to change notification settings - Fork 1
/
book
91 lines (75 loc) · 2.05 KB
/
book
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
(fun (book/ref book)
(.sys/book-ref book))
(fun (book/unref book)
(.sys/book-unref book))
(struct book/book
(refs u32)
name
(time u32)
next
pages
globals
deps
ood-flag)
(struct book/link
bl-link
bl-book)
(fun (book/find name)
(var b (ctxt/books context))
(while b
(if ((== (str/cmp (book/name b) name) 0)
(book/ref b)
(goto found)))
(set b (book/next b)))
(label found)
b)
(fun (book/get name print-hook print-hook-data)
(.sys/book-get name print-hook print-hook-data))
(fun (book/search-fun book name)
(.sys/book-search-fun book name))
(fun (book/find-in-list list cond arg1 arg2)
(var res 0)
(while list
(if ((cond (book/bl-book list) arg1 arg2)
(set res (book/bl-book list))
(goto done)))
(set list (book/bl-link list)))
(label done)
res)
(fun (book/is-older-than-file book)
(mem rbuf fs/rbuf)
(if ((fs/open rbuf (book/name book))
(var ftime (fs/node-time (fs/rbuf-node-ptr rbuf)))
(fs/close rbuf)
(> ftime (book/time book)))
(else
0)))
(fun (book/is-out-of-date book is-unsaved is-unsaved-data)
(if ((book/ood-flag book)
(- (book/ood-flag book) 1))
(else
(var ood (or (is-unsaved (book/name book) is-unsaved-data)
(book/is-older-than-file book)
(!= (book/find-in-list (book/deps book) book/is-out-of-date is-unsaved is-unsaved-data) 0)))
(set (book/ood-flag book) (+ ood 1))
ood)))
(fun (book/reset-ood-flag book)
(if ((!= (book/ood-flag book) 0)
(set (book/ood-flag book) 0)
(book/find-in-list (book/deps book) book/reset-ood-flag)))
0)
(fun (book/reset-out-of-date)
(var b (ctxt/books context))
(while b
(book/reset-ood-flag b)
(set b (book/next b))))
;; Function tables
(def (book/funtab ?name . ?funcs)
(data ?name
(4 ?(exp/global (exp/intern ".book")) . ?funcs)))
(fun (book/funtab-book ft)
(u64 ft 0))
(fun (book/funtab-ref ft)
(book/ref (book/funtab-book ft)))
(fun (book/funtab-unref ft)
(book/unref (book/funtab-book ft)))