functionalscript 0.0.472 → 0.0.474
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/README.md +80 -0
- package/com/cpp/nanocom.hpp +5 -0
- package/com/test/cpp/main.cpp +9 -0
- package/fsm/module.f.cjs +14 -2
- package/fsm/test.f.cjs +59 -26
- package/package.json +2 -2
- package/types/range_map/module.f.cjs +26 -1
- package/types/range_map/test.f.cjs +50 -0
- package/.vscode/launch.json +0 -17
- package/.vscode/tasks.json +0 -41
|
@@ -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
|
+
```
|
package/com/cpp/nanocom.hpp
CHANGED
|
@@ -75,6 +75,11 @@ namespace nanocom
|
|
|
75
75
|
virtual HRESULT QueryInterface(GUID const &riid, IUnknown const **ppvObject) const noexcept = 0;
|
|
76
76
|
virtual ULONG AddRef() const noexcept = 0;
|
|
77
77
|
virtual ULONG Release() const noexcept = 0;
|
|
78
|
+
protected:
|
|
79
|
+
IUnknown() = default;
|
|
80
|
+
private:
|
|
81
|
+
IUnknown(IUnknown const&);
|
|
82
|
+
IUnknown& operator=(IUnknown const&);
|
|
78
83
|
};
|
|
79
84
|
|
|
80
85
|
template <class I>
|
package/com/test/cpp/main.cpp
CHANGED
|
@@ -53,6 +53,15 @@ public:
|
|
|
53
53
|
DLL_EXPORT
|
|
54
54
|
extern "C" My::IMy const *c_my_create()
|
|
55
55
|
{
|
|
56
|
+
{
|
|
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
|
+
}
|
|
56
65
|
{
|
|
57
66
|
auto const x = ::nanocom::implementation<Impl>::create().copy_to_raw();
|
|
58
67
|
x->Release();
|
package/fsm/module.f.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const list = require('../types/list/module.f.cjs')
|
|
2
|
-
const { equal, isEmpty, fold, toArray, scan } = list
|
|
2
|
+
const { equal, isEmpty, fold, toArray, scan, foldScan } = list
|
|
3
3
|
const byteSet = require('../types/byte_set/module.f.cjs')
|
|
4
4
|
const { toRangeMap } = byteSet
|
|
5
5
|
const sortedSet = require('../types/sorted_set/module.f.cjs')
|
|
@@ -57,10 +57,22 @@ const addEntry = grammar => set => dfa => {
|
|
|
57
57
|
return fold(addEntry(grammar))(newDfa)(newStates)
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
const initialState = ['']
|
|
61
|
+
|
|
62
|
+
const initialStateStringify = stringifyIdentity(initialState)
|
|
63
|
+
|
|
60
64
|
/** @type {(grammar: Grammar) => Dfa} */
|
|
61
|
-
const dfa = grammar => addEntry(grammar)(
|
|
65
|
+
const dfa = grammar => addEntry(grammar)(initialState)({})
|
|
66
|
+
|
|
67
|
+
/** @type {(dfa: Dfa) => operator.Fold<number, string>} */
|
|
68
|
+
const runOp = dfa => input => s => rangeMap.get(input)(dfa[s])
|
|
69
|
+
|
|
70
|
+
/** @type {(dfa: Dfa) => (input: list.List<number>) => list.List<string>} */
|
|
71
|
+
const run = dfa => input => foldScan(runOp(dfa))(initialStateStringify)(input)
|
|
62
72
|
|
|
63
73
|
module.exports = {
|
|
64
74
|
/** @readonly */
|
|
65
75
|
dfa,
|
|
76
|
+
/** @readonly */
|
|
77
|
+
run
|
|
66
78
|
}
|
package/fsm/test.f.cjs
CHANGED
|
@@ -3,39 +3,45 @@ const byteSet = require('../types/byte_set/module.f.cjs')
|
|
|
3
3
|
const { sort, fromEntries } = require('../types/object/module.f.cjs')
|
|
4
4
|
const json = require('../json/module.f.cjs')
|
|
5
5
|
const { identity } = require('../types/function/module.f.cjs')
|
|
6
|
+
const { toArray } = require('../types/list/module.f.cjs')
|
|
6
7
|
|
|
7
8
|
/** @type {(c: string) => number} */
|
|
8
9
|
const toCharCode = c => c.charCodeAt(0)
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
dfa: () => {
|
|
12
|
-
const lowercaseAlpha = byteSet.range([toCharCode('a'), toCharCode('z')])
|
|
13
|
-
const uppercaseAlpha = byteSet.range([toCharCode('A'), toCharCode('Z')])
|
|
14
|
-
const alpha = byteSet.union(lowercaseAlpha)(uppercaseAlpha)
|
|
15
|
-
const idSymbol = byteSet.union(byteSet.one(toCharCode('_')))(byteSet.one(toCharCode('$')))
|
|
16
|
-
const idBegin = byteSet.union(alpha)(idSymbol)
|
|
17
|
-
const digit = byteSet.range([toCharCode('0'), toCharCode('9')])
|
|
18
|
-
const idNext = byteSet.union(idBegin)(digit)
|
|
19
|
-
const dot = byteSet.one(toCharCode('.'))
|
|
11
|
+
const stringifyIdentity = json.stringify(identity)
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
13
|
+
const buildDfa = () => {
|
|
14
|
+
const lowercaseAlpha = byteSet.range([toCharCode('a'), toCharCode('z')])
|
|
15
|
+
const uppercaseAlpha = byteSet.range([toCharCode('A'), toCharCode('Z')])
|
|
16
|
+
const alpha = byteSet.union(lowercaseAlpha)(uppercaseAlpha)
|
|
17
|
+
const idSymbol = byteSet.union(byteSet.one(toCharCode('_')))(byteSet.one(toCharCode('$')))
|
|
18
|
+
const idBegin = byteSet.union(alpha)(idSymbol)
|
|
19
|
+
const digit = byteSet.range([toCharCode('0'), toCharCode('9')])
|
|
20
|
+
const idNext = byteSet.union(idBegin)(digit)
|
|
21
|
+
const dot = byteSet.one(toCharCode('.'))
|
|
22
|
+
|
|
23
|
+
/** @type {_.Grammar} */
|
|
24
|
+
const grammar = [
|
|
25
|
+
['', digit, 'int'],
|
|
26
|
+
['int', digit, 'int'],
|
|
27
|
+
['', digit, 'floatBegin'],
|
|
28
|
+
['floatBegin', digit, 'floatBegin'],
|
|
29
|
+
['floatBegin', dot, 'floatDot'],
|
|
30
|
+
['floatDot', digit, 'float'],
|
|
31
|
+
['float', digit, 'float'],
|
|
32
|
+
['', idBegin, 'id'],
|
|
33
|
+
['id', idNext, 'id']
|
|
34
|
+
]
|
|
35
|
+
return _.dfa(grammar)
|
|
36
|
+
}
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+
module.exports = {
|
|
39
|
+
dfa: () => {
|
|
40
|
+
const dfa = buildDfa()
|
|
35
41
|
const entries = Object.entries(dfa)
|
|
36
42
|
const sortedEntries = sort(entries)
|
|
37
43
|
const obj = fromEntries(sortedEntries)
|
|
38
|
-
const result =
|
|
44
|
+
const result = stringifyIdentity(obj)
|
|
39
45
|
|
|
40
46
|
const expectedObj = {
|
|
41
47
|
'[""]': [
|
|
@@ -72,8 +78,35 @@ module.exports = {
|
|
|
72
78
|
],
|
|
73
79
|
'[]': []
|
|
74
80
|
};
|
|
75
|
-
const expectedResult =
|
|
81
|
+
const expectedResult = stringifyIdentity(expectedObj)
|
|
76
82
|
|
|
77
83
|
if (result !== expectedResult) {throw result }
|
|
78
|
-
}
|
|
84
|
+
},
|
|
85
|
+
run: [
|
|
86
|
+
() => {
|
|
87
|
+
const dfa = buildDfa()
|
|
88
|
+
const input = [toCharCode('a'), toCharCode('1')]
|
|
89
|
+
const result = stringifyIdentity(toArray(_.run(dfa)(input)))
|
|
90
|
+
|
|
91
|
+
const expectedOutput = [
|
|
92
|
+
'["id"]',
|
|
93
|
+
'["id"]'
|
|
94
|
+
]
|
|
95
|
+
const expectedResult = stringifyIdentity(expectedOutput)
|
|
96
|
+
if (result !== expectedResult) { throw result }
|
|
97
|
+
},
|
|
98
|
+
() => {
|
|
99
|
+
const dfa = buildDfa()
|
|
100
|
+
const input = [toCharCode('0'), toCharCode('.'), toCharCode('1')]
|
|
101
|
+
const result = stringifyIdentity(toArray(_.run(dfa)(input)))
|
|
102
|
+
|
|
103
|
+
const expectedOutput = [
|
|
104
|
+
'["floatBegin","int"]',
|
|
105
|
+
'["floatDot"]',
|
|
106
|
+
'["float"]'
|
|
107
|
+
]
|
|
108
|
+
const expectedResult = stringifyIdentity(expectedOutput)
|
|
109
|
+
if (result !== expectedResult) { throw result }
|
|
110
|
+
},
|
|
111
|
+
]
|
|
79
112
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functionalscript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.474",
|
|
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.
|
|
34
|
+
"typescript": "^4.9.3"
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -60,7 +60,32 @@ const tailReduce = equal => state => tail => {
|
|
|
60
60
|
/** @type {<T>(op: Operators<T>) => RangeMerge<T>} */
|
|
61
61
|
const merge = ({union, equal}) => genericMerge({reduceOp: reduceOp(union)(equal), tailReduce: tailReduce(equal)})(undefined)
|
|
62
62
|
|
|
63
|
+
/** @type {<T>(value: number) => (rm: RangeMapArray<T>) => T|undefined} */
|
|
64
|
+
const get = value => rm => {
|
|
65
|
+
let b = 0
|
|
66
|
+
let e = rm.length - 1
|
|
67
|
+
while (true) {
|
|
68
|
+
if (b >= rm.length) return undefined
|
|
69
|
+
if (e - b < 0) return rm[b][0]
|
|
70
|
+
const mid = b + (e - b >> 1)
|
|
71
|
+
const sign = cmp(value)(rm[mid][1])
|
|
72
|
+
switch(sign) {
|
|
73
|
+
case -1: {
|
|
74
|
+
e = mid - 1
|
|
75
|
+
break
|
|
76
|
+
}
|
|
77
|
+
case 0: { return rm[mid][0] }
|
|
78
|
+
case 1: {
|
|
79
|
+
b = mid + 1
|
|
80
|
+
break
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
63
86
|
module.exports = {
|
|
64
87
|
/** @readonly */
|
|
65
|
-
merge
|
|
88
|
+
merge,
|
|
89
|
+
/** @readonly */
|
|
90
|
+
get
|
|
66
91
|
}
|
|
@@ -77,5 +77,55 @@ module.exports = {
|
|
|
77
77
|
const result = stringify(list.toArray(merged))
|
|
78
78
|
if (result !== '[[["a"],1],[["a","b"],2],[["a"],5]]') { throw result }
|
|
79
79
|
}
|
|
80
|
+
],
|
|
81
|
+
get: [
|
|
82
|
+
() => {
|
|
83
|
+
/** @type {_.RangeMapArray<sortedSet.SortedSet<string>>} */
|
|
84
|
+
const rm = [[['a'], 10], [['b'], 20], [['c'], 30]]
|
|
85
|
+
const result = stringify(_.get(5)(rm))
|
|
86
|
+
if (result !== '["a"]') { throw result }
|
|
87
|
+
},
|
|
88
|
+
() => {
|
|
89
|
+
/** @type {_.RangeMapArray<sortedSet.SortedSet<string>>} */
|
|
90
|
+
const rm = [[['a'], 10], [['b'], 20], [['c'], 30]]
|
|
91
|
+
const result = stringify(_.get(10)(rm))
|
|
92
|
+
if (result !== '["a"]') { throw result }
|
|
93
|
+
},
|
|
94
|
+
() => {
|
|
95
|
+
/** @type {_.RangeMapArray<sortedSet.SortedSet<string>>} */
|
|
96
|
+
const rm = [[['a'], 10], [['b'], 20], [['c'], 30]]
|
|
97
|
+
const result = stringify(_.get(15)(rm))
|
|
98
|
+
if (result !== '["b"]') { throw result }
|
|
99
|
+
},
|
|
100
|
+
() => {
|
|
101
|
+
/** @type {_.RangeMapArray<sortedSet.SortedSet<string>>} */
|
|
102
|
+
const rm = [[['a'], 10], [['b'], 20], [['c'], 30]]
|
|
103
|
+
const result = stringify(_.get(20)(rm))
|
|
104
|
+
if (result !== '["b"]') { throw result }
|
|
105
|
+
},
|
|
106
|
+
() => {
|
|
107
|
+
/** @type {_.RangeMapArray<sortedSet.SortedSet<string>>} */
|
|
108
|
+
const rm = [[['a'], 10], [['b'], 20], [['c'], 30]]
|
|
109
|
+
const result = stringify(_.get(25)(rm))
|
|
110
|
+
if (result !== '["c"]') { throw result }
|
|
111
|
+
},
|
|
112
|
+
() => {
|
|
113
|
+
/** @type {_.RangeMapArray<sortedSet.SortedSet<string>>} */
|
|
114
|
+
const rm = [[['a'], 10], [['b'], 20], [['c'], 30]]
|
|
115
|
+
const result = stringify(_.get(30)(rm))
|
|
116
|
+
if (result !== '["c"]') { throw result }
|
|
117
|
+
},
|
|
118
|
+
() => {
|
|
119
|
+
/** @type {_.RangeMapArray<sortedSet.SortedSet<string>>} */
|
|
120
|
+
const rm = [[['a'], 10], [['b'], 20], [['c'], 30]]
|
|
121
|
+
const result = _.get(35)(rm)
|
|
122
|
+
if (result !== undefined) { throw result }
|
|
123
|
+
},
|
|
124
|
+
() => {
|
|
125
|
+
/** @type {_.RangeMapArray<sortedSet.SortedSet<string>>} */
|
|
126
|
+
const rm = []
|
|
127
|
+
const result = _.get(10)(rm)
|
|
128
|
+
if (result !== undefined) { throw result }
|
|
129
|
+
}
|
|
80
130
|
]
|
|
81
131
|
}
|
package/.vscode/launch.json
DELETED
|
@@ -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
|
-
}
|
package/.vscode/tasks.json
DELETED
|
@@ -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
|
-
}
|