functionalscript 0.0.359 → 0.0.362

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.
@@ -12,4 +12,4 @@ jobs:
12
12
  steps:
13
13
  - uses: actions/checkout@v2
14
14
  - run: curl https://bun.sh/install | bash
15
- - run: /home/runner/.bun/bin/bun run ./test.f.js
15
+ - run: /home/runner/.bun/bin/bun ./test.f.js
@@ -0,0 +1,47 @@
1
+ #ifndef COM_HPP
2
+ #define COM_HPP
3
+
4
+ #include <cstdint>
5
+
6
+ namespace com
7
+ {
8
+ class GUID
9
+ {
10
+ public:
11
+ uint64_t hi;
12
+ uint64_t lo;
13
+ };
14
+
15
+ typedef uint32_t HRESULT;
16
+ typedef uint32_t ULONG;
17
+
18
+ class IUnknown
19
+ {
20
+ public:
21
+ virtual HRESULT __stdcall QueryInterface(GUID const &riid, IUnknown **const ppvObject) noexcept = 0;
22
+ virtual ULONG __stdcall AddRef() noexcept = 0;
23
+ virtual ULONG __stdcall Release() noexcept = 0;
24
+ };
25
+
26
+ template <class I>
27
+ class Ref
28
+ {
29
+ public:
30
+ explicit Ref(I &other) noexcept : p(other.p)
31
+ {
32
+ p.AddRef();
33
+ }
34
+ Ref(Ref const &other) noexcept : Ref(other.p)
35
+ {
36
+ }
37
+ ~Ref() noexcept
38
+ {
39
+ p.Release();
40
+ }
41
+
42
+ private:
43
+ I &p;
44
+ };
45
+ }
46
+
47
+ #endif
@@ -0,0 +1 @@
1
+ module.exports = {}
package/com/cs/main.f.js CHANGED
@@ -47,8 +47,8 @@ const unsafe = isUnsafe => isUnsafe ? 'unsafe ' : ''
47
47
  /** @type {(t: types.Type) => readonly[boolean, string]} */
48
48
  const csType = t =>
49
49
  typeof (t) === 'string' ? [false, csBaseType(t)] :
50
- t instanceof Array ? [false, t[0]] :
51
- [true, `${csType(t['*'])[1]}*`]
50
+ t.length === 1 ? [false, t[0]] :
51
+ [true, `${csType(t[1])[1]}*`]
52
52
 
53
53
  /** @type {(f: types.Field) => string} */
54
54
  const csParam = ([name, type]) => `${csType(type)[1]} ${name}`
@@ -59,19 +59,23 @@ const csField = ([name, type]) => {
59
59
  return `public ${unsafe(isUnsafe)}${t} ${name};`
60
60
  }
61
61
 
62
- /** @type {(m: types.Method) => readonly[boolean, string]} */
63
- const csResult = m => m.length === 2 ? [false, 'void'] : csType(m[2])
62
+ /** @type {(m: types.FieldArray) => readonly[boolean, string]} */
63
+ const csResult = m => m._ === undefined ? [false, 'void'] : csType(m._)
64
64
 
65
65
  /** @type {(field: types.Field) => boolean} */
66
66
  const isUnsafeField = field => csType(field[1])[0]
67
67
 
68
- /** @type {(m: types.Method) => readonly string[]} */
69
- const csMethod = m => {
68
+ /** @type {(kv: obj.Entry<types.Type>) => boolean} */
69
+ const isParam = kv => kv[0] !== '_'
70
+
71
+ /** @type {(e: obj.Entry<types.FieldArray>) => readonly string[]} */
72
+ const csMethod = ([name, m]) => {
70
73
  const result = csResult(m)
71
- const isUnsafe = result[0] || list.some(list.map(isUnsafeField)(m[1]))
74
+ const paramArray = list.filter(isParam)(Object.entries(m))
75
+ const isUnsafe = result[0] || list.some(list.map(isUnsafeField)(paramArray))
72
76
  return [
73
77
  '[PreserveSig]',
74
- `${unsafe(isUnsafe)}${result[1]} ${m[0]}(${list.join(', ')(list.map(csParam)(m[1]))});`
78
+ `${unsafe(isUnsafe)}${result[1]} ${name}(${list.join(', ')(list.map(csParam)(paramArray))});`
75
79
  ]
76
80
  }
77
81
 
@@ -83,12 +87,12 @@ const csDef = ([n, d]) => {
83
87
  (['StructLayout(LayoutKind.Sequential)'])
84
88
  ('struct')
85
89
  (n)
86
- (() => list.map(csField)(d.struct)) :
90
+ (() => list.map(csField)(Object.entries(d.struct))) :
87
91
  csTypeDef
88
92
  ([`Guid("${d.guid}")`, 'InterfaceType(ComInterfaceType.InterfaceIsIUnknown)'])
89
93
  ('interface')
90
94
  (n)
91
- (() => list.flatMap(csMethod)(d.interface))
95
+ (() => list.flatMap(csMethod)(Object.entries(d.interface)))
92
96
  }
93
97
 
94
98
  /** @type {(name: string) => (library: types.Library) => text.Block} */
@@ -7,5 +7,5 @@ try {
7
7
  console.log(cp.execSync('dotnet build').toString())
8
8
  } catch (e) {
9
9
  // @ts-ignore
10
- console.log(e.output.toString())
10
+ console.error(e.output.toString())
11
11
  }
package/com/cs/test.f.js CHANGED
@@ -6,19 +6,28 @@ const text = require('../../text/main.f.js')
6
6
  /** @type {types.Library} */
7
7
  const library = {
8
8
  Slice: {
9
- struct: [
10
- ['Start', { '*': 'u8' }],
11
- ['Size', 'usize'],
12
- ]
9
+ struct: {
10
+ Start: ['*', 'u8'],
11
+ Size: 'usize',
12
+ },
13
13
  },
14
14
  IMy: {
15
15
  guid: 'C66FB270-2D80-49AD-BB6E-88C1F90B805D',
16
- interface: [
17
- ['GetSlice', [], ['Slice']],
18
- ['SetSlice', [['slice', ['Slice']]]],
19
- ['GetUnsafe', [], {'*': 'bool'}],
20
- ['SetUnsafe', [['p', {'*': ['Slice']}], ['size', 'u32']]],
21
- ],
16
+ interface: {
17
+ GetSlice: {
18
+ _: ['Slice']
19
+ },
20
+ SetSlice: {
21
+ slice: ['Slice']
22
+ },
23
+ GetUnsafe: {
24
+ _: ['*', 'bool']
25
+ },
26
+ SetUnsafe: {
27
+ p: ['*', ['Slice']],
28
+ size: 'u32'
29
+ },
30
+ },
22
31
  }
23
32
  }
24
33
 
@@ -9,7 +9,7 @@
9
9
  * }} Struct
10
10
  */
11
11
 
12
- /** @typedef {readonly Field[]} FieldArray */
12
+ /** @typedef {{readonly[k in string]: Type}} FieldArray */
13
13
 
14
14
  /** @typedef {readonly[string, Type]} Field */
15
15
 
@@ -20,13 +20,7 @@
20
20
  * }} Interface
21
21
  */
22
22
 
23
- /** @typedef {readonly Method[]} MethodArray */
24
-
25
- /** @typedef {readonly[string, FieldArray, Type]} GetMethod */
26
-
27
- /** @typedef {readonly[string, FieldArray]} SetMethod */
28
-
29
- /** @typedef {GetMethod|SetMethod} Method */
23
+ /** @typedef {{readonly[k in string]: FieldArray}} MethodArray */
30
24
 
31
25
  /** @typedef {BaseType|Id|Pointer} Type */
32
26
 
@@ -50,6 +44,6 @@
50
44
  * } BaseType
51
45
  */
52
46
 
53
- /** @typedef {{readonly '*': Type}} Pointer */
47
+ /** @typedef {readonly['*', Type]} Pointer */
54
48
 
55
49
  module.exports = {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.0.359",
3
+ "version": "0.0.362",
4
4
  "description": "FunctionalScript is a functional subset of JavaScript",
5
5
  "main": "main.f.js",
6
6
  "scripts": {