This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,6 @@
(executables
(names technologic)
(libraries js_of_ocaml x)
(modes wasm)
(wasm_of_ocaml
(javascript_files runtime.js)))

View file

@ -0,0 +1,3 @@
global.globalPrintFunction = function(x){
console.log(x);
}

View file

@ -0,0 +1,13 @@
module Js = Js_of_ocaml.Js
let _ =
print_endline X.buy_it;
let obj = Js.Unsafe.obj [|"name", Js.Unsafe.inject (Js.string Z.use_it)|] in
Printf.printf "%s\n%!" (X.print obj);
X.external_print (Js.string "break it");
(fun x ->
let global = Js.Unsafe.get Js.Unsafe.global "global" in
let globalPrintFunction : Js.js_string Js.t -> unit =
Js.Unsafe.get global "globalPrintFunction" in
Js.Unsafe.fun_call globalPrintFunction [|Js.Unsafe.inject x|]
) (Js.string "fix it")

View file

@ -0,0 +1 @@
let use_it = "use it"

View file

@ -0,0 +1 @@
(lang dune 3.17)

View file

@ -0,0 +1,7 @@
(library
(name x)
(libraries js_of_ocaml)
(public_name x)
(wasm_of_ocaml
(flags (--pretty)) (wasm_files runtime.js runtime.wat))
(foreign_stubs (language c) (names stubs)))

View file

@ -0,0 +1,6 @@
//Provides: jsPrint
function jsPrint(x){
globalThis.console.log(x);
}

View file

@ -0,0 +1,7 @@
(module
(import "env" "unwrap" (func $unwrap (param (ref eq)) (result anyref)))
(import "js" "jsPrint" (func $print (param anyref)))
(func (export "jsPrint") (param $x (ref eq)) (result (ref eq))
(call $print (call $unwrap (local.get $x)))
(ref.i31 (i32.const 0)))
)

View file

@ -0,0 +1,3 @@
#include <stdlib.h>
#include <stdio.h>
void jsPrint () { fprintf(stderr, "Unimplemented Javascript primitive myPrint!\n"); exit(1); }

View file

@ -0,0 +1,5 @@
module Js = Js_of_ocaml.Js
let buy_it = "buy " ^ Y.it
let print x = Js.to_string (Js.Unsafe.get x "name")
external external_print : Js.js_string Js.t -> unit = "jsPrint"

View file

@ -0,0 +1 @@
let it = "it"

View file

@ -0,0 +1,32 @@
Compilation using WasmOO
$ dune build bin/technologic.bc.wasm.js @install --profile dev
$ node ./_build/default/bin/technologic.bc.wasm.js
buy it
use it
break it
fix it
$ dune build @install --profile release
$ node ./_build/default/bin/technologic.bc.wasm.js
buy it
use it
break it
fix it
Compilation using WasmOO with `disable_dynamically_linked_foreign_archives = true`
$ cat >dune-workspace <<EOF
> (lang dune 3.17)
> (context
> (default (disable_dynamically_linked_foreign_archives true)))
> EOF
$ dune clean
$ dune build bin/technologic.bc.wasm.js @install --profile dev
Wasm_of_ocaml whole program compilation works with
`disable_dynamically_linked_foreign_archives = true`:
$ dune build bin/technologic.bc.wasm.js @install --profile release
We expect a runtime error when running this `bc-for-jsoo` file.
$ ! if dune exe bin/technologic.bc-for-jsoo ; then true ; else false ; fi 2> /dev/null