mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-31 01:11:06 +00:00
Remove GLOBAL_ARGUMENT_CNT JS binding
This is easier to manage statically so no need to track it dynamically
This commit is contained in:
parent
a805e04a81
commit
f1e8e2bee0
@ -545,7 +545,6 @@ impl<'a> Context<'a> {
|
|||||||
self.required_internal_exports.insert("__wbindgen_malloc");
|
self.required_internal_exports.insert("__wbindgen_malloc");
|
||||||
self.expose_text_encoder();
|
self.expose_text_encoder();
|
||||||
self.expose_uint8_memory();
|
self.expose_uint8_memory();
|
||||||
self.expose_push_global_argument();
|
|
||||||
self.globals.push_str(&format!("
|
self.globals.push_str(&format!("
|
||||||
function passStringToWasm(arg) {{
|
function passStringToWasm(arg) {{
|
||||||
if (typeof(arg) !== 'string')
|
if (typeof(arg) !== 'string')
|
||||||
@ -1036,17 +1035,16 @@ impl<'a> Context<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expose_push_global_argument(&mut self) {
|
fn expose_set_global_argument(&mut self) {
|
||||||
if !self.exposed_globals.insert("push_global_argument") {
|
if !self.exposed_globals.insert("set_global_argument") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.expose_uint32_memory();
|
self.expose_uint32_memory();
|
||||||
self.expose_global_argument_ptr();
|
self.expose_global_argument_ptr();
|
||||||
self.globals.push_str("
|
self.globals.push_str("
|
||||||
function pushGlobalArgument(arg) {
|
function setGlobalArgument(arg, i) {
|
||||||
const idx = globalArgumentPtr() / 4 + GLOBAL_ARGUMENT_CNT;
|
const idx = globalArgumentPtr() / 4 + i;
|
||||||
getUint32Memory()[idx] = arg;
|
getUint32Memory()[idx] = arg;
|
||||||
GLOBAL_ARGUMENT_CNT += 1;
|
|
||||||
}
|
}
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
@ -1072,7 +1070,6 @@ impl<'a> Context<'a> {
|
|||||||
self.required_internal_exports.insert("__wbindgen_global_argument_ptr");
|
self.required_internal_exports.insert("__wbindgen_global_argument_ptr");
|
||||||
self.globals.push_str("
|
self.globals.push_str("
|
||||||
let cachedGlobalArgumentPtr = null;
|
let cachedGlobalArgumentPtr = null;
|
||||||
let GLOBAL_ARGUMENT_CNT = 0;
|
|
||||||
function globalArgumentPtr() {
|
function globalArgumentPtr() {
|
||||||
if (cachedGlobalArgumentPtr === null)
|
if (cachedGlobalArgumentPtr === null)
|
||||||
cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
|
cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
|
||||||
@ -1159,7 +1156,7 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
|||||||
passed_args.push_str("this.ptr");
|
passed_args.push_str("this.ptr");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut argument_pushed = false;
|
let mut global_idx = 0;
|
||||||
for (i, arg) in function.arguments.iter().enumerate() {
|
for (i, arg) in function.arguments.iter().enumerate() {
|
||||||
let name = format!("arg{}", i);
|
let name = format!("arg{}", i);
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
@ -1218,12 +1215,12 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
|||||||
dst_ts.push_str(": ");
|
dst_ts.push_str(": ");
|
||||||
dst_ts.push_str(ty.js_ty());
|
dst_ts.push_str(ty.js_ty());
|
||||||
let func = self.cx.pass_to_wasm_function(&ty);
|
let func = self.cx.pass_to_wasm_function(&ty);
|
||||||
self.cx.expose_push_global_argument();
|
self.cx.expose_set_global_argument();
|
||||||
argument_pushed = true;
|
|
||||||
arg_conversions.push_str(&format!("\
|
arg_conversions.push_str(&format!("\
|
||||||
const [ptr{i}, len{i}] = {func}({arg});
|
const [ptr{i}, len{i}] = {func}({arg});
|
||||||
pushGlobalArgument(len{i});
|
setGlobalArgument(len{i}, {global_idx});
|
||||||
", i = i, func = func, arg = name));
|
", i = i, func = func, arg = name, global_idx = global_idx));
|
||||||
|
global_idx += 1;
|
||||||
pass(&format!("ptr{}", i));
|
pass(&format!("ptr{}", i));
|
||||||
if !ty.owned {
|
if !ty.owned {
|
||||||
destructors.push_str(&format!("\n\
|
destructors.push_str(&format!("\n\
|
||||||
@ -1329,9 +1326,6 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
|||||||
};
|
};
|
||||||
dst_ts.push_str(";");
|
dst_ts.push_str(";");
|
||||||
dst.push_str(" {\n ");
|
dst.push_str(" {\n ");
|
||||||
if argument_pushed {
|
|
||||||
dst.push_str("GLOBAL_ARGUMENT_CNT = 0;\n");
|
|
||||||
}
|
|
||||||
dst.push_str(&arg_conversions);
|
dst.push_str(&arg_conversions);
|
||||||
if destructors.len() == 0 {
|
if destructors.len() == 0 {
|
||||||
dst.push_str(&format!("\
|
dst.push_str(&format!("\
|
||||||
@ -1546,11 +1540,10 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
|||||||
}
|
}
|
||||||
let f = self.cx.pass_to_wasm_function(&ty);
|
let f = self.cx.pass_to_wasm_function(&ty);
|
||||||
self.cx.expose_uint32_memory();
|
self.cx.expose_uint32_memory();
|
||||||
self.cx.expose_push_global_argument();
|
self.cx.expose_set_global_argument();
|
||||||
format!("
|
format!("
|
||||||
GLOBAL_ARGUMENT_CNT = 0;
|
|
||||||
const [retptr, retlen] = {}({});
|
const [retptr, retlen] = {}({});
|
||||||
pushGlobalArgument(retlen);
|
setGlobalArgument(retlen, 0);
|
||||||
return retptr;
|
return retptr;
|
||||||
", f, invoc)
|
", f, invoc)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user