-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuffer.m
57 lines (47 loc) · 1.29 KB
/
buffer.m
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
export InputBuffer, InputThing
const InputThing <- typeobject InputThing
operation getChar -> [Character]
function eos -> [Boolean]
operation fillVector[VectorOfChar] -> [Integer]
end InputThing
const InputBuffer <- immutable object InputBuffer
const BufferType <- typeobject BufferType
operation collect [Character]
operation reset
function getElement[Integer] -> [Character]
function asString -> [String]
operation readString [InputThing, Character]
end BufferType
export function getSignature -> [r : Signature]
r <- BufferType
end getSignature
export operation create -> [r : BufferType]
r <- object aBuffer
const limit <- 4096
const b : VectorOfChar <- VectorofChar.create[limit]
var size : Integer <- 0
export operation reset
size <- 0
end reset
export operation collect [c : Character]
b[size] <- c
size <- size + 1
end collect
export function getElement [i : Integer] -> [r : Character]
r <- b[i]
end getElement
export function asString -> [r : String]
r <- String.FLiteral[b, 0, size]
end asString
export operation readString[f : InputThing, eof : Character]
begin
size <- f.fillVector[b]
failure
size <- 0
end failure
end
b[size] <- eof
end readString
end aBuffer
end create
end InputBuffer