functionalscript 0.3.15 → 0.4.1

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.
Files changed (65) hide show
  1. package/bnf/djs/test.f.js +36 -41
  2. package/bnf/func/module.f.d.ts +12 -5
  3. package/bnf/func/module.f.js +27 -6
  4. package/bnf/func/test.f.js +25 -84
  5. package/bnf/tag/module.f.d.ts +30 -0
  6. package/bnf/tag/module.f.js +37 -0
  7. package/bnf/tag/test.f.d.ts +1 -0
  8. package/bnf/tag/test.f.js +138 -0
  9. package/fsc/bnf.f.d.ts +2 -0
  10. package/fsc/bnf.f.js +54 -0
  11. package/fsc/json.f.d.ts +7 -0
  12. package/fsc/json.f.js +89 -0
  13. package/package.json +2 -3
  14. package/types/array/module.f.d.ts +1 -0
  15. package/types/array/module.f.js +1 -0
  16. package/types/bigint/module.f.d.ts +6 -0
  17. package/types/bigint/module.f.js +27 -5
  18. package/types/bigint/test.f.d.ts +8 -5
  19. package/types/bigint/test.f.js +91 -19
  20. package/com/cpp/module.f.d.ts +0 -10
  21. package/com/cpp/module.f.js +0 -106
  22. package/com/cpp/test.f.d.ts +0 -2
  23. package/com/cpp/test.f.js +0 -40
  24. package/com/cpp/testlib.f.d.ts +0 -2
  25. package/com/cpp/testlib.f.js +0 -5
  26. package/com/cs/module.f.d.ts +0 -12
  27. package/com/cs/module.f.js +0 -79
  28. package/com/cs/test.f.d.ts +0 -2
  29. package/com/cs/test.f.js +0 -43
  30. package/com/cs/testlib.f.d.ts +0 -2
  31. package/com/cs/testlib.f.js +0 -5
  32. package/com/rust/module.f.d.ts +0 -15
  33. package/com/rust/module.f.js +0 -164
  34. package/com/rust/test.f.d.ts +0 -2
  35. package/com/rust/test.f.js +0 -123
  36. package/com/rust/testlib.f.d.ts +0 -2
  37. package/com/rust/testlib.f.js +0 -5
  38. package/com/test/build.f.d.ts +0 -20
  39. package/com/test/build.f.js +0 -58
  40. package/com/types/module.f.d.ts +0 -28
  41. package/com/types/module.f.js +0 -7
  42. package/com/types/testlib.f.d.ts +0 -44
  43. package/com/types/testlib.f.js +0 -28
  44. package/commonjs/build/module.f.d.ts +0 -6
  45. package/commonjs/build/module.f.js +0 -66
  46. package/commonjs/build/test.f.d.ts +0 -2
  47. package/commonjs/build/test.f.js +0 -92
  48. package/commonjs/module/function/module.f.d.ts +0 -8
  49. package/commonjs/module/function/module.f.js +0 -4
  50. package/commonjs/module/module.f.d.ts +0 -18
  51. package/commonjs/module/module.f.js +0 -11
  52. package/commonjs/module.f.d.ts +0 -6
  53. package/commonjs/module.f.js +0 -1
  54. package/commonjs/package/dependencies/module.f.d.ts +0 -7
  55. package/commonjs/package/dependencies/module.f.js +0 -13
  56. package/commonjs/package/dependencies/test.f.d.ts +0 -2
  57. package/commonjs/package/dependencies/test.f.js +0 -15
  58. package/commonjs/package/module.f.d.ts +0 -17
  59. package/commonjs/package/module.f.js +0 -18
  60. package/commonjs/package/test.f.d.ts +0 -2
  61. package/commonjs/package/test.f.js +0 -27
  62. package/commonjs/path/module.f.d.ts +0 -24
  63. package/commonjs/path/module.f.js +0 -112
  64. package/commonjs/path/test.f.d.ts +0 -25
  65. package/commonjs/path/test.f.js +0 -221
package/com/cs/test.f.js DELETED
@@ -1,43 +0,0 @@
1
- import cs from "./testlib.f.js";
2
- const f = () => {
3
- const e = 'using System;\n' +
4
- 'using System.Runtime.InteropServices;\n' +
5
- '\n' +
6
- 'namespace My\n' +
7
- '{\n' +
8
- ' [StructLayout(LayoutKind.Sequential)]\n' +
9
- ' public struct Slice\n' +
10
- ' {\n' +
11
- ' public unsafe byte* Start;\n' +
12
- ' public UIntPtr Size;\n' +
13
- ' }\n' +
14
- ' [StructLayout(LayoutKind.Sequential)]\n' +
15
- ' public struct ManagedStruct\n' +
16
- ' {\n' +
17
- ' public IMy M;\n' +
18
- ' }\n' +
19
- ' [Guid("C66FB270-2D80-49AD-BB6E-88C1F90B805D")]\n' +
20
- ' [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]\n' +
21
- ' public interface IMy\n' +
22
- ' {\n' +
23
- ' [PreserveSig]\n' +
24
- ' Slice GetSlice();\n' +
25
- ' [PreserveSig]\n' +
26
- ' void SetSlice(Slice slice);\n' +
27
- ' [PreserveSig]\n' +
28
- ' unsafe byte* GetUnsafe();\n' +
29
- ' [PreserveSig]\n' +
30
- ' unsafe void SetUnsafe(Slice* p, uint size);\n' +
31
- ' [PreserveSig]\n' +
32
- ' byte Some(IMy p);\n' +
33
- ' [PreserveSig]\n' +
34
- ' IMy GetIMy(ushort a, short b);\n' +
35
- ' [PreserveSig]\n' +
36
- ' void SetManagedStruct(ManagedStruct a);\n' +
37
- ' }\n' +
38
- '}';
39
- if (cs !== e) {
40
- throw cs;
41
- }
42
- };
43
- export default f;
@@ -1,2 +0,0 @@
1
- declare const _default: string;
2
- export default _default;
@@ -1,5 +0,0 @@
1
- import { flat } from "../../text/module.f.js";
2
- import { join } from "../../types/string/module.f.js";
3
- import { cs } from "./module.f.js";
4
- import library from "../types/testlib.f.js";
5
- export default join('\n')(flat(' ')(cs('My')(library)));
@@ -1,15 +0,0 @@
1
- /**
2
- * This module generates Rust code for COM interop from a high-level type library definition.
3
- *
4
- * The module provides functions to define structs, traits, and implementations in Rust,
5
- * specifically tailored for `nanocom` interpretation.
6
- */
7
- import { type Library } from '../types/module.f.ts';
8
- import type * as text from '../../text/module.f.ts';
9
- /**
10
- * Generates Rust code for the given type library.
11
- *
12
- * @param library - The library of type definitions to generate Rust code for.
13
- * @returns A block of Rust code representing the library.
14
- */
15
- export declare const rust: (library: Library) => text.Block;
@@ -1,164 +0,0 @@
1
- /**
2
- * This module generates Rust code for COM interop from a high-level type library definition.
3
- *
4
- * The module provides functions to define structs, traits, and implementations in Rust,
5
- * specifically tailored for `nanocom` interpretation.
6
- */
7
- import { paramList } from "../types/module.f.js";
8
- import { flat, map, flatMap } from "../../types/list/module.f.js";
9
- import { fn } from "../../types/function/module.f.js";
10
- import { join } from "../../types/string/module.f.js";
11
- const { entries } = Object;
12
- const rustField = (field) => `pub ${field},`;
13
- const mapRustField = map(rustField);
14
- const rustStruct = (b) => (name) => [`#[repr(C)]`, `pub struct ${name} {`, mapRustField(b), `}`];
15
- const commaJoin = join(', ');
16
- const ref = (name) => `${name}::Ref`;
17
- const obj = (name) => `&${name}::Object`;
18
- const self = ['&self'];
19
- const paramName = ([n]) => n;
20
- const callList = (p) => map(paramName)(paramList(p));
21
- const call = (p) => commaJoin(callList(p));
22
- const virtualCall = (p) => commaJoin(flat([['self'], callList(p)]));
23
- const super_ = 'super::';
24
- const assign = ([n]) => `${n}: Self::${n},`;
25
- const mapAssign = map(assign);
26
- const this_ = ['this: &Object'];
27
- const rustType = (n) => `pub type ${n} = nanocom::${n}<Interface>;`;
28
- const whereContent = (h) => (wh) => {
29
- const w = 'where' in wh ? [
30
- h,
31
- `where`,
32
- mapComma(wh.where),
33
- '{'
34
- ] : [`${h} {`];
35
- const x = [
36
- wh.content,
37
- '}',
38
- ];
39
- return flat([w, x]);
40
- };
41
- const rustImpl = (i) => {
42
- const p = 'param' in i ? `<${i.param}>` : '';
43
- const header = `impl${p} ${i.trait} for ${i.type}`;
44
- return whereContent(header)(i);
45
- };
46
- const comma = s => `${s},`;
47
- const mapComma = map(comma);
48
- const trait = (t) => {
49
- const p = t.pub === true ? 'pub ' : '';
50
- const h = `${p}trait ${t.type}`;
51
- return whereContent(h)(t);
52
- };
53
- const traitImpl = (t) => {
54
- const i = rustImpl({
55
- param: 'T',
56
- trait: t.type,
57
- type: 'T',
58
- where,
59
- content: [],
60
- });
61
- return flat([trait({ ...t, where }), i]);
62
- };
63
- const where = ['Self: nanocom::Class<Interface = Interface>', 'nanocom::CObject<Self>: Ex'];
64
- /**
65
- * Generates Rust code for the given type library.
66
- *
67
- * @param library - The library of type definitions to generate Rust code for.
68
- * @returns A block of Rust code representing the library.
69
- */
70
- export const rust = (library) => {
71
- const type = (p) => {
72
- const f = (o) => (t) => {
73
- if (typeof t === 'string') {
74
- return t;
75
- }
76
- if (t.length === 2) {
77
- return `*const ${f(ref)(t[1])}`;
78
- }
79
- const [id] = t;
80
- const fullId = `${p}${id}`;
81
- return 'interface' in library[id] ? o(fullId) : fullId;
82
- };
83
- return f;
84
- };
85
- const pf = (p) => (o) => ([name, t]) => `${name}: ${type(p)(o)(t)}`;
86
- const param = pf(super_)(obj);
87
- const mapParam = map(param);
88
- const mapField = map(pf('')(ref));
89
- const struct = fn(entries)
90
- .then(mapField)
91
- .then(rustStruct)
92
- .result;
93
- const func = (first) => (p) => {
94
- const resultStr = '_' in p ? ` -> ${type(super_)(ref)(p._)}` : '';
95
- const params = commaJoin(flat([first, mapParam(paramList(p))]));
96
- return `(${params})${resultStr}`;
97
- };
98
- const virtualFnType = (n) => (p) => `extern "system" fn${n}${func(this_)(p)}`;
99
- const virtualFn = ([n, p]) => `${n}: unsafe ${virtualFnType('')(p)}`;
100
- const mapVirtualFn = map(virtualFn);
101
- const headerFn = ([n, p]) => `fn ${n}${func(self)(p)}`;
102
- const traitFn = (m) => `${headerFn(m)};`;
103
- const mapTraitFn = map(traitFn);
104
- const implFn = (m) => {
105
- const [n, p] = m;
106
- return [
107
- `${headerFn(m)} {`,
108
- [`unsafe { (self.interface().${n})(${virtualCall(p)}) }`],
109
- '}'
110
- ];
111
- };
112
- const flatMapImplFn = flatMap(implFn);
113
- const impl = ([n, p]) => {
114
- const type = virtualFnType(` ${n}`)(p);
115
- return [
116
- `${type} {`,
117
- [`unsafe { nanocom::CObject::from_object_unchecked(this) }.${n}(${call(p)})`],
118
- '}'
119
- ];
120
- };
121
- const flatMapImpl = flatMap(impl);
122
- const interface_ = ({ interface: i, guid }) => (name) => {
123
- const e = entries(i);
124
- return [
125
- `pub mod ${name} {`,
126
- [
127
- rustType('Object'),
128
- rustType('Ref'),
129
- rustType('Vmt'),
130
- ],
131
- rustStruct(mapVirtualFn(e))('Interface'),
132
- rustImpl({
133
- trait: 'nanocom::Interface',
134
- type: 'Interface',
135
- content: [`const GUID: nanocom::GUID = 0x${guid.replaceAll('-', '_')};`]
136
- }),
137
- trait({ pub: true, type: 'Ex', content: mapTraitFn(e) }),
138
- rustImpl({
139
- trait: 'Ex',
140
- type: 'Object',
141
- content: flatMapImplFn(e)
142
- }),
143
- traitImpl({
144
- pub: true,
145
- type: 'ClassEx',
146
- content: ['const VMT: Vmt = Vmt {',
147
- ['iunknown: nanocom::CObject::<Self>::IUNKNOWN,',
148
- 'interface: Interface {',
149
- mapAssign(e),
150
- '},',
151
- ],
152
- '};'
153
- ]
154
- }),
155
- traitImpl({
156
- type: 'PrivateClassEx',
157
- content: flatMapImpl(e)
158
- }),
159
- '}'
160
- ];
161
- };
162
- const def = ([name, type]) => ('interface' in type ? interface_(type) : struct(type.struct))(name);
163
- return flat([['#![allow(non_snake_case)]'], flatMap(def)(entries(library))]);
164
- };
@@ -1,2 +0,0 @@
1
- declare const _default: () => void;
2
- export default _default;
@@ -1,123 +0,0 @@
1
- import rust from "./testlib.f.js";
2
- export default () => {
3
- const e = '#![allow(non_snake_case)]\n' +
4
- '#[repr(C)]\n' +
5
- 'pub struct Slice {\n' +
6
- ' pub Start: *const u8,\n' +
7
- ' pub Size: usize,\n' +
8
- '}\n' +
9
- '#[repr(C)]\n' +
10
- 'pub struct ManagedStruct {\n' +
11
- ' pub M: IMy::Ref,\n' +
12
- '}\n' +
13
- 'pub mod IMy {\n' +
14
- ' pub type Object = nanocom::Object<Interface>;\n' +
15
- ' pub type Ref = nanocom::Ref<Interface>;\n' +
16
- ' pub type Vmt = nanocom::Vmt<Interface>;\n' +
17
- ' #[repr(C)]\n' +
18
- ' pub struct Interface {\n' +
19
- ' pub GetSlice: unsafe extern "system" fn(this: &Object) -> super::Slice,\n' +
20
- ' pub SetSlice: unsafe extern "system" fn(this: &Object, slice: super::Slice),\n' +
21
- ' pub GetUnsafe: unsafe extern "system" fn(this: &Object) -> *const bool,\n' +
22
- ' pub SetUnsafe: unsafe extern "system" fn(this: &Object, p: *const super::Slice, size: u32),\n' +
23
- ' pub Some: unsafe extern "system" fn(this: &Object, p: &super::IMy::Object) -> bool,\n' +
24
- ' pub GetIMy: unsafe extern "system" fn(this: &Object, a: u16, b: i16) -> super::IMy::Ref,\n' +
25
- ' pub SetManagedStruct: unsafe extern "system" fn(this: &Object, a: super::ManagedStruct),\n' +
26
- ' }\n' +
27
- ' impl nanocom::Interface for Interface {\n' +
28
- ' const GUID: nanocom::GUID = 0xC66FB270_2D80_49AD_BB6E_88C1F90B805D;\n' +
29
- ' }\n' +
30
- ' pub trait Ex {\n' +
31
- ' fn GetSlice(&self) -> super::Slice;\n' +
32
- ' fn SetSlice(&self, slice: super::Slice);\n' +
33
- ' fn GetUnsafe(&self) -> *const bool;\n' +
34
- ' fn SetUnsafe(&self, p: *const super::Slice, size: u32);\n' +
35
- ' fn Some(&self, p: &super::IMy::Object) -> bool;\n' +
36
- ' fn GetIMy(&self, a: u16, b: i16) -> super::IMy::Ref;\n' +
37
- ' fn SetManagedStruct(&self, a: super::ManagedStruct);\n' +
38
- ' }\n' +
39
- ' impl Ex for Object {\n' +
40
- ' fn GetSlice(&self) -> super::Slice {\n' +
41
- ' unsafe { (self.interface().GetSlice)(self) }\n' +
42
- ' }\n' +
43
- ' fn SetSlice(&self, slice: super::Slice) {\n' +
44
- ' unsafe { (self.interface().SetSlice)(self, slice) }\n' +
45
- ' }\n' +
46
- ' fn GetUnsafe(&self) -> *const bool {\n' +
47
- ' unsafe { (self.interface().GetUnsafe)(self) }\n' +
48
- ' }\n' +
49
- ' fn SetUnsafe(&self, p: *const super::Slice, size: u32) {\n' +
50
- ' unsafe { (self.interface().SetUnsafe)(self, p, size) }\n' +
51
- ' }\n' +
52
- ' fn Some(&self, p: &super::IMy::Object) -> bool {\n' +
53
- ' unsafe { (self.interface().Some)(self, p) }\n' +
54
- ' }\n' +
55
- ' fn GetIMy(&self, a: u16, b: i16) -> super::IMy::Ref {\n' +
56
- ' unsafe { (self.interface().GetIMy)(self, a, b) }\n' +
57
- ' }\n' +
58
- ' fn SetManagedStruct(&self, a: super::ManagedStruct) {\n' +
59
- ' unsafe { (self.interface().SetManagedStruct)(self, a) }\n' +
60
- ' }\n' +
61
- ' }\n' +
62
- ' pub trait ClassEx\n' +
63
- ' where\n' +
64
- ' Self: nanocom::Class<Interface = Interface>,\n' +
65
- ' nanocom::CObject<Self>: Ex,\n' +
66
- ' {\n' +
67
- ' const VMT: Vmt = Vmt {\n' +
68
- ' iunknown: nanocom::CObject::<Self>::IUNKNOWN,\n' +
69
- ' interface: Interface {\n' +
70
- ' GetSlice: Self::GetSlice,\n' +
71
- ' SetSlice: Self::SetSlice,\n' +
72
- ' GetUnsafe: Self::GetUnsafe,\n' +
73
- ' SetUnsafe: Self::SetUnsafe,\n' +
74
- ' Some: Self::Some,\n' +
75
- ' GetIMy: Self::GetIMy,\n' +
76
- ' SetManagedStruct: Self::SetManagedStruct,\n' +
77
- ' },\n' +
78
- ' };\n' +
79
- ' }\n' +
80
- ' impl<T> ClassEx for T\n' +
81
- ' where\n' +
82
- ' Self: nanocom::Class<Interface = Interface>,\n' +
83
- ' nanocom::CObject<Self>: Ex,\n' +
84
- ' {\n' +
85
- ' }\n' +
86
- ' trait PrivateClassEx\n' +
87
- ' where\n' +
88
- ' Self: nanocom::Class<Interface = Interface>,\n' +
89
- ' nanocom::CObject<Self>: Ex,\n' +
90
- ' {\n' +
91
- ' extern "system" fn GetSlice(this: &Object) -> super::Slice {\n' +
92
- ' unsafe { nanocom::CObject::from_object_unchecked(this) }.GetSlice()\n' +
93
- ' }\n' +
94
- ' extern "system" fn SetSlice(this: &Object, slice: super::Slice) {\n' +
95
- ' unsafe { nanocom::CObject::from_object_unchecked(this) }.SetSlice(slice)\n' +
96
- ' }\n' +
97
- ' extern "system" fn GetUnsafe(this: &Object) -> *const bool {\n' +
98
- ' unsafe { nanocom::CObject::from_object_unchecked(this) }.GetUnsafe()\n' +
99
- ' }\n' +
100
- ' extern "system" fn SetUnsafe(this: &Object, p: *const super::Slice, size: u32) {\n' +
101
- ' unsafe { nanocom::CObject::from_object_unchecked(this) }.SetUnsafe(p, size)\n' +
102
- ' }\n' +
103
- ' extern "system" fn Some(this: &Object, p: &super::IMy::Object) -> bool {\n' +
104
- ' unsafe { nanocom::CObject::from_object_unchecked(this) }.Some(p)\n' +
105
- ' }\n' +
106
- ' extern "system" fn GetIMy(this: &Object, a: u16, b: i16) -> super::IMy::Ref {\n' +
107
- ' unsafe { nanocom::CObject::from_object_unchecked(this) }.GetIMy(a, b)\n' +
108
- ' }\n' +
109
- ' extern "system" fn SetManagedStruct(this: &Object, a: super::ManagedStruct) {\n' +
110
- ' unsafe { nanocom::CObject::from_object_unchecked(this) }.SetManagedStruct(a)\n' +
111
- ' }\n' +
112
- ' }\n' +
113
- ' impl<T> PrivateClassEx for T\n' +
114
- ' where\n' +
115
- ' Self: nanocom::Class<Interface = Interface>,\n' +
116
- ' nanocom::CObject<Self>: Ex,\n' +
117
- ' {\n' +
118
- ' }\n' +
119
- '}';
120
- if (rust !== e) {
121
- throw rust;
122
- }
123
- };
@@ -1,2 +0,0 @@
1
- declare const _default: string;
2
- export default _default;
@@ -1,5 +0,0 @@
1
- import { flat } from "../../text/module.f.js";
2
- import { join } from "../../types/string/module.f.js";
3
- import { rust } from "./module.f.js";
4
- import library from "../types/testlib.f.js";
5
- export default join('\n')(flat(' ')(rust(library)));
@@ -1,20 +0,0 @@
1
- import { type List } from '../../types/list/module.f.ts';
2
- type Platform = 'aix' | 'android' | 'darwin' | 'freebsd' | 'haiku' | 'linux' | 'openbsd' | 'sunos' | 'win32' | 'cygwin' | 'netbsd';
3
- type NodeJs = {
4
- readonly dirname: string;
5
- readonly platform: Platform;
6
- };
7
- type Output = {
8
- readonly file: {
9
- readonly name: string;
10
- readonly content: string;
11
- };
12
- readonly line: List<List<string>>;
13
- };
14
- export type Func = (nodejs: NodeJs) => Output;
15
- declare const _default: {
16
- cpp: Func;
17
- cs: Func;
18
- rust: Func;
19
- };
20
- export default _default;
@@ -1,58 +0,0 @@
1
- import { flat } from "../../types/list/module.f.js";
2
- import cppContent from "../cpp/testlib.f.js";
3
- import csContent from "../cs/testlib.f.js";
4
- import rustContent from "../rust/testlib.f.js";
5
- const flags = (platform) => {
6
- switch (platform) {
7
- case 'win32':
8
- return [];
9
- case 'linux':
10
- return ['-std=c++17', '-lstdc++', '-fPIC'];
11
- default:
12
- return ['-std=c++17', '-lc++'];
13
- }
14
- };
15
- const output = (platform) => (name) => {
16
- switch (platform) {
17
- case 'win32': return `${name}.dll`;
18
- case 'darwin': return `lib${name}.dylib`;
19
- default: return `lib${name}.so`;
20
- }
21
- };
22
- const cpp = ({ dirname, platform }) => ({
23
- file: {
24
- name: `${dirname}/cpp/_result.hpp`,
25
- content: cppContent(),
26
- },
27
- line: [
28
- flat([
29
- ['clang', '-shared', '-o', output(platform)('testc')],
30
- flags(platform),
31
- [`${dirname}/cpp/main.cpp`],
32
- ]),
33
- ],
34
- });
35
- const cs = ({ dirname, platform }) => ({
36
- file: {
37
- name: `${dirname}/cs/_result.cs`,
38
- content: csContent,
39
- },
40
- line: [
41
- platform === 'win32'
42
- ? ['dotnet', 'run', '--project', `${dirname}/cs/cs.csproj`]
43
- // .Net on Linux and MacOS doesn't properly support COM object marshalling
44
- : ['dotnet', 'build', `${dirname}/cs/cs.csproj`]
45
- ],
46
- });
47
- const rust = ({ dirname }) => ({
48
- file: {
49
- name: `${dirname}/rust/src/_result.rs`,
50
- content: rustContent,
51
- },
52
- line: [['cargo', 'build' /**, '--locked' */]]
53
- });
54
- export default {
55
- cpp,
56
- cs,
57
- rust,
58
- };
@@ -1,28 +0,0 @@
1
- import type * as O from '../../types/object/module.f.ts';
2
- import { type List } from '../../types/list/module.f.ts';
3
- export type Library = {
4
- readonly [k in string]: Definition;
5
- };
6
- export type Definition = Struct | Interface;
7
- export type Struct = {
8
- readonly struct: FieldArray;
9
- };
10
- export type FieldArray = {
11
- readonly [k in string]: Type;
12
- };
13
- export type Field = O.Entry<Type>;
14
- export type Interface = {
15
- readonly interface: MethodArray;
16
- readonly guid: string;
17
- };
18
- type MethodArray = {
19
- readonly [k in string]: FieldArray;
20
- };
21
- export type Method = O.Entry<FieldArray>;
22
- export type Type = BaseType | Id | Pointer;
23
- type Id = readonly [string];
24
- export type BaseType = 'u8' | 'i8' | 'u16' | 'i16' | 'u32' | 'i32' | 'u64' | 'i64' | 'usize' | 'isize' | 'f32' | 'f64' | 'bool';
25
- type Pointer = readonly ['*', Type];
26
- export declare const paramList: (fa: FieldArray) => List<Field>;
27
- export declare const result: <T>(v: T) => (f: (type: Type) => T) => (fa: FieldArray) => T;
28
- export {};
@@ -1,7 +0,0 @@
1
- import { filter } from "../../types/list/module.f.js";
2
- import { compose } from "../../types/function/module.f.js";
3
- const { entries } = Object;
4
- const isParam = ([name]) => name !== '_';
5
- const filterParam = filter(isParam);
6
- export const paramList = compose(entries)(filterParam);
7
- export const result = (v) => (f) => (fa) => '_' in fa ? f(fa._) : v;
@@ -1,44 +0,0 @@
1
- declare const _default: {
2
- Slice: {
3
- struct: {
4
- Start: ["*", "u8"];
5
- Size: "usize";
6
- };
7
- };
8
- ManagedStruct: {
9
- struct: {
10
- M: ["IMy"];
11
- };
12
- };
13
- IMy: {
14
- guid: string;
15
- interface: {
16
- GetSlice: {
17
- _: ["Slice"];
18
- };
19
- SetSlice: {
20
- slice: ["Slice"];
21
- };
22
- GetUnsafe: {
23
- _: ["*", "bool"];
24
- };
25
- SetUnsafe: {
26
- p: ["*", ["Slice"]];
27
- size: "u32";
28
- };
29
- Some: {
30
- p: ["IMy"];
31
- _: "bool";
32
- };
33
- GetIMy: {
34
- a: "u16";
35
- b: "i16";
36
- _: ["IMy"];
37
- };
38
- SetManagedStruct: {
39
- a: ["ManagedStruct"];
40
- };
41
- };
42
- };
43
- };
44
- export default _default;
@@ -1,28 +0,0 @@
1
- export default {
2
- Slice: {
3
- struct: {
4
- Start: ['*', 'u8'],
5
- Size: 'usize',
6
- },
7
- },
8
- ManagedStruct: {
9
- struct: {
10
- M: ['IMy']
11
- }
12
- },
13
- IMy: {
14
- guid: 'C66FB270-2D80-49AD-BB6E-88C1F90B805D',
15
- interface: {
16
- GetSlice: { _: ['Slice'] },
17
- SetSlice: { slice: ['Slice'] },
18
- GetUnsafe: { _: ['*', 'bool'] },
19
- SetUnsafe: {
20
- p: ['*', ['Slice']],
21
- size: 'u32'
22
- },
23
- Some: { p: ['IMy'], _: 'bool' },
24
- GetIMy: { a: 'u16', b: 'i16', _: ['IMy'] },
25
- SetManagedStruct: { a: ['ManagedStruct'] },
26
- },
27
- }
28
- };
@@ -1,6 +0,0 @@
1
- import type * as package_ from '../package/module.f.ts';
2
- import { type MapInterface, type Id, type State } from '../module/module.f.ts';
3
- import type * as function_ from '../module/function/module.f.ts';
4
- type Result<M> = readonly [State, M];
5
- export declare const getOrBuild: (compile: function_.Compile) => (packageGet: package_.Get) => <M>(moduleMapInterface: MapInterface<M>) => (moduleId: Id) => (moduleMap: M) => Result<M>;
6
- export {};
@@ -1,66 +0,0 @@
1
- import { idToString, dir, } from "../module/module.f.js";
2
- import { empty as mapEmpty, setReplace } from "../../types/map/module.f.js";
3
- import * as object from "../../types/object/module.f.js";
4
- const { fromMap } = object;
5
- import * as path from "../path/module.f.js";
6
- const { parseAndFind } = path;
7
- import * as stringSet from "../../types/string_set/module.f.js";
8
- const { set: setSet, contains: setContains, empty: stringSetEmpty } = stringSet;
9
- const notFound = (moduleMap) => [['error', ['file not found']], moduleMap];
10
- export const getOrBuild = compile => packageGet => moduleMapInterface => {
11
- const build = buildSet => moduleId => {
12
- const moduleIdStr = idToString(moduleId);
13
- const buildSet1 = setSet(moduleIdStr)(buildSet);
14
- const moduleDir = dir(moduleId);
15
- const require_ = p => ([requireMap, m]) => {
16
- const error = e => [['error', e], [requireMap, m]];
17
- if (moduleDir === null) {
18
- return error('file not found');
19
- }
20
- const r = parseAndFind(packageGet)(moduleDir)(p);
21
- if (r === null) {
22
- return error('file not found');
23
- }
24
- const rIdStr = idToString(r.id);
25
- if (setContains(rIdStr)(buildSet1)) {
26
- return error('circular reference');
27
- }
28
- const [state, m1] = build(buildSet1)(r.id)(r.source)(m);
29
- return [state[0] === 'error' ? state : ['ok', state[1].exports], [setReplace(p)(rIdStr)(requireMap), m1]];
30
- };
31
- return source => moduleMap => {
32
- const set = s => m => [s, moduleMapInterface.setReplace(moduleIdStr)(s)(m)];
33
- const error = e => set(['error', e]);
34
- // check compilation
35
- const [kind, result] = compile(source);
36
- if (kind === 'error') {
37
- return error(['compilation error', result])(moduleMap);
38
- }
39
- // build
40
- const [[state, value], [requireMap, moduleMap2]] = result(require_)([mapEmpty, moduleMap]);
41
- const x = state === 'error' ?
42
- error(['runtime error', value]) :
43
- set(['ok', { exports: value, requireMap: fromMap(requireMap) }]);
44
- return x(moduleMap2);
45
- };
46
- };
47
- const f = (moduleId) => (moduleMap) => {
48
- const moduleIdStr = idToString(moduleId);
49
- // check moduleMap
50
- {
51
- const m = moduleMapInterface.at(moduleIdStr)(moduleMap);
52
- if (m !== null) {
53
- return [m, moduleMap];
54
- }
55
- }
56
- // check package
57
- const p = packageGet(moduleId.package);
58
- if (p === null) {
59
- return notFound(moduleMap);
60
- }
61
- // check file
62
- const source = p.file(moduleId.path.join('/'));
63
- return (source === null ? notFound : build(stringSetEmpty)(moduleId)(source))(moduleMap);
64
- };
65
- return f;
66
- };
@@ -1,2 +0,0 @@
1
- declare const _default: () => void;
2
- export default _default;