functionalscript 0.0.353 → 0.0.354
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/main.f.js +34 -13
- package/com/test.f.js +4 -0
- package/package.json +1 -1
package/com/main.f.js
CHANGED
|
@@ -46,7 +46,13 @@ const csUsing = v => `using ${v};`
|
|
|
46
46
|
/** @type {(type: string) => (name: string) => (body: text.Block) => text.Block} */
|
|
47
47
|
const csBlock = type => name => body => [`${type} ${name}`, '{', body, '}']
|
|
48
48
|
|
|
49
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* @type {(attributes: list.List<string>) =>
|
|
51
|
+
* (type: string) =>
|
|
52
|
+
* (name: string) =>
|
|
53
|
+
* (body: text.Block) =>
|
|
54
|
+
* list.List<text.Item>}
|
|
55
|
+
*/
|
|
50
56
|
const csTypeDef = attributes => type => name => body =>
|
|
51
57
|
list.flat([
|
|
52
58
|
list.map(v=>`[${v}]`)(attributes),
|
|
@@ -73,25 +79,40 @@ const csBaseType = t => {
|
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
/** @type {(t: Type) => string} */
|
|
76
|
-
const csType = t =>
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
if (t instanceof Array) {
|
|
81
|
-
return t[0]
|
|
82
|
-
}
|
|
83
|
-
return `${csType(t['*'])}*`
|
|
84
|
-
}
|
|
82
|
+
const csType = t =>
|
|
83
|
+
typeof(t) === 'string' ? csBaseType(t) :
|
|
84
|
+
t instanceof Array ? t[0] :
|
|
85
|
+
`${csType(t['*'])}*`
|
|
85
86
|
|
|
86
87
|
/** @type {(f: Field) => string} */
|
|
87
|
-
const
|
|
88
|
+
const csParam = ([name, type]) => `${csType(type)} ${name}`
|
|
89
|
+
|
|
90
|
+
/** @type {(f: Field) => string} */
|
|
91
|
+
const csField = f => `public ${csParam(f)};`
|
|
92
|
+
|
|
93
|
+
/** @type {(m: Method) => string} */
|
|
94
|
+
const csResult = m => m.length === 2 ? 'void' : csType(m[2])
|
|
95
|
+
|
|
96
|
+
/** @type {(m: Method) => readonly string[]} */
|
|
97
|
+
const csMethod = m => [
|
|
98
|
+
'[PreserveSig]',
|
|
99
|
+
`${csResult(m)} ${m[0]}(${list.join(',')(list.map(csParam)(m[1]))});`
|
|
100
|
+
]
|
|
88
101
|
|
|
89
102
|
/** @type {(e: obj.Entry<Definition>) => list.List<text.Item>} */
|
|
90
103
|
const csDef = ([n, d]) => {
|
|
91
104
|
const i = d.interface
|
|
92
105
|
return i === undefined ?
|
|
93
|
-
csTypeDef
|
|
94
|
-
|
|
106
|
+
csTypeDef
|
|
107
|
+
(['StructLayout(LayoutKind.Sequential)'])
|
|
108
|
+
('struct')
|
|
109
|
+
(n)
|
|
110
|
+
(() => list.map(csField)(d.struct)) :
|
|
111
|
+
csTypeDef
|
|
112
|
+
([`Guid("${d.guid}")`,'InterfaceType(ComInterfaceType.InterfaceIsUnknown)'])
|
|
113
|
+
('interface')
|
|
114
|
+
(n)
|
|
115
|
+
(() => list.flatMap(csMethod)(d.interface))
|
|
95
116
|
}
|
|
96
117
|
|
|
97
118
|
/** @type {(name: string) => (library: Library) => text.Block} */
|
package/com/test.f.js
CHANGED
|
@@ -37,6 +37,10 @@ const library = {
|
|
|
37
37
|
' [InterfaceType(ComInterfaceType.InterfaceIsUnknown)]\n' +
|
|
38
38
|
' public interface IMy\n' +
|
|
39
39
|
' {\n' +
|
|
40
|
+
' [PreserveSig]\n' +
|
|
41
|
+
' Slice GetSlice();\n' +
|
|
42
|
+
' [PreserveSig]\n' +
|
|
43
|
+
' void SetSlice(Slice slice);\n' +
|
|
40
44
|
' }\n' +
|
|
41
45
|
'}'
|
|
42
46
|
if (cs !== e) { throw [cs,e] }
|