Skip to content
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

Doc: document memory representation #1153

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ optimized:
[More](http://ocsigen.org/js_of_ocaml/dev/manual/tailcall) about tail call
optimization.

## Data representation

Data representation differs from the usual one. Most notably, integers are 32
bits (rather than 31 bits or 63 bits), which is their natural size in
JavaScript, and floats are not boxed. As a consequence, marshalling, polymorphic
Expand All @@ -94,6 +96,27 @@ comparison, and hashing functions can yield results different from usual:
containing floats;
- these functions may be more prone to stack overflow.

| Ocaml | javascript |
| ------------- | ------------- |
| int | number (32bit int) |
| int32 | number (32bit int) |
| nativeint | number (32bit int) |
| int64 | Object (MlInt64) |
| float | number |
| string | string or object (MlBytes) |
| bytes | object (MlBytes) |
| "immediate" (e.g. true, false, None, ()) | number (32bit int) |
| "block" | array with tag as first element (e.g. `C(1,2) => [tag,1,2]`) |
| array | block with tag 0 (e.g. `[\|1;2\|] => [0,1,2]`) |
| tuple | block with tag 0 (e.g. `(1,2) => [0,1,2]`) |
| record | block (e.g. `{x=1;y=2} => [0,1,2]`) |
| contructor with arguments | block (e.g. `C (1, 2) => [tag,1,2]`) |
| module | block |
| exception and extensible variant | block or immediate |
| function | function |



## Toplevel

- [OCaml 4.04.2](http://ocsigen.github.io/js_of_ocaml/toplevel.html#version=4.04.2)
Expand Down