-
Notifications
You must be signed in to change notification settings - Fork 478
[interpreter] Change how wast.js is built by using Js_of_ocaml #1507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4148f10
c7aab24
b50c462
dbabef2
35a7bbb
4a4fc5e
54bc584
94fee80
a443bed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
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) = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps by declaring the parameter
and then doing
it is possible to emulate the previous default parameter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tried using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can achieve that behavior using JS.Unsafe.* functions. |
||
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) |
Uh oh!
There was an error while loading. Please reload this page.