std json parser
This commit is contained in:
@@ -52,7 +52,7 @@ func CHIP8.free[c: CHIP8] : void
|
||||
c->keyboard->free()
|
||||
c->display->free()
|
||||
c->keyboard_map->free()
|
||||
mem.free(c)
|
||||
(c as ptr)->free()
|
||||
|
||||
func CHIP8.disassemble[c: CHIP8, ins_count: i64] : void
|
||||
for i in 0..ins_count
|
||||
|
||||
@@ -12,7 +12,7 @@ func main[argc: i64, argv: ptr] : i64
|
||||
io.println("ERROR: invalid url (Did you forget \"http://\"?)")
|
||||
return 1
|
||||
|
||||
if !url->substr(0, 7)->equal("http://")
|
||||
if !url->substr_n(0, 7)->equal("http://")
|
||||
io.println("ERROR: only http scheme is supported")
|
||||
return 1
|
||||
|
||||
@@ -24,23 +24,19 @@ func main[argc: i64, argv: ptr] : i64
|
||||
break
|
||||
i += 1
|
||||
|
||||
host := url->substr(host_start, i - host_start)
|
||||
host := url->substr_n(host_start, i - host_start)
|
||||
path := "/"
|
||||
if i < url_len
|
||||
path = url->substr(i, url_len - i)
|
||||
path = url->substr_n(i, url_len - i)
|
||||
|
||||
s, ok := net.connect(host, 80)
|
||||
if !ok
|
||||
panic("failed to connect")
|
||||
|
||||
req := new str.Builder
|
||||
req->append("GET ")
|
||||
req->append(path)
|
||||
req->append(" HTTP/1.0\r\nHost: ")
|
||||
req->append(host)
|
||||
req->append("\r\nConnection: close\r\n\r\n")
|
||||
net.send(s, req->data, req->size)
|
||||
req->destroy()
|
||||
// seems reasonable
|
||||
req := _stackalloc(4096)
|
||||
req_size := str.format_into(req as str, 4096, "GET %s HTTP/1.0\r\nHost: %s\r\nConnection: close\r\n\r\n", path, host)
|
||||
net.send(s, req, req_size)
|
||||
|
||||
header_buf := mem.alloc(8192) as str
|
||||
header_size := 0
|
||||
|
||||
@@ -2,4 +2,4 @@ include "std/io.zr"
|
||||
|
||||
func main[] : i64
|
||||
n := 37107287533 + 46376937677 + 74324986199 + 91942213363 + 23067588207 + 89261670696 + 28112879812 + 44274228917 + 47451445736 + 70386486105 + 62176457141 + 64906352462 + 92575867718 + 58203565325 + 80181199384 + 35398664372 + 86515506006 + 71693888707 + 54370070576 + 53282654108 + 36123272525 + 45876576172 + 17423706905 + 81142660418 + 51934325451 + 62467221648 + 15732444386 + 55037687525 + 18336384825 + 80386287592 + 78182833757 + 16726320100 + 48403098129 + 87086987551 + 59959406895 + 69793950679 + 41052684708 + 65378607361 + 35829035317 + 94953759765 + 88902802571 + 25267680276 + 36270218540 + 24074486908 + 91430288197 + 34413065578 + 23053081172 + 11487696932 + 63783299490 + 67720186971 + 95548255300 + 76085327132 + 37774242535 + 23701913275 + 29798860272 + 18495701454 + 38298203783 + 34829543829 + 40957953066 + 29746152185 + 41698116222 + 62467957194 + 23189706772 + 86188088225 + 11306739708 + 82959174767 + 97623331044 + 42846280183 + 55121603546 + 32238195734 + 75506164965 + 62177842752 + 32924185707 + 99518671430 + 73267460800 + 76841822524 + 97142617910 + 87783646182 + 10848802521 + 71329612474 + 62184073572 + 66627891981 + 60661826293 + 85786944089 + 66024396409 + 64913982680 + 16730939319 + 94809377245 + 78639167021 + 15368713711 + 40789923115 + 44889911501 + 41503128880 + 81234880673 + 82616570773 + 22918802058 + 77158542502 + 72107838435 + 20849603980 + 53503534226
|
||||
io.println(n->to_str()->substr(0, 10))
|
||||
io.println(n->to_str()->substr_n(0, 10))
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
include "std/io.zr"
|
||||
|
||||
func main[] : i64
|
||||
io.println("Hello, World!")
|
||||
@@ -1,18 +0,0 @@
|
||||
include "std/io.zr"
|
||||
include "std/os.zr"
|
||||
|
||||
func main[] : i64
|
||||
arr := []
|
||||
for i in 0..10
|
||||
arr->push(os.urandom_i64()->abs() % 1000)
|
||||
|
||||
for i in 0..arr->size
|
||||
io.println_i64(arr->nth(i))
|
||||
io.println("------------")
|
||||
|
||||
arr->quicksort()
|
||||
|
||||
for i in 0..arr->size
|
||||
io.println_i64(arr->nth(i))
|
||||
|
||||
arr->free()
|
||||
Reference in New Issue
Block a user