1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

wasm: remove dependency on thirdparty/binaryen, webassembly backend rewrite (#18120)

This commit is contained in:
l-m
2023-07-12 12:24:38 +00:00
committed by GitHub
parent 1c7df29bed
commit c422919481
40 changed files with 2895 additions and 6166 deletions

View File

@@ -6,6 +6,20 @@ fn __memory_grow(size usize) usize
fn __memory_fill(dest &u8, value isize, size isize)
fn __memory_copy(dest &u8, src &u8, size isize)
// add doc comments for the below functions
// __reinterpret_f32_u32 converts a `u32` to a `f32` without changing the bit pattern.
pub fn __reinterpret_f32_u32(v f32) u32
// __reinterpret_u32_f32 converts a `f32` to a `u32` without changing the bit pattern.
pub fn __reinterpret_u32_f32(v u32) f32
// __reinterpret_f64_u64 converts a `u64` to a `f64` without changing the bit pattern.
pub fn __reinterpret_f64_u64(v f64) u64
// __reinterpret_u64_f64 converts a `f64` to a `u64` without changing the bit pattern.
pub fn __reinterpret_u64_f64(v u64) f64
// vcalloc dynamically allocates a zeroed `n` bytes block of memory on the heap.
// vcalloc returns a `byteptr` pointing to the memory address of the allocated space.
// Unlike `v_calloc` vcalloc checks for negative values given in `n`.

View File

@@ -7,7 +7,7 @@ pub fn print(s string) {
len: usize(s.len)
}
WASM.fd_write(1, &elm, 1, -1)
WASM.fd_write(1, &elm, 1, 0)
}
// println prints a message with a line end, to stdout.
@@ -20,7 +20,7 @@ pub fn println(s string) {
len: 1
}]!
WASM.fd_write(1, &elm[0], 2, -1)
WASM.fd_write(1, &elm[0], 2, 0)
}
// eprint prints a message to stderr.
@@ -30,7 +30,7 @@ pub fn eprint(s string) {
len: usize(s.len)
}
WASM.fd_write(2, &elm, 1, -1)
WASM.fd_write(2, &elm, 1, 0)
}
// eprintln prints a message with a line end, to stderr.
@@ -43,7 +43,7 @@ pub fn eprintln(s string) {
len: 1
}]!
WASM.fd_write(2, &elm[0], 2, -1)
WASM.fd_write(2, &elm[0], 2, 0)
}
// exit terminates execution immediately and returns exit `code` to the shell.
@@ -57,6 +57,5 @@ pub fn exit(code int) {
pub fn panic(s string) {
eprint('V panic: ')
eprintln(s)
_ := *&u8(-1)
exit(1)
}

View File

@@ -52,21 +52,18 @@ fn (nn int) str_l(max int) string {
}
diff := max - index
vmemmove(buf, voidptr(buf + index), diff + 1)
/*
// === manual memory move for bare metal ===
mut c:= 0
for c < diff {
buf[c] = buf[c+index]
c++
}
buf[c] = 0
*/
return tos(buf, diff)
// return tos(memdup(&buf[0] + index, (max - index)), (max - index))
}
}
// str returns the value of the `u8` as a `string`.
// Example: assert u8(2).str() == '2'
pub fn (n u8) str() string {
return int(n).str_l(5)
}
// str returns the value of the `i8` as a `string`.
// Example: assert i8(-2).str() == '-2'
pub fn (n i8) str() string {

View File

@@ -1,4 +1,3 @@
[wasm_import_namespace: 'wasi_snapshot_preview1']
module builtin
struct CIOVec {
@@ -9,6 +8,9 @@ struct CIOVec {
type Errno = u16
type FileDesc = int
[wasm_import_namespace: 'wasi_snapshot_preview1']
fn WASM.fd_write(fd FileDesc, iovs &CIOVec, iovs_len usize, retptr &usize) Errno
[wasm_import_namespace: 'wasi_snapshot_preview1']
[noreturn]
fn WASM.proc_exit(rval int)