functionalscript 0.0.465 → 0.0.467

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/cpp/com.hpp CHANGED
@@ -15,7 +15,7 @@
15
15
 
16
16
  namespace com
17
17
  {
18
- constexpr uint64_t byteswap(uint64_t v)
18
+ constexpr uint64_t byteswap(uint64_t v) noexcept
19
19
  {
20
20
  v = v >> 8 & 0x00FF00FF00FF00FF |
21
21
  v << 8 & 0xFF00FF00FF00FF00;
@@ -97,19 +97,49 @@ namespace com
97
97
  p.Release();
98
98
  }
99
99
 
100
+ template<class U>
101
+ ref<U> upcast() const noexcept
102
+ {
103
+ return ref<U>(p);
104
+ }
105
+
106
+ I* operator->() const noexcept
107
+ {
108
+ return &p;
109
+ }
110
+
111
+ I* unsafe_result() const noexcept
112
+ {
113
+ p.AddRef();
114
+ return &p;
115
+ }
100
116
  private:
101
117
  I &p;
102
118
  };
103
119
 
120
+ template<class I>
121
+ ref<I> to_ref(I& p) noexcept
122
+ {
123
+ return ref<I>(p);
124
+ }
125
+
104
126
  constexpr static GUID const iunknown_guid =
105
127
  GUID(0x00000000'0000'0000, 0xC000'000000000046);
106
128
 
107
- template <class I>
108
- constexpr GUID interface_guid();
109
-
110
129
  template <class T>
111
130
  class implementation : public T
112
131
  {
132
+ public:
133
+ template<class ...U>
134
+ static T* create_raw(U... u)
135
+ {
136
+ return new implementation(u...);
137
+ }
138
+ template<class ...U>
139
+ static ref<T> create(U... u)
140
+ {
141
+ return to_ref(*create_raw(u...));
142
+ }
113
143
  private:
114
144
  HRESULT COM_STDCALL QueryInterface(GUID const &riid, IUnknown **const ppvObject) noexcept override
115
145
  {
@@ -142,6 +172,9 @@ namespace com
142
172
  return c;
143
173
  }
144
174
 
175
+ template<class ...U>
176
+ explicit implementation(U... u): T(u...) {}
177
+
145
178
  std::atomic<ULONG> counter;
146
179
  };
147
180
  }
@@ -47,6 +47,8 @@ const cpp = name => lib => {
47
47
 
48
48
  const type = objectType(id => `::com::ref<${id}>`)
49
49
 
50
+ const resultType = objectType(id => `${id}*`)
51
+
50
52
  /** @type {(s: types.Field) => text.Item} */
51
53
  const field = ([name, t]) => `${type(t)} ${name};`
52
54
 
@@ -56,7 +58,7 @@ const cpp = name => lib => {
56
58
  const defStruct = s => mapField(entries(s.struct))
57
59
 
58
60
  /** @type {(fa: types.FieldArray) => string} */
59
- const cppResult = resultVoid(type)
61
+ const cppResult = resultVoid(resultType)
60
62
 
61
63
  /** @type {(p: types.Field) => string} */
62
64
  const param = ([name, t]) => `${objectType(id => `${id}&`)(t)} ${name}`
@@ -27,7 +27,7 @@ const f = () =>
27
27
  ' virtual ::com::BOOL* COM_STDCALL GetUnsafe() noexcept = 0;\n' +
28
28
  ' virtual void COM_STDCALL SetUnsafe(Slice* p, uint32_t size) noexcept = 0;\n' +
29
29
  ' virtual ::com::BOOL COM_STDCALL Some(IMy& p) noexcept = 0;\n' +
30
- ' virtual ::com::ref<IMy> COM_STDCALL GetIMy() noexcept = 0;\n' +
30
+ ' virtual IMy* COM_STDCALL GetIMy() noexcept = 0;\n' +
31
31
  ' virtual void COM_STDCALL SetManagedStruct(ManagedStruct a) noexcept = 0;\n' +
32
32
  ' };\n' +
33
33
  '}'
@@ -71,8 +71,8 @@ const cpp = ({dirname, platform}) => ({
71
71
  flat([
72
72
  ['clang', '-shared', '-o', output(platform)('testc')],
73
73
  flags(platform),
74
- [`${dirname}/cpp/main.cpp`]]
75
- ),
74
+ [`${dirname}/cpp/main.cpp`],
75
+ ]),
76
76
  ],
77
77
  })
78
78
 
@@ -85,7 +85,7 @@ const cs = ({dirname, platform}) => ({
85
85
  line: [
86
86
  platform === 'win32'
87
87
  ? ['dotnet', 'run', '--project', `${dirname}/cs/cs.csproj`]
88
- // .Net on Linux and Windows doesn't properly support COM object marshalling
88
+ // .Net on Linux and MacOS doesn't properly support COM object marshalling
89
89
  : ['dotnet', 'build', `${dirname}/cs/cs.csproj`]
90
90
  ],
91
91
  })
@@ -15,11 +15,18 @@ extern "C" int c_get()
15
15
 
16
16
  class Impl: public My::IMy
17
17
  {
18
+ public:
18
19
  My::Slice COM_STDCALL GetSlice() noexcept override
19
20
  {
20
21
  }
21
22
  void COM_STDCALL SetSlice(My::Slice slice) noexcept override
22
23
  {
24
+ std::cout
25
+ << "SetSlice: "
26
+ << (slice.Start - static_cast<uint8_t*>(nullptr))
27
+ << ", "
28
+ << slice.Size
29
+ << std::endl;
23
30
  }
24
31
  ::com::BOOL *COM_STDCALL GetUnsafe() noexcept override
25
32
  {
@@ -30,16 +37,29 @@ class Impl: public My::IMy
30
37
  ::com::BOOL COM_STDCALL Some(My::IMy &p) noexcept override
31
38
  {
32
39
  }
33
- ::com::ref<My::IMy> COM_STDCALL GetIMy() noexcept override
40
+ My::IMy* COM_STDCALL GetIMy() noexcept override
34
41
  {
42
+ return ::com::to_ref(*this).unsafe_result();
35
43
  }
36
44
  void COM_STDCALL SetManagedStruct(My::ManagedStruct a) noexcept override
37
45
  {
38
46
  }
47
+ ~Impl()
48
+ {
49
+ ::std::cout << "done" << std::endl;
50
+ }
39
51
  };
40
52
 
41
53
  DLL_EXPORT
42
54
  extern "C" My::IMy* c_my_create()
43
55
  {
44
- return new ::com::implementation<Impl>();
56
+ {
57
+ auto const x = ::com::implementation<Impl>::create().unsafe_result();
58
+ x->Release();
59
+ }
60
+ {
61
+ auto const x = ::com::implementation<Impl>::create().upcast<My::IMy>();
62
+ x->SetSlice(My::Slice());
63
+ }
64
+ return ::com::implementation<Impl>::create().unsafe_result();
45
65
  }
@@ -21,4 +21,11 @@ Console.WriteLine(c_get());
21
21
  var x = rust_my_create();
22
22
  x.SetSlice(new Slice { Start = null, Size = (UIntPtr)44 });
23
23
 
24
- var y = c_my_create();
24
+ {
25
+ var y = c_my_create();
26
+ y.SetSlice(new Slice { Start = null, Size = (UIntPtr)45 });
27
+ var t = y.GetIMy();
28
+ }
29
+
30
+ GC.Collect();
31
+ Console.WriteLine("ok");
package/fsm/README.md CHANGED
@@ -107,7 +107,7 @@ const b = { ...a, z: 7 }
107
107
  ## How to Add a Property # 2
108
108
 
109
109
  ```js
110
- const map = reauire('./types/map/module.f.js')
110
+ const map = require('./types/map/module.f.js')
111
111
  const a = map.fromEntries(Object.entries({ x: 5, y: 6 }))
112
112
  const b = map.setReplace('z')(7)(a)
113
113
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.465",
3
+ "version": "0.0.467",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "module.f.cjs",
6
6
  "scripts": {
package/sha2/module.f.cjs CHANGED
@@ -22,15 +22,15 @@ const padding = input => bitsCount => {
22
22
  const appendBlockIndex = (bitsCount / 32) | 0
23
23
  const length = (bitsCount + mod(447 - bitsCount)(512) + 65) / 32
24
24
  /** @type {(i: number) => number} */
25
- const f = i =>
26
- i < appendBlockIndex ?
27
- input[i] :
28
- i === appendBlockIndex ?
29
- (appendBlockIndex >= input.length ? 0x8000_0000 : appendOneWithZeros(input[appendBlockIndex])(31 - bitsCount % 32)) :
30
- i === length - 2 ?
31
- (bitsCount / 0x1_0000_0000) | 0 :
32
- i === length - 1 ?
33
- bitsCount % 0x1_0000_0000 : 0
25
+ const f = i => {
26
+ if (i < appendBlockIndex) { return input[i] }
27
+ if (i === appendBlockIndex) {
28
+ return appendBlockIndex >= input.length ? 0x8000_0000 : appendOneWithZeros(input[appendBlockIndex])(31 - bitsCount % 32)
29
+ }
30
+ if (i === length - 2) { return (bitsCount / 0x1_0000_0000) | 0 }
31
+ if (i === length - 1) { return bitsCount % 0x1_0000_0000 }
32
+ return 0
33
+ }
34
34
  return ({ f, length })
35
35
  }
36
36
 
@@ -97,6 +97,25 @@ const nextW = ([w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, wA, wB, wC, wD, wE, wF])
97
97
  return [w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, wA, wB, wC, wD, wE, wF]
98
98
  }
99
99
 
100
+ const k = [
101
+ [
102
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
103
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
104
+ ],
105
+ [
106
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
107
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
108
+ ],
109
+ [
110
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
111
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
112
+ ],
113
+ [
114
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
115
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
116
+ ],
117
+ ];
118
+
100
119
  /** @type {(init: Hash8) => (data: Array16) => Hash8} */
101
120
  const compress = ([a0, b0, c0, d0, e0, f0, g0, h0]) => data => {
102
121
  let w = data
@@ -165,21 +184,6 @@ const computeSha256 = compute(init256)
165
184
  /** @type {Hash8} */
166
185
  const init224 = [0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4]
167
186
 
168
- const k = [
169
- [
170
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
171
- 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174],
172
- [
173
- 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
174
- 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967],
175
- [
176
- 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
177
- 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070],
178
- [
179
- 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
180
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2],
181
- ];
182
-
183
187
  /** @type {(input: readonly number[]) => (bitsCount: number) => Hash8} */
184
188
  const computeSha224 = compute(init224)
185
189