functionalscript 0.0.426 → 0.0.427
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 +42 -16
- package/com/rust/test.f.cjs +98 -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
|
@@ -29,15 +29,23 @@ 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']
|
|
41
49
|
|
|
42
50
|
/** @type {(library: types.Library) => text.Block} */
|
|
43
51
|
const rust = library => {
|
|
@@ -78,6 +86,14 @@ const rust = library => {
|
|
|
78
86
|
return `(${params})${resultStr}`
|
|
79
87
|
}
|
|
80
88
|
|
|
89
|
+
/** @type {(n: string) => (p: types.FieldArray) => string} */
|
|
90
|
+
const virtualFnType = n => p => `extern "system" fn${n}${func(this_)(p)}`
|
|
91
|
+
|
|
92
|
+
/** @type {(m: types.Method) => string} */
|
|
93
|
+
const virtualFn = ([n, p]) => `${n}: unsafe ${virtualFnType('')(p)}`
|
|
94
|
+
|
|
95
|
+
const mapVirtualFn = map(virtualFn)
|
|
96
|
+
|
|
81
97
|
/** @type {(m: types.Method) => string} */
|
|
82
98
|
const headerFn = ([n, p]) => `fn ${n}${func(self)(p)}`
|
|
83
99
|
|
|
@@ -91,35 +107,38 @@ const rust = library => {
|
|
|
91
107
|
const [n, p] = m
|
|
92
108
|
return [
|
|
93
109
|
`${headerFn(m)} {`,
|
|
94
|
-
[`unsafe { (self.interface().${n})(${
|
|
110
|
+
[`unsafe { (self.interface().${n})(${virtualCall(p)}) }`],
|
|
95
111
|
'}'
|
|
96
112
|
]
|
|
97
113
|
}
|
|
98
114
|
|
|
99
115
|
const flatMapImplFn = flatMap(implFn)
|
|
100
116
|
|
|
101
|
-
/** @type {(
|
|
102
|
-
const
|
|
117
|
+
/** @type {(m: types.Method) => text.Block} */
|
|
118
|
+
const impl = ([n, p]) => {
|
|
119
|
+
const type = virtualFnType(` ${n}`)(p)
|
|
120
|
+
return [
|
|
121
|
+
`${type} {`,
|
|
122
|
+
[`unsafe { Self::to_cobject(this) }.${n}(${call(p)})`],
|
|
123
|
+
'}'
|
|
124
|
+
]
|
|
125
|
+
}
|
|
103
126
|
|
|
104
|
-
|
|
127
|
+
const flatMapImpl = flatMap(impl)
|
|
105
128
|
|
|
106
|
-
|
|
107
|
-
|
|
129
|
+
/** @type {(i: types.Interface) => (name: string) => text.Block} */
|
|
130
|
+
const interface_ = ({ interface: i, guid }) => name => {
|
|
108
131
|
|
|
109
132
|
const e = entries(i)
|
|
110
133
|
|
|
111
|
-
const nameEx = `${name}Ex`
|
|
112
|
-
|
|
113
|
-
const nameVmt = `${name}Vmt`
|
|
114
|
-
|
|
115
134
|
return [
|
|
116
135
|
`pub mod ${name} {`,
|
|
117
136
|
[
|
|
118
|
-
'type Object = nanocom::Object<Interface>;',
|
|
119
|
-
'type Ref = nanocom::Ref<Interface>;',
|
|
120
|
-
'type Vmt = nanocom::Vmt<Interface>;',
|
|
137
|
+
'pub type Object = nanocom::Object<Interface>;',
|
|
138
|
+
'pub type Ref = nanocom::Ref<Interface>;',
|
|
139
|
+
'pub type Vmt = nanocom::Vmt<Interface>;',
|
|
121
140
|
],
|
|
122
|
-
rustStruct(
|
|
141
|
+
rustStruct(mapVirtualFn(e))('Interface'),
|
|
123
142
|
[ 'impl nanocom::Interface for Interface {',
|
|
124
143
|
[ `const GUID: nanocom::GUID = 0x${guid.replaceAll('-', '_')};`],
|
|
125
144
|
'}',
|
|
@@ -139,6 +158,13 @@ const rust = library => {
|
|
|
139
158
|
],
|
|
140
159
|
'}',
|
|
141
160
|
'impl<T: nanocom::Class<Interface = Interface>> ClassEx for T where nanocom::CObject<T>: Ex {}',
|
|
161
|
+
'trait PrivateClassEx: nanocom::Class<Interface = Interface>',
|
|
162
|
+
'where',
|
|
163
|
+
[ 'nanocom::CObject<Self>: Ex'],
|
|
164
|
+
`{`,
|
|
165
|
+
flatMapImpl(e),
|
|
166
|
+
`}`,
|
|
167
|
+
'impl<T: nanocom::Class<Interface = Interface>> PrivateClassEx for T where nanocom::CObject<T>: Ex {}',
|
|
142
168
|
],
|
|
143
169
|
'}'
|
|
144
170
|
]
|
package/com/rust/test.f.cjs
CHANGED
|
@@ -3,74 +3,101 @@ 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: nanocom::Class<Interface = Interface>\n' +
|
|
61
|
+
' where\n' +
|
|
62
|
+
' nanocom::CObject<Self>: Ex,\n' +
|
|
63
|
+
' {\n' +
|
|
64
|
+
' const INTERFACE: Interface = Interface {\n' +
|
|
65
|
+
' GetSlice: Self::GetSlice,\n' +
|
|
66
|
+
' SetSlice: Self::SetSlice,\n' +
|
|
67
|
+
' GetUnsafe: Self::GetUnsafe,\n' +
|
|
68
|
+
' SetUnsafe: Self::SetUnsafe,\n' +
|
|
69
|
+
' Some: Self::Some,\n' +
|
|
70
|
+
' GetIMy: Self::GetIMy,\n' +
|
|
71
|
+
' };\n' +
|
|
72
|
+
' }\n' +
|
|
73
|
+
' impl<T: nanocom::Class<Interface = Interface>> ClassEx for T where nanocom::CObject<T>: Ex {}\n' +
|
|
74
|
+
' trait PrivateClassEx: nanocom::Class<Interface = Interface>\n' +
|
|
75
|
+
' where\n' +
|
|
76
|
+
' nanocom::CObject<Self>: Ex\n' +
|
|
77
|
+
' {\n' +
|
|
78
|
+
' extern "system" fn GetSlice(this: &Object) -> super::Slice {\n' +
|
|
79
|
+
' unsafe { Self::to_cobject(this) }.GetSlice()\n' +
|
|
80
|
+
' }\n' +
|
|
81
|
+
' extern "system" fn SetSlice(this: &Object, slice: super::Slice) {\n' +
|
|
82
|
+
' unsafe { Self::to_cobject(this) }.SetSlice(slice)\n' +
|
|
83
|
+
' }\n' +
|
|
84
|
+
' extern "system" fn GetUnsafe(this: &Object) -> *const bool {\n' +
|
|
85
|
+
' unsafe { Self::to_cobject(this) }.GetUnsafe()\n' +
|
|
86
|
+
' }\n' +
|
|
87
|
+
' extern "system" fn SetUnsafe(this: &Object, p: *const super::Slice, size: u32) {\n' +
|
|
88
|
+
' unsafe { Self::to_cobject(this) }.SetUnsafe(p, size)\n' +
|
|
89
|
+
' }\n' +
|
|
90
|
+
' extern "system" fn Some(this: &Object, p: &super::IMy::Object) -> bool {\n' +
|
|
91
|
+
' unsafe { Self::to_cobject(this) }.Some(p)\n' +
|
|
92
|
+
' }\n' +
|
|
93
|
+
' extern "system" fn GetIMy(this: &Object) -> super::IMy::Ref {\n' +
|
|
94
|
+
' unsafe { Self::to_cobject(this) }.GetIMy()\n' +
|
|
95
|
+
' }\n' +
|
|
96
|
+
' }\n' +
|
|
97
|
+
' impl<T: nanocom::Class<Interface = Interface>> PrivateClassEx for T where nanocom::CObject<T>: Ex {}\n' +
|
|
98
|
+
'}'
|
|
99
|
+
const r = join('\n')(flat(' ')(rust(library)))
|
|
100
|
+
if (r !== e) { throw [e, r] }
|
|
101
|
+
return r
|
|
102
|
+
}
|
|
103
|
+
}
|
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
|
|