-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstd.g4th
68 lines (61 loc) · 1.4 KB
/
std.g4th
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
macro stdin 0 end
macro stdout 1 end
macro stderr 2 end
macro SYS_READ 0 end
macro SYS_WRITE 1 end
macro write SYS_WRITE syscall3 end
macro read SYS_READ syscall3 end
macro / divmod drop end
macro % divmod swap drop end
macro mod % end
macro div / end
macro load64
7 + 0
8 shl over , + swap 1 - swap
8 shl over , + swap 1 - swap
8 shl over , + swap 1 - swap
8 shl over , + swap 1 - swap
8 shl over , + swap 1 - swap
8 shl over , + swap 1 - swap
8 shl over , + swap 1 - swap
8 shl over , + swap drop
end
macro store64
2dup 255 and . 8 shr swap 1 + swap
2dup 255 and . 8 shr swap 1 + swap
2dup 255 and . 8 shr swap 1 + swap
2dup 255 and . 8 shr swap 1 + swap
2dup 255 and . 8 shr swap 1 + swap
2dup 255 and . 8 shr swap 1 + swap
2dup 255 and . 8 shr swap 1 + swap
2dup 255 and . 8 shr swap drop drop
end
// ptr -> strlen(ptr)
// string pointed to by ptr must be null terminated
macro strlen
dup
while dup , 0 != do
1 +
end
swap -
end
// ptr -> int(ptr)
// string pointed to by ptr must be null terminated
macro stoi
0
// ptr val
while over , dup 10 != do
// ptr val *ptr
48 -
// ptr val *ptr-'0'
swap
10 * +
// ptr [*ptr-'0' + val*10]
swap
// [*ptr-'0' + val*10] ptr
1 +
swap
// ptr+1 [*ptr-'0' + val*10]
end
drop swap drop
end