functionalscript 0.1.608 → 0.2.0

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 (222) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/Cargo.lock +4 -0
  3. package/Cargo.toml +4 -2
  4. package/README.md +1 -1
  5. package/com/cpp/module.f.d.mts +4 -8
  6. package/com/cpp/module.f.mjs +20 -25
  7. package/com/cpp/testlib.f.mjs +3 -4
  8. package/com/cs/module.f.d.mts +4 -8
  9. package/com/cs/module.f.mjs +18 -23
  10. package/com/cs/testlib.f.mjs +3 -5
  11. package/com/rust/module.f.d.mts +3 -7
  12. package/com/rust/module.f.mjs +25 -30
  13. package/com/rust/nanocom/src/cobject.rs +1 -1
  14. package/com/rust/testlib.f.mjs +3 -5
  15. package/com/test/build.f.d.mts +2 -2
  16. package/com/test/build.f.mjs +2 -2
  17. package/com/test/build.mjs +4 -4
  18. package/com/test/rust/src/lib.rs +4 -4
  19. package/com/types/module.f.d.mts +5 -10
  20. package/com/types/module.f.mjs +5 -12
  21. package/commonjs/build/module.f.d.mts +13 -17
  22. package/commonjs/build/module.f.mjs +23 -28
  23. package/commonjs/build/test.f.mjs +4 -4
  24. package/commonjs/module/function/module.f.d.mts +0 -2
  25. package/commonjs/module/function/module.f.mjs +0 -2
  26. package/commonjs/module/module.f.d.mts +16 -21
  27. package/commonjs/module/module.f.mjs +2 -9
  28. package/commonjs/module.d.mts +1 -5
  29. package/commonjs/module.f.d.mts +0 -2
  30. package/commonjs/module.f.mjs +0 -2
  31. package/commonjs/module.mjs +2 -7
  32. package/commonjs/package/dependencies/module.f.d.mts +3 -7
  33. package/commonjs/package/dependencies/module.f.mjs +5 -10
  34. package/commonjs/package/dependencies/test.f.mjs +1 -1
  35. package/commonjs/package/module.f.d.mts +12 -18
  36. package/commonjs/package/module.f.mjs +6 -13
  37. package/commonjs/package/test.f.mjs +1 -1
  38. package/commonjs/path/module.f.d.mts +25 -32
  39. package/commonjs/path/module.f.mjs +12 -23
  40. package/commonjs/path/test.f.mjs +11 -11
  41. package/commonjs/test.mjs +1 -1
  42. package/dev/module.f.d.mts +1 -4
  43. package/dev/module.f.mjs +1 -4
  44. package/dev/module.mjs +1 -1
  45. package/dev/test/module.f.d.mts +2 -3
  46. package/dev/test/module.f.mjs +5 -7
  47. package/djs/module.f.d.mts +13 -18
  48. package/djs/module.f.mjs +12 -19
  49. package/djs/parser/module.f.d.mts +53 -37
  50. package/djs/parser/module.f.mjs +278 -131
  51. package/djs/parser/test.f.d.mts +4 -0
  52. package/djs/parser/test.f.mjs +186 -70
  53. package/djs/test.f.mjs +4 -4
  54. package/djs/tokenizer/module.f.d.mts +6 -10
  55. package/djs/tokenizer/module.f.mjs +19 -22
  56. package/djs/tokenizer/test.f.mjs +7 -7
  57. package/doc/LANGUAGE.md +17 -16
  58. package/doc/README.md +14 -50
  59. package/fsc/README.md +0 -3
  60. package/fsc/module.f.d.mts +4 -9
  61. package/fsc/module.f.mjs +17 -24
  62. package/fsc/test.f.mjs +3 -3
  63. package/fsm/README.md +1 -1
  64. package/fsm/module.f.d.mts +13 -20
  65. package/fsm/module.f.mjs +27 -38
  66. package/fsm/test.f.mjs +8 -8
  67. package/html/README.md +24 -0
  68. package/html/module.f.d.mts +7 -12
  69. package/html/module.f.mjs +14 -23
  70. package/html/test.f.mjs +4 -4
  71. package/issues/01-test-debug.md +3 -0
  72. package/issues/{publish.md → 05-publish.md} +8 -8
  73. package/issues/17-djs-extension.md +6 -0
  74. package/issues/README.md +20 -13
  75. package/issues/lang/1000-json.md +38 -0
  76. package/issues/lang/2110-default-export.md +2 -2
  77. package/issues/lang/2310-undefined.md +1 -1
  78. package/issues/lang/2330-property-accessor.md +225 -0
  79. package/issues/lang/2360-built-in.md +54 -47
  80. package/issues/lang/3240-export.md +44 -0
  81. package/issues/lang/README.md +64 -22
  82. package/issues/test.f.d.mts +16 -0
  83. package/issues/test.f.mjs +57 -0
  84. package/js/tokenizer/module.f.d.mts +18 -17
  85. package/js/tokenizer/module.f.mjs +80 -61
  86. package/js/tokenizer/test.f.mjs +15 -12
  87. package/json/module.f.d.mts +18 -26
  88. package/json/module.f.mjs +18 -31
  89. package/json/parser/module.f.d.mts +9 -13
  90. package/json/parser/module.f.mjs +9 -14
  91. package/json/parser/test.f.mjs +7 -7
  92. package/json/serializer/module.f.d.mts +11 -20
  93. package/json/serializer/module.f.mjs +14 -29
  94. package/json/serializer/test.f.mjs +2 -2
  95. package/json/test.f.mjs +3 -3
  96. package/json/tokenizer/module.f.d.mts +6 -10
  97. package/json/tokenizer/module.f.mjs +16 -20
  98. package/json/tokenizer/test.f.mjs +6 -6
  99. package/jsr.json +1 -1
  100. package/nanvm-lib/Cargo.toml +6 -0
  101. package/nanvm-lib/src/extension.rs +119 -0
  102. package/nanvm-lib/src/interface.rs +136 -0
  103. package/nanvm-lib/src/lib.rs +7 -0
  104. package/nanvm-lib/src/naive.rs +229 -0
  105. package/nanvm-lib/src/nanenum.rs +230 -0
  106. package/nanvm-lib/src/nullish.rs +7 -0
  107. package/nanvm-lib/src/sign.rs +5 -0
  108. package/nanvm-lib/src/simple.rs +32 -0
  109. package/nanvm-lib/tests/test.f.d.mts +36 -0
  110. package/nanvm-lib/tests/test.f.mjs +79 -0
  111. package/nanvm-lib/tests/test.rs +108 -0
  112. package/nodejs/version/main.mjs +1 -1
  113. package/nodejs/version/module.f.d.mts +4 -9
  114. package/nodejs/version/module.f.mjs +2 -7
  115. package/nodejs/version/test.f.mjs +3 -3
  116. package/package.json +1 -1
  117. package/prime_field/module.f.d.mts +20 -23
  118. package/prime_field/module.f.mjs +9 -12
  119. package/prime_field/test.f.mjs +1 -1
  120. package/secp/module.f.d.mts +27 -28
  121. package/secp/module.f.mjs +38 -39
  122. package/secp/test.f.mjs +4 -4
  123. package/sha2/module.f.d.mts +8 -16
  124. package/sha2/module.f.mjs +7 -20
  125. package/sha2/test.f.mjs +4 -4
  126. package/text/README.md +2 -2
  127. package/text/ascii/module.f.d.mts +69 -72
  128. package/text/ascii/module.f.mjs +5 -10
  129. package/text/ascii/test.f.mjs +3 -3
  130. package/text/module.f.d.mts +9 -14
  131. package/text/module.f.mjs +7 -14
  132. package/text/sgr/module.f.d.mts +7 -9
  133. package/text/sgr/module.f.mjs +2 -4
  134. package/text/test.f.mjs +3 -3
  135. package/text/utf16/module.f.d.mts +8 -15
  136. package/text/utf16/module.f.mjs +17 -28
  137. package/text/utf16/test.f.mjs +5 -5
  138. package/text/utf8/module.f.d.mts +4 -9
  139. package/text/utf8/module.f.mjs +9 -16
  140. package/text/utf8/test.f.mjs +4 -4
  141. package/types/array/module.f.d.mts +14 -24
  142. package/types/array/module.f.mjs +8 -25
  143. package/types/array/test.f.mjs +3 -3
  144. package/types/bigfloat/module.f.d.mts +4 -9
  145. package/types/bigfloat/module.f.mjs +3 -10
  146. package/types/bigfloat/test.f.mjs +1 -1
  147. package/types/bigint/module.f.d.mts +16 -64
  148. package/types/bigint/module.f.mjs +11 -30
  149. package/types/bigint/test.f.mjs +1 -1
  150. package/types/btree/find/module.f.d.mts +20 -26
  151. package/types/btree/find/module.f.mjs +8 -17
  152. package/types/btree/find/test.f.mjs +7 -7
  153. package/types/btree/module.f.d.mts +4 -8
  154. package/types/btree/module.f.mjs +6 -11
  155. package/types/btree/remove/module.f.d.mts +7 -12
  156. package/types/btree/remove/module.f.mjs +10 -17
  157. package/types/btree/remove/test.f.mjs +5 -5
  158. package/types/btree/set/module.f.d.mts +3 -7
  159. package/types/btree/set/module.f.mjs +4 -9
  160. package/types/btree/set/test.f.mjs +4 -4
  161. package/types/btree/test.f.mjs +9 -9
  162. package/types/btree/types/module.f.d.mts +0 -2
  163. package/types/btree/types/module.f.mjs +0 -2
  164. package/types/byte_set/module.f.d.mts +16 -29
  165. package/types/byte_set/module.f.mjs +14 -39
  166. package/types/byte_set/test.f.mjs +5 -5
  167. package/types/function/compare/module.f.d.mts +9 -15
  168. package/types/function/compare/module.f.mjs +3 -12
  169. package/types/function/compare/test.f.mjs +1 -1
  170. package/types/function/module.f.d.mts +20 -27
  171. package/types/function/module.f.mjs +4 -15
  172. package/types/function/operator/module.f.d.mts +28 -43
  173. package/types/function/operator/module.f.mjs +14 -41
  174. package/types/function/test.f.mjs +1 -1
  175. package/types/list/module.f.d.mts +56 -91
  176. package/types/list/module.f.mjs +45 -114
  177. package/types/list/test.f.mjs +10 -10
  178. package/types/map/module.f.d.mts +15 -24
  179. package/types/map/module.f.mjs +15 -30
  180. package/types/map/test.f.mjs +2 -2
  181. package/types/nibble_set/module.f.d.mts +10 -20
  182. package/types/nibble_set/module.f.mjs +7 -24
  183. package/types/nibble_set/test.f.mjs +2 -2
  184. package/types/nullable/module.f.d.mts +3 -8
  185. package/types/nullable/module.f.mjs +2 -9
  186. package/types/nullable/test.f.mjs +1 -1
  187. package/types/number/module.f.d.mts +7 -13
  188. package/types/number/module.f.mjs +8 -19
  189. package/types/number/test.f.mjs +1 -1
  190. package/types/object/module.f.d.mts +11 -18
  191. package/types/object/module.f.mjs +9 -20
  192. package/types/object/test.f.mjs +1 -1
  193. package/types/range/module.f.d.mts +3 -8
  194. package/types/range/module.f.mjs +2 -9
  195. package/types/range/test.f.mjs +1 -1
  196. package/types/range_map/module.f.d.mts +9 -15
  197. package/types/range_map/module.f.mjs +9 -18
  198. package/types/range_map/test.f.mjs +32 -32
  199. package/types/result/module.d.mts +3 -3
  200. package/types/result/module.f.d.mts +6 -12
  201. package/types/result/module.f.mjs +3 -12
  202. package/types/result/module.mjs +2 -2
  203. package/types/sorted_list/module.f.d.mts +22 -28
  204. package/types/sorted_list/module.f.mjs +10 -19
  205. package/types/sorted_list/test.f.mjs +7 -7
  206. package/types/sorted_set/module.f.d.mts +6 -12
  207. package/types/sorted_set/module.f.mjs +7 -16
  208. package/types/sorted_set/test.f.mjs +7 -7
  209. package/types/string/module.f.d.mts +8 -14
  210. package/types/string/module.f.mjs +10 -21
  211. package/types/string/test.f.mjs +2 -2
  212. package/types/string_set/module.f.d.mts +8 -16
  213. package/types/string_set/module.f.mjs +12 -27
  214. package/types/string_set/test.f.mjs +1 -1
  215. package/issues/lang/2351-property-accessor.md +0 -44
  216. package/issues/lang/2352-property-call.md +0 -43
  217. package/issues/lang/2353-property-at.md +0 -19
  218. package/issues/test-debug.md +0 -12
  219. /package/issues/{esm.md → 02-esm.md} +0 -0
  220. /package/issues/{djs.md → 03-djs.md} +0 -0
  221. /package/issues/{fs-load.md → 11-fs-load.md} +0 -0
  222. /package/issues/lang/{2330-grouping.md → 2350-grouping.md} +0 -0
package/html/module.f.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  // @ts-self-types="./module.f.d.mts"
2
- import list, * as List from '../types/list/module.f.mjs'
2
+ import * as list from '../types/list/module.f.mjs'
3
3
  const { map, flatMap, flat, concat: listConcat } = list
4
- import s from '../types/string/module.f.mjs'
4
+ import * as s from '../types/string/module.f.mjs'
5
5
  const { concat: stringConcat } = s
6
6
  import * as O from '../types/object/module.f.mjs'
7
- import f from '../types/function/module.f.mjs'
7
+ import * as f from '../types/function/module.f.mjs'
8
8
  const { compose } = f
9
- import utf16 from '../text/utf16/module.f.mjs'
9
+ import * as utf16 from '../text/utf16/module.f.mjs'
10
10
  const { stringToList } = utf16
11
11
  const { fromCharCode } = String
12
12
  const { entries } = Object
@@ -50,7 +50,7 @@ const isVoid = tag => voidTagList.includes(tag)
50
50
  * }} Attributes
51
51
  */
52
52
 
53
- /** @typedef {List.List<Node>} Nodes */
53
+ /** @typedef {list.List<Node>} Nodes */
54
54
 
55
55
  /** @typedef {Element | string} Node */
56
56
 
@@ -71,33 +71,33 @@ const escapeCharCode = code => {
71
71
 
72
72
  const escape = compose(stringToList)(map(escapeCharCode))
73
73
 
74
- /** @type {(n: Node) => List.List<string>} */
74
+ /** @type {(n: Node) => list.List<string>} */
75
75
  const node = n => typeof n === 'string' ? escape(n) : element(n)
76
76
 
77
77
  const nodes = flatMap(node)
78
78
 
79
- /** @type {(a: O.Entry<string>) => List.List<string>} */
79
+ /** @type {(a: O.Entry<string>) => list.List<string>} */
80
80
  const attribute = ([name, value]) => flat([[' ', name, '="'], escape(value), ['"']])
81
81
 
82
- /** @type {(a: Attributes) => List.List<string>} */
82
+ /** @type {(a: Attributes) => list.List<string>} */
83
83
  const attributes = compose(entries)(flatMap(attribute))
84
84
 
85
85
  const open = (/** @type {Element2A} */[tag, a]) => flat([[`<`, tag], attributes(a), [`>`]])
86
86
 
87
87
  const close = (/** @type {string}*/tag) => ['</', tag, '>']
88
88
 
89
- /** @type {(_: Element3) => List.List<string>} */
89
+ /** @type {(_: Element3) => list.List<string>} */
90
90
  const element3 = ([tag, a, ns]) =>
91
91
  flat([open([tag, a]), nodes(ns), close(tag)])
92
92
 
93
- /** @type {(_: Element2A) => List.List<string>} */
93
+ /** @type {(_: Element2A) => list.List<string>} */
94
94
  const element2a = e => {
95
95
  const [tag] = e
96
96
  return flat([open(e), isVoid(tag) ? [] : close(tag)])
97
97
  }
98
98
 
99
- /** @type {(element: Element) => List.List<string>} */
100
- const element = e => {
99
+ /** @type {(element: Element) => list.List<string>} */
100
+ export const element = e => {
101
101
  switch (e.length) {
102
102
  case 1: { return element2a([e[0], {}]) }
103
103
  case 2: {
@@ -112,15 +112,6 @@ const element = e => {
112
112
  }
113
113
  }
114
114
 
115
- const html = compose(element)(listConcat(['<!DOCTYPE html>']))
115
+ export const html = compose(element)(listConcat(['<!DOCTYPE html>']))
116
116
 
117
- const htmlToString = compose(html)(stringConcat)
118
-
119
- export default {
120
- /** @readonly */
121
- element,
122
- /** @readonly */
123
- html,
124
- /** @readonly */
125
- htmlToString,
126
- }
117
+ export const htmlToString = compose(html)(stringConcat)
package/html/test.f.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import _, * as T from './module.f.mjs'
1
+ import * as _ from './module.f.mjs'
2
2
 
3
3
  export default {
4
4
  empty: () => {
@@ -14,19 +14,19 @@ export default {
14
14
  if (r !== '<!DOCTYPE html><area>') { throw r }
15
15
  },
16
16
  some: () => {
17
- /** @type {T.Element} */
17
+ /** @type {_.Element} */
18
18
  const x = ['div', {}, ['<div>&amp;</div>', ['a', { href: 'hello"' }, []]]]
19
19
  const s = _.htmlToString(x)
20
20
  if (s !== '<!DOCTYPE html><div>&lt;div&gt;&amp;amp;&lt;/div&gt;<a href="hello&quot;"></a></div>') { throw s }
21
21
  },
22
22
  some2: () => {
23
- /** @type {T.Element} */
23
+ /** @type {_.Element} */
24
24
  const x = ['div', ['<div>&amp;</div>', ['a', { href: 'hello"' }, []]]]
25
25
  const s = _.htmlToString(x)
26
26
  if (s !== '<!DOCTYPE html><div>&lt;div&gt;&amp;amp;&lt;/div&gt;<a href="hello&quot;"></a></div>') { throw s }
27
27
  },
28
28
  someVoid: () => {
29
- /** @type {T.Element} */
29
+ /** @type {_.Element} */
30
30
  const x = ['div', [['br', {id: '5'}], '<div>&amp;</div>', ['a', { href: 'hello"' }, []]]]
31
31
  const s = _.htmlToString(x)
32
32
  if (s !== '<!DOCTYPE html><div><br id="5">&lt;div&gt;&amp;amp;&lt;/div&gt;<a href="hello&quot;"></a></div>') { throw s }
@@ -0,0 +1,3 @@
1
+ # Allow Debugging During Test Run
2
+
3
+ Limitations: without a parser, we are not able to get full coverage.
@@ -3,19 +3,19 @@
3
3
  We are targeting the following systems:
4
4
 
5
5
  - JS:
6
- - NPM
7
- - JSR
8
- - https://esm.sh/ optional
6
+ - [X] NPM
7
+ - [X] JSR
8
+ - [ ] https://esm.sh/ optional
9
9
  - Rust:
10
- - https://crates.io/
10
+ - [ ] https://crates.io/
11
11
 
12
- ## Creating `./index.f.cjs`
12
+ ## Creating `./index.f.mjs`
13
13
 
14
- Currently, we regenerate [./index.f.cjs](./index.f.cjs) using `npm run index` during CD (publishing). However, we don't check in CI if it was regenerated. The idea is that CI should check if all generated files in Git are updated:
14
+ Currently, we regenerate [./index.f.mjs](./index.f.mjs) using `npm run index` during CD (publishing). However, we don't check in CI if it was regenerated. The idea is that CI should check if all generated files in Git are updated:
15
15
 
16
16
  - [package.json](./package.json) `version` property
17
17
  - [jsr.json](./jsr.json), `version` property
18
- - [index.f.cjs](./index.f.cjs)
18
+ - [index.f.mjs](./index.f.mjs)
19
19
 
20
20
  `version` property should be `version` calculated on a `main` branch.
21
21
 
@@ -25,7 +25,7 @@ We may abandon the idea to publish on every commit on `main`. Instead, we will p
25
25
 
26
26
  Before publishing, we have to be sure that
27
27
 
28
- 1. [index.f.cjs](./index.f.cjs) is up to date
28
+ 1. [index.f.mjs](./index.f.mjs) is up to date
29
29
  2. `version` is updated in [jsr.json](./jsr.json) and [package.json](./package.json).
30
30
 
31
31
  ## CI Jobs
@@ -0,0 +1,6 @@
1
+ # `.d.js` extension conflict
2
+
3
+ We use an extension `.d.js` for data JS files, but if we can't use it for TypeScript files, like `.d.ts` because it means declaration TypeScript files. There are several solutions to the problem:
4
+
5
+ 1. Use only `.f.js` extension but make sure that `export default` has no functions at the end. In this case we can reference `.f.js` files as well to use functions to transform data (preferred).
6
+ 2. Don't use it for TypeScript until we have type annotations in JavaScript.
package/issues/README.md CHANGED
@@ -1,24 +1,31 @@
1
1
  # Issues
2
2
 
3
- 1. [X] [test-debug](./test-debug.md).
4
- 2. [X] [esm](./esm.md)
5
- 3. [ ] [djs](./djs.md)
3
+ 1. [X] [test-debug](./01-test-debug.md).
4
+ 2. [X] [esm](./02-esm.md)
5
+ 3. [ ] [djs](./03-djs.md)
6
6
  4. [ ] VM Rust project
7
- 5. [ ] [publish](publish.md)
7
+ 5. [ ] [publish](./05-publish.md)
8
8
  6. [ ] fix index generation by including sub modules `{ ...m, add: mAdd, remove: mRemove}`.
9
9
  7. [ ] Conventions:
10
+
10
11
  ```js
11
12
  import list, * as List from 'list.mjs'
12
13
  // list is for objects.
13
14
  // List is for types and should be ignored by FJS or errored if used in code.
14
15
  ```
16
+
15
17
  8. Move logic from `.mjs` files to `.f.mjs` files.
16
- 9. Two sets of property filters:
17
- - usage `.b`:
18
- - `constructor`
19
- - ...
20
- - call `.b()`:
21
- - `push`
22
- - ...
23
- 10. [ ] Replace file extensions from `.mjs` to `.js`. Make sure `package.json/type` is equal to `module`. May be later: https://v8.dev/features/modules#mjs
24
- 11. [ ] [fs-load](./fs-load.md)
18
+ 9. [ ] Generating a Website.
19
+ 10. [ ] Short URL table.
20
+ 11. [ ] [fs-load](./11-fs-load.md)
21
+ 12. [ ] Replace file extensions from `.mjs` to `.js`. Make sure `package.json/type` is equal to `module`. May be later: https://v8.dev/features/modules#mjs
22
+ 13. [ ] Docs for JSR. See https://jsr.io/@functionalscript/functionalscript/score
23
+ 14. [ ] Combine `npm run index` and `npm run version`
24
+ 15. [ ] Generate `package.json/exports` instead of `index.f.mjs`.
25
+ 16. [ ] License in JSR file?
26
+ 17. [ ] [djs-extension](./17-djs-extension.md).
27
+ 18. [ ] Formatter for `.f.js` and `.f.ts` files.
28
+ 19. [ ] Convert FunctionalScript code using non-default `export`.
29
+ 20. [ ] Test framework should be able to run a subset of tests.
30
+ 21. [ ] Test Framework silent mode. Show progress and failled tests only.
31
+ 22. [ ] bit sequences based on bigint
@@ -10,3 +10,41 @@ JSON forms a tree of values.
10
10
  ```
11
11
 
12
12
  File extension: `.json`.
13
+
14
+ ## NPN (Normal Polish Notation)
15
+
16
+ We will use [NPN](https://en.wikipedia.org/wiki/Polish_notation) as a command format for our VM because it allows us to allocate required objects during streaming as a stack automata.
17
+
18
+
19
+ ```js
20
+ {2} "a" null "b" [3] -42.5 false "hello"
21
+
22
+ // evolution
23
+ <> {2} "a" null "b" [3] -42.5 false "hello"
24
+ { ?: ?, ?: ? } <{4}> "a" null "b" [3] -42.5 false "hello"
25
+ { "a": ?, ?: ? } <{3}> null "b" [3] -42.5 false "hello"
26
+ { "a": null, ?: ? } <{2}> "b" [3] -42.5 false "hello"
27
+ { "a": null, "b": ? } <{1}> [3] -42.5 false "hello"
28
+ { "a": null, "b": [?, ?, ?] } <{0}[3]> -42.5 false "hello"
29
+ { "a": null, "b": [-42.5, ?, ?] } <{0}[2]> false "hello"
30
+ { "a": null, "b": [-42.5, false, ?] } <{0}[1]> "hello"
31
+ { "a": null, "b": [-42.5, false, "hello"] } <>
32
+ ```
33
+
34
+ ## RPN, just for fun
35
+
36
+ [Reverse Polish Notation](https://en.wikipedia.org/wiki/Reverse_Polish_notation):
37
+
38
+ ```js
39
+ "a" null "b" -42.5 false "hello" [3] {2}
40
+
41
+ // evolution:
42
+ "a" <> null "b" -42.5 false "hello" [3] {2}
43
+ "a" null <> "b" -42.5 false "hello" [3] {2}
44
+ "a" null "b" <> -42.5 false "hello" [3] {2}
45
+ "a" null "b" -42.5 <> false "hello" [3] {2}
46
+ "a" null "b" -42.5 false <> "hello" [3] {2}
47
+ "a" null "b" -42.5 false "hello" <> [3] {2}
48
+ "a" null "b" [-42.5, false, "hello"] <> {2}
49
+ { "a" : null, "b": [-42.5, false, "hello"] } <>
50
+ ```
@@ -1,11 +1,11 @@
1
1
  # Default Export
2
2
 
3
- Parse `export default` and then JSON. This's enough to have the same functionality as JSON.
3
+ Parse `export default` and then JSON. This is enough to have the same functionality as JSON.
4
4
 
5
5
  ```js
6
6
  export default 5
7
7
  ```
8
8
 
9
- Depends on [JSON](./1110-json.md)
9
+ Depends on [JSON](./1000-json.md)
10
10
 
11
11
  See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export#using_the_default_export.
@@ -1,7 +1,7 @@
1
1
  # Undefined Type
2
2
 
3
3
  ```js
4
- export default void 0
4
+ export default undefined
5
5
  ```
6
6
 
7
7
  Depend on [default-export](./2110-default-export.md).
@@ -0,0 +1,225 @@
1
+ # Get Property
2
+
3
+ ```js
4
+ const own_property = a => b => Object.getOwnPropertyDescriptor(obj, property)?.value
5
+ // Or
6
+ const own_property = a => b => Object.hasOwn(obj, property) ? obj[property] : void 0
7
+ ```
8
+
9
+ It's translated into the VM command `own_property`:
10
+
11
+ ```rust
12
+ struct OwnProperty {
13
+ obj: Expression
14
+ property: Expression
15
+ }
16
+ ```
17
+
18
+ ## Instance Property
19
+
20
+ ```js
21
+ obj.property
22
+ obj.['property']
23
+ ```
24
+
25
+ It's translated into the VM command `instance_property`:
26
+
27
+ ```rust
28
+ struct InstanceProperty {
29
+ obj: Expression
30
+ index: u8
31
+ }
32
+ ```
33
+
34
+ If the property name is one of the implemented property names, it should be translated into `index: u8`.
35
+
36
+ If a property name is one of the prohibited property names or one of the method names, then it's a compilation error.
37
+
38
+ All other property names generate `own_property` commands.
39
+
40
+ [Object Instance Properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object#instance_properties),
41
+
42
+ |name |side-effect |
43
+ |-------------|------------------------------|
44
+ |`__proto__` |access to function constructor|
45
+ |`constructor`|access to function constructor|
46
+
47
+ ```js
48
+ const f = () => {}
49
+ {
50
+ const c = f.constructor
51
+ const g = c(`console.log('hello')`)
52
+ g() // side effect
53
+ }
54
+ {
55
+ const p = f.__proto__
56
+ const c = Object.getOwnPropertyDescriptor(p, 'constructor').value
57
+ const g = c(`console.log('hello')`)
58
+ g() // side-effect
59
+ }
60
+ ```
61
+
62
+ [Array Instance Properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#instance_properties).
63
+
64
+ | |name |side-effect|
65
+ |-|--------|-----------|
66
+ |0|`length`|no |
67
+
68
+ [Function Instance Properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function#instance_properties)
69
+
70
+ | |name |side-effect|run-time |
71
+ |-|-------------|-----------|---------|
72
+ | |`arguments` |no |error |
73
+ | |`caller` |no |error |
74
+ | |`displayName`|no | |
75
+ | |`name` |no |error |
76
+ | |`prototype` |no |undefined|
77
+
78
+ ## Instance Method Call
79
+
80
+ ```js
81
+ obj.property(parameters)
82
+ obj.['property'](parameters)
83
+ ```
84
+
85
+ It's translated into VM command `instance_method_call`:
86
+
87
+ ```rust
88
+ struct InstanceMethodCall {
89
+ obj: Expression
90
+ property: String16
91
+ parameters: Array<Expression>
92
+ }
93
+ ```
94
+
95
+ **Note**: All known instance methods can't be used in `instance_property` command! Even if they don't have side effects.
96
+
97
+ [Object Instance Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object#instance_methods)
98
+
99
+ |name |side-effect |
100
+ |----------------------|----------------|
101
+ |`__defineGetter__` |mutate |
102
+ |`__defineSetter__` |mutate |
103
+ |`__lookupGetter__` |'__proto__' |
104
+ |`__lookupSetter__` |'__proto__' |
105
+ |`hasOwnProperty` |no |
106
+ |`isPrototypeOf` |no |
107
+ |`propertyIsEnumerable`|no |
108
+ |`toLocaleString` |access to locale|
109
+ |`toString` |no |
110
+ |`valueOf` |no |
111
+
112
+ [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#instance_methods)
113
+
114
+ |name |side-effect|notes |
115
+ |----------------------|-----------|--------|
116
+ |`at` |no | |
117
+ |`concat` |no | |
118
+ |`copyWith` |no | |
119
+ |`entries` |yes |iterator|
120
+ |`every` |no | |
121
+ |`fill` |yes |mutate |
122
+ |`filter` |no | |
123
+ |`find` |no | |
124
+ |`findIndex` |no | |
125
+ |`findLast` |no | |
126
+ |`findLastIndex` |no | |
127
+ |`flat` |no | |
128
+ |`flatMap` |no | |
129
+ |`forEach` |no | |
130
+ |`includes` |no | |
131
+ |`indexOf` |no | |
132
+ |`join` |no | |
133
+ |`keys` |yes |iterator|
134
+ |`lastIndexOf` |no | |
135
+ |`map` |no | |
136
+ |`pop` |yes |mutate |
137
+ |`push` |yes |mutate |
138
+ |`reduce` |no | |
139
+ |`reduceRight` |no | |
140
+ |`reverse` |yes |mutate |
141
+ |`shift` |yes |mutate |
142
+ |`slice` |no | |
143
+ |`some` |no | |
144
+ |`sort` |yes |mutate |
145
+ |`splice` |yes |mutate |
146
+ |`toReversed` |no | |
147
+ |`toSorted` |no | |
148
+ |`toSpliced` |no | |
149
+ |`unshift` |yes |mutate |
150
+ |`values` |yes |iterator|
151
+ |`with` |no | |
152
+
153
+ [Function Instance Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function#instance_methods)
154
+
155
+ |name |side-effect|notes |
156
+ |-------|-----------|-----------------|
157
+ |`apply`|no |`this` is ignored|
158
+ |`bind` |no |`this` is ignored|
159
+ |`call` |no |`this` is ignored|
160
+
161
+ ## At
162
+
163
+ ```js
164
+ obj[42]
165
+ obj[+index]
166
+ ```
167
+
168
+ It's translated into VM command `at`:
169
+
170
+ ```rust
171
+ struct InstanceMethodCall {
172
+ obj: Expression
173
+ index: Expression
174
+ }
175
+ ```
176
+
177
+ ```js
178
+ import m from './m.f.mjs'
179
+ const a = [2, 3]
180
+ export default {
181
+ "a": a[0],
182
+ // we don't know what is the type of `m` so we force it to be a `number` or `bigint`.
183
+ "b": a[+m]
184
+ }
185
+ ```
186
+
187
+ In `obj[index]`, `index` has to be a `number`. If we don't know what is `index`, `+` requires before `index`. It means the byte code for the expression inside the `[]` should be either the unary `+`, a number literal, or a string literal (excluding some strings). If it references an object, FS gives up. FS may try deeper analyses in the future, and type inference can help a lot.
188
+
189
+ ## Iterators
190
+
191
+ Direct access to an object with the [`Iterator` protocol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) is not allowed in FunctionalScript.
192
+
193
+ ```ts
194
+ type Value<T> = { done: true } | { done?: false, value: T }
195
+ type Iterator<T> = {
196
+ next: () => Value<T>
197
+ }
198
+ ```
199
+
200
+ However, FunctionalScript allows access to objects with the `Iterable` protocol.
201
+
202
+ ```ts
203
+ type Iterable<T> = {
204
+ [Symbol.iterator]: () => Iterator<T>
205
+ }
206
+ ```
207
+
208
+ For example, JS Array implements the `Iterable` protocol.
209
+
210
+ If we need to implement support for [generators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator) in the FunctionalScript, the generator function has to be wrapped into `Iterable` interface. For example,
211
+
212
+ ```js
213
+ // compilation error!
214
+ const iterator = *() {
215
+ yield 4
216
+ yield 2
217
+ }
218
+ // ok
219
+ const iterable = {
220
+ *[Symbol.iterator]() {
221
+ yield 4
222
+ yield 2
223
+ }
224
+ }
225
+ ```
@@ -1,74 +1,81 @@
1
1
  # Built-in Objects and Functions
2
2
 
3
- The built-in objects are special. We can get a function, like `Object.getOwnPropertyDescriptor`, but not the `Object` itself.
3
+ The built-in objects are special. We can call a function, like `Object.getOwnPropertyDescriptor()`, but not the `Object` or the function.
4
4
 
5
5
  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
6
6
 
7
- Some of the JS built-in objects and functions are "not allowed" in FS. It means, an FS compiler rejects code that contains "not allowed" objects and functions.
7
+ Some of the JS built-in objects and functions are "not allowed" in FS. It means, an FS compiler rejects code that contains "not allowed" objects and functions.
8
8
 
9
9
  ## Object
10
10
 
11
11
  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
12
12
 
13
- Functions:
14
-
15
- |Function |Priority |
16
- |-------------------------|-----------|
17
- |constructor |not allowed|
18
- |assign |not allowed|
19
- |create |not allowed|
20
- |defineProperties |not allowed|
21
- |defineProperty |not allowed|
22
- |entries |1 |
23
- |freeze |not allowed|
24
- |fromEntries |1 |
25
- |getOwnPropertyDescriptor |1 |
26
- |getOwnPropertyDescriptors|1 |
27
- |getOwnPropertyNames |1 |
28
- |getOwnPropertySymbols |not allowed|
29
- |getPrototypeOf |not allowed|
30
- |groupBy |1 |
31
- |hasOwn |1 |
32
- |is |1 |
33
- |isExtensible |not allowed|
34
- |isFrozen |not allowed|
35
- |isSealed |not allowed|
36
- |keys |1 |
37
- |preventExtensions |not allowed|
38
- |seal |not allowed|
39
- |setPrototypeOf |not allowed|
40
- |values |1 |
13
+ |Function |side-effect |
14
+ |-------------------------|---------------------------|
15
+ |assign |mutate |
16
+ |create |creates a special prototype|
17
+ |defineProperties |mutate |
18
+ |defineProperty |mutate |
19
+ |entries |no |
20
+ |freeze |mutate |
21
+ |fromEntries |no |
22
+ |getOwnPropertyDescriptor |no |
23
+ |getOwnPropertyDescriptors|no |
24
+ |getOwnPropertyNames |no |
25
+ |getOwnPropertySymbols |return symbols |
26
+ |getPrototypeOf |return prototypes |
27
+ |groupBy |return null-property object|
28
+ |hasOwn |no |
29
+ |is |no |
30
+ |isExtensible |no |
31
+ |isFrozen |no |
32
+ |isSealed |no |
33
+ |keys |no |
34
+ |preventExtensions |mutate |
35
+ |seal |mutate |
36
+ |setPrototypeOf |mutate |
37
+ |values |no |
41
38
 
42
39
  ## Array
43
40
 
44
41
  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
45
42
 
46
- |Function |Priority |
43
+ |Function |side-effect|
47
44
  |-------------------------|-----------|
48
- |from |1 |
49
- |fromAsync |1 |
50
- |isArray |1 |
51
- |of |1 |
45
+ |from |no |
46
+ |fromAsync |? |
47
+ |isArray |no |
48
+ |of |no |
52
49
 
53
50
  ## BigInt
54
51
 
55
- |Function |Priority |
52
+ |Function |side-effect|
56
53
  |-------------------------|-----------|
57
- |asIntN |1 |
58
- |asUintN |1 |
54
+ |asIntN |no |
55
+ |asUintN |no |
59
56
 
60
57
  ## JSON
61
58
 
62
- |Function |Priority |
59
+ |Function |side-effects|
63
60
  |-------------------------|-----------|
64
- |`isRawJSON` |3 |
65
- |`parse` |2 |
66
- |`rawJSON` |3 |
67
- |`stringify` |2 |
61
+ |`isRawJSON` |no |
62
+ |`parse` |no |
63
+ |`rawJSON` |no |
64
+ |`stringify` |no |
68
65
 
69
66
  ## Others
70
67
 
71
- `Infinity`
72
- `isFinite()`
73
- `isNaN()`
74
- `NaN`
68
+ |Function |side-effect|
69
+ |-------------------------|-----------|
70
+ |`decodeURI()` |no |
71
+ |`decodeURIComponent()` |no |
72
+ |`encodeURI()` |no |
73
+ |`encodeURIComponent()` |no |
74
+ |`eval()` |no |
75
+
76
+ |Property |side-effect|
77
+ |------------|-----------|
78
+ |`Infinity` |no |
79
+ |`isFinite()`|no |
80
+ |`isNaN()` |no |
81
+ |`NaN` |no |
@@ -0,0 +1,44 @@
1
+ # Non-default Export
2
+
3
+ In FunctionalScript we use `export default`:
4
+
5
+ ```js
6
+ export default 17
7
+ ```
8
+
9
+ The main reason is that it's compatible with other module types, such as JSON and CommonJS.
10
+
11
+ ECMAScript supports `export` of other non-default objects. We wouldn't have much reasons to support but systems as JSR doesn't really like `default` exports.
12
+
13
+ To implement `export` we should change our definition of a module from `unknown` to
14
+
15
+ ```ts
16
+ type Module = {
17
+ readonly [k in string]?: unknonwn
18
+ readonly default?: unknown
19
+ }
20
+ ```
21
+
22
+ Or, more strict version, which allows either `export` or `export default` but not both:
23
+
24
+ ```ts
25
+ type Module = ExportMap | ExportDefault
26
+ type ExportMap = Omit<{
27
+ readonly[k in string]: unknown
28
+ }, 'default'>
29
+ type DefaultExport = {
30
+ readonly default: unknown
31
+ }
32
+ ```
33
+
34
+ We don't need to change `import` for now if we implement `import * as X from ...`. For example
35
+
36
+ ```js
37
+ // types/list/module.d.mjs
38
+ export const map = ...
39
+ ```
40
+
41
+ ```js
42
+ import * as List from 'types/list/module.f.mjs'
43
+ const { map } = List
44
+ ```