forked from joelvaneenwyk/language84
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos.84
138 lines (116 loc) · 3.05 KB
/
os.84
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
{
: file_create
: file_open
: file_close
: file_read_all
: die
: argc
: argv
: O_RDONLY 0
: O_WRONLY 1
: O_RDWR 2
: O_CREAT 64
: O_TRUNC 512
: O_CLOEXEC [512 * 1024]
: PROT_READ 1
: PROT_WRITE 2
: PROT_EXEC 4
: MAP_SHARED 1
: MAP_PRIVATE 2
: EPOLL_CTL_ADD 1
: EPOLL_CTL_DEL 2
: EPOLL_CTL_MOD 3
: EPOLL_CLOEXEC [512 * 1024]
: EPOLLIN 1
: EPOLLOUT 4
: EPOLLERR 8
: EPOLLHUP 16
: exec
: exit
: getcwd
: open
: close
: read
: write
: mmap
: munmap
: epoll_create1
: epoll_wait
: epoll_ctl
}
Where
Define (file_create name)
(Prim file_create name)
Define (file_open name)
(Prim file_open name)
Define (file_close file)
(Prim file_close file)
Define (file_read_all file)
(Prim file_read_all file)
Define (die message)
(Prim die message)
Let argc (Prim command_argc)
Define (argv i)
(Prim command_argv i)
Define (exec path args vars)
Let path_offset 0
Let arg_offsets (CHUNK.new [4 * (LIST.length args)])
Let var_offsets (CHUNK.new [4 * (LIST.length vars)])
Let table
Let path_size [(STRING.length path) + 1]
Let args_size
(LIST.reduce args 0
Func {sum arg} [sum + (STRING.length arg) + 1])
Let vars_size
(LIST.reduce vars 0
Func {sum var} [sum + (STRING.length var) + 1])
In
(CHUNK.new [path_size + args_size + vars_size])
In
Define (store_strings strings offsets prefix_size)
Let {_ prefix_size}
(LIST.reduce strings {0 prefix_size}
Func {{i offset} s}
Begin {
(CHUNK.store_uint32 offsets [4 * i] offset)
(CHUNK.store_bytes table offset s 0 (STRING.length s))
(CHUNK.store_byte table [offset + (STRING.length s)] 0)
(Return [i + 1] [offset + (STRING.length s) + 1])
})
In
prefix_size
In
Begin {
(CHUNK.store_bytes table 0 path 0 (STRING.length path))
(CHUNK.store_byte table (STRING.length path) 0)
Let prefix_size [(STRING.length path) + 1]
Let prefix_size (store_strings args arg_offsets prefix_size)
Let prefix_size (store_strings vars var_offsets prefix_size)
(Return (Prim exec path_offset arg_offsets var_offsets table))
}
Define (exit status)
(Prim exit status)
Define (getcwd)
(Prim getcwd)
Define (open name flags mode)
(Prim open name flags mode)
Define (close fd)
(Prim close fd)
Define (read fd chunk start count)
(Prim read fd chunk start count)
Define (write fd chunk start count)
(Prim write fd chunk start count)
Define (mmap i size prot flags fd offset)
(Prim mmap i size prot flags fd offset)
Define (munmap i)
(Prim munmap i)
Define (epoll_create1 flags)
(Prim epoll_create1 flags)
Define (epoll_wait epoll_fd events max_events timeout)
(Prim epoll_wait epoll_fd events max_events timeout)
Define (epoll_ctl epoll_fd op fd event)
(Prim epoll_ctl epoll_fd op fd event)
Where
Let CHUNK Package "chunk"
Let LIST Package "list"
Let STRING Package "string"