-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[interpreter] Build wast.js with Js_of_ocaml (#1507)
- Loading branch information
Showing
8 changed files
with
72 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(* Implements a wrapper library that allows the use of the reference | ||
* interpreter's encode/decode functionality in JavaScript. | ||
*) | ||
open Js_of_ocaml | ||
|
||
let _ = | ||
Js.export "WebAssemblyText" | ||
(object%js (_self) | ||
|
||
method encode (s : Js.js_string Js.t) : (Typed_array.arrayBuffer Js.t) = | ||
let def = Parse.string_to_module (Js.to_string s) in | ||
let bs = | ||
match def.Source.it with | ||
| Script.Textual m -> (Encode.encode m) | ||
| Script.Encoded (_, bs) -> bs | ||
| Script.Quoted (_, _) -> failwith "Unsupported" in | ||
let buf = new%js Typed_array.arrayBuffer (String.length bs) in | ||
let u8arr = new%js Typed_array.uint8Array_fromBuffer buf in | ||
String.iteri (fun i c -> Typed_array.set u8arr i (int_of_char c)) bs; buf | ||
|
||
method decode (buf : Typed_array.arrayBuffer Js.t) width : (Js.js_string Js.t) = | ||
let s = Typed_array.String.of_uint8Array (new%js Typed_array.uint8Array_fromBuffer buf) in | ||
let m = Decode.decode "(decode)" s in | ||
Js.string (Sexpr.to_string width (Arrange.module_ m)) | ||
|
||
end) |