Giter Site home page Giter Site logo

integers_stubs_js's People

Contributors

mitschabaude avatar mrmr1993 avatar novemberkilo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

integers_stubs_js's Issues

Difference of behavior for `Unsigned.UInt32.to_int64`.

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

Missing primitives: integers_intptr_t_size, integers_uintptr_t_size, integers_ptrdiff_t_size

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

Compare does not work because we are using int64

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.

The test from this repo does not pass

$ 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:

[ (__LOC__, -1L, -1L)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.