functionalscript 0.3.6 → 0.3.8
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/com/cpp/module.f.js +0 -1
- package/com/cs/module.f.js +5 -6
- package/com/rust/module.f.d.ts +3 -3
- package/com/rust/module.f.js +24 -29
- package/com/test/build.f.js +2 -2
- package/com/types/module.f.d.ts +1 -1
- package/com/types/module.f.js +1 -2
- package/com/types/testlib.f.js +0 -1
- package/commonjs/build/module.f.d.ts +2 -2
- package/commonjs/build/module.f.js +3 -6
- package/commonjs/build/test.f.js +0 -4
- package/commonjs/module/function/module.f.d.ts +1 -1
- package/commonjs/module/function/module.f.js +1 -1
- package/commonjs/module/module.f.d.ts +1 -1
- package/commonjs/module/module.f.js +2 -3
- package/commonjs/path/module.f.d.ts +5 -5
- package/commonjs/path/module.f.js +6 -8
- package/commonjs/path/test.f.js +1 -2
- package/crypto/prime_field/module.f.d.ts +2 -2
- package/crypto/prime_field/module.f.js +3 -4
- package/crypto/secp/module.f.d.ts +2 -2
- package/crypto/secp/module.f.js +4 -5
- package/crypto/sha2/module.f.d.ts +75 -12
- package/crypto/sha2/module.f.js +246 -139
- package/crypto/sha2/test.f.d.ts +22 -3
- package/crypto/sha2/test.f.js +120 -67
- package/dev/test/module.f.d.ts +1 -1
- package/dev/test/module.f.js +4 -5
- package/dev/test.f.js +0 -4
- package/djs/module.f.d.ts +1 -1
- package/djs/module.f.js +0 -1
- package/djs/parser/module.f.d.ts +1 -1
- package/djs/parser/module.f.js +0 -2
- package/djs/serializer/module.f.d.ts +2 -2
- package/djs/serializer/module.f.js +0 -2
- package/djs/tokenizer/module.f.js +0 -1
- package/fsc/test.f.js +0 -1
- package/html/module.f.d.ts +1 -1
- package/html/module.f.js +15 -11
- package/html/test.f.js +7 -7
- package/js/tokenizer/module.f.d.ts +2 -2
- package/js/tokenizer/module.f.js +1 -2
- package/json/parser/module.f.d.ts +2 -2
- package/json/parser/module.f.js +0 -3
- package/json/serializer/module.f.js +0 -2
- package/json/tokenizer/module.f.js +0 -1
- package/nanvm-lib/tests/test.f.d.ts +28 -0
- package/nanvm-lib/tests/test.f.js +45 -0
- package/package.json +1 -1
- package/text/ascii/module.f.d.ts +1 -1
- package/text/ascii/module.f.js +2 -3
- package/text/ascii/test.f.js +2 -4
- package/text/module.f.d.ts +18 -3
- package/text/module.f.js +22 -6
- package/text/sgr/module.f.js +1 -1
- package/text/test.f.d.ts +4 -1
- package/text/test.f.js +24 -16
- package/text/utf16/module.f.d.ts +5 -6
- package/text/utf16/module.f.js +9 -10
- package/text/utf16/test.f.js +29 -30
- package/text/utf8/module.f.d.ts +8 -5
- package/text/utf8/module.f.js +3 -5
- package/text/utf8/test.f.js +34 -35
- package/types/array/module.f.d.ts +12 -9
- package/types/array/module.f.js +10 -11
- package/types/array/test.f.d.ts +1 -0
- package/types/array/test.f.js +18 -17
- package/types/bigfloat/module.f.d.ts +1 -1
- package/types/bigfloat/module.f.js +7 -8
- package/types/bigfloat/test.f.js +1 -2
- package/types/bigint/module.f.d.ts +20 -11
- package/types/bigint/module.f.js +19 -20
- package/types/bigint/test.f.d.ts +1 -0
- package/types/bigint/test.f.js +7 -2
- package/types/bit_vec/module.f.d.ts +103 -83
- package/types/bit_vec/module.f.js +68 -110
- package/types/bit_vec/test.f.d.ts +20 -8
- package/types/bit_vec/test.f.js +110 -117
- package/types/btree/find/test.f.js +3 -4
- package/types/btree/module.f.d.ts +3 -3
- package/types/btree/module.f.js +2 -5
- package/types/btree/remove/test.f.js +2 -3
- package/types/btree/set/test.f.js +3 -6
- package/types/btree/test.f.js +0 -1
- package/types/btree/types/module.f.d.ts +3 -3
- package/types/byte_set/module.f.d.ts +2 -2
- package/types/byte_set/module.f.js +0 -2
- package/types/function/compare/module.f.d.ts +1 -1
- package/types/function/compare/module.f.js +0 -1
- package/types/function/compare/test.f.js +1 -2
- package/types/function/module.f.d.ts +1 -1
- package/types/function/module.f.js +1 -1
- package/types/function/operator/module.f.d.ts +2 -3
- package/types/function/operator/module.f.js +5 -5
- package/types/function/test.f.js +1 -2
- package/types/list/module.f.d.ts +1 -1
- package/types/list/module.f.js +9 -9
- package/types/list/test.f.js +2 -4
- package/types/map/module.f.d.ts +6 -6
- package/types/map/module.f.js +6 -15
- package/types/map/test.f.js +1 -2
- package/types/monoid/module.f.d.ts +73 -0
- package/types/monoid/module.f.js +42 -0
- package/types/monoid/test.f.d.ts +5 -0
- package/types/monoid/test.f.js +27 -0
- package/types/nibble_set/module.f.d.ts +2 -3
- package/types/nibble_set/test.f.js +1 -2
- package/types/number/test.f.js +1 -2
- package/types/object/module.f.d.ts +5 -5
- package/types/object/module.f.js +2 -4
- package/types/range_map/module.f.d.ts +4 -4
- package/types/range_map/module.f.js +3 -9
- package/types/result/module.f.d.ts +2 -3
- package/types/sorted_list/module.f.d.ts +6 -6
- package/types/sorted_list/module.f.js +2 -6
- package/types/sorted_list/test.f.js +4 -9
- package/types/sorted_set/module.f.d.ts +1 -1
- package/types/sorted_set/module.f.js +2 -5
- package/types/sorted_set/test.f.js +4 -9
- package/types/string/module.f.d.ts +3 -3
- package/types/string/module.f.js +1 -2
- package/types/string/test.f.js +2 -4
- package/types/string_set/module.f.d.ts +1 -1
- package/types/string_set/module.f.js +5 -11
package/com/cpp/module.f.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { paramList, result, } from "../types/module.f.js";
|
|
6
6
|
import * as text from "../../text/module.f.js";
|
|
7
|
-
import * as O from "../../types/object/module.f.js";
|
|
8
7
|
import { map, flatMap, flat } from "../../types/list/module.f.js";
|
|
9
8
|
import { join } from "../../types/string/module.f.js";
|
|
10
9
|
const { entries } = Object;
|
package/com/cs/module.f.js
CHANGED
|
@@ -8,7 +8,6 @@ import { result, paramList, } from "../types/module.f.js";
|
|
|
8
8
|
import { curly } from "../../text/module.f.js";
|
|
9
9
|
import { flat, map, some, flatMap } from "../../types/list/module.f.js";
|
|
10
10
|
import { join } from "../../types/string/module.f.js";
|
|
11
|
-
import * as O from "../../types/object/module.f.js";
|
|
12
11
|
const { entries } = Object;
|
|
13
12
|
const using = (v) => `using ${v};`;
|
|
14
13
|
const typeDef = (attributes) => (type) => (name) => (body) => flat([
|
|
@@ -31,20 +30,20 @@ const baseTypeMap = {
|
|
|
31
30
|
usize: 'UIntPtr',
|
|
32
31
|
};
|
|
33
32
|
const baseType = (t) => baseTypeMap[t];
|
|
34
|
-
const unsafe = isUnsafe => isUnsafe ? 'unsafe ' : '';
|
|
35
|
-
const fullType = t => typeof (t) === 'string' ?
|
|
33
|
+
const unsafe = (isUnsafe) => isUnsafe ? 'unsafe ' : '';
|
|
34
|
+
const fullType = (t) => typeof (t) === 'string' ?
|
|
36
35
|
[false, baseType(t)] :
|
|
37
36
|
t.length === 1 ?
|
|
38
37
|
[false, t[0]] :
|
|
39
38
|
[true, `${type(t[1])}*`];
|
|
40
|
-
const type = t => fullType(t)[1];
|
|
39
|
+
const type = (t) => fullType(t)[1];
|
|
41
40
|
const param = ([name, t]) => `${type(t)} ${name}`;
|
|
42
41
|
const mapParam = map(param);
|
|
43
42
|
const field = ([name, comType]) => {
|
|
44
43
|
const [isUnsafe, t] = fullType(comType);
|
|
45
44
|
return `public ${unsafe(isUnsafe)}${t} ${name};`;
|
|
46
45
|
};
|
|
47
|
-
const isUnsafeField = field => fullType(field[1])[0];
|
|
46
|
+
const isUnsafeField = (field) => fullType(field[1])[0];
|
|
48
47
|
const mapIsUnsafeField = map(isUnsafeField);
|
|
49
48
|
const resultVoid = result('void');
|
|
50
49
|
const joinComma = join(', ');
|
|
@@ -73,7 +72,7 @@ const header = [
|
|
|
73
72
|
/**
|
|
74
73
|
* Generates the C# code for a library.
|
|
75
74
|
*/
|
|
76
|
-
export const cs = name => library => {
|
|
75
|
+
export const cs = (name) => (library) => {
|
|
77
76
|
const v = flatMapDef(entries(library));
|
|
78
77
|
const ns = namespace(name)(v);
|
|
79
78
|
return flat([header, ns]);
|
package/com/rust/module.f.d.ts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* This module generates Rust code for COM interop from a high-level type library definition.
|
|
3
3
|
*
|
|
4
4
|
* The module provides functions to define structs, traits, and implementations in Rust,
|
|
5
|
-
* specifically tailored for `nanocom`
|
|
5
|
+
* specifically tailored for `nanocom` interpretation.
|
|
6
6
|
*/
|
|
7
7
|
import { type Library } from '../types/module.f.ts';
|
|
8
|
-
import * as
|
|
8
|
+
import type * as text from '../../text/module.f.ts';
|
|
9
9
|
/**
|
|
10
10
|
* Generates Rust code for the given type library.
|
|
11
11
|
*
|
|
12
12
|
* @param library - The library of type definitions to generate Rust code for.
|
|
13
13
|
* @returns A block of Rust code representing the library.
|
|
14
14
|
*/
|
|
15
|
-
export declare const rust: (library: Library) =>
|
|
15
|
+
export declare const rust: (library: Library) => text.Block;
|
package/com/rust/module.f.js
CHANGED
|
@@ -2,35 +2,30 @@
|
|
|
2
2
|
* This module generates Rust code for COM interop from a high-level type library definition.
|
|
3
3
|
*
|
|
4
4
|
* The module provides functions to define structs, traits, and implementations in Rust,
|
|
5
|
-
* specifically tailored for `nanocom`
|
|
5
|
+
* specifically tailored for `nanocom` interpretation.
|
|
6
6
|
*/
|
|
7
7
|
import { paramList } from "../types/module.f.js";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
const { flat, map, flatMap } = list;
|
|
8
|
+
import { flat, map, flatMap } from "../../types/list/module.f.js";
|
|
9
|
+
import { fn } from "../../types/function/module.f.js";
|
|
10
|
+
import { join } from "../../types/string/module.f.js";
|
|
12
11
|
const { entries } = Object;
|
|
13
|
-
|
|
14
|
-
const { fn } = func;
|
|
15
|
-
import * as string from "../../types/string/module.f.js";
|
|
16
|
-
const { join } = string;
|
|
17
|
-
const rustField = field => `pub ${field},`;
|
|
12
|
+
const rustField = (field) => `pub ${field},`;
|
|
18
13
|
const mapRustField = map(rustField);
|
|
19
|
-
const rustStruct = b => name => [`#[repr(C)]`, `pub struct ${name} {`, mapRustField(b), `}`];
|
|
14
|
+
const rustStruct = (b) => (name) => [`#[repr(C)]`, `pub struct ${name} {`, mapRustField(b), `}`];
|
|
20
15
|
const commaJoin = join(', ');
|
|
21
|
-
const ref = name => `${name}::Ref`;
|
|
22
|
-
const obj = name => `&${name}::Object`;
|
|
16
|
+
const ref = (name) => `${name}::Ref`;
|
|
17
|
+
const obj = (name) => `&${name}::Object`;
|
|
23
18
|
const self = ['&self'];
|
|
24
19
|
const paramName = ([n]) => n;
|
|
25
|
-
const callList = p => map(paramName)(paramList(p));
|
|
26
|
-
const call = p => commaJoin(callList(p));
|
|
27
|
-
const virtualCall = p => commaJoin(flat([['self'], callList(p)]));
|
|
20
|
+
const callList = (p) => map(paramName)(paramList(p));
|
|
21
|
+
const call = (p) => commaJoin(callList(p));
|
|
22
|
+
const virtualCall = (p) => commaJoin(flat([['self'], callList(p)]));
|
|
28
23
|
const super_ = 'super::';
|
|
29
24
|
const assign = ([n]) => `${n}: Self::${n},`;
|
|
30
25
|
const mapAssign = map(assign);
|
|
31
26
|
const this_ = ['this: &Object'];
|
|
32
|
-
const rustType = n => `pub type ${n} = nanocom::${n}<Interface>;`;
|
|
33
|
-
const whereContent = h => wh => {
|
|
27
|
+
const rustType = (n) => `pub type ${n} = nanocom::${n}<Interface>;`;
|
|
28
|
+
const whereContent = (h) => (wh) => {
|
|
34
29
|
const w = 'where' in wh ? [
|
|
35
30
|
h,
|
|
36
31
|
`where`,
|
|
@@ -43,19 +38,19 @@ const whereContent = h => wh => {
|
|
|
43
38
|
];
|
|
44
39
|
return flat([w, x]);
|
|
45
40
|
};
|
|
46
|
-
const rustImpl = i => {
|
|
41
|
+
const rustImpl = (i) => {
|
|
47
42
|
const p = 'param' in i ? `<${i.param}>` : '';
|
|
48
43
|
const header = `impl${p} ${i.trait} for ${i.type}`;
|
|
49
44
|
return whereContent(header)(i);
|
|
50
45
|
};
|
|
51
46
|
const comma = s => `${s},`;
|
|
52
47
|
const mapComma = map(comma);
|
|
53
|
-
const trait = t => {
|
|
48
|
+
const trait = (t) => {
|
|
54
49
|
const p = t.pub === true ? 'pub ' : '';
|
|
55
50
|
const h = `${p}trait ${t.type}`;
|
|
56
51
|
return whereContent(h)(t);
|
|
57
52
|
};
|
|
58
|
-
const traitImpl = t => {
|
|
53
|
+
const traitImpl = (t) => {
|
|
59
54
|
const i = rustImpl({
|
|
60
55
|
param: 'T',
|
|
61
56
|
trait: t.type,
|
|
@@ -73,8 +68,8 @@ const where = ['Self: nanocom::Class<Interface = Interface>', 'nanocom::CObject<
|
|
|
73
68
|
* @returns A block of Rust code representing the library.
|
|
74
69
|
*/
|
|
75
70
|
export const rust = (library) => {
|
|
76
|
-
const type = p => {
|
|
77
|
-
const f = o => t => {
|
|
71
|
+
const type = (p) => {
|
|
72
|
+
const f = (o) => (t) => {
|
|
78
73
|
if (typeof t === 'string') {
|
|
79
74
|
return t;
|
|
80
75
|
}
|
|
@@ -87,7 +82,7 @@ export const rust = (library) => {
|
|
|
87
82
|
};
|
|
88
83
|
return f;
|
|
89
84
|
};
|
|
90
|
-
const pf = p => o => ([name, t]) => `${name}: ${type(p)(o)(t)}`;
|
|
85
|
+
const pf = (p) => (o) => ([name, t]) => `${name}: ${type(p)(o)(t)}`;
|
|
91
86
|
const param = pf(super_)(obj);
|
|
92
87
|
const mapParam = map(param);
|
|
93
88
|
const mapField = map(pf('')(ref));
|
|
@@ -95,18 +90,18 @@ export const rust = (library) => {
|
|
|
95
90
|
.then(mapField)
|
|
96
91
|
.then(rustStruct)
|
|
97
92
|
.result;
|
|
98
|
-
const func = first => p => {
|
|
93
|
+
const func = (first) => (p) => {
|
|
99
94
|
const resultStr = '_' in p ? ` -> ${type(super_)(ref)(p._)}` : '';
|
|
100
95
|
const params = commaJoin(flat([first, mapParam(paramList(p))]));
|
|
101
96
|
return `(${params})${resultStr}`;
|
|
102
97
|
};
|
|
103
|
-
const virtualFnType = n => p => `extern "system" fn${n}${func(this_)(p)}`;
|
|
98
|
+
const virtualFnType = (n) => (p) => `extern "system" fn${n}${func(this_)(p)}`;
|
|
104
99
|
const virtualFn = ([n, p]) => `${n}: unsafe ${virtualFnType('')(p)}`;
|
|
105
100
|
const mapVirtualFn = map(virtualFn);
|
|
106
101
|
const headerFn = ([n, p]) => `fn ${n}${func(self)(p)}`;
|
|
107
|
-
const traitFn = m => `${headerFn(m)};`;
|
|
102
|
+
const traitFn = (m) => `${headerFn(m)};`;
|
|
108
103
|
const mapTraitFn = map(traitFn);
|
|
109
|
-
const implFn = m => {
|
|
104
|
+
const implFn = (m) => {
|
|
110
105
|
const [n, p] = m;
|
|
111
106
|
return [
|
|
112
107
|
`${headerFn(m)} {`,
|
|
@@ -124,7 +119,7 @@ export const rust = (library) => {
|
|
|
124
119
|
];
|
|
125
120
|
};
|
|
126
121
|
const flatMapImpl = flatMap(impl);
|
|
127
|
-
const interface_ = ({ interface: i, guid }) => name => {
|
|
122
|
+
const interface_ = ({ interface: i, guid }) => (name) => {
|
|
128
123
|
const e = entries(i);
|
|
129
124
|
return [
|
|
130
125
|
`pub mod ${name} {`,
|
package/com/test/build.f.js
CHANGED
|
@@ -2,7 +2,7 @@ import { flat } from "../../types/list/module.f.js";
|
|
|
2
2
|
import cppContent from "../cpp/testlib.f.js";
|
|
3
3
|
import csContent from "../cs/testlib.f.js";
|
|
4
4
|
import rustContent from "../rust/testlib.f.js";
|
|
5
|
-
const flags = platform => {
|
|
5
|
+
const flags = (platform) => {
|
|
6
6
|
switch (platform) {
|
|
7
7
|
case 'win32':
|
|
8
8
|
return [];
|
|
@@ -12,7 +12,7 @@ const flags = platform => {
|
|
|
12
12
|
return ['-std=c++17', '-lc++'];
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
-
const output = platform => name => {
|
|
15
|
+
const output = (platform) => (name) => {
|
|
16
16
|
switch (platform) {
|
|
17
17
|
case 'win32': return `${name}.dll`;
|
|
18
18
|
case 'darwin': return `lib${name}.dylib`;
|
package/com/types/module.f.d.ts
CHANGED
package/com/types/module.f.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import * as O from "../../types/object/module.f.js";
|
|
2
1
|
import { filter } from "../../types/list/module.f.js";
|
|
3
2
|
import { compose } from "../../types/function/module.f.js";
|
|
4
3
|
const { entries } = Object;
|
|
5
4
|
const isParam = ([name]) => name !== '_';
|
|
6
5
|
const filterParam = filter(isParam);
|
|
7
6
|
export const paramList = compose(entries)(filterParam);
|
|
8
|
-
export const result = v => f => fa => '_' in fa ? f(fa._) : v;
|
|
7
|
+
export const result = (v) => (f) => (fa) => '_' in fa ? f(fa._) : v;
|
package/com/types/testlib.f.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as package_ from '../package/module.f.ts';
|
|
1
|
+
import type * as package_ from '../package/module.f.ts';
|
|
2
2
|
import { type MapInterface, type Id, type State } from '../module/module.f.ts';
|
|
3
|
-
import * as function_ from '../module/function/module.f.ts';
|
|
3
|
+
import type * as function_ from '../module/function/module.f.ts';
|
|
4
4
|
type Result<M> = readonly [State, M];
|
|
5
5
|
export declare const getOrBuild: (compile: function_.Compile) => (packageGet: package_.Get) => <M>(moduleMapInterface: MapInterface<M>) => (moduleId: Id) => (moduleMap: M) => Result<M>;
|
|
6
6
|
export {};
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import * as package_ from "../package/module.f.js";
|
|
2
1
|
import { idToString, dir, } from "../module/module.f.js";
|
|
3
|
-
import
|
|
4
|
-
import * as map from "../../types/map/module.f.js";
|
|
5
|
-
const { empty: mapEmpty, setReplace } = map;
|
|
2
|
+
import { empty as mapEmpty, setReplace } from "../../types/map/module.f.js";
|
|
6
3
|
import * as object from "../../types/object/module.f.js";
|
|
7
4
|
const { fromMap } = object;
|
|
8
5
|
import * as path from "../path/module.f.js";
|
|
9
6
|
const { parseAndFind } = path;
|
|
10
7
|
import * as stringSet from "../../types/string_set/module.f.js";
|
|
11
8
|
const { set: setSet, contains: setContains, empty: stringSetEmpty } = stringSet;
|
|
12
|
-
const notFound = moduleMap => [['error', ['file not found']], moduleMap];
|
|
9
|
+
const notFound = (moduleMap) => [['error', ['file not found']], moduleMap];
|
|
13
10
|
export const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
14
11
|
const build = buildSet => moduleId => {
|
|
15
12
|
const moduleIdStr = idToString(moduleId);
|
|
@@ -47,7 +44,7 @@ export const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
|
47
44
|
return x(moduleMap2);
|
|
48
45
|
};
|
|
49
46
|
};
|
|
50
|
-
const f = moduleId => moduleMap => {
|
|
47
|
+
const f = (moduleId) => (moduleMap) => {
|
|
51
48
|
const moduleIdStr = idToString(moduleId);
|
|
52
49
|
// check moduleMap
|
|
53
50
|
{
|
package/commonjs/build/test.f.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import * as _ from "./module.f.js";
|
|
2
2
|
import * as map from "../../types/map/module.f.js";
|
|
3
|
-
import * as Module from "../module/module.f.js";
|
|
4
|
-
import * as ModuleFunction from "../module/function/module.f.js";
|
|
5
|
-
import * as Result from "../../types/result/module.f.js";
|
|
6
|
-
import * as Package from "../package/module.f.js";
|
|
7
3
|
import { at } from "../../types/object/module.f.js";
|
|
8
4
|
const compileMap = {
|
|
9
5
|
':index.js': [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* An IO interface for creating and running module functions.
|
|
3
3
|
*/
|
|
4
|
-
import * as TypesResult from '../../../types/result/module.f.ts';
|
|
4
|
+
import type * as TypesResult from '../../../types/result/module.f.ts';
|
|
5
5
|
export type Function_ = <M>(require: Require<M>) => (prior: M) => Result<M>;
|
|
6
6
|
export type Result<M> = readonly [TypesResult.Result<unknown, unknown>, M];
|
|
7
7
|
export type Require<M> = (path: string) => (prior: M) => Result<M>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as O from '../../types/object/module.f.ts';
|
|
1
|
+
import type * as O from '../../types/object/module.f.ts';
|
|
2
2
|
export type MapInterface<M> = {
|
|
3
3
|
readonly at: (moduleId: string) => (moduleMap: M) => State | null;
|
|
4
4
|
readonly setReplace: (moduleId: string) => (moduleState: State) => (moduleMap: M) => M;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export const dir = id => {
|
|
1
|
+
export const dir = (id) => {
|
|
3
2
|
const len = id.path.length;
|
|
4
3
|
if (len < 1) {
|
|
5
4
|
return null;
|
|
@@ -9,4 +8,4 @@ export const dir = id => {
|
|
|
9
8
|
path: id.path.slice(0, len - 1)
|
|
10
9
|
};
|
|
11
10
|
};
|
|
12
|
-
export const idToString = id => `${id.package}/${id.path.join('/')}`;
|
|
11
|
+
export const idToString = (id) => `${id.package}/${id.path.join('/')}`;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type List } from '../../types/list/module.f.ts';
|
|
2
|
-
import * as Package from '../package/module.f.ts';
|
|
3
|
-
import * as Module from '../module/module.f.ts';
|
|
2
|
+
import type * as Package from '../package/module.f.ts';
|
|
3
|
+
import type * as Module from '../module/module.f.ts';
|
|
4
4
|
type Items = readonly string[];
|
|
5
5
|
type LocalPath = {
|
|
6
6
|
readonly external: boolean;
|
|
@@ -8,17 +8,17 @@ type LocalPath = {
|
|
|
8
8
|
readonly items: Items;
|
|
9
9
|
};
|
|
10
10
|
export declare const parseLocal: (local: string) => (path: string) => LocalPath | null;
|
|
11
|
-
type Path = {
|
|
11
|
+
export type Path = {
|
|
12
12
|
readonly package: string;
|
|
13
13
|
readonly items: Items;
|
|
14
14
|
readonly dir: boolean;
|
|
15
15
|
};
|
|
16
16
|
export declare const parseGlobal: (d: (local: string) => string | null) => (dir: boolean) => (items: List<string>) => Path | null;
|
|
17
17
|
export declare const parse: (packageId: string) => (dependencies: (local: string) => string | null) => (local: string) => (path: string) => Path | null;
|
|
18
|
-
type FoundResult = {
|
|
18
|
+
export type FoundResult = {
|
|
19
19
|
readonly id: Module.Id;
|
|
20
20
|
readonly source: string;
|
|
21
21
|
};
|
|
22
|
-
type Result = FoundResult | null;
|
|
22
|
+
export type Result = FoundResult | null;
|
|
23
23
|
export declare const parseAndFind: (packageGet: Package.Get) => (moduleId: Module.Id) => (path: string) => Result;
|
|
24
24
|
export {};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { next, fold, reverse, first, flat, toArray, filterMap, isEmpty, concat, empty } from "../../types/list/module.f.js";
|
|
2
2
|
import { join } from "../../types/string/module.f.js";
|
|
3
|
-
import * as Package from "../package/module.f.js";
|
|
4
|
-
import * as Module from "../module/module.f.js";
|
|
5
3
|
const split = path => path.split('/');
|
|
6
|
-
const normItemsOp = first => prior => {
|
|
4
|
+
const normItemsOp = (first) => (prior) => {
|
|
7
5
|
if (prior === null) {
|
|
8
6
|
return null;
|
|
9
7
|
}
|
|
@@ -25,13 +23,13 @@ const normItemsOp = first => prior => {
|
|
|
25
23
|
}
|
|
26
24
|
}
|
|
27
25
|
};
|
|
28
|
-
const normItems = items => {
|
|
26
|
+
const normItems = (items) => {
|
|
29
27
|
const result = fold(normItemsOp)([empty])(items);
|
|
30
28
|
return result === null ? result : [reverse(result[0])];
|
|
31
29
|
};
|
|
32
30
|
const firstNull = first(null);
|
|
33
|
-
export const parseLocal = local => {
|
|
34
|
-
const fSeq = path => {
|
|
31
|
+
export const parseLocal = (local) => {
|
|
32
|
+
const fSeq = (path) => {
|
|
35
33
|
const pathSeq = split(path);
|
|
36
34
|
const dir = [null, '', '.', '..'].includes(pathSeq[pathSeq.length - 1]);
|
|
37
35
|
return ['.', '..'].includes(firstNull(pathSeq)) ?
|
|
@@ -51,7 +49,7 @@ export const parseLocal = local => {
|
|
|
51
49
|
};
|
|
52
50
|
};
|
|
53
51
|
};
|
|
54
|
-
const variants = prior => () => {
|
|
52
|
+
const variants = (prior) => () => {
|
|
55
53
|
const [a, b] = prior;
|
|
56
54
|
const r = next(b);
|
|
57
55
|
if (r === empty) {
|
|
@@ -61,7 +59,7 @@ const variants = prior => () => {
|
|
|
61
59
|
const n = [a === null ? first : `${a}/${first}`, tail];
|
|
62
60
|
return { first: n, tail: variants(n) };
|
|
63
61
|
};
|
|
64
|
-
const mapDependency = d => ([external, internal]) => {
|
|
62
|
+
const mapDependency = (d) => ([external, internal]) => {
|
|
65
63
|
const id = d(external);
|
|
66
64
|
return id === null ? null : [id, internal];
|
|
67
65
|
};
|
package/commonjs/path/test.f.js
CHANGED
|
@@ -3,8 +3,7 @@ import { todo } from "../../dev/module.f.js";
|
|
|
3
3
|
import * as json from "../../json/module.f.js";
|
|
4
4
|
import { identity } from "../../types/function/module.f.js";
|
|
5
5
|
import { at } from "../../types/object/module.f.js";
|
|
6
|
-
|
|
7
|
-
const i = o => s => at(s)(o);
|
|
6
|
+
const i = (o) => (s) => at(s)(o);
|
|
8
7
|
const stringify = json.stringify(identity);
|
|
9
8
|
export default {
|
|
10
9
|
0: () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as Operator from '../../types/function/operator/module.f.ts';
|
|
1
|
+
import type * as Operator from '../../types/function/operator/module.f.ts';
|
|
2
2
|
type Reduce = Operator.Reduce<bigint>;
|
|
3
3
|
type Unary = Operator.Unary<bigint, bigint>;
|
|
4
4
|
/**
|
|
@@ -39,5 +39,5 @@ export declare const prime_field: (p: bigint) => PrimeField;
|
|
|
39
39
|
* if (root !== 2n) { throw root }
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
export declare const sqrt: (
|
|
42
|
+
export declare const sqrt: ({ p, mul, pow }: PrimeField) => (a: bigint) => bigint | null;
|
|
43
43
|
export {};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { scalar_mul } from "../../types/bigint/module.f.js";
|
|
1
|
+
import { repeat } from "../../types/monoid/module.f.js";
|
|
3
2
|
/**
|
|
4
3
|
* Creates a prime field with the specified prime modulus and associated operations.
|
|
5
4
|
*
|
|
6
5
|
* @param p - A prime number to define the field.
|
|
7
6
|
* @returns The prime field object.
|
|
8
7
|
*/
|
|
9
|
-
export const prime_field = p => {
|
|
8
|
+
export const prime_field = (p) => {
|
|
10
9
|
const sub = a => b => {
|
|
11
10
|
const r = a - b;
|
|
12
11
|
return r < 0 ? r + p : r;
|
|
@@ -33,7 +32,7 @@ export const prime_field = p => {
|
|
|
33
32
|
};
|
|
34
33
|
const middle = p >> 1n;
|
|
35
34
|
const pow2 = a => mul(a)(a);
|
|
36
|
-
const pow =
|
|
35
|
+
const pow = repeat({ identity: 1n, operation: mul });
|
|
37
36
|
return {
|
|
38
37
|
p,
|
|
39
38
|
middle,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as Operator from '../../types/function/operator/module.f.ts';
|
|
1
|
+
import type * as Operator from '../../types/function/operator/module.f.ts';
|
|
2
2
|
import { type PrimeField } from '../prime_field/module.f.ts';
|
|
3
3
|
/**
|
|
4
4
|
* A 2D point represented as a pair of `bigint` values `[x, y]`.
|
|
@@ -50,7 +50,7 @@ type Curve = {
|
|
|
50
50
|
* const mulPoint = curveInstance.mul([1n, 1n])(3n); // Multiply a point by 3
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
|
-
export declare const curve: (
|
|
53
|
+
export declare const curve: ({ p, a: [a0, a1], n }: Init) => Curve;
|
|
54
54
|
export declare const eq: (a: Point) => (b: Point) => boolean;
|
|
55
55
|
/**
|
|
56
56
|
* https://neuromancer.sk/std/secg/secp192r1
|
package/crypto/secp/module.f.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as Operator from "../../types/function/operator/module.f.js";
|
|
2
1
|
import { prime_field, sqrt } from "../prime_field/module.f.js";
|
|
3
|
-
import {
|
|
2
|
+
import { repeat } from "../../types/monoid/module.f.js";
|
|
4
3
|
/**
|
|
5
4
|
* Constructs an elliptic curve with the given initialization parameters.
|
|
6
5
|
*
|
|
@@ -32,7 +31,7 @@ export const curve = ({ p, a: [a0, a1], n }) => {
|
|
|
32
31
|
/**
|
|
33
32
|
* y**2 = a1*x**3 + a0
|
|
34
33
|
*/
|
|
35
|
-
const y2 = x => addA0(add(pow3(x))(mulA1(x)));
|
|
34
|
+
const y2 = (x) => addA0(add(pow3(x))(mulA1(x)));
|
|
36
35
|
const addPoint = p => q => {
|
|
37
36
|
if (p === null) {
|
|
38
37
|
return q;
|
|
@@ -71,10 +70,10 @@ export const curve = ({ p, a: [a0, a1], n }) => {
|
|
|
71
70
|
return [x, neg(y)];
|
|
72
71
|
},
|
|
73
72
|
add: addPoint,
|
|
74
|
-
mul:
|
|
73
|
+
mul: repeat({ identity: null, operation: addPoint })
|
|
75
74
|
};
|
|
76
75
|
};
|
|
77
|
-
export const eq = a => b => {
|
|
76
|
+
export const eq = (a) => (b) => {
|
|
78
77
|
if (a === null || b === null) {
|
|
79
78
|
return a === b;
|
|
80
79
|
}
|
|
@@ -1,13 +1,76 @@
|
|
|
1
|
-
import
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { Array16, Array8 } from '../../types/array/module.f.ts';
|
|
2
|
+
import { type Vec } from '../../types/bit_vec/module.f.ts';
|
|
3
|
+
export type V8 = Array8<bigint>;
|
|
4
|
+
export type V16 = Array16<bigint>;
|
|
5
|
+
/**
|
|
6
|
+
* Type definition for the state of the SHA-2 algorithm.
|
|
7
|
+
*/
|
|
8
|
+
export type State = {
|
|
9
|
+
/**
|
|
10
|
+
* The current hash value.
|
|
11
|
+
*/
|
|
12
|
+
readonly hash: V8;
|
|
13
|
+
/**
|
|
14
|
+
* The length of the data processed so far.
|
|
15
|
+
*/
|
|
16
|
+
readonly len: bigint;
|
|
17
|
+
/**
|
|
18
|
+
* The remaining data that has not yet been processed.
|
|
19
|
+
*/
|
|
20
|
+
readonly remainder: Vec;
|
|
5
21
|
};
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
22
|
+
export type Base = {
|
|
23
|
+
readonly bitLength: bigint;
|
|
24
|
+
readonly chunkLength: bigint;
|
|
25
|
+
readonly compress: (i: V8) => (u: bigint) => V8;
|
|
26
|
+
readonly fromV8: (a: V8) => bigint;
|
|
27
|
+
readonly append: (state: State) => (v: Vec) => State;
|
|
28
|
+
readonly end: (hashLength: bigint) => (state: State) => bigint;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* SHA2. See https://en.wikipedia.org/wiki/SHA-2
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
*
|
|
35
|
+
* ```js
|
|
36
|
+
* const s = msbUtf8("The quick brown fox jumps over the lazy dog.")
|
|
37
|
+
* let state = sha224.init
|
|
38
|
+
* state = sha224.append(state)(s)
|
|
39
|
+
* const h = sha224.end(state) // 0x619cba8e8e05826e9b8c519c0a5c68f4fb653e8a3d8aa04bb2c8cd4cn
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export type Sha2 = {
|
|
43
|
+
/**
|
|
44
|
+
* Initial state of the SHA-2 algorithm.
|
|
45
|
+
*/
|
|
46
|
+
readonly init: State;
|
|
47
|
+
/**
|
|
48
|
+
* Appends data to the state and returns the new state.
|
|
49
|
+
*
|
|
50
|
+
* @param state The current state.
|
|
51
|
+
* @param v The data to append.
|
|
52
|
+
* @returns The new state after appending data.
|
|
53
|
+
*/
|
|
54
|
+
readonly append: (state: State) => (v: Vec) => State;
|
|
55
|
+
/**
|
|
56
|
+
* Finalizes the hash and returns the result as a bigint.
|
|
57
|
+
*
|
|
58
|
+
* @param state The final state.
|
|
59
|
+
* @returns The resulting hash.
|
|
60
|
+
*/
|
|
61
|
+
readonly end: (state: State) => bigint;
|
|
62
|
+
};
|
|
63
|
+
export declare const base32: Base;
|
|
64
|
+
export declare const base64: Base;
|
|
65
|
+
/** SHA-256 */
|
|
66
|
+
export declare const sha256: Sha2;
|
|
67
|
+
/** SHA-224 */
|
|
68
|
+
export declare const sha224: Sha2;
|
|
69
|
+
/** SHA-512 */
|
|
70
|
+
export declare const sha512: Sha2;
|
|
71
|
+
/** SHA-384 */
|
|
72
|
+
export declare const sha384: Sha2;
|
|
73
|
+
/** SHA-512/256 */
|
|
74
|
+
export declare const sha512x256: Sha2;
|
|
75
|
+
/** SHA-512/224 */
|
|
76
|
+
export declare const sha512x224: Sha2;
|