o1-labs / integers_stubs_js Goto Github PK
View Code? Open in Web Editor NEWJavascript stubs for the integers library in js_of_ocaml
License: MIT License
Javascript stubs for the integers library in js_of_ocaml
License: MIT License
Missing primitives:
integers_uint32_to_hexstring
integers_uint64_to_hexstring
This is the code generated by js_of_ocaml:
var
Intptr = signed_typedef(cst_intptr_t, runtime.integers_intptr_t_size(0)),
Uintptr =
unsigned_typedef(cst_uintptr_t, runtime.integers_uintptr_t_size(0)),
intptr_t = Intptr[39],
uintptr_t = Uintptr[32],
Ptrdiff =
signed_typedef(cst_ptrdiff_t, runtime.integers_ptrdiff_t_size(0)),
ptrdiff_t = Ptrdiff[39],
Thanks,
Jonathan
The way UInt64s are handled does not properly install the written comparison function.
I believe this is because uint64 values are actually represented as int64 so the setting of custom functions here does nothing:
caml_custom_ops["integers:uint64"] =
{ serialize: caml_int64_marshal
, deserialize: caml_int64_unmarshal
, hash: caml_int64_hash
, compare: integers_uint64_compare };
As a result, the compare function for uint64s is the signed compare, and thus does not work correctly.
$ dune build ./test/test.bc.js
$ node _build/default/test/test.bc.js
UInt8
x_64, y_64, z, z_64, M.of_int64, Done
Checking::: 254 = 254? 254 = 254? 0
x_64, y_64, z, z_64, M.of_int64, Done
Checking::: 254 = 254? 254 = 254? 0
[...]
x_64, y_64, z, z_64, M.of_int64, Done
Checking::: 4294967294 = 4294967294? 4294967294 = 4294967294? 0
Checking::: 4294967294 = 4294967294? 4294967294 = 4294967294? 0
Checking::: 510 = 510? 510 = 510? 0
Checking::: 131070 = 131070? 131070 = 131070? 0
Checking::: 33554430 = 33554430? 33554430 = 33554430? 0
Checking::: 4294967294 = 4294967294? 4294967294 = 4294967294? 0
UInt64
x_64, y_64, z, z_64, M.of_int64, Done
Checking::: 9223372036854775803 = -4? 9223372036854775803 = 18446744073709551612? 1
Fatal error: exception Failure("File "test/test.ml", line 55, characters 7-14")
/home/olivier/ocaml_package_repos/integers_stubs_js/_build/default/test/test.bc.js:6772
if(err.js_error) throw err.js_error;
^
Error: Js exception containing backtrace
at caml_exn_with_js_backtrace (/home/olivier/ocaml_package_repos/integers_stubs_js/_build/default/test/test.bc.js:283:21)
at caml_maybe_attach_backtrace (/home/olivier/ocaml_package_repos/integers_stubs_js/_build/default/test/test.bc.js:288:15)
at failwith (/home/olivier/ocaml_package_repos/integers_stubs_js/_build/default/test/test.bc.js:10940:11)
at caml_call1 (/home/olivier/ocaml_package_repos/integers_stubs_js/_build/default/test/test.bc.js:25502:15)
at check (/home/olivier/ocaml_package_repos/integers_stubs_js/_build/default/test/test.bc.js:25643:19)
at caml_call1 (/home/olivier/ocaml_package_repos/integers_stubs_js/_build/default/test/test.bc.js:12773:15)
at iter (/home/olivier/ocaml_package_repos/integers_stubs_js/_build/default/test/test.bc.js:12981:6)
at caml_call2 (/home/olivier/ocaml_package_repos/integers_stubs_js/_build/default/test/test.bc.js:25507:15)
at test_module (/home/olivier/ocaml_package_repos/integers_stubs_js/_build/default/test/test.bc.js:25645:5)
at /home/olivier/ocaml_package_repos/integers_stubs_js/_build/default/test/test.bc.js:25709:4
Node.js v20.11.0
The failure apparently happens when running the check
function on -1L, -1L
:
integers_stubs_js/test/test.ml
Line 55 in 141e0bc
Saved me lot of time when I tried to port some code for the browser!
The native version of Unsigned.UInt32.to_int64
returns an int64 holding the exact same value as the given uint32, which I suppose is the expected behavior. The js stubs version, when the leftmost bit is 1, yields a different, very large number instead. I suspect the stubs are filling the 32 leftmost bits with ones instead zeroes.
let ui32 = Unsigned.UInt32.of_int 3748276426 in
let i64 = Unsigned.UInt32.to_int64 ui32 in
Format.eprintf "%Ld@." i64
Native output: 3748276426
Javascript output: 281478724987082
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.