From 34eec534d4a3a9d67c09da45956493a5884b6b46 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 9 Oct 2023 14:29:34 +0200 Subject: [PATCH] Runtime: lookup inside jsoo_runtime in caml_dynlink_lookup_symbol --- CHANGES.md | 3 ++- runtime/dynlink.js | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cb4f762d79..aa8af27ede 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,8 +11,9 @@ ## Bug fixes * Runtime: fix Dom_html.onIE (#1493) * Runtime: add conversion functions + strict equality for compatibility with Wasm_of_ocaml (#1492) +* Runtime: Dynlink should be able to find symbols in jsoo_runtime #1517 * Compiler: fix global flow analysis (#1494) -* COmpiler: fix js parser/printer wrt async functions (#1515) +* Compiler: fix js parser/printer wrt async functions (#1515) # 5.4.0 (2023-07-06) - Lille diff --git a/runtime/dynlink.js b/runtime/dynlink.js index 8b0bd4e3bc..9664498a9b 100644 --- a/runtime/dynlink.js +++ b/runtime/dynlink.js @@ -16,33 +16,41 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -//Provides: current_libs -var current_libs = [0, globalThis] +//Provides: get_current_libs +var current_libs; +function get_current_libs () { + if(!current_libs) + current_libs = [0, globalThis, globalThis.jsoo_runtime] + return current_libs +} //Provides: caml_dynlink_open_lib -//Requires: current_libs, caml_failwith +//Requires: get_current_libs, caml_failwith //Requires: caml_jsstring_of_string function caml_dynlink_open_lib (_mode,file) { var name = caml_jsstring_of_string(file); console.log("Dynlink: try to open ", name); //caml_failwith("file not found: "+name) + var current_libs = get_current_libs(); current_libs.push({}); return current_libs.length; } //Provides: caml_dynlink_close_lib -//Requires: current_libs +//Requires: get_current_libs function caml_dynlink_close_lib (idx) { + var current_libs = get_current_libs(); current_libs[idx]=null; return 0; } //Provides: caml_dynlink_lookup_symbol -//Requires: current_libs +//Requires: get_current_libs //Requires: caml_jsstring_of_string function caml_dynlink_lookup_symbol (idx, fun_name) { var name = caml_jsstring_of_string(fun_name); console.log("Dynlink: looking for symbol", name); + var current_libs = get_current_libs(); if(current_libs[idx] && current_libs[idx][name]) return {name: name, symbol: current_libs[idx][name]}; return 0; @@ -56,8 +64,9 @@ function caml_dynlink_add_primitive (dll_addr) { } //Provides: caml_dynlink_get_current_libs -//Requires: current_libs +//Requires: get_current_libs function caml_dynlink_get_current_libs () { + var current_libs = get_current_libs(); var len = current_libs.length; var a = new Array(len); for(var i=0; i < len; i++)