functionalscript 0.0.457 → 0.0.459

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.
@@ -65,7 +65,7 @@ const cpp = name => lib => {
65
65
 
66
66
  /** @type {(m: types.Method) => text.Item} */
67
67
  const method = ([name, paramArray]) =>
68
- `virtual ${cppResult(paramArray)} COM_STDCALL ${name}(${join(', ')(mapParam(paramList(paramArray)))}) = 0;`
68
+ `virtual ${cppResult(paramArray)} COM_STDCALL ${name}(${join(', ')(mapParam(paramList(paramArray)))}) noexcept = 0;`
69
69
 
70
70
  const mapMethod = map(method)
71
71
 
@@ -21,13 +21,13 @@ const f = () =>
21
21
  ' };\n' +
22
22
  ' struct IMy: ::com::IUnknown\n' +
23
23
  ' {\n' +
24
- ' virtual Slice COM_STDCALL GetSlice() = 0;\n' +
25
- ' virtual void COM_STDCALL SetSlice(Slice slice) = 0;\n' +
26
- ' virtual ::com::BOOL* COM_STDCALL GetUnsafe() = 0;\n' +
27
- ' virtual void COM_STDCALL SetUnsafe(Slice* p, uint32_t size) = 0;\n' +
28
- ' virtual ::com::BOOL COM_STDCALL Some(IMy& p) = 0;\n' +
29
- ' virtual ::com::ref<IMy> COM_STDCALL GetIMy() = 0;\n' +
30
- ' virtual void COM_STDCALL SetManagedStruct(ManagedStruct a) = 0;\n' +
24
+ ' virtual Slice COM_STDCALL GetSlice() noexcept = 0;\n' +
25
+ ' virtual void COM_STDCALL SetSlice(Slice slice) noexcept = 0;\n' +
26
+ ' virtual ::com::BOOL* COM_STDCALL GetUnsafe() noexcept = 0;\n' +
27
+ ' virtual void COM_STDCALL SetUnsafe(Slice* p, uint32_t size) noexcept = 0;\n' +
28
+ ' virtual ::com::BOOL COM_STDCALL Some(IMy& p) noexcept = 0;\n' +
29
+ ' virtual ::com::ref<IMy> COM_STDCALL GetIMy() noexcept = 0;\n' +
30
+ ' virtual void COM_STDCALL SetManagedStruct(ManagedStruct a) noexcept = 0;\n' +
31
31
  ' };\n' +
32
32
  '}'
33
33
  if (cpp !== e) { throw cpp }
@@ -1,11 +1,12 @@
1
1
  const { writeFileSync } = require('node:fs')
2
2
  const { execSync } = require('node:child_process')
3
- const { platform } = require('node:process')
3
+ const { platform, exit } = require('node:process')
4
4
  const build = require('./build.f.cjs')
5
5
  const { cpp, cs, rust } = build
6
6
  const { join } = require('../../types/string/module.f.cjs')
7
7
  const { log, error } = console
8
8
  const { bold, reset } = require('../../text/sgr/module.f.cjs')
9
+ const { list } = require('../../types/module.f.cjs')
9
10
 
10
11
  const nodeJs = {
11
12
  dirname: __dirname,
@@ -17,13 +18,16 @@ const run = f => {
17
18
  const { file: { name, content }, line } = f(nodeJs)
18
19
  log(`${bold}writing: ${name}${reset}`)
19
20
  writeFileSync(name, content)
20
- const cmd = join(' ')(line)
21
- log(`${bold}running: ${cmd}${reset}`)
22
- try {
23
- log(execSync(cmd).toString())
24
- } catch (e) {
25
- // @ts-ignore
26
- error(e.output.toString())
21
+ for (const i of list.iterable(line)) {
22
+ const cmd = join(' ')(i)
23
+ log(`${bold}running: ${cmd}${reset}`)
24
+ try {
25
+ log(execSync(cmd).toString())
26
+ } catch (e) {
27
+ // @ts-ignore
28
+ error(e.output.toString())
29
+ exit(-1)
30
+ }
27
31
  }
28
32
  }
29
33
 
@@ -34,7 +34,7 @@ const rustContent = require("../rust/testlib.f.cjs")
34
34
  * readonly name: string
35
35
  * readonly content: string
36
36
  * }
37
- * readonly line: list.List<string>
37
+ * readonly line: list.List<list.List<string>>
38
38
  * }} Output
39
39
  */
40
40
 
@@ -52,18 +52,32 @@ const flags = platform => {
52
52
  }
53
53
  }
54
54
 
55
+ /** @type {(platform: Platform) => (name: string) => string} */
56
+ const output = platform => name => {
57
+ switch (platform) {
58
+ case 'win32': return `${name}.dll`
59
+ case 'darwin': return `lib${name}.dylib`
60
+ default: return `lib${name}.so`
61
+ }
62
+ }
63
+
55
64
  /** @type {Func} */
56
- const cpp = ({dirname, platform}) => ({
57
- file: {
58
- name: `${dirname}/cpp/_result.hpp`,
59
- content: cppContent,
60
- },
61
- line: flat([
62
- ['clang'],
63
- flags(platform),
64
- [`${dirname}/cpp/main.cpp`]]
65
- ),
66
- })
65
+ const cpp = ({dirname, platform}) => {
66
+ const extension = platform === 'win32' ? 'dll' : 'so'
67
+ return {
68
+ file: {
69
+ name: `${dirname}/cpp/_result.hpp`,
70
+ content: cppContent,
71
+ },
72
+ line: [
73
+ flat([
74
+ ['clang', '-shared', '-o', output(platform)('main')],
75
+ flags(platform),
76
+ [`${dirname}/cpp/main.cpp`]]
77
+ ),
78
+ ],
79
+ }
80
+ }
67
81
 
68
82
  /** @type {Func} */
69
83
  const cs = ({dirname}) => ({
@@ -71,7 +85,7 @@ const cs = ({dirname}) => ({
71
85
  name: `${dirname}/cs/_result.cs`,
72
86
  content: csContent,
73
87
  },
74
- line: ['dotnet', 'build', `${dirname}/cs/cs.csproj`],
88
+ line: [['dotnet', 'build', `${dirname}/cs/cs.csproj`]],
75
89
  })
76
90
 
77
91
  /** @type {Func} */
@@ -80,7 +94,7 @@ const rust = ({dirname}) => ({
80
94
  name: `${dirname}/rust/src/_result.rs`,
81
95
  content: rustContent,
82
96
  },
83
- line: ['cargo', 'build']
97
+ line: [['cargo', 'build']]
84
98
  })
85
99
 
86
100
  module.exports = {
@@ -1,9 +1,2 @@
1
1
  #include "../../cpp/com.hpp"
2
2
  #include "_result.hpp"
3
-
4
- #include <iostream>
5
-
6
- int main()
7
- {
8
- std::cout << "Hello world!" << std::endl;
9
- }
package/fsm/README.md CHANGED
@@ -39,16 +39,75 @@ const idNext = byteSet.union(idBegin)(digit)
39
39
  const dot = byteSet('.')
40
40
 
41
41
  const grammar = [
42
- ['init', digit, 'int'],
42
+ ['', digit, 'int'],
43
43
  ['int', digit, 'int'],
44
44
  //
45
- ['init', digit, 'floatBegin'],
45
+ ['', digit, 'floatBegin'],
46
46
  ['floatBegin', digit, 'floatBegin'],
47
47
  ['floatBegin', dot, 'floatDot'],
48
48
  ['floatDot', digit, 'float'],
49
49
  ['float', digit, 'float'],
50
50
  //
51
- ['init', idBegin, 'id'],
51
+ ['', idBegin, 'id'],
52
52
  ['id', idNext, 'id'],
53
53
  ]
54
54
  ```
55
+
56
+ ```js
57
+ const result = {
58
+ "['']": {
59
+ digit: "['floatBegin','int']",
60
+ idBegin: "['id']"
61
+ },
62
+ "['floatBegin','int']": {
63
+ digit: "['floatBegin','int']",
64
+ dot: "['floatDot']",
65
+ },
66
+ "['floatDot']": {
67
+ digit: "['float']"
68
+ },
69
+ "['float']": {
70
+ digit: "['float']"
71
+ },
72
+ "['id']": {
73
+ idNext: "['id']"
74
+ }
75
+ }
76
+ ```
77
+
78
+ ```js
79
+ const result = [
80
+ { // 0
81
+ digit: 1,
82
+ idBegin: 4
83
+ },
84
+ { // 1
85
+ digit: 1,
86
+ dot: 2,
87
+ },
88
+ { // 2
89
+ digit: 3
90
+ },
91
+ { // 3
92
+ digit: 3
93
+ },
94
+ { // 4
95
+ idNext: 4
96
+ }
97
+ }
98
+ ```
99
+
100
+ ## How to Add a Property # 1
101
+
102
+ ```js
103
+ const a = { x: 5, y: 6 }
104
+ const b = { ...a, z: 7 }
105
+ ```
106
+
107
+ ## How to Add a Property # 2
108
+
109
+ ```js
110
+ const map = reauire('./types/map/module.f.js')
111
+ const a = map.fromEntries(Object.entries({ x: 5, y: 6 }))
112
+ const b = map.setReplace('z')(7)(a)
113
+ ```
package/fsm/module.f.cjs CHANGED
@@ -14,15 +14,10 @@ const byteSet = require('../types/byte_set/module.f.cjs')
14
14
  * }} Dfa
15
15
  */
16
16
 
17
- /** @type {(faId: string) => string} */
18
- const escape = faId => faId.replaceAll('\\', '\\\\').replaceAll('|', '\\|')
19
-
20
17
  /** @type {(grammar: Grammar) => Dfa} */
21
18
  const dfa = grammar => todo()
22
19
 
23
20
  module.exports = {
24
- /** @readonly */
25
- escape,
26
21
  /** @readonly */
27
22
  dfa,
28
23
  }
package/fsm/test.f.cjs CHANGED
@@ -1,14 +1,5 @@
1
1
  const _ = require('./module.f.cjs')
2
2
 
3
3
  module.exports = {
4
- escape: [
5
- () => {
6
- const result = _.escape('abc')
7
- if (result !== 'abc') { throw result }
8
- },
9
- () => {
10
- const result = _.escape('\\a|b|c\\')
11
- if (result !== '\\\\a\\|b\\|c\\\\') { throw result }
12
- }
13
- ]
4
+
14
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.457",
3
+ "version": "0.0.459",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -1,4 +1,8 @@
1
1
  const { fn } = require('../function/module.f.cjs')
2
+ const rangeMap = require('../range_map/module.f.cjs')
3
+ const sortedSet = require('../sorted_set/module.f.cjs')
4
+ const list = require('../list/module.f.cjs')
5
+ const { reverse, countdown, flat, map } = list
2
6
 
3
7
  /** @typedef {bigint} ByteSet */
4
8
  /** @typedef {number} Byte */
@@ -42,6 +46,20 @@ const setRange = fn(range).then(union).result
42
46
  /** @type {(n: Byte) => (s: ByteSet) => ByteSet} */
43
47
  const unset = n => s => difference(s)(one(n))
44
48
 
49
+ const counter = reverse(countdown(256))
50
+
51
+ /** @type {(n: ByteSet) => (s: string) => (i: number) => rangeMap.RangeMap<sortedSet.SortedSet<string>>} */
52
+ const toRangeMapOp = n => s => i =>
53
+ {
54
+ const current = has(i + 1)(n)
55
+ const prev = has(i)(n)
56
+ if (current === prev) { return undefined }
57
+ return [[prev ? [s] : [], i]]
58
+ }
59
+
60
+ /** @type {(n: ByteSet) => (s: string) => rangeMap.RangeMap<sortedSet.SortedSet<string>>} */
61
+ const toRangeMap = n => s => flat(map(toRangeMapOp(n)(s))(counter))
62
+
45
63
  module.exports = {
46
64
  /** @readonly */
47
65
  empty,
@@ -61,4 +79,6 @@ module.exports = {
61
79
  range,
62
80
  /** @readonly */
63
81
  complement,
82
+ /** @readonly */
83
+ toRangeMap,
64
84
  }
@@ -1,5 +1,11 @@
1
1
  const _ = require('./module.f.cjs')
2
2
  const { every, countdown, map } = require('../list/module.f.cjs')
3
+ const json = require('../../json/module.f.cjs')
4
+ const { sort } = require('../object/module.f.cjs')
5
+ const { toArray } = require('../list/module.f.cjs')
6
+
7
+ /** @type {(a: readonly json.Unknown[]) => string} */
8
+ const stringify = a => json.stringify(sort)(a)
3
9
 
4
10
  module.exports = {
5
11
  has: [
@@ -52,5 +58,25 @@ module.exports = {
52
58
  const r = _.complement(_.universe)
53
59
  if (r !== _.empty) { throw r }
54
60
  },
55
- }
61
+ },
62
+ toRangeMap: [
63
+ () => {
64
+ const result = stringify(toArray(_.toRangeMap(_.empty)('a')))
65
+ if (result !== '[]') { throw result }
66
+ },
67
+ () => {
68
+ const s = _.set(0)(_.empty)
69
+ const result = stringify(toArray(_.toRangeMap(s)('a')))
70
+ if (result !== '[[["a"],0]]') { throw result }
71
+ },
72
+ () => {
73
+ const s = _.setRange([1,2])(_.empty)
74
+ const result = stringify(toArray(_.toRangeMap(s)('a')))
75
+ if (result !== '[[[],0],[["a"],2]]') { throw result }
76
+ },
77
+ () => {
78
+ const result = stringify(toArray(_.toRangeMap(_.universe)('a')))
79
+ if (result !== '[[["a"],255]]') { throw result }
80
+ },
81
+ ]
56
82
  }