_builtin prefix
This commit is contained in:
@@ -125,37 +125,37 @@ extern closedir
|
|||||||
extern exit
|
extern exit
|
||||||
extern gettimeofday
|
extern gettimeofday
|
||||||
|
|
||||||
section .text.deref
|
section .text._builtin_deref
|
||||||
deref:
|
_builtin_deref:
|
||||||
mov rax, qword [rdi]
|
mov rax, qword [rdi]
|
||||||
ret
|
ret
|
||||||
|
|
||||||
section .text.IO.stdin
|
section .text._builtin_stdin
|
||||||
IO.stdin:
|
_builtin_stdin:
|
||||||
mov rax, [rel stdin]
|
mov rax, [rel stdin]
|
||||||
ret
|
ret
|
||||||
|
|
||||||
section .text.Bit.lshift
|
section .text._builtin_lshift
|
||||||
Bit.lshift:
|
_builtin_lshift:
|
||||||
mov rcx, rsi
|
mov rcx, rsi
|
||||||
mov rax, rdi
|
mov rax, rdi
|
||||||
shl rax, cl
|
shl rax, cl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
section .text.Bit.rshift
|
section .text._builtin_rshift
|
||||||
Bit.rshift:
|
_builtin_rshift:
|
||||||
mov rcx, rsi
|
mov rcx, rsi
|
||||||
mov rax, rdi
|
mov rax, rdi
|
||||||
sar rax, cl
|
sar rax, cl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
section .text.String.set
|
section .text._builtin_string_set
|
||||||
String.set:
|
_builtin_string_set:
|
||||||
mov [rdi + rsi], dl
|
mov [rdi + rsi], dl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
section .text.OS.listdir
|
section .text._builtin_listdir
|
||||||
OS.listdir:
|
_builtin_listdir:
|
||||||
push r14
|
push r14
|
||||||
push rbx
|
push rbx
|
||||||
push rax
|
push rax
|
||||||
@@ -165,29 +165,29 @@ OS.listdir:
|
|||||||
mov rdi, r14
|
mov rdi, r14
|
||||||
call opendir
|
call opendir
|
||||||
mov r14, rax
|
mov r14, rax
|
||||||
.OS.listdir.1:
|
._builtin_listdir.1:
|
||||||
mov rdi, r14
|
mov rdi, r14
|
||||||
call readdir
|
call readdir
|
||||||
test rax, rax
|
test rax, rax
|
||||||
je .OS.listdir.3
|
je ._builtin_listdir.3
|
||||||
cmp byte [rax+19], 46
|
cmp byte [rax+19], 46
|
||||||
jne .OS.listdir.2
|
jne ._builtin_listdir.2
|
||||||
movzx ecx, byte [rax+20]
|
movzx ecx, byte [rax+20]
|
||||||
test ecx, ecx
|
test ecx, ecx
|
||||||
je .OS.listdir.1
|
je ._builtin_listdir.1
|
||||||
cmp ecx, 46
|
cmp ecx, 46
|
||||||
jne .OS.listdir.2
|
jne ._builtin_listdir.2
|
||||||
cmp byte [rax+21], 0
|
cmp byte [rax+21], 0
|
||||||
je .OS.listdir.1
|
je ._builtin_listdir.1
|
||||||
.OS.listdir.2:
|
._builtin_listdir.2:
|
||||||
add rax, 19
|
add rax, 19
|
||||||
mov rdi, rax
|
mov rdi, rax
|
||||||
call strdup
|
call strdup
|
||||||
mov rsi, rax
|
mov rsi, rax
|
||||||
mov rdi, rbx
|
mov rdi, rbx
|
||||||
call Array.push
|
call Array.push
|
||||||
jmp .OS.listdir.1
|
jmp ._builtin_listdir.1
|
||||||
.OS.listdir.3:
|
._builtin_listdir.3:
|
||||||
mov rdi, r14
|
mov rdi, r14
|
||||||
call closedir
|
call closedir
|
||||||
mov rax, rbx
|
mov rax, rbx
|
||||||
@@ -196,14 +196,14 @@ OS.listdir:
|
|||||||
pop r14
|
pop r14
|
||||||
ret
|
ret
|
||||||
|
|
||||||
section .text.Array.set
|
section .text._builtin_array_set
|
||||||
Array.set:
|
_builtin_array_set:
|
||||||
mov rax, [rdi]
|
mov rax, [rdi]
|
||||||
mov [rax + rsi*8], rdx
|
mov [rax + rsi*8], rdx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
section .text.Array.push
|
section .text._builtin_array_push
|
||||||
Array.push:
|
_builtin_array_push:
|
||||||
push r14
|
push r14
|
||||||
push rbx
|
push rbx
|
||||||
push rax
|
push rax
|
||||||
@@ -212,7 +212,7 @@ Array.push:
|
|||||||
mov rax, [rdi]
|
mov rax, [rdi]
|
||||||
mov rcx, [rdi + 16]
|
mov rcx, [rdi + 16]
|
||||||
cmp rcx, [rdi + 8]
|
cmp rcx, [rdi + 8]
|
||||||
jne .Array.push.1
|
jne ._builtin_array_push.1
|
||||||
lea rdx, [rcx + rcx]
|
lea rdx, [rcx + rcx]
|
||||||
mov rsi, 4
|
mov rsi, 4
|
||||||
test rcx, rcx
|
test rcx, rcx
|
||||||
@@ -223,7 +223,7 @@ Array.push:
|
|||||||
call realloc
|
call realloc
|
||||||
mov [rbx], rax
|
mov [rbx], rax
|
||||||
mov rcx, [rbx + 16]
|
mov rcx, [rbx + 16]
|
||||||
.Array.push.1:
|
._builtin_array_push.1:
|
||||||
mov [rax + rcx*8], r14
|
mov [rax + rcx*8], r14
|
||||||
inc qword [rbx + 16]
|
inc qword [rbx + 16]
|
||||||
add rsp, 8
|
add rsp, 8
|
||||||
@@ -231,13 +231,13 @@ Array.push:
|
|||||||
pop r14
|
pop r14
|
||||||
ret
|
ret
|
||||||
|
|
||||||
section .text.Array.size
|
section .text._builtin_array_size
|
||||||
Array.size:
|
_builtin_array_size:
|
||||||
mov rax, [rdi + 16]
|
mov rax, [rdi + 16]
|
||||||
ret
|
ret
|
||||||
|
|
||||||
section .text.Array.free
|
section .text._builtin_array_free
|
||||||
Array.free:
|
_builtin_array_free:
|
||||||
push rbx
|
push rbx
|
||||||
mov rbx, rdi
|
mov rbx, rdi
|
||||||
mov rdi, [rdi]
|
mov rdi, [rdi]
|
||||||
|
|||||||
36
src/std.zr
36
src/std.zr
@@ -9,7 +9,10 @@ func print_i64[x: I64] : I64
|
|||||||
printf("%ld\n", x)
|
printf("%ld\n", x)
|
||||||
|
|
||||||
func String.nth[s: String, n: I64] : U8
|
func String.nth[s: String, n: I64] : U8
|
||||||
return deref(s + n)
|
return _builtin_deref(s + n)
|
||||||
|
|
||||||
|
func String.set[s: String, n: I64] : I64
|
||||||
|
_builtin_string_set(s, n)
|
||||||
|
|
||||||
func String.is_whitespace[c: U8] : Bool
|
func String.is_whitespace[c: U8] : Bool
|
||||||
return c == ' ' || c == 10 || c == 13 || c == 9
|
return c == ' ' || c == 10 || c == 13 || c == 9
|
||||||
@@ -20,10 +23,10 @@ func String.concat[a: String, b: String] : String
|
|||||||
strcat(c, b)
|
strcat(c, b)
|
||||||
return c
|
return c
|
||||||
|
|
||||||
func String.find[s: String, needle: U8] : I64
|
func String.find[s: String, c: U8] : I64
|
||||||
let s_len: I64 = strlen(s)
|
let s_len: I64 = strlen(s)
|
||||||
for i in 0..s_len
|
for i in 0..s_len
|
||||||
if String.nth(s, i) == needle
|
if String.nth(s, i) == c
|
||||||
return i
|
return i
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
@@ -57,6 +60,9 @@ func String.rev[s: String] : String
|
|||||||
String.set(out, len, 0)
|
String.set(out, len, 0)
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
func IO.stdin[]: Ptr
|
||||||
|
return _builtin_stdin()
|
||||||
|
|
||||||
func IO.read_line[]: String
|
func IO.read_line[]: String
|
||||||
let buffer: String = malloc(1024)
|
let buffer: String = malloc(1024)
|
||||||
fgets(buffer, 1024, IO.stdin())
|
fgets(buffer, 1024, IO.stdin())
|
||||||
@@ -163,21 +169,39 @@ func Math.urandom[]: I64
|
|||||||
let file: Ptr = fopen("/dev/urandom", "rb")
|
let file: Ptr = fopen("/dev/urandom", "rb")
|
||||||
fread(buffer, 8, 1, file)
|
fread(buffer, 8, 1, file)
|
||||||
fclose(file)
|
fclose(file)
|
||||||
let n: I64 = deref(buffer)
|
let n: I64 = _builtin_deref(buffer)
|
||||||
free(buffer)
|
free(buffer)
|
||||||
return n
|
return n
|
||||||
|
|
||||||
func Array.new[] : Array
|
func Array.new[] : Array
|
||||||
return calloc(1, 24)
|
return calloc(1, 24)
|
||||||
|
|
||||||
|
func Array.set[xs: Array, n: I64, x: I64] : I64
|
||||||
|
_builtin_array_set(xs, n, x)
|
||||||
|
|
||||||
|
func Array.push[xs: Array, x: I64] : I64
|
||||||
|
return _builtin_array_push(xs, x)
|
||||||
|
|
||||||
|
func Array.size[xs: Array] : I64
|
||||||
|
return _builtin_array_size(xs)
|
||||||
|
|
||||||
func OS.time[] : I64
|
func OS.time[] : I64
|
||||||
let tv: Ptr = malloc(16)
|
let tv: Ptr = malloc(16)
|
||||||
gettimeofday(tv, 0)
|
gettimeofday(tv, 0)
|
||||||
let seconds: I64 = deref(tv)
|
let seconds: I64 = _builtin_deref(tv)
|
||||||
let microseconds: I64 = deref(tv+8)
|
let microseconds: I64 = _builtin_deref(tv+8)
|
||||||
free(tv)
|
free(tv)
|
||||||
return seconds * 1000 + microseconds / 1000
|
return seconds * 1000 + microseconds / 1000
|
||||||
|
|
||||||
|
func OS.listdir[path: String] : Array
|
||||||
|
return _builtin_listdir(path)
|
||||||
|
|
||||||
|
func Bit.lshift[a: I64, b: I64] : I64
|
||||||
|
return _builtin_lshift(a, b)
|
||||||
|
|
||||||
|
func Bit.rshift[a: I64, b: I64] : I64
|
||||||
|
return _builtin_rshift(a, b)
|
||||||
|
|
||||||
func Crypto.hex_encode[s: String] : String
|
func Crypto.hex_encode[s: String] : String
|
||||||
let hex_chars: String = "0123456789abcdef"
|
let hex_chars: String = "0123456789abcdef"
|
||||||
let s_len: I64 = strlen(s)
|
let s_len: I64 = strlen(s)
|
||||||
|
|||||||
Reference in New Issue
Block a user