functionalscript 0.0.435 → 0.0.436

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.
@@ -3,7 +3,7 @@ const { paramList } = types
3
3
  const text = require('../../text/module.f.cjs')
4
4
  const obj = require('../../types/object/module.f.cjs')
5
5
  const list = require('../../types/list/module.f.cjs')
6
- const { map, flatMap } = list
6
+ const { map, flatMap, flat } = list
7
7
  const { join } = require('../../types/string/module.f.cjs')
8
8
  const { entries } = Object
9
9
 
@@ -77,9 +77,14 @@ const cpp = name => lib => {
77
77
  ? struct(name)(defStruct(d))
78
78
  : struct(`${name}: ::com::IUnknown`)(defInterface(d))
79
79
 
80
+ /** @type {(kv: obj.Entry<types.Definition>) => text.Block} */
81
+ const forward = ([name]) => [`struct ${name};`]
82
+
83
+ const e = entries(lib)
84
+
80
85
  return list.flat([
81
86
  ['#pragma once', ''],
82
- namespace(name)(flatMap(def)(entries(lib)))
87
+ namespace(name)(flat([flatMap(forward)(e), flatMap(def)(e)]))
83
88
  ])
84
89
  }
85
90
 
@@ -11,10 +11,16 @@ const f = () =>
11
11
  '\n' +
12
12
  'namespace My\n' +
13
13
  '{\n' +
14
+ ' struct Slice;\n' +
15
+ ' struct ManagedStruct;\n' +
16
+ ' struct IMy;\n' +
14
17
  ' struct Slice\n' +
15
18
  ' {\n' +
16
19
  ' uint8_t* Start;\n' +
17
20
  ' size_t Size;\n' +
21
+ ' };\n' +
22
+ ' struct ManagedStruct\n' +
23
+ ' {\n' +
18
24
  ' ::com::ref<IMy> M;\n' +
19
25
  ' };\n' +
20
26
  ' struct IMy: ::com::IUnknown\n' +
@@ -25,6 +31,7 @@ const f = () =>
25
31
  ' virtual void COM_STDCALL SetUnsafe(Slice* p, uint32_t size) = 0;\n' +
26
32
  ' virtual ::com::BOOL COM_STDCALL Some(IMy& p) = 0;\n' +
27
33
  ' virtual ::com::ref<IMy> COM_STDCALL GetIMy() = 0;\n' +
34
+ ' virtual void COM_STDCALL SetManagedStruct(ManagedStruct a) = 0;\n' +
28
35
  ' };\n' +
29
36
  '}'
30
37
  if (r !== e) { throw r }
package/com/cs/test.f.cjs CHANGED
@@ -17,6 +17,10 @@ const f = () =>
17
17
  ' {\n' +
18
18
  ' public unsafe byte* Start;\n' +
19
19
  ' public UIntPtr Size;\n' +
20
+ ' }\n' +
21
+ ' [StructLayout(LayoutKind.Sequential)]\n' +
22
+ ' public struct ManagedStruct\n' +
23
+ ' {\n' +
20
24
  ' public IMy M;\n' +
21
25
  ' }\n' +
22
26
  ' [Guid("C66FB270-2D80-49AD-BB6E-88C1F90B805D")]\n' +
@@ -35,9 +39,11 @@ const f = () =>
35
39
  ' bool Some(IMy p);\n' +
36
40
  ' [PreserveSig]\n' +
37
41
  ' IMy GetIMy();\n' +
42
+ ' [PreserveSig]\n' +
43
+ ' void SetManagedStruct(ManagedStruct a);\n' +
38
44
  ' }\n' +
39
45
  '}'
40
- if (cs !== e) { throw [cs,e] }
46
+ if (cs !== e) { throw cs }
41
47
  return cs
42
48
  }
43
49
 
@@ -11,6 +11,9 @@ module.exports = {
11
11
  'pub struct Slice {\n' +
12
12
  ' pub Start: *const u8,\n' +
13
13
  ' pub Size: usize,\n' +
14
+ '}\n' +
15
+ '#[repr(C)]\n' +
16
+ 'pub struct ManagedStruct {\n' +
14
17
  ' pub M: IMy::Ref,\n' +
15
18
  '}\n' +
16
19
  'pub mod IMy {\n' +
@@ -25,6 +28,7 @@ module.exports = {
25
28
  ' pub SetUnsafe: unsafe extern "system" fn(this: &Object, p: *const super::Slice, size: u32),\n' +
26
29
  ' pub Some: unsafe extern "system" fn(this: &Object, p: &super::IMy::Object) -> bool,\n' +
27
30
  ' pub GetIMy: unsafe extern "system" fn(this: &Object) -> super::IMy::Ref,\n' +
31
+ ' pub SetManagedStruct: unsafe extern "system" fn(this: &Object, a: super::ManagedStruct),\n' +
28
32
  ' }\n' +
29
33
  ' impl nanocom::Interface for Interface {\n' +
30
34
  ' const GUID: nanocom::GUID = 0xC66FB270_2D80_49AD_BB6E_88C1F90B805D;\n' +
@@ -36,6 +40,7 @@ module.exports = {
36
40
  ' fn SetUnsafe(&self, p: *const super::Slice, size: u32);\n' +
37
41
  ' fn Some(&self, p: &super::IMy::Object) -> bool;\n' +
38
42
  ' fn GetIMy(&self) -> super::IMy::Ref;\n' +
43
+ ' fn SetManagedStruct(&self, a: super::ManagedStruct);\n' +
39
44
  ' }\n' +
40
45
  ' impl Ex for Object {\n' +
41
46
  ' fn GetSlice(&self) -> super::Slice {\n' +
@@ -56,6 +61,9 @@ module.exports = {
56
61
  ' fn GetIMy(&self) -> super::IMy::Ref {\n' +
57
62
  ' unsafe { (self.interface().GetIMy)(self) }\n' +
58
63
  ' }\n' +
64
+ ' fn SetManagedStruct(&self, a: super::ManagedStruct) {\n' +
65
+ ' unsafe { (self.interface().SetManagedStruct)(self, a) }\n' +
66
+ ' }\n' +
59
67
  ' }\n' +
60
68
  ' pub trait ClassEx\n' +
61
69
  ' where\n' +
@@ -69,6 +77,7 @@ module.exports = {
69
77
  ' SetUnsafe: Self::SetUnsafe,\n' +
70
78
  ' Some: Self::Some,\n' +
71
79
  ' GetIMy: Self::GetIMy,\n' +
80
+ ' SetManagedStruct: Self::SetManagedStruct,\n' +
72
81
  ' };\n' +
73
82
  ' }\n' +
74
83
  ' impl<T> ClassEx for T\n' +
@@ -100,6 +109,9 @@ module.exports = {
100
109
  ' extern "system" fn GetIMy(this: &Object) -> super::IMy::Ref {\n' +
101
110
  ' unsafe { Self::to_cobject(this) }.GetIMy()\n' +
102
111
  ' }\n' +
112
+ ' extern "system" fn SetManagedStruct(this: &Object, a: super::ManagedStruct) {\n' +
113
+ ' unsafe { Self::to_cobject(this) }.SetManagedStruct(a)\n' +
114
+ ' }\n' +
103
115
  ' }\n' +
104
116
  ' impl<T> PrivateClassEx for T\n' +
105
117
  ' where\n' +
@@ -109,7 +121,7 @@ module.exports = {
109
121
  ' }\n' +
110
122
  '}'
111
123
  const r = join('\n')(flat(' ')(rust(library)))
112
- if (r !== e) { throw [e, r] }
124
+ if (r !== e) { throw r }
113
125
  return r
114
126
  }
115
127
  }
@@ -0,0 +1,37 @@
1
+ const fs = require('node:fs')
2
+ const cp = require('node:child_process')
3
+ const os = require('node:os');
4
+ const cpp = require('../cpp/test.f.cjs').result
5
+ const { string: { join }, list: { flat } } = require('../../types/module.f.cjs')
6
+
7
+ const dirname = __dirname
8
+
9
+ fs.writeFileSync(`${dirname}/cpp/_result.hpp`, cpp)
10
+ try {
11
+ const flags = os.platform() === 'win32' ? [] : ['-std=c++11', '-lc++']
12
+ const line = join(' ')(flat([['clang'], flags, [dirname + '/cpp/main.cpp']]))
13
+ console.log(cp.execSync(line).toString())
14
+ } catch (e) {
15
+ // @ts-ignore
16
+ console.error(e.output.toString())
17
+ }
18
+
19
+ const cs = require('../cs/test.f.cjs').result
20
+
21
+ fs.writeFileSync(`${dirname}/cs/_result.cs`, cs)
22
+ try {
23
+ console.log(cp.execSync(`dotnet build ${dirname}/cs/cs.csproj`).toString())
24
+ } catch (e) {
25
+ // @ts-ignore
26
+ console.error(e.output.toString())
27
+ }
28
+
29
+ const rust = require("../rust/test.f.cjs").result();
30
+
31
+ fs.writeFileSync(`${dirname}/rust/src/_result.rs`, rust);
32
+ try {
33
+ console.log(cp.execSync("cargo build").toString());
34
+ } catch (e) {
35
+ // @ts-ignore
36
+ console.error(e.output.toString());
37
+ }
@@ -1,4 +1,4 @@
1
- #include "../com.hpp"
1
+ #include "../../cpp/com.hpp"
2
2
  #include "_result.hpp"
3
3
 
4
4
  #include <iostream>
File without changes
@@ -6,9 +6,13 @@ module.exports = {
6
6
  struct: {
7
7
  Start: ['*', 'u8'],
8
8
  Size: 'usize',
9
- M: ['IMy'],
10
9
  },
11
10
  },
11
+ ManagedStruct: {
12
+ struct: {
13
+ M: ['IMy']
14
+ }
15
+ },
12
16
  IMy: {
13
17
  guid: 'C66FB270-2D80-49AD-BB6E-88C1F90B805D',
14
18
  interface: {
@@ -20,7 +24,8 @@ module.exports = {
20
24
  size: 'u32'
21
25
  },
22
26
  Some: { p: ['IMy'], _: 'bool' },
23
- GetIMy: { _: ['IMy'] }
27
+ GetIMy: { _: ['IMy'] },
28
+ SetManagedStruct: { a: ['ManagedStruct'] },
24
29
  },
25
30
  }
26
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.435",
3
+ "version": "0.0.436",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "homepage": "https://github.com/functionalscript/functionalscript#readme",
31
31
  "devDependencies": {
32
- "@types/node": "^18.7.18",
33
- "typescript": "^4.8.3"
32
+ "@types/node": "^18.8.3",
33
+ "typescript": "^4.8.4"
34
34
  }
35
35
  }
@@ -1,15 +0,0 @@
1
- const fs = require('node:fs')
2
- const cp = require('node:child_process')
3
- const os = require('node:os');
4
- const cpp = require('../../cpp/test.f.cjs').result
5
- const { string: { join }, list: { flat } } = require('../../../types/module.f.cjs')
6
-
7
- fs.writeFileSync('_result.hpp', cpp)
8
- try {
9
- const flags = os.platform() === 'win32' ? [] : ['-std=c++11', '-lc++']
10
- const line = join(' ')(flat([['clang'], flags, ['main.cpp']]))
11
- console.log(cp.execSync(line).toString())
12
- } catch (e) {
13
- // @ts-ignore
14
- console.error(e.output.toString())
15
- }
@@ -1,11 +0,0 @@
1
- const fs = require('node:fs')
2
- const cp = require('node:child_process')
3
- const cs = require('../../cs/test.f.cjs').result
4
-
5
- fs.writeFileSync('_result.cs', cs)
6
- try {
7
- console.log(cp.execSync('dotnet build').toString())
8
- } catch (e) {
9
- // @ts-ignore
10
- console.error(e.output.toString())
11
- }