-
Notifications
You must be signed in to change notification settings - Fork 2
/
handler.fs
54 lines (41 loc) · 1.26 KB
/
handler.fs
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
module handler
0
1+ dup constant matchop
1+ dup constant openop
1+ dup constant closeop
1+ dup constant readop
1+ dup constant writeop
1+ dup constant seekop
constant maxops
variable handlers handlers off
: handler
create handlers linked
here maxops cells dup allot erase ;
export handler
: op: pad ! : pad @ cells postpone literal postpone + ;
matchop op: matches ! ;
openop op: opens ! ;
closeop op: closes ! ;
readop op: reads ! ;
writeop op: writes ! ;
seekop op: seeks ! ;
export opens closes reads writes seeks matches
matchop op: matcher @ ;
openop op: opener @ ;
closeop op: closer @ ;
readop op: reader @ ;
writeop op: writer @ ;
seekop op: seeker @ ;
export opener closer reader writer seeker matcher
: dispatch @ dup if execute false else true then ;
matchop op: match dispatch abort" no matcher" ;
openop op: rawopen dispatch if drop 2drop 0 -21 then ;
closeop op: close dispatch if drop -21 then ;
readop op: read dispatch if drop 2drop 0 -21 then ;
writeop op: write dispatch if drop 2drop -21 then ;
seekop op: seek dispatch if drop 2drop -21 then ;
: open ( c-addr u fam -- handle handler ior)
>r handlers begin @ >r r@ match r> swap until
r> swap >r r@ rawopen r> swap ;
export rawopen open close read write seek
end-module