-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathybot_bookmarked_stream.xtm
104 lines (81 loc) · 2.85 KB
/
ybot_bookmarked_stream.xtm
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
92
93
94
95
96
97
98
99
100
101
102
103
104
(bind-type BookmarkedStream <apr_file_t*,List{i64}*,bool*>)
(bind-func next:[i8,BookmarkedStream*]*
(lambda (stream)
(yfs_read_byte (tref stream 0) (tref stream 2))))
(bind-func peek:[i8,BookmarkedStream*]*
(lambda (stream)
(yfs_peek_byte (tref stream 0))))
(bind-func goto:[bool,BookmarkedStream*,i64]*
(lambda (stream index)
(let ((new_index:i64 (yfs_file_seek (tref stream 0) index)))
(= new_index index))))
(bind-func goto_start:[bool,BookmarkedStream*]*
(lambda (stream)
(goto stream 0)))
(bind-func playhead:[i64,BookmarkedStream*]*
(lambda (stream)
(yfs_current_playhead (tref stream 0))))
(bind-func push_bookmark:[void,BookmarkedStream*]*
(lambda (stream)
(tset! stream 1 (cons (playhead stream) (tref stream 1)))
void))
(bind-func pop_bookmark:[i64,BookmarkedStream*]*
(lambda (stream)
(let ((output (car (tref stream 1))))
(tset! stream 1 (cdr (tref stream 1)))
output)))
(bind-func step_back:[bool,BookmarkedStream*]*
(lambda (stream)
(goto stream (- (playhead stream) 1))))
(bind-func backtrack:[bool,BookmarkedStream*]*
(lambda (stream)
(cond
((non-empty (tref stream 1))
(goto stream (pop_bookmark stream)))
(else #f))))
(bind-func peek_bookmark:[i64,BookmarkedStream*]*
(lambda (stream)
(car (tref stream 1))))
(bind-func end_of_stream:[bool,BookmarkedStream*]*
(lambda (stream)
(@ (tref stream 2))))
(bind-func print:[void,BookmarkedStream*]*
(lambda (stream)
(let ((sorted:List{i64}* (sort (tref stream 1) null (lambda (a:i64 b:i64) (< a b)))))
(goto stream 0)
(let ((loop:[void,i64,List{i64}*]*
(lambda (index:i64 marks:List{i64}*)
;(println "Index: " index)
(cond
((end_of_stream stream) void)
(else
(cond
((and (non-empty marks) (= index (car marks)))
(highlighter "white")
(colour_pencil "black")
(printf "%c" (next stream))
(loop (+ index 1) (cdr marks)))
(else
(highlighter "normal")
(printf "%c" (next stream))
(loop (+ index 1) marks))))))))
(loop 0 sorted)))))
;; (bind-func test-stream:[void,i8*]*
;; (lambda (path)
;; (let* ((eof:bool* (zalloc))
;; (file:apr_file_t* (yfs_open path))
;; (stream:BookmarkedStream* (BookmarkedStream file null eof))
;; (i:i64 0) (j:i64 0) (k:i64 0) (n:i64 0))
;; (dotimes (i 12)
;; (next stream))
;; (push_bookmark stream)
;; (dotimes (j 26)
;; (next stream))
;; (push_bookmark stream)
;; (dotimes (k 32)
;; (next stream))
;; (push_bookmark stream)
;; (print stream)
;; (println "")
;; (yfs_close file)
;; void)))