functionalscript 0.0.402 → 0.0.405
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/README.md +1 -1
- package/{LANGUAGE.md → doc/LANGUAGE.md} +7 -1
- package/doc/predefined.md +143 -0
- package/package.json +1 -1
- package/sha2/module.f.cjs +38 -38
- package/types/btree/module.f.cjs +5 -4
- package/types/map/module.f.cjs +17 -16
- package/types/map/test.f.cjs +2 -2
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ FunctionalScript is a purely functional programming language and a strict subset
|
|
|
7
7
|
- [asm.JS](https://en.wikipedia.org/wiki/Asm.js)/[WebAssembly](https://en.wikipedia.org/wiki/WebAssembly), as a subset of JavaScript.
|
|
8
8
|
- [TypeScript](https://en.wikipedia.org/wiki/TypeScript), as a superset of JavaScript.
|
|
9
9
|
|
|
10
|
-
[A brief description of FunctionalScript Programming Language](./LANGUAGE.md).
|
|
10
|
+
[A brief description of FunctionalScript Programming Language](./doc/LANGUAGE.md).
|
|
11
11
|
|
|
12
12
|
Create a new FunctionalScript repository on GitHub [here](https://github.com/functionalscript/template/generate).
|
|
13
13
|
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# FunctionalScript Programming Language
|
|
2
2
|
|
|
3
|
+
Principals:
|
|
4
|
+
- FunctionalScript VM should behaves the same way as a JavaScript VM
|
|
5
|
+
- Any unsupported feature should be reported at compile-time.
|
|
6
|
+
|
|
3
7
|
## 1. Module Ecosystem
|
|
4
8
|
|
|
5
9
|
FunctionalScript uses [CommonJS](https://en.wikipedia.org/wiki/CommonJS) conventions as a module ecosystem. For example,
|
|
@@ -139,7 +143,9 @@ Expressions could fall under these categories:
|
|
|
139
143
|
- Relations Operators: `in`, `instanceof`.
|
|
140
144
|
- Member Operators: `.`, `[]`.
|
|
141
145
|
|
|
142
|
-
**Note:** the `.` member operator has prohibited property names, such as `constructor` and `push`. To access such properties, it's recommended to use the
|
|
146
|
+
**Note:** the `.` member operator has prohibited property names, such as `constructor` and `push`. To access such properties, it's recommended to use the
|
|
147
|
+
[Object.getOwnPropertyDescriptor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor) function.
|
|
148
|
+
`[]` accepts only numbers. For example `+'0'`
|
|
143
149
|
|
|
144
150
|
## 8. Arrow Functions
|
|
145
151
|
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Predefined Object And Properties
|
|
2
|
+
|
|
3
|
+
## Global Objects
|
|
4
|
+
|
|
5
|
+
Global objects. Global objects can't be assigned to something `const r = Object`. They can only be used as namespaces `Object.getOwnProperties()`.
|
|
6
|
+
|
|
7
|
+
### Value properties
|
|
8
|
+
|
|
9
|
+
- [x] `Infinity`
|
|
10
|
+
- [x] `NaN`
|
|
11
|
+
- [x] `undefined`
|
|
12
|
+
- [ ] `globalThis`
|
|
13
|
+
|
|
14
|
+
### Function properties
|
|
15
|
+
|
|
16
|
+
- [ ] `eval`
|
|
17
|
+
- [x] `isFinite()`
|
|
18
|
+
- [x] `isNan()`
|
|
19
|
+
- [x] `parseFloat()`
|
|
20
|
+
- [x] `parseInt()`
|
|
21
|
+
- [ ] `encodeURI()`
|
|
22
|
+
- [ ] `encodeURIComponent()`
|
|
23
|
+
- [ ] `decodeURI()`
|
|
24
|
+
- [ ] `decodeURIComponent()`
|
|
25
|
+
|
|
26
|
+
### Fundamental objects
|
|
27
|
+
|
|
28
|
+
- [x] `Object`. For example `Object.entries`, `Object.fromEntries`.
|
|
29
|
+
- [ ] `Function`
|
|
30
|
+
- [ ] `Boolean`
|
|
31
|
+
- [ ] `Symbol`
|
|
32
|
+
|
|
33
|
+
### Error objects
|
|
34
|
+
|
|
35
|
+
- [ ] `Number`
|
|
36
|
+
- [ ] `BigInt`
|
|
37
|
+
- [ ] `Math`
|
|
38
|
+
- [ ] `Date`
|
|
39
|
+
|
|
40
|
+
### Text processing
|
|
41
|
+
|
|
42
|
+
- [ ] `String`
|
|
43
|
+
- [ ] `RegExp`
|
|
44
|
+
|
|
45
|
+
### Indexed collections:
|
|
46
|
+
|
|
47
|
+
- [x] `Array`. For example `x instanceof Array`
|
|
48
|
+
- [ ] `Int8Array`
|
|
49
|
+
- [ ] `UInt8Array`
|
|
50
|
+
- [ ] `UInt8ClampedArray`
|
|
51
|
+
- [ ] `Int16Array`
|
|
52
|
+
- [ ] `UInt16Array`
|
|
53
|
+
- [ ] `Int32Array`
|
|
54
|
+
- [ ] `UInt32Array`
|
|
55
|
+
- [ ] `Float32Array`
|
|
56
|
+
- [ ] `Float64Array`
|
|
57
|
+
- [ ] `BigInt64Array`
|
|
58
|
+
- [ ] `BigUint64Array`
|
|
59
|
+
|
|
60
|
+
### Keyed collections:
|
|
61
|
+
|
|
62
|
+
- [ ] `Map`
|
|
63
|
+
- [ ] `Set`
|
|
64
|
+
- [ ] `WeakMap`
|
|
65
|
+
- [ ] `WeakSet`
|
|
66
|
+
|
|
67
|
+
### Structured data:
|
|
68
|
+
|
|
69
|
+
- [ ] `ArrayBuffer`
|
|
70
|
+
- [ ] `SharedArrayBuffer`
|
|
71
|
+
- [ ] `Atomics`
|
|
72
|
+
- [ ] `DataView`
|
|
73
|
+
- [x] `JSON`. For example `JSON.stringify`
|
|
74
|
+
|
|
75
|
+
### Control abstraction objects
|
|
76
|
+
|
|
77
|
+
- [ ] `Promise`
|
|
78
|
+
- [ ] `Generator`
|
|
79
|
+
- [ ] `GeneratorFunction`
|
|
80
|
+
- [ ] `AsyncFunction`
|
|
81
|
+
- [ ] `AsyncGeneratorFunction`
|
|
82
|
+
|
|
83
|
+
### Reflection
|
|
84
|
+
|
|
85
|
+
- [ ] `Reflect`
|
|
86
|
+
- [ ] `Proxy`
|
|
87
|
+
|
|
88
|
+
### Internalization
|
|
89
|
+
|
|
90
|
+
- [ ] `Intl`
|
|
91
|
+
|
|
92
|
+
### WebAssembly
|
|
93
|
+
|
|
94
|
+
- [ ] `WebAssembly`
|
|
95
|
+
- [ ] `WebAssembly.Module`
|
|
96
|
+
- [ ] `WebAssembly.Instance`
|
|
97
|
+
- [ ] `WebAssembly.Memory`
|
|
98
|
+
- [ ] `WebAssembly.Table`
|
|
99
|
+
- [ ] `WebAssembly.CompileError`
|
|
100
|
+
- [ ] `WebAssembly.LinkError`
|
|
101
|
+
- [ ] `WebAssembly.RuntimeError`
|
|
102
|
+
|
|
103
|
+
## Prohibited Properties
|
|
104
|
+
|
|
105
|
+
Allowed types:
|
|
106
|
+
|
|
107
|
+
- object `{}`
|
|
108
|
+
- `null` has no properties
|
|
109
|
+
- array `[]`
|
|
110
|
+
- number `-3`
|
|
111
|
+
- bigint `42n`
|
|
112
|
+
- string `"xx"`
|
|
113
|
+
- boolean `true`
|
|
114
|
+
- function `x => x * x`
|
|
115
|
+
- `undefined` has no properties
|
|
116
|
+
|
|
117
|
+
### Object
|
|
118
|
+
|
|
119
|
+
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
120
|
+
|
|
121
|
+
- [ ] ! `constructor`. The property can create a new function. For example
|
|
122
|
+
```js
|
|
123
|
+
const f = (() => undefined).constructor('a', 'return a * a')
|
|
124
|
+
```
|
|
125
|
+
- [ ] deprecated `__proto__`
|
|
126
|
+
- [ ] ! deprecated `__defineGetter__`. The property can mutate an object.
|
|
127
|
+
- [ ] ! deprecated `__defineSetter__`. The property can mutate an object.
|
|
128
|
+
- [ ] deprecated `__lookupGetter__`
|
|
129
|
+
- [ ] deprecated `__lookupSetter__`
|
|
130
|
+
|
|
131
|
+
### Array
|
|
132
|
+
|
|
133
|
+
These properties can mutate an array:
|
|
134
|
+
|
|
135
|
+
- [ ] ! `copyWithin`.
|
|
136
|
+
- [ ] ! `fill`
|
|
137
|
+
- [ ] ! `pop`
|
|
138
|
+
- [ ] ! `push`
|
|
139
|
+
- [ ] ! `reverse`
|
|
140
|
+
- [ ] ! `shift`
|
|
141
|
+
- [ ] ! `sort`
|
|
142
|
+
- [ ] ! `splice`
|
|
143
|
+
- [ ] ! `unshift`
|
package/package.json
CHANGED
package/sha2/module.f.cjs
CHANGED
|
@@ -74,41 +74,41 @@ const smallSigma0 = smallSigma(7)(18)(3)
|
|
|
74
74
|
const smallSigma1 = smallSigma(17)(19)(10)
|
|
75
75
|
|
|
76
76
|
/** @type {(a: array.Array4<number>) => number} */
|
|
77
|
-
const wi =
|
|
78
|
-
|
|
79
|
-
/** @type {(
|
|
80
|
-
const nextW =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return [
|
|
77
|
+
const wi = ([a0, a1, a2, a3]) => (smallSigma1(a0) + a1 + smallSigma0(a2) + a3) | 0
|
|
78
|
+
|
|
79
|
+
/** @type {(w: Array16) => Array16} */
|
|
80
|
+
const nextW = ([w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, wA, wB, wC, wD, wE, wF]) => {
|
|
81
|
+
w0 = wi([wE, w9, w1, w0])
|
|
82
|
+
w1 = wi([wF, wA, w2, w1])
|
|
83
|
+
w2 = wi([w0, wB, w3, w2])
|
|
84
|
+
w3 = wi([w1, wC, w4, w3])
|
|
85
|
+
w4 = wi([w2, wD, w5, w4])
|
|
86
|
+
w5 = wi([w3, wE, w6, w5])
|
|
87
|
+
w6 = wi([w4, wF, w7, w6])
|
|
88
|
+
w7 = wi([w5, w0, w8, w7])
|
|
89
|
+
w8 = wi([w6, w1, w9, w8])
|
|
90
|
+
w9 = wi([w7, w2, wA, w9])
|
|
91
|
+
wA = wi([w8, w3, wB, wA])
|
|
92
|
+
wB = wi([w9, w4, wC, wB])
|
|
93
|
+
wC = wi([wA, w5, wD, wC])
|
|
94
|
+
wD = wi([wB, w6, wE, wD])
|
|
95
|
+
wE = wi([wC, w7, wF, wE])
|
|
96
|
+
wF = wi([wD, w8, w0, wF])
|
|
97
|
+
return [w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, wA, wB, wC, wD, wE, wF]
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
/** @type {(init: Hash8) => (data: Array16) => Hash8} */
|
|
101
|
-
const compress =
|
|
101
|
+
const compress = ([a0, b0, c0, d0, e0, f0, g0, h0]) => data => {
|
|
102
102
|
let w = data
|
|
103
103
|
|
|
104
|
-
let a =
|
|
105
|
-
let b =
|
|
106
|
-
let c =
|
|
107
|
-
let d =
|
|
108
|
-
let e =
|
|
109
|
-
let f =
|
|
110
|
-
let g =
|
|
111
|
-
let h =
|
|
104
|
+
let a = a0
|
|
105
|
+
let b = b0
|
|
106
|
+
let c = c0
|
|
107
|
+
let d = d0
|
|
108
|
+
let e = e0
|
|
109
|
+
let f = f0
|
|
110
|
+
let g = g0
|
|
111
|
+
let h = h0
|
|
112
112
|
|
|
113
113
|
for (let i = 0; i < 4; ++i) {
|
|
114
114
|
const ki = k[i]
|
|
@@ -128,14 +128,14 @@ const compress = init => data => {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
return [
|
|
131
|
-
(
|
|
132
|
-
(
|
|
133
|
-
(
|
|
134
|
-
(
|
|
135
|
-
(
|
|
136
|
-
(
|
|
137
|
-
(
|
|
138
|
-
(
|
|
131
|
+
(a0 + a) | 0,
|
|
132
|
+
(b0 + b) | 0,
|
|
133
|
+
(c0 + c) | 0,
|
|
134
|
+
(d0 + d) | 0,
|
|
135
|
+
(e0 + e) | 0,
|
|
136
|
+
(f0 + f) | 0,
|
|
137
|
+
(g0 + g) | 0,
|
|
138
|
+
(h0 + h) | 0,
|
|
139
139
|
]
|
|
140
140
|
}
|
|
141
141
|
|
package/types/btree/module.f.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const list = require('../list/module.f.cjs')
|
|
2
|
-
const
|
|
2
|
+
const { flat } = list
|
|
3
|
+
const { map } = require('../option/module.f.cjs')
|
|
3
4
|
const _ = require('./types/module.f.cjs')
|
|
4
5
|
|
|
5
6
|
/** @type {<T>(node: _.Node<T>) => list.Thunk<T>} */
|
|
@@ -7,14 +8,14 @@ const nodeValues = node => () => {
|
|
|
7
8
|
switch (node.length) {
|
|
8
9
|
case 1: case 2: { return node }
|
|
9
10
|
case 3: {
|
|
10
|
-
return
|
|
11
|
+
return flat([
|
|
11
12
|
nodeValues(node[0]),
|
|
12
13
|
[node[1]],
|
|
13
14
|
nodeValues(node[2])
|
|
14
15
|
])
|
|
15
16
|
}
|
|
16
17
|
default: {
|
|
17
|
-
return
|
|
18
|
+
return flat([
|
|
18
19
|
nodeValues(node[0]),
|
|
19
20
|
[node[1]],
|
|
20
21
|
nodeValues(node[2]),
|
|
@@ -26,7 +27,7 @@ const nodeValues = node => () => {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
/** @type {<T>(tree: _.Tree<T>) => list.List<T>} */
|
|
29
|
-
const values =
|
|
30
|
+
const values = map(nodeValues)
|
|
30
31
|
|
|
31
32
|
module.exports = {
|
|
32
33
|
/** @readonly */
|
package/types/map/module.f.cjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
const btreeTypes = require('../btree/types/module.f.cjs')
|
|
2
|
-
const {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const {
|
|
3
|
+
values,
|
|
4
|
+
find: { value, find },
|
|
5
|
+
set: { set },
|
|
6
|
+
remove: { remove: btreeRemove }
|
|
7
|
+
} = require("../btree/module.f.cjs")
|
|
6
8
|
const compare = require('../function/compare/module.f.cjs')
|
|
7
9
|
const { cmp } = require('../string/module.f.cjs')
|
|
8
10
|
const list = require('../list/module.f.cjs')
|
|
9
11
|
const { fold } = list
|
|
10
|
-
const { remove: btreeRemove } = require('../btree/remove/module.f.cjs')
|
|
11
12
|
const operator = require('../function/operator/module.f.cjs')
|
|
12
13
|
|
|
13
14
|
/** @typedef {compare.Sign} Sign */
|
|
@@ -37,26 +38,26 @@ const at = name => map => {
|
|
|
37
38
|
return result === undefined ? undefined : result[1]
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
/** @type {<T>(
|
|
41
|
-
const
|
|
41
|
+
/** @type {<T>(reduce: operator.Reduce<T>) => (entry: Entry<T>) => (map: Map<T>) => Map<T>} */
|
|
42
|
+
const setReduceEntry = reduce => entry => set(keyCmp(entry[0]))(old => old === undefined ? entry : [old[0], reduce(old[1])(entry[1])])
|
|
42
43
|
|
|
43
|
-
/** @type {<T>(
|
|
44
|
-
const
|
|
44
|
+
/** @type {<T>(reduce: operator.Reduce<T>) => (name: string) => (value: T) => (map: Map<T>) => Map<T>} */
|
|
45
|
+
const setReduce = reduce => name => value => setReduceEntry(reduce)([name, value])
|
|
46
|
+
|
|
47
|
+
/** @type {<T>(a: T) => (b: T) => T} */
|
|
48
|
+
const replace = () => b => b
|
|
45
49
|
|
|
46
50
|
/** @type {(name: string) => <T>(value: T) => (map: Map<T>) => Map<T>} */
|
|
47
|
-
const setReplace = name => value =>
|
|
51
|
+
const setReplace = name => value => setReduceEntry(replace)([name, value])
|
|
48
52
|
|
|
49
53
|
/** @type {<T>(map: Map<T>) => list.List<Entry<T>>} */
|
|
50
54
|
const entries = values
|
|
51
55
|
|
|
52
|
-
/** @type {<T>(a: T) => (b: T) => T} */
|
|
53
|
-
const replace = () => b => b
|
|
54
|
-
|
|
55
56
|
/** @type {<T>(entries: list.List<Entry<T>>) => Map<T>} */
|
|
56
|
-
const fromEntries = fold(
|
|
57
|
+
const fromEntries = fold(setReduceEntry(replace))(undefined)
|
|
57
58
|
|
|
58
59
|
/** @type {(name: string) => <T>(map: Map<T>) => Map<T>} */
|
|
59
|
-
const remove =
|
|
60
|
+
const remove = name => btreeRemove(keyCmp(name))
|
|
60
61
|
|
|
61
62
|
module.exports = {
|
|
62
63
|
/** @readonly */
|
|
@@ -64,7 +65,7 @@ module.exports = {
|
|
|
64
65
|
/** @readonly */
|
|
65
66
|
at,
|
|
66
67
|
/** @readonly */
|
|
67
|
-
|
|
68
|
+
setReduce,
|
|
68
69
|
/** @readonly */
|
|
69
70
|
setReplace,
|
|
70
71
|
/** @readonly */
|
package/types/map/test.f.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { at, setReplace,
|
|
1
|
+
const { at, setReplace, setReduce, empty, entries, remove } = require('./module.f.cjs')
|
|
2
2
|
const seq = require('../list/module.f.cjs')
|
|
3
3
|
|
|
4
4
|
{
|
|
@@ -41,7 +41,7 @@ const seq = require('../list/module.f.cjs')
|
|
|
41
41
|
m = remove('Hello world!')(m)
|
|
42
42
|
if (at('Hello world!')(m) !== undefined) { throw m }
|
|
43
43
|
|
|
44
|
-
m =
|
|
44
|
+
m = setReduce(a => b => a + b)('a')(43)(m)
|
|
45
45
|
if (at('a')(m) !== 44) { throw 'error' }
|
|
46
46
|
}
|
|
47
47
|
|