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 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 [Object.getOwnPropertyDescriptor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor) function.
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.402",
3
+ "version": "0.0.405",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
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 = a => (smallSigma1(a[0]) + a[1] + smallSigma0(a[2]) + a[3]) | 0
78
-
79
- /** @type {(input: Array16) => Array16} */
80
- const nextW = w => {
81
- const _0 = wi([w[14], w[ 9], w[ 1], w[ 0]])
82
- const _1 = wi([w[15], w[10], w[ 2], w[ 1]])
83
- const _2 = wi([ _0, w[11], w[ 3], w[ 2]])
84
- const _3 = wi([ _1, w[12], w[ 4], w[ 3]])
85
- const _4 = wi([ _2, w[13], w[ 5], w[ 4]])
86
- const _5 = wi([ _3, w[14], w[ 6], w[ 5]])
87
- const _6 = wi([ _4, w[15], w[ 7], w[ 6]])
88
- const _7 = wi([ _5, _0, w[ 8], w[ 7]])
89
- const _8 = wi([ _6, _1, w[ 9], w[ 8]])
90
- const _9 = wi([ _7, _2, w[10], w[ 9]])
91
- const _A = wi([ _8, _3, w[11], w[10]])
92
- const _B = wi([ _9, _4, w[12], w[11]])
93
- const _C = wi([ _A, _5, w[13], w[12]])
94
- const _D = wi([ _B, _6, w[14], w[13]])
95
- const _E = wi([ _C, _7, w[15], w[14]])
96
- const _F = wi([ _D, _8, _0, w[15]])
97
- return [_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _A, _B, _C, _D, _E, _F]
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 = init => data => {
101
+ const compress = ([a0, b0, c0, d0, e0, f0, g0, h0]) => data => {
102
102
  let w = data
103
103
 
104
- let a = init[0]
105
- let b = init[1]
106
- let c = init[2]
107
- let d = init[3]
108
- let e = init[4]
109
- let f = init[5]
110
- let g = init[6]
111
- let h = init[7]
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
- (init[0] + a) | 0,
132
- (init[1] + b) | 0,
133
- (init[2] + c) | 0,
134
- (init[3] + d) | 0,
135
- (init[4] + e) | 0,
136
- (init[5] + f) | 0,
137
- (init[6] + g) | 0,
138
- (init[7] + h) | 0,
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
 
@@ -1,5 +1,6 @@
1
1
  const list = require('../list/module.f.cjs')
2
- const option = require('../option/module.f.cjs')
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 list.flat([
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 list.flat([
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 = option.map(nodeValues)
30
+ const values = map(nodeValues)
30
31
 
31
32
  module.exports = {
32
33
  /** @readonly */
@@ -1,13 +1,14 @@
1
1
  const btreeTypes = require('../btree/types/module.f.cjs')
2
- const { values } = require("../btree/module.f.cjs")
3
- const btreeFind = require('../btree/find/module.f.cjs')
4
- const { value, find } = btreeFind
5
- const btreeSet = require('../btree/set/module.f.cjs').set
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>(o: operator.Reduce<T>) => (entry: Entry<T>) => (map: Map<T>) => Map<T>} */
41
- const setUpdateEntry = o => entry => btreeSet(keyCmp(entry[0]))(old => old === undefined ? entry : [old[0], o(old[1])(entry[1])])
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>(o: operator.Reduce<T>) => (name: string) => (value: T) => (map: Map<T>) => Map<T>} */
44
- const setUpdate = o => name => value => setUpdateEntry(o)([name, value])
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 => setUpdateEntry(replace)([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(setUpdateEntry(replace))(undefined)
57
+ const fromEntries = fold(setReduceEntry(replace))(undefined)
57
58
 
58
59
  /** @type {(name: string) => <T>(map: Map<T>) => Map<T>} */
59
- const remove = name => btreeRemove(keyCmp(name))
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
- setUpdate,
68
+ setReduce,
68
69
  /** @readonly */
69
70
  setReplace,
70
71
  /** @readonly */
@@ -1,4 +1,4 @@
1
- const { at, setReplace, setUpdate, empty, entries, remove } = require('./module.f.cjs')
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 = setUpdate(a => b => a + b)('a')(43)(m)
44
+ m = setReduce(a => b => a + b)('a')(43)(m)
45
45
  if (at('a')(m) !== 44) { throw 'error' }
46
46
  }
47
47