functionalscript 0.0.426 → 0.0.428
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/Cargo.lock +7 -0
- package/Cargo.toml +2 -1
- package/com/cpp/test/build.cjs +1 -1
- package/com/cpp/{testlib.f.cjs → test.f.cjs} +0 -0
- package/com/cs/test/build.cjs +1 -1
- package/com/cs/{testlib.f.cjs → test.f.cjs} +0 -0
- package/com/rust/module.f.cjs +134 -35
- package/com/rust/test.f.cjs +110 -71
- package/package.json +1 -1
- package/test.mjs +4 -2
package/Cargo.lock
CHANGED
package/Cargo.toml
CHANGED
package/com/cpp/test/build.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const fs = require('node:fs')
|
|
2
2
|
const cp = require('node:child_process')
|
|
3
3
|
const os = require('node:os');
|
|
4
|
-
const cpp = require('../
|
|
4
|
+
const cpp = require('../test.f.cjs').result
|
|
5
5
|
const { string: { join }, list: { flat } } = require('../../../types/module.f.cjs')
|
|
6
6
|
|
|
7
7
|
fs.writeFileSync('_result.hpp', cpp)
|
|
File without changes
|
package/com/cs/test/build.cjs
CHANGED
|
File without changes
|
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')
|
|
@@ -29,15 +29,100 @@ const self = ['&self']
|
|
|
29
29
|
/** @type {(p: types.Field) => string} */
|
|
30
30
|
const paramName = ([n]) => n
|
|
31
31
|
|
|
32
|
+
/** @type {(p: types.FieldArray) => list.Thunk<string>} */
|
|
33
|
+
const callList = p => map(paramName)(paramList(p))
|
|
34
|
+
|
|
35
|
+
/** @type {(p: types.FieldArray) => string} */
|
|
36
|
+
const call = p => commaJoin(callList(p))
|
|
37
|
+
|
|
32
38
|
/** @type {(p: types.FieldArray) => string} */
|
|
33
|
-
const
|
|
39
|
+
const virtualCall = p => commaJoin(flat([['self'], callList(p)]))
|
|
40
|
+
|
|
41
|
+
const super_ = 'super::'
|
|
34
42
|
|
|
35
43
|
/** @type {(m: types.Method) => string} */
|
|
36
44
|
const assign = ([n]) => `${n}: Self::${n},`
|
|
37
45
|
|
|
38
46
|
const mapAssign = map(assign)
|
|
39
47
|
|
|
40
|
-
const
|
|
48
|
+
const this_ = ['this: &Object']
|
|
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']
|
|
41
126
|
|
|
42
127
|
/** @type {(library: types.Library) => text.Block} */
|
|
43
128
|
const rust = library => {
|
|
@@ -78,6 +163,14 @@ const rust = library => {
|
|
|
78
163
|
return `(${params})${resultStr}`
|
|
79
164
|
}
|
|
80
165
|
|
|
166
|
+
/** @type {(n: string) => (p: types.FieldArray) => string} */
|
|
167
|
+
const virtualFnType = n => p => `extern "system" fn${n}${func(this_)(p)}`
|
|
168
|
+
|
|
169
|
+
/** @type {(m: types.Method) => string} */
|
|
170
|
+
const virtualFn = ([n, p]) => `${n}: unsafe ${virtualFnType('')(p)}`
|
|
171
|
+
|
|
172
|
+
const mapVirtualFn = map(virtualFn)
|
|
173
|
+
|
|
81
174
|
/** @type {(m: types.Method) => string} */
|
|
82
175
|
const headerFn = ([n, p]) => `fn ${n}${func(self)(p)}`
|
|
83
176
|
|
|
@@ -91,55 +184,61 @@ const rust = library => {
|
|
|
91
184
|
const [n, p] = m
|
|
92
185
|
return [
|
|
93
186
|
`${headerFn(m)} {`,
|
|
94
|
-
[`unsafe { (self.interface().${n})(${
|
|
187
|
+
[`unsafe { (self.interface().${n})(${virtualCall(p)}) }`],
|
|
95
188
|
'}'
|
|
96
189
|
]
|
|
97
190
|
}
|
|
98
191
|
|
|
99
192
|
const flatMapImplFn = flatMap(implFn)
|
|
100
193
|
|
|
101
|
-
/** @type {(
|
|
102
|
-
const
|
|
194
|
+
/** @type {(m: types.Method) => text.Block} */
|
|
195
|
+
const impl = ([n, p]) => {
|
|
196
|
+
const type = virtualFnType(` ${n}`)(p)
|
|
197
|
+
return [
|
|
198
|
+
`${type} {`,
|
|
199
|
+
[`unsafe { Self::to_cobject(this) }.${n}(${call(p)})`],
|
|
200
|
+
'}'
|
|
201
|
+
]
|
|
202
|
+
}
|
|
103
203
|
|
|
104
|
-
|
|
204
|
+
const flatMapImpl = flatMap(impl)
|
|
105
205
|
|
|
106
|
-
|
|
107
|
-
|
|
206
|
+
/** @type {(i: types.Interface) => (name: string) => text.Block} */
|
|
207
|
+
const interface_ = ({ interface: i, guid }) => name => {
|
|
108
208
|
|
|
109
209
|
const e = entries(i)
|
|
110
210
|
|
|
111
|
-
const nameEx = `${name}Ex`
|
|
112
|
-
|
|
113
|
-
const nameVmt = `${name}Vmt`
|
|
114
|
-
|
|
115
211
|
return [
|
|
116
212
|
`pub mod ${name} {`,
|
|
117
213
|
[
|
|
118
|
-
'
|
|
119
|
-
'
|
|
120
|
-
'
|
|
214
|
+
rustType('Object'),
|
|
215
|
+
rustType('Ref'),
|
|
216
|
+
rustType('Vmt'),
|
|
121
217
|
],
|
|
122
|
-
rustStruct(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
'
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
'
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
218
|
+
rustStruct(mapVirtualFn(e))('Interface'),
|
|
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 {`,
|
|
137
234
|
mapAssign(e),
|
|
138
235
|
'};'
|
|
139
|
-
]
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
236
|
+
]
|
|
237
|
+
}),
|
|
238
|
+
traitImpl({
|
|
239
|
+
type: 'PrivateClassEx',
|
|
240
|
+
content: flatMapImpl(e)
|
|
241
|
+
}),
|
|
143
242
|
'}'
|
|
144
243
|
]
|
|
145
244
|
}
|
package/com/rust/test.f.cjs
CHANGED
|
@@ -3,74 +3,113 @@ const { flat } = require('../../text/module.f.cjs')
|
|
|
3
3
|
const { join } = require('../../types/string/module.f.cjs')
|
|
4
4
|
const library = require('../types/testlib.f.cjs')
|
|
5
5
|
|
|
6
|
-
module.exports =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
6
|
+
module.exports = {
|
|
7
|
+
result: () => {
|
|
8
|
+
const e =
|
|
9
|
+
'#![allow(non_snake_case)]\n' +
|
|
10
|
+
'#[repr(C)]\n' +
|
|
11
|
+
'pub struct Slice {\n' +
|
|
12
|
+
' pub Start: *const u8,\n' +
|
|
13
|
+
' pub Size: usize,\n' +
|
|
14
|
+
' pub M: IMy::Ref,\n' +
|
|
15
|
+
'}\n' +
|
|
16
|
+
'pub mod IMy {\n' +
|
|
17
|
+
' pub type Object = nanocom::Object<Interface>;\n' +
|
|
18
|
+
' pub type Ref = nanocom::Ref<Interface>;\n' +
|
|
19
|
+
' pub type Vmt = nanocom::Vmt<Interface>;\n' +
|
|
20
|
+
' #[repr(C)]\n' +
|
|
21
|
+
' pub struct Interface {\n' +
|
|
22
|
+
' pub GetSlice: unsafe extern "system" fn(this: &Object) -> super::Slice,\n' +
|
|
23
|
+
' pub SetSlice: unsafe extern "system" fn(this: &Object, slice: super::Slice),\n' +
|
|
24
|
+
' pub GetUnsafe: unsafe extern "system" fn(this: &Object) -> *const bool,\n' +
|
|
25
|
+
' pub SetUnsafe: unsafe extern "system" fn(this: &Object, p: *const super::Slice, size: u32),\n' +
|
|
26
|
+
' pub Some: unsafe extern "system" fn(this: &Object, p: &super::IMy::Object) -> bool,\n' +
|
|
27
|
+
' pub GetIMy: unsafe extern "system" fn(this: &Object) -> super::IMy::Ref,\n' +
|
|
28
|
+
' }\n' +
|
|
29
|
+
' impl nanocom::Interface for Interface {\n' +
|
|
30
|
+
' const GUID: nanocom::GUID = 0xC66FB270_2D80_49AD_BB6E_88C1F90B805D;\n' +
|
|
31
|
+
' }\n' +
|
|
32
|
+
' pub trait Ex {\n' +
|
|
33
|
+
' fn GetSlice(&self) -> super::Slice;\n' +
|
|
34
|
+
' fn SetSlice(&self, slice: super::Slice);\n' +
|
|
35
|
+
' fn GetUnsafe(&self) -> *const bool;\n' +
|
|
36
|
+
' fn SetUnsafe(&self, p: *const super::Slice, size: u32);\n' +
|
|
37
|
+
' fn Some(&self, p: &super::IMy::Object) -> bool;\n' +
|
|
38
|
+
' fn GetIMy(&self) -> super::IMy::Ref;\n' +
|
|
39
|
+
' }\n' +
|
|
40
|
+
' impl Ex for Object {\n' +
|
|
41
|
+
' fn GetSlice(&self) -> super::Slice {\n' +
|
|
42
|
+
' unsafe { (self.interface().GetSlice)(self) }\n' +
|
|
43
|
+
' }\n' +
|
|
44
|
+
' fn SetSlice(&self, slice: super::Slice) {\n' +
|
|
45
|
+
' unsafe { (self.interface().SetSlice)(self, slice) }\n' +
|
|
46
|
+
' }\n' +
|
|
47
|
+
' fn GetUnsafe(&self) -> *const bool {\n' +
|
|
48
|
+
' unsafe { (self.interface().GetUnsafe)(self) }\n' +
|
|
49
|
+
' }\n' +
|
|
50
|
+
' fn SetUnsafe(&self, p: *const super::Slice, size: u32) {\n' +
|
|
51
|
+
' unsafe { (self.interface().SetUnsafe)(self, p, size) }\n' +
|
|
52
|
+
' }\n' +
|
|
53
|
+
' fn Some(&self, p: &super::IMy::Object) -> bool {\n' +
|
|
54
|
+
' unsafe { (self.interface().Some)(self, p) }\n' +
|
|
55
|
+
' }\n' +
|
|
56
|
+
' fn GetIMy(&self) -> super::IMy::Ref {\n' +
|
|
57
|
+
' unsafe { (self.interface().GetIMy)(self) }\n' +
|
|
58
|
+
' }\n' +
|
|
59
|
+
' }\n' +
|
|
60
|
+
' pub trait ClassEx\n' +
|
|
61
|
+
' where\n' +
|
|
62
|
+
' Self: nanocom::Class<Interface = Interface>,\n' +
|
|
63
|
+
' nanocom::CObject<Self>: Ex,\n' +
|
|
64
|
+
' {\n' +
|
|
65
|
+
' const INTERFACE: Interface = Interface {\n' +
|
|
66
|
+
' GetSlice: Self::GetSlice,\n' +
|
|
67
|
+
' SetSlice: Self::SetSlice,\n' +
|
|
68
|
+
' GetUnsafe: Self::GetUnsafe,\n' +
|
|
69
|
+
' SetUnsafe: Self::SetUnsafe,\n' +
|
|
70
|
+
' Some: Self::Some,\n' +
|
|
71
|
+
' GetIMy: Self::GetIMy,\n' +
|
|
72
|
+
' };\n' +
|
|
73
|
+
' }\n' +
|
|
74
|
+
' impl<T> ClassEx for T\n' +
|
|
75
|
+
' where\n' +
|
|
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' +
|
|
84
|
+
' {\n' +
|
|
85
|
+
' extern "system" fn GetSlice(this: &Object) -> super::Slice {\n' +
|
|
86
|
+
' unsafe { Self::to_cobject(this) }.GetSlice()\n' +
|
|
87
|
+
' }\n' +
|
|
88
|
+
' extern "system" fn SetSlice(this: &Object, slice: super::Slice) {\n' +
|
|
89
|
+
' unsafe { Self::to_cobject(this) }.SetSlice(slice)\n' +
|
|
90
|
+
' }\n' +
|
|
91
|
+
' extern "system" fn GetUnsafe(this: &Object) -> *const bool {\n' +
|
|
92
|
+
' unsafe { Self::to_cobject(this) }.GetUnsafe()\n' +
|
|
93
|
+
' }\n' +
|
|
94
|
+
' extern "system" fn SetUnsafe(this: &Object, p: *const super::Slice, size: u32) {\n' +
|
|
95
|
+
' unsafe { Self::to_cobject(this) }.SetUnsafe(p, size)\n' +
|
|
96
|
+
' }\n' +
|
|
97
|
+
' extern "system" fn Some(this: &Object, p: &super::IMy::Object) -> bool {\n' +
|
|
98
|
+
' unsafe { Self::to_cobject(this) }.Some(p)\n' +
|
|
99
|
+
' }\n' +
|
|
100
|
+
' extern "system" fn GetIMy(this: &Object) -> super::IMy::Ref {\n' +
|
|
101
|
+
' unsafe { Self::to_cobject(this) }.GetIMy()\n' +
|
|
102
|
+
' }\n' +
|
|
103
|
+
' }\n' +
|
|
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' +
|
|
110
|
+
'}'
|
|
111
|
+
const r = join('\n')(flat(' ')(rust(library)))
|
|
112
|
+
if (r !== e) { throw [e, r] }
|
|
113
|
+
return r
|
|
114
|
+
}
|
|
115
|
+
}
|
package/package.json
CHANGED
package/test.mjs
CHANGED
|
@@ -65,7 +65,7 @@ const load = async () => {
|
|
|
65
65
|
await f(file)
|
|
66
66
|
}
|
|
67
67
|
} else if (name.endsWith('.f.cjs')) {
|
|
68
|
-
console.log(`loading ${file}`)
|
|
68
|
+
// console.log(`loading ${file}`)
|
|
69
69
|
const source = await readFile(file, 'utf8')
|
|
70
70
|
map.push([file, Function('module', 'require', `"use strict";${source}`)])
|
|
71
71
|
}
|
|
@@ -107,7 +107,7 @@ const build = async () => {
|
|
|
107
107
|
const module = {
|
|
108
108
|
dependencies: {}
|
|
109
109
|
}
|
|
110
|
-
console.log(`${i}building ${pathStr}`)
|
|
110
|
+
// console.log(`${i}building ${pathStr}`)
|
|
111
111
|
const getModule = req(newBase)(`${i}| `)
|
|
112
112
|
const newReq = s => {
|
|
113
113
|
const [p, result] = getModule(s)
|
|
@@ -130,10 +130,12 @@ const modules = await build()
|
|
|
130
130
|
|
|
131
131
|
// graph
|
|
132
132
|
|
|
133
|
+
/*
|
|
133
134
|
for (const [k, v] of Object.entries(modules)) {
|
|
134
135
|
console.log(`: ${k}`)
|
|
135
136
|
console.log(Object.keys(v.dependencies))
|
|
136
137
|
}
|
|
138
|
+
*/
|
|
137
139
|
|
|
138
140
|
// test runner.
|
|
139
141
|
|