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.
Files changed (2) hide show
  1. package/doc/vm.md +111 -144
  2. package/package.json +1 -1
package/doc/vm.md CHANGED
@@ -1,17 +1,35 @@
1
- # VM
1
+ # NaNVM
2
2
 
3
- [Tagged Pointer](https://en.wikipedia.org/wiki/Tagged_pointer).
3
+ https://en.wikipedia.org/wiki/Double-precision_floating-point_format
4
4
 
5
- ## Common (3 bit)
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
- - `false`
8
- - `true`
9
- - `undefined`
10
- - `""`
11
- - `+infinity`
12
- - `-infinity`
13
- - `-0`
14
- - `NaN`
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
- ## Value
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
- https://en.wikipedia.org/wiki/Double-precision_floating-point_format
46
+ 53 bits.
58
47
 
59
- - 1 bit - sign (S)
60
- - 11 bit - exponent (E)
61
- - 52 bit - fraction (F)
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
- |E |Description |
64
- |-------------|------------------------|
65
- |000_0000_0000|F = 0: signed zeros |
66
- | |F != 0: subnormals |
67
- |000_0000_0001|E = 2^-1022 |
68
- |... | |
69
- |011_1111_1111|E = 2^0 |
70
- |100_0000_0000|E = 2^1 |
71
- |... | |
72
- |111_1111_1110|E = 2^1023 |
73
- |111_1111_1111|F = 0: signed infinities|
74
- | |F != 0: NaN |
75
-
76
- ## Float60
77
-
78
- - 1 bit - sign
79
- - 7 bit - exponent
80
- - 52 bit - fraction
81
-
82
- |E |Description|
83
- |--------|-----------|
84
- |000_0000|E = 2^-63 |
85
- |... | |
86
- |011_1111|E = 2^0 |
87
- |100_0000|E = 2^1 |
88
- |... | |
89
- |111_1111|E = 2^64 |
90
-
91
- Note: the type has no `+0`, `-0`, `+inf`, `-inf`, `NaN`.
92
-
93
- ## Object Structure
94
-
95
- Value Size = 8
96
- Counter size = max_memory_size / value_size.
97
-
98
- ### Type
99
-
100
- - `000`: double
101
- - `001`: string
102
- - `010`: array
103
- - `011`: object
104
- - `100`: bigInt
105
- - `101`: function
106
- - `110`:
107
- - `111`:
108
-
109
- ### Type & Counter
110
-
111
- - AtomicUSize:
112
- - `3`: type
113
- - `...`: counter
114
-
115
- ### String
116
-
117
- ```rust
118
- struct String {
119
- length: u32,
120
- array: [u16; self.length],
121
- }
122
- ```
123
-
124
- ### Function
125
-
126
- ```rust
127
- struct Function<length: u32> {
128
- func: pointer,
129
- array: [value; length]
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.389",
3
+ "version": "0.0.390",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {