functionalscript 0.0.389 → 0.0.390
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/doc/vm.md +111 -144
- package/package.json +1 -1
package/doc/vm.md
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
#
|
|
1
|
+
# NaNVM
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
https://en.wikipedia.org/wiki/Double-precision_floating-point_format
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
https://anniecherkaev.com/the-secret-life-of-nan
|
|
6
|
+
https://brionv.com/log/2018/05/17/javascript-engine-internals-nan-boxing/
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
|
|
9
|
+
- 1 bit - sign (S)
|
|
10
|
+
- 11 bit - exponent (E)
|
|
11
|
+
- 52 bit - fraction (F)
|
|
12
|
+
|
|
13
|
+
|SE |F |Value |
|
|
14
|
+
|---|--------------|----------------|
|
|
15
|
+
|000|00000_00000000|+000000_00000000|
|
|
16
|
+
|...| | |
|
|
17
|
+
|3FF|00000_00000000|+000000_00000001|
|
|
18
|
+
|...| | |
|
|
19
|
+
|434|00000_00000000|+200000_00000000|
|
|
20
|
+
|...| | |
|
|
21
|
+
|7FF|00000_00000000|+inf |
|
|
22
|
+
|...| |NaN |
|
|
23
|
+
|800|00000_00000000|-0.0 |
|
|
24
|
+
|...| | |
|
|
25
|
+
|BFF|00000_00000000|-000000_00000001|
|
|
26
|
+
|...| | |
|
|
27
|
+
|C34|00000_00000000|-200000_00000000|
|
|
28
|
+
|...| | |
|
|
29
|
+
|FFF|00000_00000000|-inf |
|
|
30
|
+
|...| |NaN |
|
|
31
|
+
|
|
32
|
+
integer range: `[-2^53; +2^53]`.
|
|
15
33
|
|
|
16
34
|
## 6-bit Id String
|
|
17
35
|
|
|
@@ -23,141 +41,90 @@
|
|
|
23
41
|
|`_` |`\x5F` | 1| 26|
|
|
24
42
|
|`a`..`z`|`\x61`..`\x7A`|1A| 40|
|
|
25
43
|
|
|
26
|
-
##
|
|
27
|
-
|
|
28
|
-
Alignment: 8 bytes.
|
|
29
|
-
|
|
30
|
-
Pointer: 2^64 / 2^3 = 2^61 bit
|
|
31
|
-
|
|
32
|
-
- `63`: 9 x 7 bit string
|
|
33
|
-
- `63`:
|
|
34
|
-
- `61`: pointer + null, alignment - 8 bytes
|
|
35
|
-
- `61`:
|
|
36
|
-
- `60`: 4 x 15 bit string
|
|
37
|
-
- `60`: 10 x 6 bit string
|
|
38
|
-
- `61`:
|
|
39
|
-
- `60`: 6 x 10 bit string
|
|
40
|
-
- `60`: 5 x 12 bit string
|
|
41
|
-
- `61`
|
|
42
|
-
- `60`: float60
|
|
43
|
-
- `60`:
|
|
44
|
-
- `59`: bigInt59 (-576_460_752_303_423_488..576_460_752_303_423_487)
|
|
45
|
-
- `59`:
|
|
46
|
-
- `56`: 8 x 7-bit string
|
|
47
|
-
- `56`: 7 x 8-bit string
|
|
48
|
-
- `53`: int53
|
|
49
|
-
- `53`: stringUInt53
|
|
50
|
-
- `48`: 3 x 16 bit string
|
|
51
|
-
- `32`: 2 x 16 bit string
|
|
52
|
-
- `16`: 1 x UTF16 string
|
|
53
|
-
- `3`: common
|
|
54
|
-
|
|
55
|
-
## Float64
|
|
44
|
+
## 7FF & FFF
|
|
56
45
|
|
|
57
|
-
|
|
46
|
+
53 bits.
|
|
58
47
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
-
|
|
48
|
+
Other values:
|
|
49
|
+
|
|
50
|
+
- `NaN`
|
|
51
|
+
- `+Inf`: 0x7FF00000_00000000
|
|
52
|
+
- `-Inf`: 0xFFF00000_00000000
|
|
53
|
+
- pointer + null:
|
|
54
|
+
- 32 bit for 32 bit platforms.
|
|
55
|
+
- 48 bit for current AMD64 https://en.wikipedia.org/wiki/X86-64#Canonical_form_addresses and ARM64
|
|
56
|
+
note: with alignments it can be further narrowed to 44-45 bit.
|
|
57
|
+
- `true`
|
|
58
|
+
- `false`
|
|
59
|
+
- `undefined`
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
-
|
|
79
|
-
-
|
|
80
|
-
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### BigInt
|
|
134
|
-
|
|
135
|
-
```rust
|
|
136
|
-
struct BigInt {
|
|
137
|
-
length: u32,
|
|
138
|
-
array: [u64; self.length],
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### Array
|
|
143
|
-
|
|
144
|
-
```rust
|
|
145
|
-
struct Array {
|
|
146
|
-
length: u32,
|
|
147
|
-
array: [Value; self.length],
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
### Object
|
|
152
|
-
|
|
153
|
-
```rust
|
|
154
|
-
struct Object {
|
|
155
|
-
length: u32,
|
|
156
|
-
array: [(Value, Value), self.length],
|
|
157
|
-
indexArray: [u32, (self.length * log2(self.length) + 31) / u32],
|
|
158
|
-
}
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
Note: see https://262.ecma-international.org/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys and https://262.ecma-international.org/6.0/#sec-object-type
|
|
61
|
+
Optimization for
|
|
62
|
+
- string
|
|
63
|
+
- bigInt
|
|
64
|
+
|
|
65
|
+
Least used letters in English: Q, J, Z and X.
|
|
66
|
+
|
|
67
|
+
### Layout 52
|
|
68
|
+
|
|
69
|
+
Starts with `0xFFF`
|
|
70
|
+
|
|
71
|
+
- `50`:
|
|
72
|
+
- `48`: stringUInt48 (0..281_474_976_710_655)
|
|
73
|
+
- `48`: 8 x 6 string
|
|
74
|
+
- `48`: `42` 7 x 6 string
|
|
75
|
+
- `48`: 6 x 8 string
|
|
76
|
+
- `50`:
|
|
77
|
+
- `48`: `45` 5 x 9 string
|
|
78
|
+
- `48`: 4 x 12 string
|
|
79
|
+
- `48`: 3 x 16 string
|
|
80
|
+
- `48`: `32`: 2 x 16 string
|
|
81
|
+
- `50`:
|
|
82
|
+
- `48`: `16`: 1 x 16 string
|
|
83
|
+
- `48`: `0`: ""
|
|
84
|
+
- `48`: false
|
|
85
|
+
- `48`: true
|
|
86
|
+
- `50`:
|
|
87
|
+
- `48`: ptr
|
|
88
|
+
- `48`: bigInt48 (140_737_488_355_328..140_737_488_355_327)
|
|
89
|
+
- `48`: undefined
|
|
90
|
+
- `48`: `-inf`
|
|
91
|
+
|
|
92
|
+
| | | |type |
|
|
93
|
+
|------|--|-------------|-----------|
|
|
94
|
+
|`1111`|48|stringUInt48 |`string` |
|
|
95
|
+
|`1110`|48|8 x 6 string | |
|
|
96
|
+
|`1101`|48|7 x 7 stringA| |
|
|
97
|
+
|`1100`|48|7 x 7 stringB| |
|
|
98
|
+
|`1011`|48|6 x 8 string | |
|
|
99
|
+
|`1010`|45|5 x 9 string | |
|
|
100
|
+
|`1001`|48|4 x 12 string| |
|
|
101
|
+
|`1000`|48|3 x 16 string| |
|
|
102
|
+
|`0111`|32|2 x 16 string| |
|
|
103
|
+
|`0110`|16|1 x 16 string| |
|
|
104
|
+
|`0101`| 0|empty string | |
|
|
105
|
+
|`0100`| 0|undefined |`undefined`|
|
|
106
|
+
|`0011`|48|ptr |... |
|
|
107
|
+
|`0010`|48|bigInt48 |`bigint` |
|
|
108
|
+
|`0001`| 0|bool |`bool` |
|
|
109
|
+
|`0000`| 0|-inf |`number` |
|
|
110
|
+
|
|
111
|
+
## Pointer Kind
|
|
112
|
+
|
|
113
|
+
Alignment 8 bytes. 3 bits.
|
|
114
|
+
|
|
115
|
+
| |type | |
|
|
116
|
+
|----|----------|---------------|
|
|
117
|
+
|00.0|`object` |null |
|
|
118
|
+
|00.1| |object |
|
|
119
|
+
|01.0|`string` |string |
|
|
120
|
+
|01.1| | |
|
|
121
|
+
|10.0|`function`|function |
|
|
122
|
+
|10.1| |static function|
|
|
123
|
+
|11.0|`bigint` |bigint |
|
|
124
|
+
|11.1| | |
|
|
125
|
+
|
|
126
|
+
## Order of object properties
|
|
127
|
+
|
|
128
|
+
See https://262.ecma-international.org/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys and https://262.ecma-international.org/6.0/#sec-object-type
|
|
162
129
|
|
|
163
130
|
An integer index for Node.js, Deno and Bun means a value from `0` to `4294967294` including. 4_294_967_294 = 0xFFFF_FFFE. But an integer index in the ES6 standard is +0..2^53-1.
|