summaryrefslogtreecommitdiff
path: root/ports/webassembly/api.js
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2024-06-19 15:17:21 +1000
committerDamien George <damien@micropython.org>2024-06-20 00:26:08 +1000
commit88513d12268f5a5c3f3488f1a2d70cb605129537 (patch)
tree7eb51b3fdb24235fae31c36f454e5e8972d9940b /ports/webassembly/api.js
parent13195a678d0155a52818beaa5ffc4f4678a4226d (diff)
webassembly/api: Allow specifying the pystack size.
This allows increasing the Python recursion depth if needed. Also increase the default to 2k words. There is enough RAM in the browser/node context for this to be increased, and having a larger pystack allows more complex code to run without hitting the limit. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'ports/webassembly/api.js')
-rw-r--r--ports/webassembly/api.js17
1 files changed, 12 insertions, 5 deletions
diff --git a/ports/webassembly/api.js b/ports/webassembly/api.js
index c00edf575..0718d13d6 100644
--- a/ports/webassembly/api.js
+++ b/ports/webassembly/api.js
@@ -25,6 +25,7 @@
*/
// Options:
+// - pystack: size in words of the MicroPython Python stack.
// - heapsize: size in bytes of the MicroPython GC heap.
// - url: location to load `micropython.mjs`.
// - stdin: function to return input characters.
@@ -34,10 +35,11 @@
// - stderr: same behaviour as stdout but for error output.
// - linebuffer: whether to buffer line-by-line to stdout/stderr.
export async function loadMicroPython(options) {
- const { heapsize, url, stdin, stdout, stderr, linebuffer } = Object.assign(
- { heapsize: 1024 * 1024, linebuffer: true },
- options,
- );
+ const { pystack, heapsize, url, stdin, stdout, stderr, linebuffer } =
+ Object.assign(
+ { pystack: 2 * 1024, heapsize: 1024 * 1024, linebuffer: true },
+ options,
+ );
let Module = {};
Module.locateFile = (path, scriptDirectory) =>
url || scriptDirectory + path;
@@ -96,7 +98,12 @@ export async function loadMicroPython(options) {
);
return proxy_convert_mp_to_js_obj_jsside_with_free(value);
};
- Module.ccall("mp_js_init", "null", ["number"], [heapsize]);
+ Module.ccall(
+ "mp_js_init",
+ "null",
+ ["number", "number"],
+ [pystack, heapsize],
+ );
Module.ccall("proxy_c_init", "null", [], []);
return {
_module: Module,