mirror of
https://github.com/vlang/v.git
synced 2025-08-04 02:07:28 -04:00
builtin,v.gen.wasm: support -b wasm -d no_imports
(#24188)
This commit is contained in:
parent
36ec2355b2
commit
d559a62cfe
@ -12,8 +12,12 @@ __global g_heap_base = usize(vwasm_heap_base())
|
|||||||
@[unsafe]
|
@[unsafe]
|
||||||
pub fn malloc(n isize) &u8 {
|
pub fn malloc(n isize) &u8 {
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
|
$if no_imports ? {
|
||||||
|
return unsafe { nil }
|
||||||
|
} $else {
|
||||||
panic('malloc(n <= 0)')
|
panic('malloc(n <= 0)')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res := g_heap_base
|
res := g_heap_base
|
||||||
g_heap_base += usize(n)
|
g_heap_base += usize(n)
|
||||||
|
@ -43,9 +43,11 @@ pub fn vwasm_memory_grow(size int) int {
|
|||||||
@[unsafe]
|
@[unsafe]
|
||||||
pub fn vcalloc(n isize) &u8 {
|
pub fn vcalloc(n isize) &u8 {
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
panic('vcalloc(n <= 0)')
|
$if no_imports ? {
|
||||||
} else if n == 0 {
|
return unsafe { nil }
|
||||||
return &u8(0)
|
} $else {
|
||||||
|
panic('valloc(n <= 0)')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res := unsafe { malloc(n) }
|
res := unsafe { malloc(n) }
|
||||||
|
@ -47,6 +47,9 @@ pub fn (mut g Gen) comptime_cond(cond ast.Expr, pkg_exists bool) bool {
|
|||||||
ast.ComptimeCall {
|
ast.ComptimeCall {
|
||||||
return pkg_exists // more documentation needed here...
|
return pkg_exists // more documentation needed here...
|
||||||
}
|
}
|
||||||
|
ast.PostfixExpr {
|
||||||
|
return g.comptime_if_to_ifdef((cond.expr as ast.Ident).name, true)
|
||||||
|
}
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
g.w_error('wasm.comptime_cond(): unhandled node: ' + cond.type_name())
|
g.w_error('wasm.comptime_cond(): unhandled node: ' + cond.type_name())
|
||||||
@ -118,6 +121,14 @@ pub fn (mut g Gen) comptime_if_to_ifdef(name string, is_comptime_option bool) bo
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// note: this works but there might be some things missing from what I saw in the other platforms
|
||||||
|
// but it is better than nothing
|
||||||
|
if name in g.pref.compile_defines {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// taken from JS: what does it do??
|
// taken from JS: what does it do??
|
||||||
/*
|
/*
|
||||||
if is_comptime_option
|
if is_comptime_option
|
||||||
|
@ -16,6 +16,10 @@ For more general build help, see also `v help build`.
|
|||||||
Overrides the default stack_top value used by the WebAssembly compiler.
|
Overrides the default stack_top value used by the WebAssembly compiler.
|
||||||
Useful for some platforms with unusual memory requirements.
|
Useful for some platforms with unusual memory requirements.
|
||||||
|
|
||||||
|
-d no_imports
|
||||||
|
Removes the default imports from the builtins. Useful for embedded targets where
|
||||||
|
you can't control the imports.
|
||||||
|
|
||||||
-os <browser|wasi>, -target-os <browser|wasi>
|
-os <browser|wasi>, -target-os <browser|wasi>
|
||||||
Change the target WebAssembly execution environment that V compiles for.
|
Change the target WebAssembly execution environment that V compiles for.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user