functionalscript 0.0.427 → 0.0.429
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/rust/module.f.cjs +102 -29
- package/com/rust/test.f.cjs +17 -5
- package/commonjs/build/module.f.cjs +1 -1
- package/fsm/README.md +4 -0
- package/fsm/module.f.cjs +28 -0
- package/package.json +1 -1
- package/types/byte_set/module.f.cjs +57 -0
- package/types/{byteSet → byte_set}/test.f.cjs +0 -0
- package/types/module.f.cjs +3 -1
- package/types/{nibbleSet → nibble_set}/module.f.cjs +0 -0
- package/types/{nibbleSet → nibble_set}/test.f.cjs +0 -0
- package/types/{stringset → string_set}/module.f.cjs +0 -0
- package/types/{stringset → string_set}/test.f.cjs +0 -0
- package/types/byteSet/module.f.cjs +0 -30
package/com/rust/module.f.cjs
CHANGED
|
@@ -3,7 +3,7 @@ const { paramList } = types
|
|
|
3
3
|
const text = require('../../text/module.f.cjs')
|
|
4
4
|
const object = require('../../types/object/module.f.cjs')
|
|
5
5
|
const list = require('../../types/list/module.f.cjs')
|
|
6
|
-
const { flat, map, flatMap } = list
|
|
6
|
+
const { flat, map, flatMap, isEmpty } = list
|
|
7
7
|
const { entries } = Object
|
|
8
8
|
const { fn } = require('../../types/function/module.f.cjs')
|
|
9
9
|
const { join } = require('../../types/string/module.f.cjs')
|
|
@@ -47,6 +47,83 @@ const mapAssign = map(assign)
|
|
|
47
47
|
|
|
48
48
|
const this_ = ['this: &Object']
|
|
49
49
|
|
|
50
|
+
/** @type {(n: string) => string} */
|
|
51
|
+
const rustType = n => `pub type ${n} = nanocom::${n}<Interface>;`
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @typedef {{
|
|
55
|
+
* readonly where?: readonly string[]
|
|
56
|
+
* readonly content: text.Block
|
|
57
|
+
* }} WhereContent
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/** @type {(h: string) => (wh: WhereContent) => text.Block} */
|
|
61
|
+
const whereContent = h => ({ where, content }) => {
|
|
62
|
+
const w = isEmpty(where) ? [`${h} {`] : [
|
|
63
|
+
h,
|
|
64
|
+
`where`,
|
|
65
|
+
mapComma(where),
|
|
66
|
+
'{'
|
|
67
|
+
]
|
|
68
|
+
const x = [
|
|
69
|
+
content,
|
|
70
|
+
'}',
|
|
71
|
+
]
|
|
72
|
+
return flat([w, x])
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @typedef {{
|
|
77
|
+
* readonly param?: string
|
|
78
|
+
* readonly trait: string
|
|
79
|
+
* readonly type: string
|
|
80
|
+
* readonly where?: readonly string[]
|
|
81
|
+
* readonly content: text.Block
|
|
82
|
+
* }} Impl
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
/** @type {(impl: Impl) => text.Block} */
|
|
86
|
+
const rustImpl = i => {
|
|
87
|
+
const p = i.param === undefined ? '' : `<${i.param}>`
|
|
88
|
+
const header = `impl${p} ${i.trait} for ${i.type}`
|
|
89
|
+
return whereContent(header)(i)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @typedef {{
|
|
94
|
+
* readonly pub?: true
|
|
95
|
+
* readonly type: string
|
|
96
|
+
* readonly where?: readonly string[]
|
|
97
|
+
* readonly content: text.Block
|
|
98
|
+
* }} Trait
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
/** @type {(s: string) => string} */
|
|
102
|
+
const comma = s => `${s},`
|
|
103
|
+
|
|
104
|
+
const mapComma = map(comma)
|
|
105
|
+
|
|
106
|
+
/** @type {(t: Trait) => text.Block} */
|
|
107
|
+
const trait = t => {
|
|
108
|
+
const p = t.pub === true ? 'pub ' : ''
|
|
109
|
+
const h = `${p}trait ${t.type}`
|
|
110
|
+
return whereContent(h)(t)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** @type {(t: Trait) => text.Block} */
|
|
114
|
+
const traitImpl = t => {
|
|
115
|
+
const i = rustImpl({
|
|
116
|
+
param: 'T',
|
|
117
|
+
trait: t.type,
|
|
118
|
+
type: 'T',
|
|
119
|
+
where,
|
|
120
|
+
content: [],
|
|
121
|
+
})
|
|
122
|
+
return flat([trait({ ...t, where }), i])
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const where = ['Self: nanocom::Class<Interface = Interface>', 'nanocom::CObject<Self>: Ex']
|
|
126
|
+
|
|
50
127
|
/** @type {(library: types.Library) => text.Block} */
|
|
51
128
|
const rust = library => {
|
|
52
129
|
|
|
@@ -134,38 +211,34 @@ const rust = library => {
|
|
|
134
211
|
return [
|
|
135
212
|
`pub mod ${name} {`,
|
|
136
213
|
[
|
|
137
|
-
'
|
|
138
|
-
'
|
|
139
|
-
'
|
|
214
|
+
rustType('Object'),
|
|
215
|
+
rustType('Ref'),
|
|
216
|
+
rustType('Vmt'),
|
|
140
217
|
],
|
|
141
218
|
rustStruct(mapVirtualFn(e))('Interface'),
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
'
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
'
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
219
|
+
rustImpl({
|
|
220
|
+
trait: 'nanocom::Interface',
|
|
221
|
+
type: 'Interface',
|
|
222
|
+
content: [`const GUID: nanocom::GUID = 0x${guid.replaceAll('-', '_')};`]
|
|
223
|
+
}),
|
|
224
|
+
trait({ pub: true, type: 'Ex', content: mapTraitFn(e) }),
|
|
225
|
+
rustImpl({
|
|
226
|
+
trait: 'Ex',
|
|
227
|
+
type: 'Object',
|
|
228
|
+
content: flatMapImplFn(e)
|
|
229
|
+
}),
|
|
230
|
+
traitImpl({
|
|
231
|
+
pub: true,
|
|
232
|
+
type: 'ClassEx',
|
|
233
|
+
content: [`const INTERFACE: Interface = Interface {`,
|
|
156
234
|
mapAssign(e),
|
|
157
235
|
'};'
|
|
158
|
-
]
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
`{`,
|
|
165
|
-
flatMapImpl(e),
|
|
166
|
-
`}`,
|
|
167
|
-
'impl<T: nanocom::Class<Interface = Interface>> PrivateClassEx for T where nanocom::CObject<T>: Ex {}',
|
|
168
|
-
],
|
|
236
|
+
]
|
|
237
|
+
}),
|
|
238
|
+
traitImpl({
|
|
239
|
+
type: 'PrivateClassEx',
|
|
240
|
+
content: flatMapImpl(e)
|
|
241
|
+
}),
|
|
169
242
|
'}'
|
|
170
243
|
]
|
|
171
244
|
}
|
package/com/rust/test.f.cjs
CHANGED
|
@@ -57,8 +57,9 @@ module.exports = {
|
|
|
57
57
|
' unsafe { (self.interface().GetIMy)(self) }\n' +
|
|
58
58
|
' }\n' +
|
|
59
59
|
' }\n' +
|
|
60
|
-
' pub trait ClassEx
|
|
60
|
+
' pub trait ClassEx\n' +
|
|
61
61
|
' where\n' +
|
|
62
|
+
' Self: nanocom::Class<Interface = Interface>,\n' +
|
|
62
63
|
' nanocom::CObject<Self>: Ex,\n' +
|
|
63
64
|
' {\n' +
|
|
64
65
|
' const INTERFACE: Interface = Interface {\n' +
|
|
@@ -70,10 +71,16 @@ module.exports = {
|
|
|
70
71
|
' GetIMy: Self::GetIMy,\n' +
|
|
71
72
|
' };\n' +
|
|
72
73
|
' }\n' +
|
|
73
|
-
' impl<T
|
|
74
|
-
' trait PrivateClassEx: nanocom::Class<Interface = Interface>\n' +
|
|
74
|
+
' impl<T> ClassEx for T\n' +
|
|
75
75
|
' where\n' +
|
|
76
|
-
' nanocom::
|
|
76
|
+
' Self: nanocom::Class<Interface = Interface>,\n' +
|
|
77
|
+
' nanocom::CObject<Self>: Ex,\n' +
|
|
78
|
+
' {\n' +
|
|
79
|
+
' }\n' +
|
|
80
|
+
' trait PrivateClassEx\n' +
|
|
81
|
+
' where\n' +
|
|
82
|
+
' Self: nanocom::Class<Interface = Interface>,\n' +
|
|
83
|
+
' nanocom::CObject<Self>: Ex,\n' +
|
|
77
84
|
' {\n' +
|
|
78
85
|
' extern "system" fn GetSlice(this: &Object) -> super::Slice {\n' +
|
|
79
86
|
' unsafe { Self::to_cobject(this) }.GetSlice()\n' +
|
|
@@ -94,7 +101,12 @@ module.exports = {
|
|
|
94
101
|
' unsafe { Self::to_cobject(this) }.GetIMy()\n' +
|
|
95
102
|
' }\n' +
|
|
96
103
|
' }\n' +
|
|
97
|
-
' impl<T
|
|
104
|
+
' impl<T> PrivateClassEx for T\n' +
|
|
105
|
+
' where\n' +
|
|
106
|
+
' Self: nanocom::Class<Interface = Interface>,\n' +
|
|
107
|
+
' nanocom::CObject<Self>: Ex,\n' +
|
|
108
|
+
' {\n' +
|
|
109
|
+
' }\n' +
|
|
98
110
|
'}'
|
|
99
111
|
const r = join('\n')(flat(' ')(rust(library)))
|
|
100
112
|
if (r !== e) { throw [e, r] }
|
|
@@ -8,7 +8,7 @@ const object = require('../../types/object/module.f.cjs')
|
|
|
8
8
|
const { fromMap } = object
|
|
9
9
|
const path = require('../path/module.f.cjs')
|
|
10
10
|
const { parseAndFind } = path
|
|
11
|
-
const stringSet = require('../../types/
|
|
11
|
+
const stringSet = require('../../types/string_set/module.f.cjs')
|
|
12
12
|
const { set: setSet, contains: setContains } = stringSet
|
|
13
13
|
|
|
14
14
|
/**
|
package/fsm/README.md
ADDED
package/fsm/module.f.cjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const { todo } = require('../dev/module.f.cjs')
|
|
2
|
+
const list = require('../types/list/module.f.cjs')
|
|
3
|
+
const byteSet = require('../types/byte_set/module.f.cjs')
|
|
4
|
+
|
|
5
|
+
/** @typedef {readonly[string, byteSet.ByteSet, string]} Rule */
|
|
6
|
+
|
|
7
|
+
/** @typedef {list.List<Rule>} Grammar */
|
|
8
|
+
|
|
9
|
+
/** @typedef {readonly string[]} ByteMap */
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {{
|
|
13
|
+
* readonly[state in string]: ByteMap
|
|
14
|
+
* }} Dfa
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** @type {(faId: string) => string} */
|
|
18
|
+
const escape = faId => todo()
|
|
19
|
+
|
|
20
|
+
/** @type {(grammar: Grammar) => Dfa} */
|
|
21
|
+
const dfa = grammar => todo()
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
/** @readonly */
|
|
25
|
+
escape,
|
|
26
|
+
/** @readonly */
|
|
27
|
+
dfa,
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const { fn } = require('../function/module.f.cjs')
|
|
2
|
+
|
|
3
|
+
/** @typedef {bigint} ByteSet */
|
|
4
|
+
/** @typedef {number} Byte */
|
|
5
|
+
|
|
6
|
+
/** @type {(n: Byte) => (s: ByteSet) => boolean} */
|
|
7
|
+
const has = n => s => ((s >> BigInt(n)) & 1n) === 1n
|
|
8
|
+
|
|
9
|
+
// create a set
|
|
10
|
+
|
|
11
|
+
const empty = 0n
|
|
12
|
+
|
|
13
|
+
/** @type {(n: Byte) => ByteSet} */
|
|
14
|
+
const one = n => 1n << BigInt(n)
|
|
15
|
+
|
|
16
|
+
/** @type {(r: readonly[Byte, Byte]) => ByteSet} */
|
|
17
|
+
const range = ([b, e]) => one(e - b + 1) - 1n << BigInt(b)
|
|
18
|
+
|
|
19
|
+
// set operations
|
|
20
|
+
|
|
21
|
+
/** @type {(a: ByteSet) => (b: ByteSet) => ByteSet} */
|
|
22
|
+
const union = a => b => a | b
|
|
23
|
+
|
|
24
|
+
/** @type {(a: ByteSet) => (b: ByteSet) => ByteSet} */
|
|
25
|
+
const intersect = a => b => a & b
|
|
26
|
+
|
|
27
|
+
/** @type {(a: ByteSet) => (b: ByteSet) => ByteSet} */
|
|
28
|
+
const difference = a => b => intersect(a)(complement(b))
|
|
29
|
+
|
|
30
|
+
/** @type {(n: ByteSet) => ByteSet} */
|
|
31
|
+
const complement = n => ~n
|
|
32
|
+
|
|
33
|
+
// additional operations
|
|
34
|
+
|
|
35
|
+
const set = fn(one).then(union).result
|
|
36
|
+
|
|
37
|
+
const setRange = fn(range).then(union).result
|
|
38
|
+
|
|
39
|
+
/** @type {(n: Byte) => (s: ByteSet) => ByteSet} */
|
|
40
|
+
const unset = n => s => difference(s)(one(n))
|
|
41
|
+
|
|
42
|
+
module.exports = {
|
|
43
|
+
/** @readonly */
|
|
44
|
+
empty,
|
|
45
|
+
/** @readonly */
|
|
46
|
+
has,
|
|
47
|
+
/** @readonly */
|
|
48
|
+
set,
|
|
49
|
+
/** @readonly */
|
|
50
|
+
unset,
|
|
51
|
+
/** @readonly */
|
|
52
|
+
union,
|
|
53
|
+
/** @readonly */
|
|
54
|
+
setRange,
|
|
55
|
+
/** @readonly */
|
|
56
|
+
range,
|
|
57
|
+
}
|
|
File without changes
|
package/types/module.f.cjs
CHANGED
|
@@ -10,13 +10,15 @@ module.exports = {
|
|
|
10
10
|
/** @readonly */
|
|
11
11
|
map: require('./map/module.f.cjs'),
|
|
12
12
|
/** @readonly */
|
|
13
|
+
nibbleSet: require('./nibble_set/module.f.cjs'),
|
|
14
|
+
/** @readonly */
|
|
13
15
|
object: require('./object/module.f.cjs'),
|
|
14
16
|
/** @readonly */
|
|
15
17
|
range: require('./range/module.f.cjs'),
|
|
16
18
|
/** @readonly */
|
|
17
19
|
result: require('./result/module.f.cjs'),
|
|
18
20
|
/** @readonly */
|
|
19
|
-
|
|
21
|
+
stringSet: require('./string_set/module.f.cjs'),
|
|
20
22
|
/** @readonly */
|
|
21
23
|
bigint: require('./bigint/module.f.cjs'),
|
|
22
24
|
/** @readonly */
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/** @typedef {bigint} byteSet */
|
|
2
|
-
/** @typedef {number} byte */
|
|
3
|
-
|
|
4
|
-
/** @type {(n: byte) => (s: byteSet) => boolean} */
|
|
5
|
-
const has = n => s => ((s >> BigInt(n)) & 1n) === 1n
|
|
6
|
-
|
|
7
|
-
/** @type {(n: byte) => (s: byteSet) => byteSet} */
|
|
8
|
-
const set = n => s => s | (1n << BigInt(n))
|
|
9
|
-
|
|
10
|
-
/** @type {(n: byte) => (s: byteSet) => byteSet} */
|
|
11
|
-
const unset = n => s => s & ~(1n << BigInt(n))
|
|
12
|
-
|
|
13
|
-
/** @type {(r: readonly[number, number]) => (s: byteSet) => byteSet} */
|
|
14
|
-
const setRange = ([b, e]) => s => s | ((1n << BigInt(e - b + 1)) - 1n << BigInt(b))
|
|
15
|
-
|
|
16
|
-
// how to define FA???
|
|
17
|
-
// const stateA = [init, set] ????
|
|
18
|
-
|
|
19
|
-
module.exports = {
|
|
20
|
-
/** @readonly */
|
|
21
|
-
empty: 0n,
|
|
22
|
-
/** @readonly */
|
|
23
|
-
has,
|
|
24
|
-
/** @readonly */
|
|
25
|
-
set,
|
|
26
|
-
/** @readonly */
|
|
27
|
-
unset,
|
|
28
|
-
/** @readonly */
|
|
29
|
-
setRange
|
|
30
|
-
}
|