typecheck return types
This commit is contained in:
@@ -10,7 +10,7 @@ func err.code[] : i64
|
||||
return mem.read64(_builtin_err_code())
|
||||
|
||||
func err.msg[] : str
|
||||
return mem.read64(_builtin_err_msg())
|
||||
return mem.read64(_builtin_err_msg()) as str
|
||||
|
||||
func err.check[] : bool
|
||||
return err.code() != 0
|
||||
@@ -73,7 +73,7 @@ func mem._request_space?[size: i64] : mem.Block
|
||||
let blk_ptr: ptr = _builtin_syscall(SYS_mmap, 0, alloc_size, 3, 34, -1, 0) as ptr
|
||||
if blk_ptr == -1
|
||||
err.set(ERR_ALLOC_FAILED, "mem._request_space: mmap failed")
|
||||
return 0
|
||||
return 0 as mem.Block
|
||||
|
||||
let blk: mem.Block = blk_ptr as mem.Block
|
||||
|
||||
@@ -173,11 +173,11 @@ func mem.realloc?[x: ptr, new_size: i64] : ptr
|
||||
|
||||
if new_size < 0
|
||||
err.set(ERR_ALLOC_FAILED, "mem.realloc? called with negative size")
|
||||
return 0
|
||||
return 0 as ptr
|
||||
|
||||
if new_size == 0
|
||||
mem.free(x)
|
||||
return 0
|
||||
return 0 as ptr
|
||||
|
||||
new_size = mem._align(new_size)
|
||||
|
||||
@@ -204,7 +204,7 @@ func mem.realloc?[x: ptr, new_size: i64] : ptr
|
||||
|
||||
let new_ptr: ptr = mem.alloc?(new_size)
|
||||
if err.check()
|
||||
return 0
|
||||
return 0 as ptr
|
||||
|
||||
mem.copy(x, new_ptr, math.min(blk->size, new_size))
|
||||
mem.free(x)
|
||||
@@ -232,16 +232,16 @@ func mem.read8[x: ptr] : u8
|
||||
return x[0]
|
||||
|
||||
func mem.read16[x: ptr] : i64
|
||||
return x[0] | (x[1] << 8)
|
||||
return x[0] as i64 | (x[1] << 8)
|
||||
|
||||
func mem.read16be[x: ptr] : i64
|
||||
return (x[0] << 8) | x[1]
|
||||
return (x[0] << 8) as i64 | x[1]
|
||||
|
||||
func mem.read32[x: ptr] : i64
|
||||
return x[0] | (x[1] << 8) | (x[2] << 16) | (x[3] << 24)
|
||||
return x[0] as i64 | (x[1] << 8) | (x[2] << 16) | (x[3] << 24)
|
||||
|
||||
func mem.read32be[x: ptr] : i64
|
||||
return (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3]
|
||||
return (x[0] as i64 << 24) | (x[1] << 16) | (x[2] << 8) | x[3]
|
||||
|
||||
func mem.read64[x: ptr] : i64
|
||||
return _builtin_read64(x)
|
||||
@@ -349,7 +349,7 @@ func io.Buffer.alloc?[size: i64] : io.Buffer
|
||||
buffer->data = mem.alloc?(size)
|
||||
if err.check()
|
||||
mem.free(buffer)
|
||||
return 0
|
||||
return 0 as io.Buffer
|
||||
return buffer
|
||||
|
||||
func io.Buffer.free[buf: io.Buffer] : void
|
||||
@@ -364,7 +364,7 @@ func io.read_text_file?[path: str] : str
|
||||
let fd: i64 = _builtin_syscall(SYS_openat, -100, path, 0, 0)
|
||||
if fd < 0
|
||||
err.set(ERR_OPEN_FAILED, "io.read_text_file?: failed to open file")
|
||||
return 0
|
||||
return 0 as str
|
||||
|
||||
let size: i64 = _builtin_syscall(SYS_lseek, fd, 0, 2)
|
||||
_builtin_syscall(SYS_lseek, fd, 0, 0)
|
||||
@@ -372,7 +372,7 @@ func io.read_text_file?[path: str] : str
|
||||
let buffer: str = mem.alloc?(size + 1) as str
|
||||
if err.check()
|
||||
_builtin_syscall(SYS_close, fd)
|
||||
return 0
|
||||
return 0 as str
|
||||
|
||||
let n: i64 = _builtin_syscall(SYS_read, fd, buffer, size)
|
||||
_builtin_syscall(SYS_close, fd)
|
||||
@@ -380,7 +380,7 @@ func io.read_text_file?[path: str] : str
|
||||
if n != size
|
||||
mem.free(buffer)
|
||||
err.set(ERR_READ_FAILED, "io.read_text_file?: failed to read file")
|
||||
return 0
|
||||
return 0 as str
|
||||
|
||||
buffer[n] = 0
|
||||
return buffer
|
||||
@@ -390,7 +390,7 @@ func io.read_binary_file?[path: str] : io.Buffer
|
||||
let fd: i64 = _builtin_syscall(SYS_openat, -100, path, 0, 0)
|
||||
if fd < 0
|
||||
err.set(ERR_OPEN_FAILED, "io.read_binary_file?: failed to open file")
|
||||
return 0
|
||||
return 0 as io.Buffer
|
||||
|
||||
let buf: io.Buffer = new io.Buffer
|
||||
buf->size = _builtin_syscall(SYS_lseek, fd, 0, 2)
|
||||
@@ -400,7 +400,7 @@ func io.read_binary_file?[path: str] : io.Buffer
|
||||
if err.check()
|
||||
io.Buffer.free(buf)
|
||||
_builtin_syscall(SYS_close, fd)
|
||||
return 0
|
||||
return 0 as io.Buffer
|
||||
|
||||
let n: i64 = _builtin_syscall(SYS_read, fd, buf->data, buf->size)
|
||||
_builtin_syscall(SYS_close, fd)
|
||||
@@ -408,7 +408,7 @@ func io.read_binary_file?[path: str] : io.Buffer
|
||||
if n != buf->size
|
||||
io.Buffer.free(buf)
|
||||
err.set(ERR_READ_FAILED, "io.read_binary_file?: failed to read file")
|
||||
return 0
|
||||
return 0 as io.Buffer
|
||||
|
||||
return buf
|
||||
|
||||
@@ -664,7 +664,7 @@ func str.hex_encode[s: str, s_len: i64] : str
|
||||
out[j] = 0
|
||||
return out
|
||||
|
||||
func str._hex_digit_to_int[d: u8] : i64
|
||||
func str._hex_digit_to_int[d: u8] : u8
|
||||
if d >= 'a' && d <= 'f'
|
||||
return d - 'a' + 10
|
||||
if d >= 'A' && d <= 'F'
|
||||
@@ -902,13 +902,13 @@ func os.urandom?[n: i64]: ptr
|
||||
err.clear()
|
||||
let buffer: ptr = mem.alloc(n)
|
||||
if err.check()
|
||||
return 0
|
||||
return 0 as ptr
|
||||
|
||||
let fd: i64 = _builtin_syscall(SYS_openat, -100, "/dev/urandom", 0, 0)
|
||||
if fd < 0
|
||||
mem.free(buffer)
|
||||
err.set(ERR_READ_FAILED, "os.urandom?: failed to open /dev/urandom")
|
||||
return 0
|
||||
return 0 as ptr
|
||||
|
||||
let bytes_read: i64 = _builtin_syscall(SYS_read, fd, buffer, n)
|
||||
_builtin_syscall(SYS_close, fd)
|
||||
@@ -916,7 +916,7 @@ func os.urandom?[n: i64]: ptr
|
||||
if n != bytes_read
|
||||
mem.free(buffer)
|
||||
err.set(ERR_READ_FAILED, "os.urandom?: failed to read /dev/urandom")
|
||||
return 0
|
||||
return 0 as ptr
|
||||
|
||||
return buffer
|
||||
|
||||
@@ -968,7 +968,7 @@ func os.list_directory?[path: str] : Array
|
||||
let fd: i64 = _builtin_syscall(SYS_openat, -100, path, 0, 0)
|
||||
if fd < 0
|
||||
err.set(ERR_OPEN_FAILED, "os.list_directory?: failed to open dir")
|
||||
return 0
|
||||
return 0 as Array
|
||||
|
||||
let files: Array = []
|
||||
let buf: ptr = mem.alloc(1024)
|
||||
@@ -983,7 +983,7 @@ func os.list_directory?[path: str] : Array
|
||||
|
||||
_builtin_syscall(SYS_close, fd)
|
||||
err.set(ERR_SYSCALL_FAILED, "os.list_directory?: getdents64() failed")
|
||||
return 0
|
||||
return 0 as Array
|
||||
else if n == 0
|
||||
break
|
||||
|
||||
|
||||
Reference in New Issue
Block a user