functionalscript 0.0.438 → 0.0.440

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.
@@ -1,7 +1,7 @@
1
1
  # This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
2
  # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
3
 
4
- name: node ci & pack
4
+ name: COM Test
5
5
 
6
6
  on:
7
7
  push:
@@ -12,15 +12,17 @@ on:
12
12
  jobs:
13
13
  build:
14
14
 
15
- runs-on: ubuntu-latest
15
+ strategy:
16
+ matrix:
17
+ os: ['ubuntu-latest', 'windows-latest', 'macos-12']
18
+
19
+ runs-on: ${{ matrix.os }}
16
20
 
17
21
  steps:
18
22
  - uses: actions/checkout@v2
19
- - name: Use Node.js
23
+ - name: Use Node.js 19
20
24
  uses: actions/setup-node@v2
21
25
  with:
22
- node-version: 18
26
+ node-version: 19
23
27
  - run: npm ci
24
- - run: npm test
25
- - run: npm run version
26
- - run: npm pack
28
+ - run: node ./com/test/build.cjs
@@ -1,7 +1,7 @@
1
1
  # This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
2
  # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
3
 
4
- name: node install
4
+ name: node CI
5
5
 
6
6
  on:
7
7
  push:
@@ -16,7 +16,7 @@ jobs:
16
16
 
17
17
  strategy:
18
18
  matrix:
19
- node-version: [16.x, 18.x]
19
+ node-version: [16.x, 18.x, 19.x]
20
20
  # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
21
 
22
22
  steps:
@@ -25,7 +25,7 @@ jobs:
25
25
  uses: actions/setup-node@v2
26
26
  with:
27
27
  node-version: ${{ matrix.node-version }}
28
- - run: npm install
28
+ - run: npm ci
29
29
  - run: npm test
30
30
  - run: npm run version
31
31
  - run: npm pack
@@ -14,7 +14,7 @@ jobs:
14
14
  - uses: actions/checkout@v2
15
15
  - uses: actions/setup-node@v2
16
16
  with:
17
- node-version: 18
17
+ node-version: 19
18
18
  - run: npm ci
19
19
  - run: npm test
20
20
 
@@ -27,7 +27,7 @@ jobs:
27
27
  fetch-depth: 0
28
28
  - uses: actions/setup-node@v2
29
29
  with:
30
- node-version: 18
30
+ node-version: 19
31
31
  registry-url: https://registry.npmjs.org/
32
32
  - run: npm ci
33
33
  - run: npm run version
package/com/cpp/com.hpp CHANGED
@@ -3,7 +3,7 @@
3
3
  #include <cstdint>
4
4
  #include <cstddef>
5
5
 
6
- #if defined(__aarch64__)
6
+ #if defined(__aarch64__) || defined(__amd64__)
7
7
  #define COM_STDCALL
8
8
  #elif defined(__clang__)
9
9
  #define COM_STDCALL __attribute__((stdcall))
@@ -82,7 +82,7 @@ const cpp = name => lib => {
82
82
 
83
83
  const e = entries(lib)
84
84
 
85
- return list.flat([
85
+ return flat([
86
86
  ['#pragma once', ''],
87
87
  namespace(name)(flat([flatMap(forward)(e), flatMap(def)(e)]))
88
88
  ])
@@ -1,37 +1,32 @@
1
- const fs = require('node:fs')
2
- const cp = require('node:child_process')
3
- const os = require('node:os');
4
- const cpp = require('../cpp/test.f.cjs').result
5
- const { string: { join }, list: { flat } } = require('../../types/module.f.cjs')
1
+ const { writeFileSync } = require('node:fs')
2
+ const { execSync } = require('node:child_process')
3
+ const { platform } = require('node:process')
4
+ const build = require('./build.f.cjs')
5
+ const { cpp, cs, rust } = build
6
+ const { join } = require('../../types/string/module.f.cjs')
7
+ const { log, error } = console
8
+ const { bold, reset } = require('../../text/sgr/module.f.cjs')
6
9
 
7
- const dirname = __dirname
8
-
9
- fs.writeFileSync(`${dirname}/cpp/_result.hpp`, cpp)
10
- try {
11
- const flags = os.platform() === 'win32' ? [] : ['-std=c++11', '-lc++']
12
- const line = join(' ')(flat([['clang'], flags, [dirname + '/cpp/main.cpp']]))
13
- console.log(cp.execSync(line).toString())
14
- } catch (e) {
15
- // @ts-ignore
16
- console.error(e.output.toString())
10
+ const nodeJs = {
11
+ dirname: __dirname,
12
+ platform,
17
13
  }
18
14
 
19
- const cs = require('../cs/test.f.cjs').result
20
-
21
- fs.writeFileSync(`${dirname}/cs/_result.cs`, cs)
22
- try {
23
- console.log(cp.execSync(`dotnet build ${dirname}/cs/cs.csproj`).toString())
24
- } catch (e) {
25
- // @ts-ignore
26
- console.error(e.output.toString())
15
+ /** @type {(f: build.Func) => void} */
16
+ const run = f => {
17
+ const { file: { name, content }, line } = f(nodeJs)
18
+ log(`${bold}writing: ${name}${reset}`)
19
+ 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())
27
+ }
27
28
  }
28
29
 
29
- const rust = require("../rust/test.f.cjs").result();
30
-
31
- fs.writeFileSync(`${dirname}/rust/src/_result.rs`, rust);
32
- try {
33
- console.log(cp.execSync("cargo build").toString());
34
- } catch (e) {
35
- // @ts-ignore
36
- console.error(e.output.toString());
37
- }
30
+ run(cpp)
31
+ run(cs)
32
+ run(rust)
@@ -0,0 +1,93 @@
1
+ const list = require('../../types/list/module.f.cjs')
2
+ const { flat } = list
3
+
4
+ const cppContent = require('../cpp/test.f.cjs').result
5
+ const csContent = require('../cs/test.f.cjs').result
6
+ const rustContent = require("../rust/test.f.cjs").result();
7
+
8
+ /**
9
+ * @typedef {|
10
+ * 'aix' |
11
+ * 'android' |
12
+ * 'darwin' |
13
+ * 'freebsd' |
14
+ * 'haiku' |
15
+ * 'linux' |
16
+ * 'openbsd' |
17
+ * 'sunos' |
18
+ * 'win32' |
19
+ * 'cygwin' |
20
+ * 'netbsd'
21
+ * } Platform
22
+ */
23
+
24
+ /**
25
+ * @typedef {{
26
+ * readonly dirname: string
27
+ * readonly platform: Platform
28
+ * }} NodeJs
29
+ */
30
+
31
+ /**
32
+ * @typedef {{
33
+ * readonly file: {
34
+ * readonly name: string
35
+ * readonly content: string
36
+ * }
37
+ * readonly line: list.List<string>
38
+ * }} Output
39
+ */
40
+
41
+ /** @typedef {(nodejs: NodeJs) => Output} Func */
42
+
43
+ /** @type {(platform: Platform) => readonly string[]} */
44
+ const flags = platform => {
45
+ switch (platform) {
46
+ case 'win32':
47
+ return []
48
+ case 'linux':
49
+ return ['-lstdc++']
50
+ default:
51
+ return ['-std=c++11', '-lc++']
52
+ }
53
+ }
54
+
55
+ /** @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
+ })
67
+
68
+ /** @type {Func} */
69
+ const cs = ({dirname}) => ({
70
+ file: {
71
+ name: `${dirname}/cs/_result.cs`,
72
+ content: csContent,
73
+ },
74
+ line: ['dotnet', 'build', `${dirname}/cs/cs.csproj`],
75
+ })
76
+
77
+ /** @type {Func} */
78
+ const rust = ({dirname}) => ({
79
+ file: {
80
+ name: `${dirname}/rust/src/_result.rs`,
81
+ content: rustContent,
82
+ },
83
+ line: ['cargo', 'build']
84
+ })
85
+
86
+ module.exports = {
87
+ /** @readonly */
88
+ cpp,
89
+ /** @readonly */
90
+ cs,
91
+ /** @readonly */
92
+ rust,
93
+ }
@@ -0,0 +1,9 @@
1
+ [package]
2
+ name = "testrust"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
+
8
+ [dependencies]
9
+ nanocom = { path = "../../rust/nanocom" }
@@ -0,0 +1 @@
1
+ mod _result;
@@ -1,5 +1,6 @@
1
1
  const list = require('../../types/list/module.f.cjs')
2
2
  const { fold } = list
3
+ const { reset, fgGreen } = require('../../text/sgr/module.f.cjs')
3
4
 
4
5
  /**
5
6
  * @typedef {{
@@ -34,17 +35,6 @@ const { fold } = list
34
35
  * }} Input
35
36
  */
36
37
 
37
- /**
38
- * https://en.wikipedia.org/wiki/ANSI_escape_code#SGR
39
- *
40
- * @type {(c: number) => string}
41
- */
42
- const sgr = c => `\x1b[${c.toString()}m`
43
-
44
- const reset = sgr(0)
45
-
46
- const fgGreen = sgr(32)
47
-
48
38
  /** @type {(s: string) => boolean} */
49
39
  const isTest = s => s.endsWith('test.f.cjs')
50
40
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.438",
3
+ "version": "0.0.440",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "homepage": "https://github.com/functionalscript/functionalscript#readme",
31
31
  "devDependencies": {
32
- "@types/node": "^18.8.4",
32
+ "@types/node": "^18.11.2",
33
33
  "typescript": "^4.8.4"
34
34
  }
35
35
  }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * https://en.wikipedia.org/wiki/ANSI_escape_code#SGR
3
+ *
4
+ * @type {(c: number) => string}
5
+ */
6
+ const sgr = c => `\x1b[${c.toString()}m`
7
+
8
+ module.exports = {
9
+ /** @readonly */
10
+ sgr,
11
+ /** @readonly */
12
+ reset: sgr(0),
13
+ /** @readonly */
14
+ bold: sgr(1),
15
+ /** @readonly */
16
+ fgGreen: sgr(32),
17
+ }
@@ -294,16 +294,18 @@ const zip = a => b => () => {
294
294
  return { first: [aResult.first, bResult.first], tail: zip(aResult.tail)(bResult.tail) }
295
295
  }
296
296
 
297
- /** @type {<T>(e: operator.Equal<T>) => (a: List<T>) => (b: List<T>) => List<boolean>} */
298
- const equalZip = e => a => b => () => {
299
- const [aResult, bResult] = [next(a), next(b)]
300
- return aResult === undefined || bResult === undefined
301
- ? { first: aResult === bResult, tail: undefined }
302
- : { first: e(aResult.first)(bResult.first), tail: equalZip(e)(aResult.tail)(bResult.tail) }
303
- }
304
-
305
297
  /** @type {<T>(e: operator.Equal<T>) => (a: List<T>) => (b: List<T>) => boolean} */
306
- const equal = e => a => b => every(equalZip(e)(a)(b))
298
+ const equal = e => {
299
+ /** @typedef {typeof e extends operator.Equal<infer T> ? T : never} T */
300
+ /** @type {(a: List<T>) => (b: List<T>) => List<boolean>} */
301
+ const f = a => b => () => {
302
+ const [aResult, bResult] = [next(a), next(b)]
303
+ return aResult === undefined || bResult === undefined
304
+ ? { first: aResult === bResult, tail: undefined }
305
+ : { first: e(aResult.first)(bResult.first), tail: f(aResult.tail)(bResult.tail) }
306
+ }
307
+ return a => b => every(f(a)(b))
308
+ }
307
309
 
308
310
  module.exports = {
309
311
  /** @readonly */
@@ -1,7 +1,8 @@
1
- const compare = require("../function/compare/module.f.cjs")
2
- const list = require("../list/module.f.cjs")
3
- const option = require("../option/module.f.cjs")
1
+ const compare = require('../function/compare/module.f.cjs')
2
+ const list = require('../list/module.f.cjs')
3
+ const option = require('../option/module.f.cjs')
4
4
  const { next } = list
5
+ const { identity } = require('../function/module.f.cjs')
5
6
 
6
7
  /**
7
8
  * @template T
@@ -13,55 +14,74 @@ const { next } = list
13
14
  * @typedef {(a: T) => (b: T) => compare.Sign} Cmp
14
15
  */
15
16
 
16
- /** @typedef {number} Byte */
17
-
18
17
  /**
19
18
  * @template T
20
- * @typedef {SortedList<[Byte, readonly string[]]>} RangeMap
19
+ * @typedef {SortedList<[T, number]>} RangeMap
21
20
  */
22
21
 
23
22
  /**
24
- * @template S
25
23
  * @template T
24
+ * @template S
26
25
  * @typedef {(state: S) => (a: T) => (b: T) => readonly[option.Option<T>, compare.Sign, S]} ReduceOp
27
26
  */
28
27
 
29
28
  /**
30
- * @template S
31
29
  * @template T
30
+ * @template S
32
31
  * @typedef {(state: S) => (tail: list.List<T>) => list.List<T>} TailReduce
33
32
  */
34
33
 
35
34
  /**
35
+ * @template T
36
36
  * @template S
37
+ * @typedef {{
38
+ * readonly reduceOp: ReduceOp<T,S>
39
+ * readonly tailReduce: TailReduce<T,S>
40
+ * }} MergeReduce
41
+ */
42
+
43
+ /** @type {<T,S>(reduce: MergeReduce<T,S>) => (state: S) => (a: list.List<T>) => (b: list.List<T>) => list.List<T>} */
44
+ const genericMerge = reduce => {
45
+ const { reduceOp, tailReduce } = reduce
46
+ /** @typedef {typeof reduce extends MergeReduce<infer T, infer S> ? [T, S] : never} TS */
47
+ /** @typedef {TS[0]} T */
48
+ /** @typedef {TS[1]} S */
49
+ /** @type {(state: S) => (a: list.List<T>) => (b: list.List<T>) => list.List<T>} */
50
+ const f = state => a => b => () => {
51
+ const aResult = next(a)
52
+ if (aResult === undefined) { return tailReduce(state)(b) }
53
+ const bResult = next(b)
54
+ if (bResult === undefined) { return tailReduce(state)(a) }
55
+ const [first, sign, stateNext] = reduceOp(state)(aResult.first)(bResult.first)
56
+ const aNext = sign === 1 ? a : aResult.tail
57
+ const bNext = sign === -1 ? b : bResult.tail
58
+ const tail = f(stateNext)(aNext)(bNext)
59
+ return first === undefined ? tail : { first, tail }
60
+ }
61
+ return f
62
+ }
63
+
64
+ /**
37
65
  * @template T
38
- * @typedef {(init: S) => (reduce: ReduceOp<S,T>) => (tailReduce: TailReduce<S, T>) => (a: list.List<T>) => (b: list.List<T>) => list.List<T>} GenericMerge
66
+ * @typedef {ReduceOp<T, undefined>} CmpReduceOp
39
67
  */
40
68
 
41
69
  /** @type {<T>(cmp: Cmp<T>) => (a: SortedList<T>) => (b: SortedList<T>) => SortedList<T>} */
42
- const merge = cmp => genericMerge(undefined)(cmpReduce(cmp))(mergeTail)
70
+ const merge = cmp => {
71
+ /** @typedef {typeof cmp extends Cmp<infer T> ? T : never} T*/
72
+ /** @type {TailReduce<T, undefined>} */
73
+ const tailReduce = mergeTail
74
+ return genericMerge({ reduceOp: cmpReduce(cmp), tailReduce })(undefined)
75
+ }
43
76
 
44
- /** @type {<S,T>(cmp: Cmp<T>) => ReduceOp<S, T>} */
45
- const cmpReduce = cmp => state => a => b => {
77
+ /** @type {<T>(cmp: Cmp<T>) => CmpReduceOp<T>} */
78
+ const cmpReduce = cmp => () => a => b => {
46
79
  const sign = cmp(a)(b)
47
- return [sign === 1 ? b : a, sign, state]
80
+ return [sign === 1 ? b : a, sign, undefined]
48
81
  }
49
82
 
50
- /** @type {<S,T>(state: S) => (tail: list.List<T>) => list.List<T>} */
51
- const mergeTail = s => input => input
52
-
53
- /** @type {<S,T>(init: S) => (reduce: ReduceOp<S,T>) => (tailReduce: TailReduce<S, T>) => (a: list.List<T>) => (b: list.List<T>) => list.List<T>} */
54
- const genericMerge = init => reduce => tailReduce => a => b => () => {
55
- const aResult = next(a)
56
- if (aResult === undefined) { return tailReduce(init)(b) }
57
- const bResult = next(b)
58
- if (bResult === undefined) { return tailReduce(init)(a) }
59
- const [result, sign, state] = reduce(init)(aResult.first)(bResult.first)
60
- const aNext = sign === 1 ? a : aResult.tail
61
- const bNext = sign === -1 ? b : bResult.tail
62
- const mergeNext = genericMerge(state)(reduce)(tailReduce)(aNext)(bNext)
63
- return result === undefined ? mergeNext : { first: result, tail: mergeNext }
64
- }
83
+ /** @type {() => <T>(tail: list.List<T>) => list.List<T>} */
84
+ const mergeTail = () => identity
65
85
 
66
86
  module.exports = {
67
87
  /** @readonly */
@@ -24,16 +24,15 @@ const union = cmp => a => b => toArray(merge(cmp)(a)(b))
24
24
  const intersect = cmp => a => b => toArray(intersectMerge(cmp)(a)(b))
25
25
 
26
26
  /** @type {<T>(cmp: Cmp<T>) => (a: sortedList.SortedList<T>) => (b: sortedList.SortedList<T>) => sortedList.SortedList<T>} */
27
- const intersectMerge = cmp => genericMerge(undefined)(intersectReduce(cmp))(intersectTail)
27
+ const intersectMerge = cmp => genericMerge({ reduceOp: intersectReduce(cmp), tailReduce: intersectTail })(undefined)
28
28
 
29
- /** @type {<S,T>(cmp: Cmp<T>) => sortedList.ReduceOp<S, T>} */
29
+ /** @type {<T,S>(cmp: Cmp<T>) => sortedList.ReduceOp<T,S>} */
30
30
  const intersectReduce = cmp => state => a => b => {
31
31
  const sign = cmp(a)(b)
32
32
  return [sign === 0 ? a : undefined, sign, state]
33
33
  }
34
34
 
35
- /** @type {<S,T>(state: S) => (tail: list.List<T>) => list.List<T>} */
36
- const intersectTail = s => input => undefined
35
+ const intersectTail = () => () => undefined
37
36
 
38
37
  module.exports = {
39
38
  /** @readonly */