functionalscript 0.0.350 → 0.0.353
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/README.md +3 -0
- package/com/main.f.js +115 -0
- package/com/test.f.js +45 -0
- package/commonjs/README.md +2 -2
- package/package.json +1 -1
- package/test.f.js +2 -0
- package/text/main.f.js +27 -0
- package/text/test.f.js +19 -0
- package/types/list/main.f.js +6 -2
- package/types/list/test.f.js +10 -0
package/com/README.md
ADDED
package/com/main.f.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
const text = require('../text/main.f.js')
|
|
2
|
+
const list = require('../types/list/main.f')
|
|
3
|
+
const obj = require('../types/object/main.f.js')
|
|
4
|
+
|
|
5
|
+
/** @typedef {{readonly[k in string]: Definition}} Library */
|
|
6
|
+
|
|
7
|
+
/** @typedef {Struct|Interface} Definition */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {{
|
|
11
|
+
* readonly interface?: undefined
|
|
12
|
+
* readonly struct: FieldArray
|
|
13
|
+
* }} Struct
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** @typedef {readonly Field[]} FieldArray */
|
|
17
|
+
|
|
18
|
+
/** @typedef {[string, Type]} Field */
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {{
|
|
22
|
+
* readonly interface: MethodArray
|
|
23
|
+
* readonly guid: string
|
|
24
|
+
* }} Interface
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** @typedef {readonly Method[]} MethodArray */
|
|
28
|
+
|
|
29
|
+
/** @typedef {readonly[string, FieldArray, Type]} GetMethod */
|
|
30
|
+
|
|
31
|
+
/** @typedef {readonly[string, FieldArray]} SetMethod */
|
|
32
|
+
|
|
33
|
+
/** @typedef {GetMethod|SetMethod} Method */
|
|
34
|
+
|
|
35
|
+
/** @typedef {BaseType|Id|Pointer} Type */
|
|
36
|
+
|
|
37
|
+
/** @typedef {readonly[string]} Id */
|
|
38
|
+
|
|
39
|
+
/** @typedef {'u8'|'i8'|'u16'|'i16'|'u32'|'i32'|'u64'|'i64'|'usize'|'isize'|'f32'|'f64'|'bool'} BaseType */
|
|
40
|
+
|
|
41
|
+
/** @typedef {{readonly '*': Type}} Pointer */
|
|
42
|
+
|
|
43
|
+
/** @type {(v: string) => string} */
|
|
44
|
+
const csUsing = v => `using ${v};`
|
|
45
|
+
|
|
46
|
+
/** @type {(type: string) => (name: string) => (body: text.Block) => text.Block} */
|
|
47
|
+
const csBlock = type => name => body => [`${type} ${name}`, '{', body, '}']
|
|
48
|
+
|
|
49
|
+
/** @type {(attributes: list.List<string>) => (type: string) => (name: string) => (body: text.Block) => list.List<text.Item>} */
|
|
50
|
+
const csTypeDef = attributes => type => name => body =>
|
|
51
|
+
list.flat([
|
|
52
|
+
list.map(v=>`[${v}]`)(attributes),
|
|
53
|
+
csBlock(`public ${type}`)(name)(body)
|
|
54
|
+
])
|
|
55
|
+
|
|
56
|
+
/** @type {(t: BaseType) => string} */
|
|
57
|
+
const csBaseType = t => {
|
|
58
|
+
switch (t) {
|
|
59
|
+
case 'bool': return 'bool'
|
|
60
|
+
case 'f32': return 'float'
|
|
61
|
+
case 'f64': return 'double'
|
|
62
|
+
case 'i16': return 'short'
|
|
63
|
+
case 'i32': return 'int'
|
|
64
|
+
case 'i64': return 'long'
|
|
65
|
+
case 'i8': return 'sbyte'
|
|
66
|
+
case 'isize': return 'IntPtr'
|
|
67
|
+
case 'u16': return 'ushort'
|
|
68
|
+
case 'u32': return 'uint'
|
|
69
|
+
case 'u64': return 'ulong'
|
|
70
|
+
case 'u8': return 'byte'
|
|
71
|
+
case 'usize': return 'UIntPtr'
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** @type {(t: Type) => string} */
|
|
76
|
+
const csType = t => {
|
|
77
|
+
if (typeof(t) === 'string') {
|
|
78
|
+
return csBaseType(t)
|
|
79
|
+
}
|
|
80
|
+
if (t instanceof Array) {
|
|
81
|
+
return t[0]
|
|
82
|
+
}
|
|
83
|
+
return `${csType(t['*'])}*`
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** @type {(f: Field) => string} */
|
|
87
|
+
const csField = f => `public ${csType(f[1])} ${f[0]};`
|
|
88
|
+
|
|
89
|
+
/** @type {(e: obj.Entry<Definition>) => list.List<text.Item>} */
|
|
90
|
+
const csDef = ([n, d]) => {
|
|
91
|
+
const i = d.interface
|
|
92
|
+
return i === undefined ?
|
|
93
|
+
csTypeDef(['StructLayout(LayoutKind.Sequential)'])('struct')(n)(() => list.map(csField)(d.struct)) :
|
|
94
|
+
csTypeDef([`Guid("${d.guid}")`,'InterfaceType(ComInterfaceType.InterfaceIsUnknown)'])('interface')(n)([])
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** @type {(name: string) => (library: Library) => text.Block} */
|
|
98
|
+
const cs = name => library => {
|
|
99
|
+
const v = list.flatMap(csDef)(Object.entries(library))
|
|
100
|
+
|
|
101
|
+
/** @type {text.Block} */
|
|
102
|
+
const h = [
|
|
103
|
+
csUsing('System'),
|
|
104
|
+
csUsing('System.Runtime.InteropServices'),
|
|
105
|
+
''
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
const ns = csBlock('namespace')(name)(() => v)
|
|
109
|
+
return () => list.flat([h, ns])
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
module.exports = {
|
|
113
|
+
/** @readonly */
|
|
114
|
+
cs,
|
|
115
|
+
}
|
package/com/test.f.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const _ = require('./main.f.js')
|
|
2
|
+
const list = require('../types/list/main.f.js')
|
|
3
|
+
const text = require('../text/main.f.js')
|
|
4
|
+
|
|
5
|
+
/** @type {_.Library} */
|
|
6
|
+
const library = {
|
|
7
|
+
Slice: {
|
|
8
|
+
struct: [
|
|
9
|
+
['Start', { '*': 'u8' }],
|
|
10
|
+
['Size', 'usize'],
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
IMy: {
|
|
14
|
+
guid: 'C66FB270-2D80-49AD-BB6E-88C1F90B805D',
|
|
15
|
+
interface: [
|
|
16
|
+
['GetSlice', [], ['Slice']],
|
|
17
|
+
['SetSlice', [['slice', ['Slice']]]],
|
|
18
|
+
],
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
{
|
|
23
|
+
const cs = list.join('\n')(text.flat(' ')(_.cs('My')(library)))
|
|
24
|
+
const e =
|
|
25
|
+
'using System;\n' +
|
|
26
|
+
'using System.Runtime.InteropServices;\n' +
|
|
27
|
+
'\n' +
|
|
28
|
+
'namespace My\n' +
|
|
29
|
+
'{\n' +
|
|
30
|
+
' [StructLayout(LayoutKind.Sequential)]\n' +
|
|
31
|
+
' public struct Slice\n' +
|
|
32
|
+
' {\n' +
|
|
33
|
+
' public byte* Start;\n' +
|
|
34
|
+
' public UIntPtr Size;\n' +
|
|
35
|
+
' }\n' +
|
|
36
|
+
' [Guid("C66FB270-2D80-49AD-BB6E-88C1F90B805D")]\n' +
|
|
37
|
+
' [InterfaceType(ComInterfaceType.InterfaceIsUnknown)]\n' +
|
|
38
|
+
' public interface IMy\n' +
|
|
39
|
+
' {\n' +
|
|
40
|
+
' }\n' +
|
|
41
|
+
'}'
|
|
42
|
+
if (cs !== e) { throw [cs,e] }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = {}
|
package/commonjs/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Package
|
|
4
4
|
|
|
5
|
-
[package/
|
|
5
|
+
[package/main.f.js](package/main.f.js)
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
8
|
// A dictionary of packages.
|
|
@@ -31,7 +31,7 @@ type Package = {
|
|
|
31
31
|
|
|
32
32
|
## Module
|
|
33
33
|
|
|
34
|
-
[module/
|
|
34
|
+
[module/main.f.js](module/main.f.js)
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
37
|
// A module map is a dictionary of modules.
|
package/package.json
CHANGED
package/test.f.js
CHANGED
|
@@ -16,6 +16,8 @@ require('./types/stringset/test.f.js')
|
|
|
16
16
|
require('./commonjs/build/test.f.js')
|
|
17
17
|
require('./types/range/test.f.js')
|
|
18
18
|
require('./html/test.f.js')
|
|
19
|
+
require('./text/test.f.js')
|
|
20
|
+
require('./com/test.f.js')
|
|
19
21
|
|
|
20
22
|
/** @type {() => never} */
|
|
21
23
|
const assert = () => { throw 'assert' }
|
package/text/main.f.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const list = require('../types/list/main.f.js')
|
|
2
|
+
|
|
3
|
+
/** @typedef {ItemThunk|ItemArray} Block */
|
|
4
|
+
|
|
5
|
+
/** @typedef {readonly Item[]} ItemArray */
|
|
6
|
+
|
|
7
|
+
/** @typedef {() => list.List<Item>} ItemThunk */
|
|
8
|
+
|
|
9
|
+
/** @typedef {string|ItemArray|ItemThunk} Item */
|
|
10
|
+
|
|
11
|
+
/** @type {(indent: string) => (text: Block) => list.List<string>} */
|
|
12
|
+
const flat = indent => {
|
|
13
|
+
|
|
14
|
+
/** @type {(prefix: string) => (text: Block) => list.List<string>} */
|
|
15
|
+
const f = prefix => {
|
|
16
|
+
/** @type {(item: Item) => list.List<string>} */
|
|
17
|
+
const g = item => typeof (item) === 'string' ? [`${prefix}${item}`] : f(`${prefix}${indent}`)(item)
|
|
18
|
+
return list.flatMap(g)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return f('')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = {
|
|
25
|
+
/** @readonly */
|
|
26
|
+
flat,
|
|
27
|
+
}
|
package/text/test.f.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const _ = require('./main.f.js')
|
|
2
|
+
const list = require('../types/list/main.f.js')
|
|
3
|
+
|
|
4
|
+
{
|
|
5
|
+
/** @type {_.Block} */
|
|
6
|
+
const text = [
|
|
7
|
+
'a',
|
|
8
|
+
'b',
|
|
9
|
+
() => [
|
|
10
|
+
'c',
|
|
11
|
+
() => ['d'],
|
|
12
|
+
],
|
|
13
|
+
'e',
|
|
14
|
+
]
|
|
15
|
+
const result = list.join('\n')(_.flat(':')(text))
|
|
16
|
+
if (result !== 'a\nb\n:c\n::d\ne') { throw result }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = {}
|
package/types/list/main.f.js
CHANGED
|
@@ -172,8 +172,7 @@ const drop = n => apply(dropStep(n))
|
|
|
172
172
|
/** @type {<D>(def: D) => <T>(input: List<T>) => D|T} */
|
|
173
173
|
const first = def => input => {
|
|
174
174
|
const result = next(input)
|
|
175
|
-
|
|
176
|
-
return result.first
|
|
175
|
+
return result === undefined ? def : result.first
|
|
177
176
|
}
|
|
178
177
|
|
|
179
178
|
/** @type {<D>(first: D) => <T>(tail: List<T>) => D|T} */
|
|
@@ -215,6 +214,9 @@ const countdown = count => () => {
|
|
|
215
214
|
return { first, tail: countdown(first) }
|
|
216
215
|
}
|
|
217
216
|
|
|
217
|
+
/** @type {<T>(v: T) => (c: number) => List<T>} */
|
|
218
|
+
const repeat = v => n => map(() => v)(countdown(n))
|
|
219
|
+
|
|
218
220
|
/** @type {<T>(list: List<T>) => List<T>} */
|
|
219
221
|
const cycle = list => () => {
|
|
220
222
|
const i = next(list)
|
|
@@ -355,6 +357,8 @@ module.exports = {
|
|
|
355
357
|
/** @readonly */
|
|
356
358
|
countdown,
|
|
357
359
|
/** @readonly */
|
|
360
|
+
repeat,
|
|
361
|
+
/** @readonly */
|
|
358
362
|
cycle,
|
|
359
363
|
/** @readonly */
|
|
360
364
|
scan,
|
package/types/list/test.f.js
CHANGED
|
@@ -354,6 +354,16 @@ const stress = () => {
|
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
+
{
|
|
358
|
+
const s = _.join('.')(_.repeat('x')(0))
|
|
359
|
+
if (s != '') { throw s }
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
{
|
|
363
|
+
const s = _.join('.')(_.repeat('x')(5))
|
|
364
|
+
if (s != 'x.x.x.x.x') { throw s }
|
|
365
|
+
}
|
|
366
|
+
|
|
357
367
|
// stress()
|
|
358
368
|
|
|
359
369
|
module.exports = {
|