-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
82 lines (77 loc) · 1.25 KB
/
main.go
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
//go:build !small
package main
import (
. "github.com/ktye/wg/module"
)
func main() { // _start
kinit()
doargs()
write(Ku(2932601077199979)) // "ktye/k\n"
store()
for {
write(Ku(32))
x := readfile(mk(Ct, 0))
try(x)
}
}
func store() {
g := (1 << (I32(128) - 16)) - Memorysize2()
if g > 0 {
Memorygrow2(g)
}
Memorycopy2(0, 0, int32(1)<<I32(128))
}
func catch() {
Memorycopy3(0, 0, int32(65536)*Memorysize2())
}
func try(x K) {
defer Catch(catch)
repl(x)
store()
}
func doargs() {
a := ndrop(1, getargv())
an := nn(a)
ee := Ku(25901) // -e
for i := int32(0); i < an; i++ {
x := x0(a)
if match(x, ee) != 0 { // -e (exit)
if i < an-1 {
dx(x)
x = x1(a)
dx(ee)
repl(x)
}
Exit(0)
}
dofile(x, readfile(rx(x)))
a += 8
}
dx(ee)
}
func dofile(x K, c K) {
kk := Ku(27438) // .k
tt := Ku(29742) // .t
xe := ntake(-2, rx(x))
if match(xe, kk) != 0 { // file.k (execute)
dx(val(c))
} else if match(xe, tt) != 0 { // file.t (test)
test(c)
} else { // file (assign file:bytes..)
dx(Asn(sc(rx(x)), c))
}
dxy(xe, x)
dxy(tt, kk)
}
func getargv() K {
n := Args()
r := mk(Lt, n)
rp := int32(r)
for i := int32(0); i < n; i++ {
s := mk(Ct, Arg(i, 0))
Arg(i, int32(s))
SetI64(rp, int64(s))
rp += 8
}
return r
}