-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstd.goof
More file actions
144 lines (129 loc) · 2.88 KB
/
std.goof
File metadata and controls
144 lines (129 loc) · 2.88 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const stdin 0 end
const stdout 1 end
const stderr 2 end
const SYS_READ 0 end
const SYS_WRITE 1 end
const SYS_CLOSE 3 end
const SYS_FSTAT 5 end
const SYS_MMAP 9 end
const SYS_SLEEP 35 end
const SYS_FORK 57 end
const SYS_EXECV 59 end
const SYS_EXIT 60 end
const SYS_WAIT4 61 end
const SYS_FCHMOD 91 end
const SYS_OPENAT 257 end
const O_RDONLY 0 end
const O_WRONLY 1 end
const O_RDWR 2 end
const O_CREAT 64 end
const O_TRUNC 512 end
// printf("%d", (mode_t)0666);
const MODE0666 436 end
const AT_FDCWD -100 end
const MAP_PRIVATE 2 end
const PROT_READ 1 end
macro write SYS_WRITE syscall3 end
macro read SYS_READ syscall3 end
macro openat SYS_OPENAT syscall3 end
macro fchmod SYS_FCHMOD syscall2 end
macro mmap SYS_MMAP syscall6 end
macro fstat SYS_FSTAT syscall2 end
macro fork SYS_FORK syscall0 end
macro wait4 SYS_WAIT4 syscall4 end
macro execve SYS_EXECV syscall3 end
macro sleep SYS_SLEEP syscall2 end
macro close SYS_CLOSE syscall1 end
macro exit SYS_EXIT syscall1 drop end
macro / divmod drop end
macro % divmod swap drop end
const sizeof(stat) 144 end
macro stat.st_dev 0 + end
macro stat.st_ino 8 + end
macro stat.st_mode 24 + end
macro stat.st_nlink 16 + end
macro stat.st_uid 28 + end
macro stat.st_gid 32 + end
macro stat.st_rdev 40 + end
macro stat.st_size 48 + end
macro stat.st_blksize 56 + end
macro stat.st_blocks 64 + end
macro stat.st_atim 72 + end
macro stat.st_mtim 88 + end
macro stat.st_ctim 104 + end
const sizeof(stat.st_dev) 8 end
const sizeof(stat.st_ino) 8 end
const sizeof(stat.st_mode) 4 end
const sizeof(stat.st_nlink) 8 end
const sizeof(stat.st_uid) 4 end
const sizeof(stat.st_gid) 4 end
const sizeof(stat.st_rdev) 8 end
const sizeof(stat.st_size) 8 end
const sizeof(stat.st_blksize) 8 end
const sizeof(stat.st_blocks) 8 end
const sizeof(stat.st_atim) 16 end
const sizeof(stat.st_mtim) 16 end
const sizeof(stat.st_ctim) 16 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 (bool)
if over , 45 = do
drop
1 +
1 (bool)
end
swap
0
// flag ptr val
over ,
// flag ptr val *ptr
while dup 58 < over 47 > & 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]
over ,
end
drop swap
drop
// flag val
if over do
-1 *
end
swap drop
end
macro puts
stdout write drop
end
macro fputs
,64 write drop
end
macro eputs
stderr write drop
end
// ptr -> *ptr++
macro inc64 dup ,64 1 + .64 end
// ptr -> *ptr--
macro dec64 dup ,64 1 - .64 end
// n -> &argv[n]
macro nth_argv
8 * argv + ,64 (ptr)
end
// s1, s2 -> true / false
macro streq
end