functionalscript 0.0.470 → 0.0.472

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.
@@ -33,11 +33,33 @@ const resultVoid = types.result('void')
33
33
 
34
34
  const namespace = text.curly('namespace')
35
35
 
36
+ /** @type {(id: string) => string} */
37
+ const comRef = id => `::nanocom::ref<${id}>`
38
+
39
+ /** @type {(id: string) => string} */
40
+ const ptr = id => `${id} const*`
41
+
42
+ /** @type {(id: string) => string} */
43
+ const ref = id => `${id} const&`
44
+
45
+ /** @type {(p: types.Field) => string} */
46
+ const paramName = ([name]) => name
47
+
48
+ const mapParamName = map(paramName)
49
+
50
+ const joinComma = join(', ')
51
+
36
52
  /** @type {(name: string) => (lib: types.Library) => text.Block} */
37
53
  const cpp = name => lib => {
38
54
 
39
- /** @type {(t: types.Type) => boolean} */
40
- const isInterface = t => t instanceof Array && t.length === 1 && lib[t[0]].interface !== undefined
55
+ /** @type {(t: types.Type) => string|undefined} */
56
+ const interface_ = t => {
57
+ if (!(t instanceof Array) || t.length !== 1) {
58
+ return undefined
59
+ }
60
+ const [name] = t
61
+ return lib[name].interface !== undefined ? name : undefined
62
+ }
41
63
 
42
64
  /** @type {(i: (t: string) => string) => (t: types.Type) => string} */
43
65
  const objectType = i => t => {
@@ -48,9 +70,9 @@ const cpp = name => lib => {
48
70
  return i(id)
49
71
  }
50
72
 
51
- const type = objectType(id => `::com::ref<${id}>`)
73
+ const type = objectType(comRef)
52
74
 
53
- const resultType = objectType(id => `${id} const*`)
75
+ const resultType = objectType(ptr)
54
76
 
55
77
  /** @type {(s: types.Field) => text.Item} */
56
78
  const field = ([name, t]) => `${type(t)} ${name};`
@@ -64,20 +86,34 @@ const cpp = name => lib => {
64
86
  const cppResult = resultVoid(resultType)
65
87
 
66
88
  /** @type {(p: types.Field) => string} */
67
- const param = ([name, t]) => `${objectType(id => `${id} const&`)(t)} ${name}`
89
+ const param = ([name, t]) => `${objectType(ref)(t)} ${name}`
68
90
 
69
91
  const mapParam = map(param)
70
92
 
71
- /** @type {(m: types.Method) => string} */
72
- const virtualName = ([name, paramArray]) => isInterface(paramArray._) ? `${name}_` : name
73
-
74
- /** @type {(m: types.Method) => text.Item} */
75
- const method = m => {
76
- const [, paramArray] = m
77
- return `virtual ${cppResult(paramArray)} COM_STDCALL ${virtualName(m)}(${join(', ')(mapParam(paramList(paramArray)))}) const noexcept = 0;`
93
+ /** @type {(result: string) => (paramArrayStr: string) => (name: string) => text.Item} */
94
+ const methodHeader = result => paramArrayStr => name =>
95
+ `virtual ${result} ${name}${paramArrayStr} const noexcept = 0;`
96
+
97
+ /** @type {(m: types.Method) => readonly text.Item[]} */
98
+ const method = ([name, paramArray]) => {
99
+ const result = cppResult(paramArray)
100
+ const paramL = paramList(paramArray)
101
+ const paramArrayStr = `(${joinComma(mapParam(paramL))})`
102
+ const m = methodHeader(result)(paramArrayStr)
103
+ const resultName = interface_(paramArray._)
104
+ if (resultName === undefined) {
105
+ return [m(name)]
106
+ }
107
+ return [
108
+ m(`${name}_`),
109
+ `${comRef(resultName)} ${name}${paramArrayStr} const noexcept`,
110
+ '{',
111
+ [`return ::nanocom::move_to_ref(${name}_(${joinComma(mapParamName(paramL))}));`],
112
+ '}',
113
+ ]
78
114
  }
79
115
 
80
- const mapMethod = map(method)
116
+ const mapMethod = flatMap(method)
81
117
 
82
118
  /** @type {(i: types.Interface) => text.Block} */
83
119
  const defInterface = ({ guid, interface: i }) => {
@@ -85,7 +121,7 @@ const cpp = name => lib => {
85
121
  const lo = g.substring(0, 16);
86
122
  const hi = g.substring(16);
87
123
  return flat([
88
- [`constexpr static ::com::GUID const guid = ::com::GUID(0x${lo}, 0x${hi});`],
124
+ [`constexpr static ::nanocom::GUID const guid = ::nanocom::GUID(0x${lo}, 0x${hi});`],
89
125
  mapMethod(entries(i))
90
126
  ])
91
127
  }
@@ -93,7 +129,13 @@ const cpp = name => lib => {
93
129
  /** @type {(kv: obj.Entry<types.Definition>) => text.Block} */
94
130
  const def = ([name, d]) => d.interface === undefined
95
131
  ? struct(name)(defStruct(d))
96
- : [`class ${name} : public ::com::IUnknown`, '{', 'public:', defInterface(d), '};']
132
+ : [
133
+ `class ${name} : public ::nanocom::IUnknown`,
134
+ '{',
135
+ 'public:',
136
+ defInterface(d),
137
+ '};'
138
+ ]
97
139
 
98
140
  /** @type {(kv: obj.Entry<types.Definition>) => text.Block} */
99
141
  const forward = ([name]) => [`struct ${name};`]
@@ -5,17 +5,9 @@
5
5
  #include <atomic>
6
6
  #include <iostream>
7
7
 
8
- #if defined(__aarch64__) || defined(__amd64__)
9
- #define COM_STDCALL
10
- #elif defined(__clang__)
11
- #define COM_STDCALL __attribute__((stdcall))
12
- #else
13
- #define COM_STDCALL __stdcall
14
- #endif
15
-
16
8
  static_assert(sizeof(bool) == 1);
17
9
 
18
- namespace com
10
+ namespace nanocom
19
11
  {
20
12
  constexpr uint64_t byteswap(uint64_t v) noexcept
21
13
  {
@@ -80,9 +72,9 @@ namespace com
80
72
  class IUnknown
81
73
  {
82
74
  public:
83
- virtual HRESULT COM_STDCALL QueryInterface(GUID const &riid, IUnknown const **ppvObject) const noexcept = 0;
84
- virtual ULONG COM_STDCALL AddRef() const noexcept = 0;
85
- virtual ULONG COM_STDCALL Release() const noexcept = 0;
75
+ virtual HRESULT QueryInterface(GUID const &riid, IUnknown const **ppvObject) const noexcept = 0;
76
+ virtual ULONG AddRef() const noexcept = 0;
77
+ virtual ULONG Release() const noexcept = 0;
86
78
  };
87
79
 
88
80
  template <class I>
@@ -155,7 +147,7 @@ namespace com
155
147
  }
156
148
 
157
149
  private:
158
- HRESULT COM_STDCALL QueryInterface(GUID const &riid, IUnknown const **const ppvObject) const noexcept override
150
+ HRESULT QueryInterface(GUID const &riid, IUnknown const **const ppvObject) const noexcept override
159
151
  {
160
152
  // std::cout << "riid: " << riid << std::endl;
161
153
  // std::cout << "iunknown: " << iunknown_guid << std::endl;
@@ -175,12 +167,12 @@ namespace com
175
167
  return counter.fetch_add(1);
176
168
  }
177
169
 
178
- ULONG COM_STDCALL AddRef() const noexcept override
170
+ ULONG AddRef() const noexcept override
179
171
  {
180
172
  return add_ref() + 1;
181
173
  }
182
174
 
183
- ULONG COM_STDCALL Release() const noexcept override
175
+ ULONG Release() const noexcept override
184
176
  {
185
177
  auto const c = counter.fetch_sub(1) - 1;
186
178
  if (c == 0)
@@ -17,19 +17,23 @@ const f = () =>
17
17
  ' };\n' +
18
18
  ' struct ManagedStruct\n' +
19
19
  ' {\n' +
20
- ' ::com::ref<IMy> M;\n' +
20
+ ' ::nanocom::ref<IMy> M;\n' +
21
21
  ' };\n' +
22
- ' class IMy : public ::com::IUnknown\n' +
22
+ ' class IMy : public ::nanocom::IUnknown\n' +
23
23
  ' {\n' +
24
24
  ' public:\n' +
25
- ' constexpr static ::com::GUID const guid = ::com::GUID(0xC66FB2702D8049AD, 0xBB6E88C1F90B805D);\n' +
26
- ' virtual Slice COM_STDCALL GetSlice() const noexcept = 0;\n' +
27
- ' virtual void COM_STDCALL SetSlice(Slice slice) const noexcept = 0;\n' +
28
- ' virtual bool const* COM_STDCALL GetUnsafe() const noexcept = 0;\n' +
29
- ' virtual void COM_STDCALL SetUnsafe(Slice const* p, uint32_t size) const noexcept = 0;\n' +
30
- ' virtual bool COM_STDCALL Some(IMy const& p) const noexcept = 0;\n' +
31
- ' virtual IMy const* COM_STDCALL GetIMy_() const noexcept = 0;\n' +
32
- ' virtual void COM_STDCALL SetManagedStruct(ManagedStruct a) const noexcept = 0;\n' +
25
+ ' constexpr static ::nanocom::GUID const guid = ::nanocom::GUID(0xC66FB2702D8049AD, 0xBB6E88C1F90B805D);\n' +
26
+ ' virtual Slice GetSlice() const noexcept = 0;\n' +
27
+ ' virtual void SetSlice(Slice slice) const noexcept = 0;\n' +
28
+ ' virtual bool const* GetUnsafe() const noexcept = 0;\n' +
29
+ ' virtual void SetUnsafe(Slice const* p, uint32_t size) const noexcept = 0;\n' +
30
+ ' virtual bool Some(IMy const& p) const noexcept = 0;\n' +
31
+ ' virtual IMy const* GetIMy_(uint16_t a, int16_t b) const noexcept = 0;\n' +
32
+ ' ::nanocom::ref<IMy> GetIMy(uint16_t a, int16_t b) const noexcept\n' +
33
+ ' {\n' +
34
+ ' return ::nanocom::move_to_ref(GetIMy_(a, b));\n' +
35
+ ' }\n' +
36
+ ' virtual void SetManagedStruct(ManagedStruct a) const noexcept = 0;\n' +
33
37
  ' };\n' +
34
38
  '}'
35
39
  if (cpp !== e) { throw cpp }
package/com/cs/test.f.cjs CHANGED
@@ -34,7 +34,7 @@ const f = () =>
34
34
  ' [PreserveSig]\n' +
35
35
  ' byte Some(IMy p);\n' +
36
36
  ' [PreserveSig]\n' +
37
- ' IMy GetIMy();\n' +
37
+ ' IMy GetIMy(ushort a, short b);\n' +
38
38
  ' [PreserveSig]\n' +
39
39
  ' void SetManagedStruct(ManagedStruct a);\n' +
40
40
  ' }\n' +
@@ -23,7 +23,7 @@ module.exports = () => {
23
23
  ' pub GetUnsafe: unsafe extern "system" fn(this: &Object) -> *const bool,\n' +
24
24
  ' pub SetUnsafe: unsafe extern "system" fn(this: &Object, p: *const super::Slice, size: u32),\n' +
25
25
  ' pub Some: unsafe extern "system" fn(this: &Object, p: &super::IMy::Object) -> bool,\n' +
26
- ' pub GetIMy: unsafe extern "system" fn(this: &Object) -> super::IMy::Ref,\n' +
26
+ ' pub GetIMy: unsafe extern "system" fn(this: &Object, a: u16, b: i16) -> super::IMy::Ref,\n' +
27
27
  ' pub SetManagedStruct: unsafe extern "system" fn(this: &Object, a: super::ManagedStruct),\n' +
28
28
  ' }\n' +
29
29
  ' impl nanocom::Interface for Interface {\n' +
@@ -35,7 +35,7 @@ module.exports = () => {
35
35
  ' fn GetUnsafe(&self) -> *const bool;\n' +
36
36
  ' fn SetUnsafe(&self, p: *const super::Slice, size: u32);\n' +
37
37
  ' fn Some(&self, p: &super::IMy::Object) -> bool;\n' +
38
- ' fn GetIMy(&self) -> super::IMy::Ref;\n' +
38
+ ' fn GetIMy(&self, a: u16, b: i16) -> super::IMy::Ref;\n' +
39
39
  ' fn SetManagedStruct(&self, a: super::ManagedStruct);\n' +
40
40
  ' }\n' +
41
41
  ' impl Ex for Object {\n' +
@@ -54,8 +54,8 @@ module.exports = () => {
54
54
  ' fn Some(&self, p: &super::IMy::Object) -> bool {\n' +
55
55
  ' unsafe { (self.interface().Some)(self, p) }\n' +
56
56
  ' }\n' +
57
- ' fn GetIMy(&self) -> super::IMy::Ref {\n' +
58
- ' unsafe { (self.interface().GetIMy)(self) }\n' +
57
+ ' fn GetIMy(&self, a: u16, b: i16) -> super::IMy::Ref {\n' +
58
+ ' unsafe { (self.interface().GetIMy)(self, a, b) }\n' +
59
59
  ' }\n' +
60
60
  ' fn SetManagedStruct(&self, a: super::ManagedStruct) {\n' +
61
61
  ' unsafe { (self.interface().SetManagedStruct)(self, a) }\n' +
@@ -105,8 +105,8 @@ module.exports = () => {
105
105
  ' extern "system" fn Some(this: &Object, p: &super::IMy::Object) -> bool {\n' +
106
106
  ' unsafe { nanocom::CObject::from_object_unchecked(this) }.Some(p)\n' +
107
107
  ' }\n' +
108
- ' extern "system" fn GetIMy(this: &Object) -> super::IMy::Ref {\n' +
109
- ' unsafe { nanocom::CObject::from_object_unchecked(this) }.GetIMy()\n' +
108
+ ' extern "system" fn GetIMy(this: &Object, a: u16, b: i16) -> super::IMy::Ref {\n' +
109
+ ' unsafe { nanocom::CObject::from_object_unchecked(this) }.GetIMy(a, b)\n' +
110
110
  ' }\n' +
111
111
  ' extern "system" fn SetManagedStruct(this: &Object, a: super::ManagedStruct) {\n' +
112
112
  ' unsafe { nanocom::CObject::from_object_unchecked(this) }.SetManagedStruct(a)\n' +
@@ -1,4 +1,4 @@
1
- #include "../../cpp/com.hpp"
1
+ #include "../../cpp/nanocom.hpp"
2
2
  #include "_result.hpp"
3
3
 
4
4
  #ifdef _WIN32
@@ -16,10 +16,10 @@ extern "C" int c_get()
16
16
  class Impl : public My::IMy
17
17
  {
18
18
  public:
19
- My::Slice COM_STDCALL GetSlice() const noexcept override
19
+ My::Slice GetSlice() const noexcept override
20
20
  {
21
21
  }
22
- void COM_STDCALL SetSlice(My::Slice slice) const noexcept override
22
+ void SetSlice(My::Slice slice) const noexcept override
23
23
  {
24
24
  std::cout
25
25
  << "SetSlice: "
@@ -28,24 +28,20 @@ public:
28
28
  << slice.Size
29
29
  << std::endl;
30
30
  }
31
- bool const *COM_STDCALL GetUnsafe() const noexcept override
31
+ bool const *GetUnsafe() const noexcept override
32
32
  {
33
33
  }
34
- void COM_STDCALL SetUnsafe(My::Slice const *p, uint32_t size) const noexcept override
34
+ void SetUnsafe(My::Slice const *p, uint32_t size) const noexcept override
35
35
  {
36
36
  }
37
- bool COM_STDCALL Some(My::IMy const &p) const noexcept override
37
+ bool Some(My::IMy const &p) const noexcept override
38
38
  {
39
39
  }
40
- My::IMy const *COM_STDCALL GetIMy_() const noexcept override
40
+ My::IMy const *GetIMy_(uint16_t a, int16_t b) const noexcept override
41
41
  {
42
- return ::com::to_ref(*this).copy_to_raw();
42
+ return ::nanocom::to_ref(*this).copy_to_raw();
43
43
  }
44
- com::ref<My::IMy> GetIMy() const noexcept
45
- {
46
- return com::move_to_ref(GetIMy_());
47
- }
48
- void COM_STDCALL SetManagedStruct(My::ManagedStruct a) const noexcept override
44
+ void SetManagedStruct(My::ManagedStruct a) const noexcept override
49
45
  {
50
46
  }
51
47
  ~Impl()
@@ -58,12 +54,12 @@ DLL_EXPORT
58
54
  extern "C" My::IMy const *c_my_create()
59
55
  {
60
56
  {
61
- auto const x = ::com::implementation<Impl>::create().copy_to_raw();
57
+ auto const x = ::nanocom::implementation<Impl>::create().copy_to_raw();
62
58
  x->Release();
63
59
  }
64
60
  {
65
- auto const x = ::com::implementation<Impl>::create().upcast<My::IMy>();
61
+ auto const x = ::nanocom::implementation<Impl>::create().upcast<My::IMy>();
66
62
  x->SetSlice(My::Slice());
67
63
  }
68
- return ::com::implementation<Impl>::create().copy_to_raw();
64
+ return ::nanocom::implementation<Impl>::create().copy_to_raw();
69
65
  }
@@ -24,7 +24,7 @@ x.SetSlice(new Slice { Start = null, Size = (UIntPtr)44 });
24
24
  {
25
25
  var y = c_my_create();
26
26
  y.SetSlice(new Slice { Start = null, Size = (UIntPtr)45 });
27
- var t = y.GetIMy();
27
+ var t = y.GetIMy(1, 2);
28
28
  }
29
29
 
30
30
  GC.Collect();
@@ -36,7 +36,7 @@ impl _result::IMy::Ex for nanocom::CObject<My> {
36
36
  todo!()
37
37
  }
38
38
 
39
- fn GetIMy(&self) -> _result::IMy::Ref {
39
+ fn GetIMy(&self, a: u16, b: i16) -> _result::IMy::Ref {
40
40
  todo!()
41
41
  }
42
42
 
@@ -24,7 +24,7 @@ module.exports = {
24
24
  size: 'u32'
25
25
  },
26
26
  Some: { p: ['IMy'], _: 'bool' },
27
- GetIMy: { _: ['IMy'] },
27
+ GetIMy: { a: 'u16', b: 'i16', _: ['IMy'] },
28
28
  SetManagedStruct: { a: ['ManagedStruct'] },
29
29
  },
30
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.470",
3
+ "version": "0.0.472",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {