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
|
(* This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at https://mozilla.org/MPL/2.0/. *)
import cstring, cstdio, cstdlib
type
ElnaLocation* = record
line: Word;
column: Word
end
ElnaPosition* = record
start_location: ElnaLocation;
end_location: ElnaLocation
end
proc write*(fd: Int; buf: Pointer; Word: Int): Int
extern
proc write_s*(value: String)
begin
(* fwrite(cast(value.ptr: Pointer), value.length, 1u, stdout) *)
write(1, cast(value.ptr: Pointer), cast(value.length: Int))
end
proc write_z*(value: ^Char)
begin
write(1, cast(value: Pointer), cast(strlen(value): Int))
end
proc write_b*(value: Bool)
begin
if value then
write_s("true")
else
write_s("false")
end
end
proc write_c*(value: Char)
begin
putchar(cast(value: Int));
fflush(nil)
end
proc write_i*(value: Int)
var
digit: Int
n: Word
buffer: [10]Char
begin
n := 10u;
if value = 0 then
write_c('0')
end;
while value <> 0 do
digit := value % 10;
value := value / 10;
buffer[n] := cast(cast('0': Int) + digit: Char);
n := n - 1u
end;
while n < 10u do
n := n + 1u;
write_c(buffer[n])
end
end
proc write_u*(value: Word)
begin
write_i(cast(value: Int))
end
proc free_and_nil*(pointer: Pointer): Pointer
begin
free(pointer);
return nil
end
(* Returns true or false depending whether two strings are equal. *)
proc string_compare*(lhs_pointer: ^Char; lhs_length: Word; rhs_pointer: String): Bool
var
result: Bool
begin
if lhs_length = rhs_pointer.length then
result := memcmp(lhs_pointer, rhs_pointer.ptr, lhs_length) = 0
else
result := false
end;
return result
end
end.
|