functionalscript 0.0.362 → 0.0.363
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/main.f.js +10 -1
- package/com/cpp/test/build.js +11 -0
- package/com/cpp/test/main.cpp +5 -0
- package/com/cpp/test.f.js +3 -0
- package/com/cs/main.f.js +31 -31
- package/com/cs/test.f.js +3 -9
- package/html/main.f.js +1 -1
- package/json/tokenizer/test.f.js +1 -1
- package/package.json +1 -1
- package/text/main.f.js +5 -0
- package/types/list/main.f.js +20 -23
- package/types/list/test.f.js +2 -2
package/com/cpp/main.f.js
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
const types = require('../types/main.f.js')
|
|
2
|
+
const text = require('../../text/main.f.js')
|
|
3
|
+
|
|
4
|
+
/** @type {(name: string) => (library: types.Library) => text.Block} */
|
|
5
|
+
const cpp = name => lib => []
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
/** @readonly */
|
|
9
|
+
cpp,
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const fs = require('node:fs')
|
|
2
|
+
const cp = require('node:child_process')
|
|
3
|
+
// const cs = require('../test.f.js').result
|
|
4
|
+
|
|
5
|
+
// fs.writeFileSync('_result.cpp', cs)
|
|
6
|
+
try {
|
|
7
|
+
console.log(cp.execSync('clang main.cpp').toString())
|
|
8
|
+
} catch (e) {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
console.error(e.output.toString())
|
|
11
|
+
}
|
package/com/cs/main.f.js
CHANGED
|
@@ -4,10 +4,7 @@ const list = require('../../types/list/main.f.js')
|
|
|
4
4
|
const obj = require('../../types/object/main.f.js')
|
|
5
5
|
|
|
6
6
|
/** @type {(v: string) => string} */
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
/** @type {(type: string) => (name: string) => (body: text.Block) => text.Block} */
|
|
10
|
-
const csBlock = type => name => body => [`${type} ${name}`, '{', body, '}']
|
|
7
|
+
const using = v => `using ${v};`
|
|
11
8
|
|
|
12
9
|
/**
|
|
13
10
|
* @type {(attributes: list.List<string>) =>
|
|
@@ -16,14 +13,14 @@ const csBlock = type => name => body => [`${type} ${name}`, '{', body, '}']
|
|
|
16
13
|
* (body: text.Block) =>
|
|
17
14
|
* list.List<text.Item>}
|
|
18
15
|
*/
|
|
19
|
-
const
|
|
16
|
+
const typeDef = attributes => type => name => body =>
|
|
20
17
|
list.flat([
|
|
21
18
|
list.map(v => `[${v}]`)(attributes),
|
|
22
|
-
|
|
19
|
+
text.curly(`public ${type}`)(name)(body)
|
|
23
20
|
])
|
|
24
21
|
|
|
25
22
|
/** @type {(t: types.BaseType) => string} */
|
|
26
|
-
const
|
|
23
|
+
const baseType = t => {
|
|
27
24
|
switch (t) {
|
|
28
25
|
case 'bool': return 'bool'
|
|
29
26
|
case 'f32': return 'float'
|
|
@@ -45,69 +42,72 @@ const csBaseType = t => {
|
|
|
45
42
|
const unsafe = isUnsafe => isUnsafe ? 'unsafe ' : ''
|
|
46
43
|
|
|
47
44
|
/** @type {(t: types.Type) => readonly[boolean, string]} */
|
|
48
|
-
const
|
|
49
|
-
typeof (t) === 'string' ? [false,
|
|
45
|
+
const type = t =>
|
|
46
|
+
typeof (t) === 'string' ? [false, baseType(t)] :
|
|
50
47
|
t.length === 1 ? [false, t[0]] :
|
|
51
|
-
[true, `${
|
|
48
|
+
[true, `${type(t[1])[1]}*`]
|
|
52
49
|
|
|
53
50
|
/** @type {(f: types.Field) => string} */
|
|
54
|
-
const
|
|
51
|
+
const param = ([name, t]) => `${type(t)[1]} ${name}`
|
|
55
52
|
|
|
56
53
|
/** @type {(f: types.Field) => string} */
|
|
57
|
-
const
|
|
58
|
-
const [isUnsafe, t] =
|
|
54
|
+
const field = ([name, comType]) => {
|
|
55
|
+
const [isUnsafe, t] = type(comType)
|
|
59
56
|
return `public ${unsafe(isUnsafe)}${t} ${name};`
|
|
60
57
|
}
|
|
61
58
|
|
|
62
|
-
/** @type {(m: types.FieldArray) =>
|
|
63
|
-
const
|
|
59
|
+
/** @type {(m: types.FieldArray) => string} */
|
|
60
|
+
const result = m => {
|
|
61
|
+
const result = m._
|
|
62
|
+
return result === undefined ? 'void' : type(result)[1]
|
|
63
|
+
}
|
|
64
64
|
|
|
65
65
|
/** @type {(field: types.Field) => boolean} */
|
|
66
|
-
const isUnsafeField = field =>
|
|
66
|
+
const isUnsafeField = field => type(field[1])[0]
|
|
67
67
|
|
|
68
68
|
/** @type {(kv: obj.Entry<types.Type>) => boolean} */
|
|
69
69
|
const isParam = kv => kv[0] !== '_'
|
|
70
70
|
|
|
71
71
|
/** @type {(e: obj.Entry<types.FieldArray>) => readonly string[]} */
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const isUnsafe =
|
|
72
|
+
const method = ([name, m]) => {
|
|
73
|
+
const paramAndResultList = Object.entries(m)
|
|
74
|
+
const paramList = list.filter(isParam)(paramAndResultList)
|
|
75
|
+
const isUnsafe = list.some(list.map(isUnsafeField)(paramAndResultList))
|
|
76
76
|
return [
|
|
77
77
|
'[PreserveSig]',
|
|
78
|
-
`${unsafe(isUnsafe)}${result
|
|
78
|
+
`${unsafe(isUnsafe)}${result(m)} ${name}(${list.join(', ')(list.map(param)(paramList))});`
|
|
79
79
|
]
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/** @type {(e: obj.Entry<types.Definition>) => list.List<text.Item>} */
|
|
83
|
-
const
|
|
83
|
+
const def = ([n, d]) => {
|
|
84
84
|
const i = d.interface
|
|
85
85
|
return i === undefined ?
|
|
86
|
-
|
|
86
|
+
typeDef
|
|
87
87
|
(['StructLayout(LayoutKind.Sequential)'])
|
|
88
88
|
('struct')
|
|
89
89
|
(n)
|
|
90
|
-
(
|
|
91
|
-
|
|
90
|
+
(list.map(field)(Object.entries(d.struct))) :
|
|
91
|
+
typeDef
|
|
92
92
|
([`Guid("${d.guid}")`, 'InterfaceType(ComInterfaceType.InterfaceIsIUnknown)'])
|
|
93
93
|
('interface')
|
|
94
94
|
(n)
|
|
95
|
-
(
|
|
95
|
+
(list.flatMap(method)(Object.entries(d.interface)))
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/** @type {(name: string) => (library: types.Library) => text.Block} */
|
|
99
99
|
const cs = name => library => {
|
|
100
|
-
const v = list.flatMap(
|
|
100
|
+
const v = list.flatMap(def)(Object.entries(library))
|
|
101
101
|
|
|
102
102
|
/** @type {text.Block} */
|
|
103
103
|
const h = [
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
using('System'),
|
|
105
|
+
using('System.Runtime.InteropServices'),
|
|
106
106
|
''
|
|
107
107
|
]
|
|
108
108
|
|
|
109
|
-
const ns =
|
|
110
|
-
return
|
|
109
|
+
const ns = text.curly('namespace')(name)(() => v)
|
|
110
|
+
return list.flat([h, ns])
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
module.exports = {
|
package/com/cs/test.f.js
CHANGED
|
@@ -14,15 +14,9 @@ const library = {
|
|
|
14
14
|
IMy: {
|
|
15
15
|
guid: 'C66FB270-2D80-49AD-BB6E-88C1F90B805D',
|
|
16
16
|
interface: {
|
|
17
|
-
GetSlice: {
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
SetSlice: {
|
|
21
|
-
slice: ['Slice']
|
|
22
|
-
},
|
|
23
|
-
GetUnsafe: {
|
|
24
|
-
_: ['*', 'bool']
|
|
25
|
-
},
|
|
17
|
+
GetSlice: { _: ['Slice'] },
|
|
18
|
+
SetSlice: { slice: ['Slice'] },
|
|
19
|
+
GetUnsafe: { _: ['*', 'bool'] },
|
|
26
20
|
SetUnsafe: {
|
|
27
21
|
p: ['*', ['Slice']],
|
|
28
22
|
size: 'u32'
|
package/html/main.f.js
CHANGED
|
@@ -73,7 +73,7 @@ const escapeCharCode = code => {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
const escape = compose(list.
|
|
76
|
+
const escape = compose(list.toCharCodeList)(list.map(escapeCharCode))
|
|
77
77
|
|
|
78
78
|
/** @type {(n: Node) => list.List<string>} */
|
|
79
79
|
const node = n => typeof n === 'string' ? escape(n) : element(n)
|
package/json/tokenizer/test.f.js
CHANGED
|
@@ -4,7 +4,7 @@ const json = require('../main.f.js')
|
|
|
4
4
|
const { sort } = require('../../types/object/main.f.js')
|
|
5
5
|
|
|
6
6
|
/** @type {(s: string) => readonly tokenizer.JsonToken[]} */
|
|
7
|
-
const tokenizeString = s => list.toArray(tokenizer.tokenize(list.
|
|
7
|
+
const tokenizeString = s => list.toArray(tokenizer.tokenize(list.toCharCodeList(s)))
|
|
8
8
|
|
|
9
9
|
const stringify = json.stringify(sort)
|
|
10
10
|
|
package/package.json
CHANGED
package/text/main.f.js
CHANGED
|
@@ -21,7 +21,12 @@ const flat = indent => {
|
|
|
21
21
|
return f('')
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/** @type {(type: string) => (name: string) => (body: Block) => Block} */
|
|
25
|
+
const curly = type => name => body => [`${type} ${name}`, '{', body, '}']
|
|
26
|
+
|
|
24
27
|
module.exports = {
|
|
25
28
|
/** @readonly */
|
|
26
29
|
flat,
|
|
30
|
+
/** @readonly */
|
|
31
|
+
curly,
|
|
27
32
|
}
|
package/types/list/main.f.js
CHANGED
|
@@ -105,7 +105,7 @@ const toArray = list => {
|
|
|
105
105
|
return u instanceof Array ? u : Array.from(iterable(u))
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
/** @type {<I, O>(step: (n: NonEmpty<I>) => List<O>) => (input: List<I>) =>
|
|
108
|
+
/** @type {<I, O>(step: (n: NonEmpty<I>) => List<O>) => (input: List<I>) => Thunk<O>} */
|
|
109
109
|
const apply = f => input => () => {
|
|
110
110
|
const n = next(input)
|
|
111
111
|
if (n === undefined) { return undefined }
|
|
@@ -115,16 +115,16 @@ const apply = f => input => () => {
|
|
|
115
115
|
/** @type {<T>(n: NonEmpty<List<T>>) => List<T>} */
|
|
116
116
|
const flatStep = n => concat(n.first)(flat(n.tail))
|
|
117
117
|
|
|
118
|
-
/** @type {<T>(list: List<List<T>>) =>
|
|
118
|
+
/** @type {<T>(list: List<List<T>>) => Thunk<T>} */
|
|
119
119
|
const flat = apply(flatStep)
|
|
120
120
|
|
|
121
121
|
/** @type {<I, O>(f: (value: I) => O) => (n: NonEmpty<I>) => List<O>} */
|
|
122
122
|
const mapStep = f => n => ({ first: f(n.first), tail: map(f)(n.tail) })
|
|
123
123
|
|
|
124
|
-
/** @type {<I, O>(f: (value: I) => O) => (input: List<I>) =>
|
|
124
|
+
/** @type {<I, O>(f: (value: I) => O) => (input: List<I>) => Thunk<O>} */
|
|
125
125
|
const map = f => apply(mapStep(f))
|
|
126
126
|
|
|
127
|
-
/** @type {<I, O>(f: (value: I) => List<O>) => (input: List<I>) =>
|
|
127
|
+
/** @type {<I, O>(f: (value: I) => List<O>) => (input: List<I>) => Thunk<O>} */
|
|
128
128
|
const flatMap = f => compose(map(f))(flat)
|
|
129
129
|
|
|
130
130
|
/** @type {<T>(f: (value: T) => boolean) => (n: NonEmpty<T>) => List<T>} */
|
|
@@ -133,7 +133,7 @@ const filterStep = f => n => {
|
|
|
133
133
|
return f(n.first) ? { first: n.first, tail } : tail
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
/** @type {<T>(f: (value: T) => boolean) => (input: List<T>) =>
|
|
136
|
+
/** @type {<T>(f: (value: T) => boolean) => (input: List<T>) => Thunk<T>} */
|
|
137
137
|
const filter = f => apply(filterStep(f))
|
|
138
138
|
|
|
139
139
|
/** @type {<I, O>(f: (value: I) => O|undefined) => (n: NonEmpty<I>) => List<O>} */
|
|
@@ -142,31 +142,31 @@ const filterMapStep = f => n => {
|
|
|
142
142
|
return first === undefined ? tail : { first, tail }
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
/** @type {<I, O>(f: (value: I) => O|undefined) => (input: List<I>) =>
|
|
145
|
+
/** @type {<I, O>(f: (value: I) => O|undefined) => (input: List<I>) => Thunk<O>} */
|
|
146
146
|
const filterMap = f => apply(filterMapStep(f))
|
|
147
147
|
|
|
148
148
|
/** @type {<T>(f: (value: T) => boolean) => (n: NonEmpty<T>) => List<T>} */
|
|
149
149
|
const takeWhileStep = f => n => f(n.first) ? { first: n.first, tail: takeWhile(f)(n.tail) } : undefined
|
|
150
150
|
|
|
151
|
-
/** @type {<T>(f: (value: T) => boolean) => (input: List<T>) =>
|
|
151
|
+
/** @type {<T>(f: (value: T) => boolean) => (input: List<T>) => Thunk<T>} */
|
|
152
152
|
const takeWhile = f => apply(takeWhileStep(f))
|
|
153
153
|
|
|
154
154
|
/** @type {(n: number) => <T>(result: NonEmpty<T>) => List<T>} */
|
|
155
155
|
const takeStep = n => ne => 0 < n ? { first: ne.first, tail: take(n - 1)(ne.tail) } : undefined
|
|
156
156
|
|
|
157
|
-
/** @type {(n: number) => <T>(input: List<T>) =>
|
|
157
|
+
/** @type {(n: number) => <T>(input: List<T>) => Thunk<T>} */
|
|
158
158
|
const take = n => apply(takeStep(n))
|
|
159
159
|
|
|
160
160
|
/** @type {<T>(f: (value: T) => boolean) => (ne: NonEmpty<T>) => List<T>} */
|
|
161
161
|
const dropWhileStep = f => ne => f(ne.first) ? dropWhile(f)(ne.tail) : ne
|
|
162
162
|
|
|
163
|
-
/** @type {<T>(f: (value: T) => boolean) => (input: List<T>) =>
|
|
163
|
+
/** @type {<T>(f: (value: T) => boolean) => (input: List<T>) => Thunk<T>} */
|
|
164
164
|
const dropWhile = f => apply(dropWhileStep(f))
|
|
165
165
|
|
|
166
166
|
/** @type {(n: number) => <T>(ne: NonEmpty<T>) => List<T>} */
|
|
167
167
|
const dropStep = n => ne => 0 < n ? drop(n - 1)(ne.tail) : ne
|
|
168
168
|
|
|
169
|
-
/** @type {(n: number) => <T>(input: List<T>) =>
|
|
169
|
+
/** @type {(n: number) => <T>(input: List<T>) => Thunk<T>} */
|
|
170
170
|
const drop = n => apply(dropStep(n))
|
|
171
171
|
|
|
172
172
|
/** @type {<D>(def: D) => <T>(input: List<T>) => D|T} */
|
|
@@ -214,7 +214,7 @@ const countdown = count => () => {
|
|
|
214
214
|
return { first, tail: countdown(first) }
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
/** @type {<T>(v: T) => (c: number) =>
|
|
217
|
+
/** @type {<T>(v: T) => (c: number) => Thunk<T>} */
|
|
218
218
|
const repeat = v => n => map(() => v)(countdown(n))
|
|
219
219
|
|
|
220
220
|
/** @type {<T>(list: List<T>) => List<T>} */
|
|
@@ -229,13 +229,13 @@ const scanStep = op => ne => {
|
|
|
229
229
|
return { first, tail: scan(newOp)(ne.tail) }
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
/** @type {<I, O>(op: operator.Scan<I, O>) => (input: List<I>) =>
|
|
232
|
+
/** @type {<I, O>(op: operator.Scan<I, O>) => (input: List<I>) => Thunk<O>} */
|
|
233
233
|
const scan = op => apply(scanStep(op))
|
|
234
234
|
|
|
235
|
-
/** @type {<I, S, O>(op: operator.StateScan<I, S, O>) => (init: S) => (input: List<I>) =>
|
|
235
|
+
/** @type {<I, S, O>(op: operator.StateScan<I, S, O>) => (init: S) => (input: List<I>) => Thunk<O>} */
|
|
236
236
|
const stateScan = op => init => scan(stateScanToScan(op)(init))
|
|
237
237
|
|
|
238
|
-
/** @type {<I,O>(op: operator.Reduce<I, O>) => (init: O) => (input: List<I>) =>
|
|
238
|
+
/** @type {<I,O>(op: operator.Reduce<I, O>) => (init: O) => (input: List<I>) => Thunk<O>} */
|
|
239
239
|
const reduceScan = op => init => scan(reduceToScan(op)(init))
|
|
240
240
|
|
|
241
241
|
/** @type {<I,O>(op: operator.Reduce<I, O>) => (init: O) => (input: List<I>) => O} */
|
|
@@ -264,7 +264,7 @@ const length = reduce(operator.counter)(0)
|
|
|
264
264
|
/** @type {(index: number) => <T>(value: T) => readonly[Entry<T>, number]} */
|
|
265
265
|
const entryOperator = index => value => [[index, value], index + 1]
|
|
266
266
|
|
|
267
|
-
/** @type {<T>(input: List<T>) =>
|
|
267
|
+
/** @type {<T>(input: List<T>) => Thunk<Entry<T>>} */
|
|
268
268
|
const entries = input => {
|
|
269
269
|
/** @typedef {typeof input extends List<infer T> ? T : never} T */
|
|
270
270
|
return stateScan(/** @type {operator.StateScan<T, Number, Entry<T>>} */(entryOperator))(0)(input)
|
|
@@ -276,16 +276,13 @@ const reverseOperator = first => tail => ({ first, tail })
|
|
|
276
276
|
/** @type {<T>(input: List<T>) => List<T>} */
|
|
277
277
|
const reverse = reduce(reverseOperator)(undefined)
|
|
278
278
|
|
|
279
|
-
/** @type {<A>(a: A) => <B>(b: B) => readonly[A, B]} */
|
|
280
|
-
const tuple2 = a => b => [a, b]
|
|
281
|
-
|
|
282
279
|
/** @type {<A>(a: List<A>) => <B>(b: List<B>) => List<readonly[A, B]>} */
|
|
283
280
|
const zip = a => b => () => {
|
|
284
281
|
const aResult = next(a)
|
|
285
282
|
if (aResult === undefined) { return undefined }
|
|
286
283
|
const bResult = next(b)
|
|
287
284
|
if (bResult === undefined) { return undefined }
|
|
288
|
-
return { first:
|
|
285
|
+
return { first: [aResult.first, bResult.first], tail: zip(aResult.tail)(bResult.tail) }
|
|
289
286
|
}
|
|
290
287
|
|
|
291
288
|
/** @type {<T>(e: operator.Equal<T>) => (a: List<T>) => (b: List<T>) => List<boolean>} */
|
|
@@ -300,7 +297,7 @@ const equalZip = e => a => b => () => {
|
|
|
300
297
|
const equal = e => a => b => every(equalZip(e)(a)(b))
|
|
301
298
|
|
|
302
299
|
/** @type {(s: string) => List<number>} */
|
|
303
|
-
const
|
|
300
|
+
const toCharCodeList = s => {
|
|
304
301
|
/** @type {(i: number) => Result<number>} */
|
|
305
302
|
const at = i => {
|
|
306
303
|
const first = s.charCodeAt(i)
|
|
@@ -309,7 +306,7 @@ const toCharCodes = s => {
|
|
|
309
306
|
return at(0)
|
|
310
307
|
}
|
|
311
308
|
|
|
312
|
-
const
|
|
309
|
+
const fromCharCodeList = compose(map(String.fromCharCode))(fold(operator.concat)(''))
|
|
313
310
|
|
|
314
311
|
module.exports = {
|
|
315
312
|
/** @readonly */
|
|
@@ -389,7 +386,7 @@ module.exports = {
|
|
|
389
386
|
/** @readonly */
|
|
390
387
|
equal,
|
|
391
388
|
/** @readonly */
|
|
392
|
-
|
|
389
|
+
toCharCodeList,
|
|
393
390
|
/** @readonly */
|
|
394
|
-
|
|
391
|
+
fromCharCodeList,
|
|
395
392
|
}
|
package/types/list/test.f.js
CHANGED
|
@@ -235,8 +235,8 @@ const stringify = sequence => json.stringify(sort)(_.toArray(sequence))
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
{
|
|
238
|
-
const r = _.
|
|
239
|
-
const x = _.
|
|
238
|
+
const r = _.toCharCodeList("Hello world!")
|
|
239
|
+
const x = _.fromCharCodeList(r)
|
|
240
240
|
if (x !== "Hello world!") { throw x }
|
|
241
241
|
}
|
|
242
242
|
|