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

wasm: add support for [export]ed functions (#18055)

This commit is contained in:
squidink7 2023-04-27 03:09:58 +09:30 committed by GitHub
parent c4b34c9482
commit 4bfe270c41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -309,11 +309,17 @@ fn (mut g Gen) fn_decl(node ast.FnDecl) {
for idx := paraml.len; idx < g.local_temporaries.len; idx++ { for idx := paraml.len; idx < g.local_temporaries.len; idx++ {
temporaries << g.local_temporaries[idx].typ temporaries << g.local_temporaries[idx].typ
} }
function := binaryen.addfunction(g.mod, name.str, params_type, return_type, temporaries.data, function := binaryen.addfunction(g.mod, name.str, params_type, return_type, temporaries.data,
temporaries.len, wasm_expr) temporaries.len, wasm_expr)
mut export_name := name.str
if cattr := node.attrs.find_first('export') {
export_name = cattr.arg.str
}
//&& g.pref.os == .browser //&& g.pref.os == .browser
if node.is_pub && node.mod == 'main' { if node.is_pub && node.mod == 'main' {
binaryen.addfunctionexport(g.mod, name.str, name.str) binaryen.addfunctionexport(g.mod, name.str, export_name)
} }
if g.pref.is_debug { if g.pref.is_debug {
binaryen.functionsetdebuglocation(function, wasm_expr, g.file_path_idx, node.pos.line_nr, binaryen.functionsetdebuglocation(function, wasm_expr, g.file_path_idx, node.pos.line_nr,