functionalscript 0.0.389 → 0.0.392
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/com/cpp/module.f.cjs +41 -31
- package/com/cs/module.f.cjs +60 -41
- package/com/types/module.f.cjs +6 -2
- package/commonjs/build/module.f.cjs +19 -14
- package/commonjs/package/dependencies/module.f.cjs +5 -2
- package/commonjs/package/module.f.cjs +4 -2
- package/commonjs/path/module.f.cjs +16 -14
- package/dev/test/module.f.cjs +19 -0
- package/doc/vm.md +126 -118
- package/html/module.f.cjs +14 -9
- package/json/module.f.cjs +18 -11
- package/json/tokenizer/module.f.cjs +128 -164
- package/nodejs/version/module.f.cjs +4 -4
- package/package.json +1 -1
- package/sha2/module.f.cjs +29 -29
- package/test.f.cjs +1 -1
- package/text/encoding/module.f.cjs +0 -2
- package/text/module.f.cjs +2 -1
- package/types/array/module.f.cjs +2 -1
- package/types/btree/find/module.f.cjs +3 -2
- package/types/btree/remove/module.f.cjs +6 -5
- package/types/btree/set/module.f.cjs +9 -5
- package/types/list/module.f.cjs +38 -12
- package/types/map/module.f.cjs +11 -10
- package/types/module.f.cjs +1 -1
- package/types/object/module.f.cjs +9 -6
- package/types/object/test.html +9 -0
- package/types/result/module.cjs +3 -2
- package/types/{stringset → string_set}/module.f.cjs +12 -8
- /package/types/{stringset → string_set}/test.f.cjs +0 -0
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,96 +41,103 @@
|
|
|
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
|
-
- 11 bit - exponent (E)
|
|
61
|
-
- 52 bit - fraction (F)
|
|
62
|
-
|
|
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 |
|
|
48
|
+
Other values:
|
|
90
49
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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`
|
|
99
60
|
|
|
100
|
-
|
|
101
|
-
-
|
|
102
|
-
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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`|48|ptr |? |
|
|
106
|
+
|`0011`| 0|undefined |`undefined`|
|
|
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` |object |
|
|
118
|
+
|00.1| |array |
|
|
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
|
+
## Object
|
|
108
127
|
|
|
109
|
-
|
|
128
|
+
```rust
|
|
129
|
+
struct Object {
|
|
130
|
+
propertySet: PropertySet
|
|
131
|
+
iterable: Func<Iterator>
|
|
132
|
+
}
|
|
110
133
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
134
|
+
struct Array {
|
|
135
|
+
length: u32,
|
|
136
|
+
array: [Value; self.lenght],
|
|
137
|
+
}
|
|
138
|
+
```
|
|
114
139
|
|
|
115
|
-
|
|
140
|
+
## String
|
|
116
141
|
|
|
117
142
|
```rust
|
|
118
143
|
struct String {
|
|
@@ -121,16 +146,16 @@ struct String {
|
|
|
121
146
|
}
|
|
122
147
|
```
|
|
123
148
|
|
|
124
|
-
|
|
149
|
+
## Function
|
|
125
150
|
|
|
126
151
|
```rust
|
|
127
|
-
struct Function
|
|
128
|
-
|
|
129
|
-
array: [
|
|
152
|
+
struct Function {
|
|
153
|
+
pointer: FunctionBody,
|
|
154
|
+
array: [Value; length],
|
|
130
155
|
}
|
|
131
156
|
```
|
|
132
157
|
|
|
133
|
-
|
|
158
|
+
## BigInt
|
|
134
159
|
|
|
135
160
|
```rust
|
|
136
161
|
struct BigInt {
|
|
@@ -139,25 +164,8 @@ struct BigInt {
|
|
|
139
164
|
}
|
|
140
165
|
```
|
|
141
166
|
|
|
142
|
-
|
|
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
|
-
```
|
|
167
|
+
## Order of object properties
|
|
160
168
|
|
|
161
|
-
|
|
169
|
+
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
170
|
|
|
163
171
|
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/html/module.f.cjs
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
const list = require('../types/list/module.f.cjs')
|
|
2
|
+
const { map, flatMap, flat, concat, fold } = list
|
|
2
3
|
const object = require('../types/object/module.f.cjs')
|
|
3
|
-
const {
|
|
4
|
+
const { compose } = require('../types/function/module.f.cjs')
|
|
4
5
|
const encoding = require('../text/encoding/module.f.cjs');
|
|
6
|
+
const { stringToUtf16List } = encoding
|
|
7
|
+
|
|
8
|
+
const { fromCharCode } = String
|
|
9
|
+
const { entries } = Object
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* @typedef {|
|
|
@@ -70,22 +75,22 @@ const escapeCharCode = code => {
|
|
|
70
75
|
case 0x26: return '&'
|
|
71
76
|
case 0x3C: return '<'
|
|
72
77
|
case 0x3E: return '>'
|
|
73
|
-
default: return
|
|
78
|
+
default: return fromCharCode(code)
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
|
|
77
|
-
const escape = compose(
|
|
82
|
+
const escape = compose(stringToUtf16List)(map(escapeCharCode))
|
|
78
83
|
|
|
79
84
|
/** @type {(n: Node) => list.List<string>} */
|
|
80
85
|
const node = n => typeof n === 'string' ? escape(n) : element(n)
|
|
81
86
|
|
|
82
|
-
const nodes =
|
|
87
|
+
const nodes = flatMap(node)
|
|
83
88
|
|
|
84
89
|
/** @type {(a: object.Entry<string>) => list.List<string>} */
|
|
85
|
-
const attribute = ([name, value]) =>
|
|
90
|
+
const attribute = ([name, value]) => flat([[' ', name, '="'], escape(value), ['"']])
|
|
86
91
|
|
|
87
92
|
/** @type {(a: Attributes) => list.List<string>} */
|
|
88
|
-
const attributes = compose(
|
|
93
|
+
const attributes = compose(entries)(flatMap(attribute))
|
|
89
94
|
|
|
90
95
|
/** @type {(element: Element) => list.List<string>} */
|
|
91
96
|
const element = e => {
|
|
@@ -104,12 +109,12 @@ const element = e => {
|
|
|
104
109
|
}
|
|
105
110
|
}
|
|
106
111
|
}
|
|
107
|
-
return
|
|
112
|
+
return flat(f())
|
|
108
113
|
}
|
|
109
114
|
|
|
110
|
-
const html = compose(element)(
|
|
115
|
+
const html = compose(element)(concat(['<!DOCTYPE html>']))
|
|
111
116
|
|
|
112
|
-
const htmlToString =
|
|
117
|
+
const htmlToString = compose(html)(list.stringConcat)
|
|
113
118
|
|
|
114
119
|
module.exports = {
|
|
115
120
|
/** @readonly */
|
package/json/module.f.cjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
const list = require('../types/list/module.f.cjs')
|
|
2
|
+
const { next, flat, fold, map, stringConcat } = list
|
|
2
3
|
const object = require('../types/object/module.f.cjs')
|
|
4
|
+
const { at } = object
|
|
3
5
|
const operator = require('../types/function/operator/module.f.cjs')
|
|
4
6
|
const { compose } = require('../types/function/module.f.cjs')
|
|
7
|
+
const { entries } = Object
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* @typedef {{
|
|
@@ -17,20 +20,22 @@ const { compose } = require('../types/function/module.f.cjs')
|
|
|
17
20
|
const setProperty = value => {
|
|
18
21
|
/** @type {(path: list.List<string>) => (src: Unknown|undefined) => Unknown} */
|
|
19
22
|
const f = path => src => {
|
|
20
|
-
const result =
|
|
23
|
+
const result = next(path)
|
|
21
24
|
if (result === undefined) { return value }
|
|
22
25
|
const srcObject = (src === undefined || src === null || typeof src !== 'object' || src instanceof Array) ? {} : src
|
|
23
26
|
const { first, tail } = result
|
|
24
|
-
return { ...srcObject, [first]: f(tail)(
|
|
27
|
+
return { ...srcObject, [first]: f(tail)(at(first)(srcObject)) }
|
|
25
28
|
}
|
|
26
29
|
return f
|
|
27
30
|
}
|
|
28
31
|
|
|
32
|
+
const jsonStringify = JSON.stringify
|
|
33
|
+
|
|
29
34
|
/** @type {(_: string) => list.List<string>} */
|
|
30
|
-
const stringSerialize = input => [
|
|
35
|
+
const stringSerialize = input => [jsonStringify(input)]
|
|
31
36
|
|
|
32
37
|
/** @type {(_: number) => list.List<string>} */
|
|
33
|
-
const numberSerialize = input => [
|
|
38
|
+
const numberSerialize = input => [jsonStringify(input)]
|
|
34
39
|
|
|
35
40
|
const nullSerialize = ['null']
|
|
36
41
|
|
|
@@ -45,16 +50,16 @@ const colon = [':']
|
|
|
45
50
|
const comma = [',']
|
|
46
51
|
|
|
47
52
|
/** @type {operator.Fold<list.List<string>>} */
|
|
48
|
-
const joinOp = b => prior =>
|
|
53
|
+
const joinOp = b => prior => flat([prior, comma, b])
|
|
49
54
|
|
|
50
55
|
/** @type {(input: list.List<list.List<string>>) => list.List<string>} */
|
|
51
|
-
const join =
|
|
56
|
+
const join = fold(joinOp)([])
|
|
52
57
|
|
|
53
58
|
/** @type {(open: string) => (close: string) => (input: list.List<list.List<string>>) => list.List<string>} */
|
|
54
59
|
const wrap = open => close => {
|
|
55
60
|
const seqOpen = [open]
|
|
56
61
|
const seqClose = [close]
|
|
57
|
-
return input =>
|
|
62
|
+
return input => flat([seqOpen, join(input), seqClose])
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
const objectWrap = wrap('{')('}')
|
|
@@ -70,13 +75,14 @@ const arrayWrap = wrap('[')(']')
|
|
|
70
75
|
/** @type {(mapEntries: MapEntries) => (value: Unknown) => list.List<string>} */
|
|
71
76
|
const serialize = sort => {
|
|
72
77
|
/** @type {(kv: readonly[string, Unknown]) => list.List<string>} */
|
|
73
|
-
const propertySerialize = ([k, v]) =>
|
|
78
|
+
const propertySerialize = ([k, v]) => flat([
|
|
74
79
|
stringSerialize(k),
|
|
75
80
|
colon,
|
|
76
81
|
f(v)
|
|
77
82
|
])
|
|
83
|
+
const mapPropertySerialize = map(propertySerialize)
|
|
78
84
|
/** @type {(object: Object) => list.List<string>} */
|
|
79
|
-
const objectSerialize = input => objectWrap(
|
|
85
|
+
const objectSerialize = input => objectWrap(mapPropertySerialize(sort(entries(input))))
|
|
80
86
|
/** @type {(value: Unknown) => list.List<string>} */
|
|
81
87
|
const f = value => {
|
|
82
88
|
switch (typeof value) {
|
|
@@ -90,8 +96,9 @@ const serialize = sort => {
|
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
98
|
}
|
|
99
|
+
const mapF = map(f)
|
|
93
100
|
/** @type {(input: Array) => list.List<string>} */
|
|
94
|
-
const arraySerialize = compose(
|
|
101
|
+
const arraySerialize = compose(mapF)(arrayWrap)
|
|
95
102
|
return f
|
|
96
103
|
}
|
|
97
104
|
|
|
@@ -101,7 +108,7 @@ const serialize = sort => {
|
|
|
101
108
|
*
|
|
102
109
|
* @type {(mapEntries: MapEntries) => (value: Unknown) => string}
|
|
103
110
|
*/
|
|
104
|
-
const stringify = sort => compose(serialize(sort))(
|
|
111
|
+
const stringify = sort => compose(serialize(sort))(stringConcat)
|
|
105
112
|
|
|
106
113
|
/** @type {(value: string) => Unknown} */
|
|
107
114
|
const parse = JSON.parse
|