File: contrib-architecture.md

package info (click to toggle)
node-webassemblyjs 1.11.4%2Bdfsg%2B~cs10.11.17-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 8,328 kB
  • sloc: javascript: 29,410; makefile: 85; sh: 42; ansic: 16
file content (56 lines) | stat: -rw-r--r-- 2,306 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
title: Architecture
id: contrib-architecture
---

## Compiler

Code parsing and manipulations.

### AST

Tools to manipulate and use our internal AST. You can see its definitions [here](https://github.com/xtuc/webassemblyjs/blob/master/types/AST.js).

### Parsing

The parsing is available for the following formats:

- [WebAssembly Text Format](https://webassembly.github.io/spec/text/index.html) (wat)
- [WAST Script Syntax](https://github.com/WebAssembly/spec/tree/master/interpreter#scripts) (wast)
- [WebAssembly Binary Format](https://webassembly.github.io/spec/binary/index.html) (wasm)

## Interpreter

### Kernel

Provides core features (memory management, execution, ...).

#### Why is this using a giant switch/case?

As explained here: [56#issuecomment-355736921](https://github.com/xtuc/webassemblyjs/issues/56#issuecomment-355736921), it's a critical part of the interpreter and needs to be very fast.
Note that most of the interpreter uses that technique.

#### Memory management

The WebAssembly specification uses a pointer/Addr structure, where some runtime values are stored (like functions). Unfortunately (for me) JavaScript doesn't expose pointers to the user-land.

For now the memory management is backend by an Array, where the Addr is the index. This is subject to change because is doesn't provides the same semantics than manual memory management would.

Note that garbage collection is done by the host (the JavaScript engine), there is probably no need to re-implement. On the other hand we need to unsure that we don't retain unused object.

#### The call stack

To be as close as possible to a native environement the execution relies on StackFrames (its structure is defined [here](https://github.com/xtuc/webassemblyjs/blob/9559f8d94435cd7f1c77ca4ff8cee6016b0dc4d3/src/interpreter/kernel/stackframe.js)).

The context in which StackFrames are executed is the call stack.

The stack call depth is unspecified currently by WebAssembly and is controlled by the host environement, its limit might vary.

### Runtime

Our runtime instance values.

## Notes

-  Text format supports floating point hexadecimals as described in this article [maurobringolf.ch/2017/12/hexadecimal-floating-point-notation](https://maurobringolf.ch/2017/12/hexadecimal-floating-point-notation)