functionalscript 0.0.471 → 0.0.473

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.
@@ -0,0 +1,80 @@
1
+ # COM C++ library
2
+
3
+ ## Example
4
+
5
+ ### `nanocom` library
6
+
7
+ ```cpp
8
+ class IUnknown
9
+ {
10
+ public:
11
+ virtual HRESULT QueryInterface(GUID const &riid, IUnknown const **ppvObject) const noexcept = 0;
12
+ virtual ULONG AddRef() const noexcept = 0;
13
+ virtual ULONG Release() const noexcept = 0;
14
+ protected:
15
+ IUnknown() {}
16
+ private:
17
+ IUnknown(IUnknown const&);
18
+ IUnknown& operator=(IUnknown const &);
19
+ };
20
+
21
+ template<class I>
22
+ class base: public I
23
+ {
24
+ public:
25
+ HRESULT QueryInterface(GUID const &riid, IUnknown const **ppvObject) const noexcept override { ... }
26
+ ULONG AddRef() const noexcept override { ... }
27
+ ULONG Release() const noexcept override { ... }
28
+ };
29
+
30
+ template<class I, class T>
31
+ class impl;
32
+ ```
33
+
34
+ ### Generated
35
+
36
+ ```cpp
37
+ class IAbc : public IUnknown
38
+ {
39
+ public:
40
+ constexpr static GUID const guid = GUID(...);
41
+ virtual IAbc* GetIAbc_() const noexcept = 0;
42
+ ref<IAbc> GetIAbc() const noexcept
43
+ {
44
+ return move_to_ref(GetIAbc_());
45
+ }
46
+ protected:
47
+ IAbc() {}
48
+ };
49
+
50
+ template<class T>
51
+ class impl<IAbc, T> : public base<IAbc>
52
+ {
53
+ public:
54
+ T value;
55
+ IAbc* GetIAbc_() const noexcept override
56
+ {
57
+ return IAbc_GetIAbc(*this).copy_to_ref();
58
+ }
59
+ template <class... U>
60
+ static ref<T> create(U... u)
61
+ {
62
+ T const *const p = new implementation(u...);
63
+ return to_ref(*p);
64
+ }
65
+ private:
66
+ template <class... U>
67
+ explicit implementation(U... u) : value(u...) {}
68
+ };
69
+ ```
70
+
71
+ ### Manually Written Code
72
+
73
+ ```cpp
74
+ struct Abc {};
75
+
76
+ ref<IAbc> IAbc_GetIAbc(impl<IAbc, Abc> const & self)
77
+ {
78
+ return to_ref(self);
79
+ }
80
+ ```
@@ -34,7 +34,7 @@ const resultVoid = types.result('void')
34
34
  const namespace = text.curly('namespace')
35
35
 
36
36
  /** @type {(id: string) => string} */
37
- const comRef = id => `::com::ref<${id}>`
37
+ const comRef = id => `::nanocom::ref<${id}>`
38
38
 
39
39
  /** @type {(id: string) => string} */
40
40
  const ptr = id => `${id} const*`
@@ -92,7 +92,7 @@ const cpp = name => lib => {
92
92
 
93
93
  /** @type {(result: string) => (paramArrayStr: string) => (name: string) => text.Item} */
94
94
  const methodHeader = result => paramArrayStr => name =>
95
- `virtual ${result} COM_STDCALL ${name}${paramArrayStr} const noexcept = 0;`
95
+ `virtual ${result} ${name}${paramArrayStr} const noexcept = 0;`
96
96
 
97
97
  /** @type {(m: types.Method) => readonly text.Item[]} */
98
98
  const method = ([name, paramArray]) => {
@@ -108,7 +108,7 @@ const cpp = name => lib => {
108
108
  m(`${name}_`),
109
109
  `${comRef(resultName)} ${name}${paramArrayStr} const noexcept`,
110
110
  '{',
111
- [`return ::com::move_to_ref(${name}_(${joinComma(mapParamName(paramL))}));`],
111
+ [`return ::nanocom::move_to_ref(${name}_(${joinComma(mapParamName(paramL))}));`],
112
112
  '}',
113
113
  ]
114
114
  }
@@ -121,7 +121,7 @@ const cpp = name => lib => {
121
121
  const lo = g.substring(0, 16);
122
122
  const hi = g.substring(16);
123
123
  return flat([
124
- [`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});`],
125
125
  mapMethod(entries(i))
126
126
  ])
127
127
  }
@@ -129,7 +129,13 @@ const cpp = name => lib => {
129
129
  /** @type {(kv: obj.Entry<types.Definition>) => text.Block} */
130
130
  const def = ([name, d]) => d.interface === undefined
131
131
  ? struct(name)(defStruct(d))
132
- : [`class ${name} : public ::com::IUnknown`, '{', 'public:', defInterface(d), '};']
132
+ : [
133
+ `class ${name} : public ::nanocom::IUnknown`,
134
+ '{',
135
+ 'public:',
136
+ defInterface(d),
137
+ '};'
138
+ ]
133
139
 
134
140
  /** @type {(kv: obj.Entry<types.Definition>) => text.Block} */
135
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,14 @@ 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;
78
+ protected:
79
+ IUnknown() = default;
80
+ private:
81
+ IUnknown(IUnknown const&);
82
+ IUnknown& operator=(IUnknown const&);
86
83
  };
87
84
 
88
85
  template <class I>
@@ -155,7 +152,7 @@ namespace com
155
152
  }
156
153
 
157
154
  private:
158
- HRESULT COM_STDCALL QueryInterface(GUID const &riid, IUnknown const **const ppvObject) const noexcept override
155
+ HRESULT QueryInterface(GUID const &riid, IUnknown const **const ppvObject) const noexcept override
159
156
  {
160
157
  // std::cout << "riid: " << riid << std::endl;
161
158
  // std::cout << "iunknown: " << iunknown_guid << std::endl;
@@ -175,12 +172,12 @@ namespace com
175
172
  return counter.fetch_add(1);
176
173
  }
177
174
 
178
- ULONG COM_STDCALL AddRef() const noexcept override
175
+ ULONG AddRef() const noexcept override
179
176
  {
180
177
  return add_ref() + 1;
181
178
  }
182
179
 
183
- ULONG COM_STDCALL Release() const noexcept override
180
+ ULONG Release() const noexcept override
184
181
  {
185
182
  auto const c = counter.fetch_sub(1) - 1;
186
183
  if (c == 0)
@@ -17,23 +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_(uint16_t a, int16_t b) const noexcept = 0;\n' +
32
- ' ::com::ref<IMy> GetIMy(uint16_t a, int16_t b) const noexcept\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
33
  ' {\n' +
34
- ' return ::com::move_to_ref(GetIMy_(a, b));\n' +
34
+ ' return ::nanocom::move_to_ref(GetIMy_(a, b));\n' +
35
35
  ' }\n' +
36
- ' virtual void COM_STDCALL SetManagedStruct(ManagedStruct a) const noexcept = 0;\n' +
36
+ ' virtual void SetManagedStruct(ManagedStruct a) const noexcept = 0;\n' +
37
37
  ' };\n' +
38
38
  '}'
39
39
  if (cpp !== e) { throw cpp }
@@ -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,20 +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_(uint16_t a, int16_t b) 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
- void COM_STDCALL SetManagedStruct(My::ManagedStruct a) const noexcept override
44
+ void SetManagedStruct(My::ManagedStruct a) const noexcept override
45
45
  {
46
46
  }
47
47
  ~Impl()
@@ -54,12 +54,21 @@ DLL_EXPORT
54
54
  extern "C" My::IMy const *c_my_create()
55
55
  {
56
56
  {
57
- auto const x = ::com::implementation<Impl>::create().copy_to_raw();
57
+ auto const a = ::nanocom::implementation<Impl>::create().copy_to_raw();
58
+ // auto const c = *x; // no copy constructor
59
+ Impl *b;
60
+ b = const_cast<Impl*>(::nanocom::implementation<Impl>::create().copy_to_raw());
61
+ // *b = *a; // no assignment operator
62
+ b->Release();
63
+ a->Release();
64
+ }
65
+ {
66
+ auto const x = ::nanocom::implementation<Impl>::create().copy_to_raw();
58
67
  x->Release();
59
68
  }
60
69
  {
61
- auto const x = ::com::implementation<Impl>::create().upcast<My::IMy>();
70
+ auto const x = ::nanocom::implementation<Impl>::create().upcast<My::IMy>();
62
71
  x->SetSlice(My::Slice());
63
72
  }
64
- return ::com::implementation<Impl>::create().copy_to_raw();
73
+ return ::nanocom::implementation<Impl>::create().copy_to_raw();
65
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.471",
3
+ "version": "0.0.473",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
@@ -31,6 +31,6 @@
31
31
  "homepage": "https://github.com/functionalscript/functionalscript#readme",
32
32
  "devDependencies": {
33
33
  "@types/node": "^18.11.9",
34
- "typescript": "^4.8.4"
34
+ "typescript": "^4.9.3"
35
35
  }
36
36
  }
@@ -1,17 +0,0 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "type": "pwa-node",
9
- "request": "launch",
10
- "name": "Launch Program",
11
- "skipFiles": [
12
- "<node_internals>/**"
13
- ],
14
- "program": "${workspaceFolder}\\test.js"
15
- }
16
- ]
17
- }
@@ -1,41 +0,0 @@
1
- {
2
- "version": "2.0.0",
3
- "tasks": [
4
- {
5
- "label": "build",
6
- "command": "dotnet",
7
- "type": "process",
8
- "args": [
9
- "build",
10
- "${workspaceFolder}/com/cs/test/test.csproj",
11
- "/property:GenerateFullPaths=true",
12
- "/consoleloggerparameters:NoSummary"
13
- ],
14
- "problemMatcher": "$msCompile"
15
- },
16
- {
17
- "label": "publish",
18
- "command": "dotnet",
19
- "type": "process",
20
- "args": [
21
- "publish",
22
- "${workspaceFolder}/com/cs/test/test.csproj",
23
- "/property:GenerateFullPaths=true",
24
- "/consoleloggerparameters:NoSummary"
25
- ],
26
- "problemMatcher": "$msCompile"
27
- },
28
- {
29
- "label": "watch",
30
- "command": "dotnet",
31
- "type": "process",
32
- "args": [
33
- "watch",
34
- "run",
35
- "--project",
36
- "${workspaceFolder}/com/cs/test/test.csproj"
37
- ],
38
- "problemMatcher": "$msCompile"
39
- }
40
- ]
41
- }