@ohos-ports/nbind 0.0.0-stage → 0.3.15-beta.1
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/.editorconfig +7 -0
- package/LICENSE +22 -0
- package/README.md +1393 -2
- package/autogypi.json +11 -0
- package/bin/ci-trigger +40 -0
- package/bin/copyasm.js +77 -0
- package/bin/emcc +21 -0
- package/bin/emcc-path.js +7 -0
- package/bin/ndts.js +22 -0
- package/config.js +7 -0
- package/dist/Type.d.ts +92 -0
- package/dist/Type.js +180 -0
- package/dist/common.d.ts +9 -0
- package/dist/common.js +10 -0
- package/dist/em-api.js +2353 -0
- package/dist/int64.d.ts +9 -0
- package/dist/int64.js +64 -0
- package/dist/nbind.d.ts +49 -0
- package/dist/nbind.js +154 -0
- package/dist/reflect.d.ts +69 -0
- package/dist/reflect.js +261 -0
- package/dist/shim.d.ts +1 -0
- package/dist/shim.js +2 -0
- package/dist/todts.d.ts +5 -0
- package/dist/todts.js +146 -0
- package/include/nbind/ArgStorage.h +67 -0
- package/include/nbind/BindClass.h +290 -0
- package/include/nbind/BindDefiner.h +295 -0
- package/include/nbind/Buffer.h +50 -0
- package/include/nbind/FunctionDefiner.h +51 -0
- package/include/nbind/MethodDef.h +50 -0
- package/include/nbind/Policy.h +255 -0
- package/include/nbind/TypeID.h +84 -0
- package/include/nbind/TypeStd.h +66 -0
- package/include/nbind/TypeTransformer.h +38 -0
- package/include/nbind/api.h +100 -0
- package/include/nbind/common.h +22 -0
- package/include/nbind/em/ArgFromWire.h +31 -0
- package/include/nbind/em/BindingStd.h +221 -0
- package/include/nbind/em/BindingType.h +204 -0
- package/include/nbind/em/Buffer.h +37 -0
- package/include/nbind/em/Callback.h +186 -0
- package/include/nbind/em/Caller.h +61 -0
- package/include/nbind/em/Creator.h +30 -0
- package/include/nbind/em/External.h +63 -0
- package/include/nbind/em/Int64.h +131 -0
- package/include/nbind/em/NBind.h +63 -0
- package/include/nbind/em/Pool.h +34 -0
- package/include/nbind/em/StdFunction.h +40 -0
- package/include/nbind/em/ValueObj.h +54 -0
- package/include/nbind/nbind.h +19 -0
- package/include/nbind/noconflict.h +91 -0
- package/include/nbind/signature/BaseSignature.h +238 -0
- package/include/nbind/signature/CallbackSignature.h +59 -0
- package/include/nbind/signature/ConstructorSignature.h +76 -0
- package/include/nbind/signature/FunctionSignature.h +63 -0
- package/include/nbind/signature/GetterSignature.h +62 -0
- package/include/nbind/signature/MethodSignature.h +61 -0
- package/include/nbind/signature/SetterSignature.h +63 -0
- package/include/nbind/signature/SignatureParam.h +39 -0
- package/include/nbind/v8/ArgFromWire.h +69 -0
- package/include/nbind/v8/BindWrapper.h +295 -0
- package/include/nbind/v8/BindingStd.h +180 -0
- package/include/nbind/v8/BindingType.h +241 -0
- package/include/nbind/v8/Buffer.h +59 -0
- package/include/nbind/v8/Callback.h +165 -0
- package/include/nbind/v8/Caller.h +140 -0
- package/include/nbind/v8/Convert.h +80 -0
- package/include/nbind/v8/Creator.h +26 -0
- package/include/nbind/v8/External.h +119 -0
- package/include/nbind/v8/Int64.h +195 -0
- package/include/nbind/v8/NBind.h +63 -0
- package/include/nbind/v8/Output.h +36 -0
- package/include/nbind/v8/Overloader.h +215 -0
- package/include/nbind/v8/StdFunction.h +44 -0
- package/include/nbind/v8/ValueObj.h +137 -0
- package/include/nbind/wire.h +79 -0
- package/package.json +69 -4
- package/src/checkver.js +31 -0
- package/src/common.cc +129 -0
- package/src/em/Binding.cc +313 -0
- package/src/em/tsconfig.json +22 -0
- package/src/nbind-common.gypi +14 -0
- package/src/nbind.gypi +98 -0
- package/src/post.js +2 -0
- package/src/pre.js +48 -0
- package/src/reflect.cc +170 -0
- package/src/symbols.txt +1 -0
- package/src/tsconfig.json +23 -0
- package/src/tslint.json +86 -0
- package/src/v8/Binding.cc +391 -0
- package/src/v8/Buffer.cc +73 -0
package/src/common.cc
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd.
|
|
2
|
+
// Released under the MIT license, see LICENSE.
|
|
3
|
+
|
|
4
|
+
#include "nbind/nbind.h"
|
|
5
|
+
|
|
6
|
+
using namespace nbind;
|
|
7
|
+
|
|
8
|
+
// const char *nbind :: emptyGetter = ""; unused for now.
|
|
9
|
+
const char *nbind :: emptySetter = "";
|
|
10
|
+
|
|
11
|
+
// Linkage for module-wide error message.
|
|
12
|
+
char *Status :: message;
|
|
13
|
+
|
|
14
|
+
void NBind :: bind_value(const char *name, cbFunction &func) {
|
|
15
|
+
for(auto *bindClass : getClassList()) {
|
|
16
|
+
if(!bindClass) continue;
|
|
17
|
+
|
|
18
|
+
if(strcmp(bindClass->getName(), name) == 0) {
|
|
19
|
+
bindClass->setValueConstructorJS(func);
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Type description helpers.
|
|
26
|
+
|
|
27
|
+
template <typename ArgType>
|
|
28
|
+
struct isSignless {
|
|
29
|
+
static constexpr bool value = false;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
template <>
|
|
33
|
+
struct isSignless<char> {
|
|
34
|
+
static constexpr bool value = true;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// This function takes a list of primitive types as the template argument.
|
|
38
|
+
// It defines 3 arrays with information about them: type IDs, sizes and properties of the types.
|
|
39
|
+
// For example uint32_t, float64_t and const char * can be distinguished by their size and the property flags
|
|
40
|
+
// char, const, pointer, float and unsigned.
|
|
41
|
+
// Char is not treated as a simple int8_t because as a const pointer it can also identify a string literal.
|
|
42
|
+
|
|
43
|
+
template <typename... Args>
|
|
44
|
+
static const void **definePrimitiveTypes() {
|
|
45
|
+
static TYPEID typeList[] = { Typer<Args>::makeID()..., nullptr };
|
|
46
|
+
static const uint8_t sizeList[] = { sizeof(Args)... };
|
|
47
|
+
static const uint8_t flagList[] = { static_cast<uint8_t>(
|
|
48
|
+
// Type is unsigned?
|
|
49
|
+
(static_cast<Args>(-1) >= 0 ? TypeFlags::isUnsigned : TypeFlags::none) |
|
|
50
|
+
// Type is signless (char)?
|
|
51
|
+
(isSignless<Args>::value ? TypeFlags::isSignless : TypeFlags::none) |
|
|
52
|
+
// Type is floating point?
|
|
53
|
+
(static_cast<Args>(0.5) != 0 ? TypeFlags::isFloat : TypeFlags::none)
|
|
54
|
+
)... };
|
|
55
|
+
|
|
56
|
+
static const void *data[] = {
|
|
57
|
+
typeList,
|
|
58
|
+
sizeList,
|
|
59
|
+
flagList
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return(data);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Linkage for lists of all C++ class and function wrappers.
|
|
66
|
+
|
|
67
|
+
std::forward_list<BindClassBase *> &nbind :: getClassList() {
|
|
68
|
+
// This stops working if moved outside the function.
|
|
69
|
+
static std::forward_list<BindClassBase *> classList;
|
|
70
|
+
|
|
71
|
+
return(classList);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
std::forward_list<MethodDef> &nbind :: getFunctionList() {
|
|
75
|
+
// This stops working if moved outside the function.
|
|
76
|
+
static std::forward_list<MethodDef> functionList;
|
|
77
|
+
|
|
78
|
+
return(functionList);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const void **nbind :: getPrimitiveList() {
|
|
82
|
+
static const void **primitiveList = definePrimitiveTypes<
|
|
83
|
+
unsigned char, signed char, char,
|
|
84
|
+
unsigned short, signed short,
|
|
85
|
+
unsigned int, signed int,
|
|
86
|
+
unsigned long, signed long,
|
|
87
|
+
unsigned long long, signed long long,
|
|
88
|
+
|
|
89
|
+
float, double
|
|
90
|
+
>();
|
|
91
|
+
|
|
92
|
+
return(primitiveList);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#define NBIND_TYPE(type) Typer<type>::makeID(), #type
|
|
96
|
+
|
|
97
|
+
const void **nbind :: getNamedTypeList() {
|
|
98
|
+
static const void *typeList[] = {
|
|
99
|
+
NBIND_TYPE(void),
|
|
100
|
+
NBIND_TYPE(bool),
|
|
101
|
+
NBIND_TYPE(std::string),
|
|
102
|
+
// NBIND_TYPE(cbFunction),
|
|
103
|
+
NBIND_TYPE(cbFunction &),
|
|
104
|
+
NBIND_TYPE(const cbFunction &),
|
|
105
|
+
NBIND_TYPE(External),
|
|
106
|
+
NBIND_TYPE(Buffer),
|
|
107
|
+
nullptr
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return(typeList);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
void nbind :: registerClass(BindClassBase &spec) {
|
|
114
|
+
getClassList().emplace_front(&spec);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
void nbind :: registerFunction(
|
|
118
|
+
const char *name,
|
|
119
|
+
funcPtr ptr,
|
|
120
|
+
unsigned int num,
|
|
121
|
+
BaseSignature *signature,
|
|
122
|
+
TypeFlags flags
|
|
123
|
+
) {
|
|
124
|
+
getFunctionList().emplace_front(name, ptr, num, signature, flags);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#include "nbind/nbind.h"
|
|
128
|
+
|
|
129
|
+
NBIND_CLASS(Int64) {}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
// This file is part of nbind, copyright (C) 2014-2016 BusFaster Ltd.
|
|
2
|
+
// Released under the MIT license, see LICENSE.
|
|
3
|
+
|
|
4
|
+
#ifdef EMSCRIPTEN
|
|
5
|
+
|
|
6
|
+
#include <cstdlib>
|
|
7
|
+
#include <cstring>
|
|
8
|
+
|
|
9
|
+
#include "nbind/BindDefiner.h"
|
|
10
|
+
|
|
11
|
+
using namespace nbind;
|
|
12
|
+
|
|
13
|
+
extern "C" {
|
|
14
|
+
extern void _nbind_register_pool(unsigned int pageSize, unsigned int *usedPtr, unsigned char *rootPtr, unsigned char **pagePtr);
|
|
15
|
+
extern void _nbind_register_primitive(TYPEID typeID, unsigned int size, unsigned char flag);
|
|
16
|
+
extern void _nbind_register_type(TYPEID typeID, const char *name);
|
|
17
|
+
extern void _nbind_register_class(const TYPEID *typeList,
|
|
18
|
+
const char **policies, const TYPEID *superList, void *(**upcastList)(void *),
|
|
19
|
+
unsigned int superCount,
|
|
20
|
+
funcPtr destructor,
|
|
21
|
+
const char *name
|
|
22
|
+
);
|
|
23
|
+
extern void _nbind_register_function(TYPEID boundID,
|
|
24
|
+
const char **policies, const TYPEID *types, unsigned int typeCount,
|
|
25
|
+
funcPtr func, funcPtr direct, unsigned int signatureType,
|
|
26
|
+
const char *name, unsigned int num, unsigned int flags
|
|
27
|
+
);
|
|
28
|
+
extern void _nbind_finish();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
unsigned int Pool::used = 0;
|
|
32
|
+
unsigned char *Pool::rootPage = new unsigned char[Pool::pageSize];
|
|
33
|
+
unsigned char *Pool::page = nullptr;
|
|
34
|
+
|
|
35
|
+
/** Simple linear allocator. Return consecutive blocks on a constant-sized
|
|
36
|
+
* root page. Blocks that don't fit are allocated in a linked list on the heap.
|
|
37
|
+
* The memory is used like a stack to pass function parameters and return
|
|
38
|
+
* values.
|
|
39
|
+
*
|
|
40
|
+
* Alloca could be used instead for parameters of calls to JavaScript,
|
|
41
|
+
* but not for return values of calls from JavaScript because they may get
|
|
42
|
+
* corrupted when the invoker function's stack frame is freed.
|
|
43
|
+
* It's easier to use a single allocator for both cases.
|
|
44
|
+
*
|
|
45
|
+
* Returned bytes must be aligned to 8 bytes to support storing doubles.
|
|
46
|
+
* Asm.js can't handle unaligned access. */
|
|
47
|
+
|
|
48
|
+
uintptr_t NBind :: lalloc(size_t size) {
|
|
49
|
+
// Round size up to a multiple of 8 bytes (size of a double)
|
|
50
|
+
// to align pointers allocated later.
|
|
51
|
+
size = (size + 7) & ~7;
|
|
52
|
+
|
|
53
|
+
// Check if block won't fit on the root page or is bigger than half its size.
|
|
54
|
+
// The latter condition avoids filling the root page with large blocks,
|
|
55
|
+
// unnecessarily slowing down allocation of any later small blocks.
|
|
56
|
+
|
|
57
|
+
if(size > Pool::pageSize / 2 || size > Pool::pageSize - Pool::used) {
|
|
58
|
+
// Allocate a block on the heap.
|
|
59
|
+
|
|
60
|
+
// TODO: make sure the memory allocated here is properly aligned!
|
|
61
|
+
// Allocate a new block in the heap and reserve 8 bytes
|
|
62
|
+
// (to maintain alignment) for a header pointing to the previous block.
|
|
63
|
+
|
|
64
|
+
unsigned char *page = new unsigned char[size + 8];
|
|
65
|
+
if(!page) return(0); // Out of memory, should throw?
|
|
66
|
+
|
|
67
|
+
// Store address of previous block at the start of the new block.
|
|
68
|
+
*(unsigned char **)page = Pool::page;
|
|
69
|
+
|
|
70
|
+
// Make the new block the current one.
|
|
71
|
+
Pool::page = page;
|
|
72
|
+
|
|
73
|
+
return(reinterpret_cast<uintptr_t>(page) + 8);
|
|
74
|
+
} else {
|
|
75
|
+
uintptr_t result = reinterpret_cast<uintptr_t>(Pool::rootPage) + Pool::used;
|
|
76
|
+
|
|
77
|
+
// Allocate a block on the root page by simply growing the used byte count.
|
|
78
|
+
Pool::used += size;
|
|
79
|
+
|
|
80
|
+
return(result);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Reset linear allocator to a previous state, effectively to free
|
|
85
|
+
* a stack frame. Set root page used byte count to match the earlier state
|
|
86
|
+
* and free all blocks allocated since then. */
|
|
87
|
+
|
|
88
|
+
void NBind :: lreset(unsigned int used, uintptr_t page) {
|
|
89
|
+
// Free all blocks allocated since the earlier state.
|
|
90
|
+
|
|
91
|
+
while(Pool::page != reinterpret_cast<unsigned char *>(page)) {
|
|
92
|
+
unsigned char *topPage = Pool::page;
|
|
93
|
+
Pool::page = *(unsigned char **)topPage;
|
|
94
|
+
delete topPage;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
Pool::used = used;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
NBindID :: NBindID(TYPEID id) : id(id) {}
|
|
101
|
+
NBindID :: NBindID(uintptr_t ptr) : id(reinterpret_cast<TYPEID>(ptr)) {}
|
|
102
|
+
|
|
103
|
+
const void *NBindID :: getStructure() const {
|
|
104
|
+
return(structure);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
StructureType NBindID :: getStructureType() const {
|
|
108
|
+
return(*structureType);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
void NBindID :: toJS(cbOutput output) const {
|
|
112
|
+
output(reinterpret_cast<uintptr_t>(id));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** RAII constructor to store the lalloc pool state. */
|
|
116
|
+
|
|
117
|
+
PoolRestore :: PoolRestore() : used(Pool::used), page(Pool::page) {}
|
|
118
|
+
|
|
119
|
+
/** RAII destructor to restore the lalloc pool state. */
|
|
120
|
+
|
|
121
|
+
PoolRestore :: ~PoolRestore() {
|
|
122
|
+
NBind::lreset(used, reinterpret_cast<unsigned int>(page));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
typedef BaseSignature :: SignatureType SignatureType;
|
|
126
|
+
|
|
127
|
+
static void initModule() {
|
|
128
|
+
_nbind_register_pool(Pool::pageSize, &Pool::used, Pool::rootPage, &Pool::page);
|
|
129
|
+
|
|
130
|
+
const void **primitiveData = getPrimitiveList();
|
|
131
|
+
const uint8_t *sizePtr = static_cast<const uint8_t *>(primitiveData[1]);
|
|
132
|
+
const uint8_t *flagPtr = static_cast<const uint8_t *>(primitiveData[2]);
|
|
133
|
+
|
|
134
|
+
for(const TYPEID *type = static_cast<const TYPEID *>(primitiveData[0]); *type; ++type) {
|
|
135
|
+
_nbind_register_primitive(*type, *(sizePtr++), *(flagPtr++));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
for(const void **type = getNamedTypeList(); *type; type += 2) {
|
|
139
|
+
_nbind_register_type(
|
|
140
|
+
static_cast<TYPEID>(type[0]),
|
|
141
|
+
static_cast<const char *>(type[1])
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
_nbind_register_type(Typer<cbOutput::CreateValue>::makeID(), "_nbind_new");
|
|
146
|
+
|
|
147
|
+
// Register all classes before any functions or methods,
|
|
148
|
+
// so they'll have class type IDs available.
|
|
149
|
+
|
|
150
|
+
auto &classList = getClassList();
|
|
151
|
+
|
|
152
|
+
for(auto *bindClass : classList) bindClass->unvisit();
|
|
153
|
+
|
|
154
|
+
auto posPrev = classList.before_begin();
|
|
155
|
+
auto pos = classList.begin();
|
|
156
|
+
|
|
157
|
+
while(pos != classList.end()) {
|
|
158
|
+
auto *bindClass = *pos++;
|
|
159
|
+
|
|
160
|
+
// Avoid registering the same class twice.
|
|
161
|
+
if(bindClass->isVisited()) {
|
|
162
|
+
classList.erase_after(posPrev);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
bindClass->visit();
|
|
167
|
+
++posPrev;
|
|
168
|
+
|
|
169
|
+
const unsigned int superCount = bindClass->getSuperClassCount();
|
|
170
|
+
TYPEID superIdList[superCount];
|
|
171
|
+
TYPEID *superPtr = superIdList;
|
|
172
|
+
void *(*upcastList[superCount])(void *);
|
|
173
|
+
auto *upcastPtr = upcastList;
|
|
174
|
+
|
|
175
|
+
for(auto &spec : bindClass->getSuperClassList()) {
|
|
176
|
+
*superPtr++ = spec.superClass.getTypes()[0];
|
|
177
|
+
*upcastPtr++ = spec.upcast;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
_nbind_register_class(
|
|
181
|
+
bindClass->getTypes(),
|
|
182
|
+
bindClass->getPolicies(),
|
|
183
|
+
superIdList,
|
|
184
|
+
upcastList,
|
|
185
|
+
bindClass->getSuperClassCount(),
|
|
186
|
+
bindClass->getDeleter(),
|
|
187
|
+
bindClass->getName()
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Register all functions.
|
|
192
|
+
|
|
193
|
+
for(auto &func : getFunctionList()) {
|
|
194
|
+
const BaseSignature *signature = func.getSignature();
|
|
195
|
+
|
|
196
|
+
_nbind_register_function(
|
|
197
|
+
0,
|
|
198
|
+
signature->getPolicies(),
|
|
199
|
+
signature->getTypeList(),
|
|
200
|
+
signature->getArity() + 1,
|
|
201
|
+
signature->getCaller(),
|
|
202
|
+
func.getPtr(),
|
|
203
|
+
static_cast<unsigned int>(signature->getType()),
|
|
204
|
+
func.getName(),
|
|
205
|
+
func.getNum(),
|
|
206
|
+
static_cast<unsigned int>(func.getFlags())
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Register all methods.
|
|
211
|
+
|
|
212
|
+
for(auto *bindClass : getClassList()) {
|
|
213
|
+
if(!bindClass) continue;
|
|
214
|
+
|
|
215
|
+
TYPEID id = bindClass->getTypes()[0];
|
|
216
|
+
|
|
217
|
+
for(auto &func : bindClass->getMethodList()) {
|
|
218
|
+
|
|
219
|
+
const BaseSignature *signature = func.getSignature();
|
|
220
|
+
|
|
221
|
+
if(signature == nullptr) {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
switch(signature->getType()) {
|
|
226
|
+
case SignatureType :: none:
|
|
227
|
+
|
|
228
|
+
// Impossible!
|
|
229
|
+
abort();
|
|
230
|
+
|
|
231
|
+
case SignatureType :: method:
|
|
232
|
+
case SignatureType :: getter:
|
|
233
|
+
case SignatureType :: setter:
|
|
234
|
+
|
|
235
|
+
_nbind_register_function(
|
|
236
|
+
id,
|
|
237
|
+
signature->getPolicies(),
|
|
238
|
+
signature->getTypeList(),
|
|
239
|
+
signature->getArity() + 1,
|
|
240
|
+
signature->getCaller(),
|
|
241
|
+
nullptr,
|
|
242
|
+
static_cast<unsigned int>(signature->getType()),
|
|
243
|
+
func.getName(),
|
|
244
|
+
func.getNum(),
|
|
245
|
+
static_cast<unsigned int>(func.getFlags())
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
break;
|
|
249
|
+
|
|
250
|
+
case SignatureType :: func:
|
|
251
|
+
|
|
252
|
+
_nbind_register_function(
|
|
253
|
+
id,
|
|
254
|
+
signature->getPolicies(),
|
|
255
|
+
signature->getTypeList(),
|
|
256
|
+
signature->getArity() + 1,
|
|
257
|
+
signature->getCaller(),
|
|
258
|
+
func.getPtr(),
|
|
259
|
+
static_cast<unsigned int>(signature->getType()),
|
|
260
|
+
func.getName(),
|
|
261
|
+
func.getNum(),
|
|
262
|
+
static_cast<unsigned int>(func.getFlags())
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
break;
|
|
266
|
+
|
|
267
|
+
case SignatureType :: construct:
|
|
268
|
+
|
|
269
|
+
_nbind_register_function(
|
|
270
|
+
id,
|
|
271
|
+
signature->getPolicies(),
|
|
272
|
+
signature->getTypeList(),
|
|
273
|
+
signature->getArity() + 1,
|
|
274
|
+
signature->getCaller(),
|
|
275
|
+
signature->getValueConstructor(),
|
|
276
|
+
static_cast<unsigned int>(signature->getType()),
|
|
277
|
+
nullptr, 0, 0
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Set up inheritance.
|
|
286
|
+
|
|
287
|
+
_nbind_finish();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
extern "C" {
|
|
291
|
+
void nbind_init(void) {
|
|
292
|
+
initModule();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
#include "nbind/nbind.h"
|
|
297
|
+
|
|
298
|
+
NBIND_CLASS(NBind) {
|
|
299
|
+
construct<>();
|
|
300
|
+
|
|
301
|
+
method(bind_value);
|
|
302
|
+
method(reflect);
|
|
303
|
+
method(queryType);
|
|
304
|
+
|
|
305
|
+
method(lalloc);
|
|
306
|
+
method(lreset);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
NBIND_CLASS(NBindID) {
|
|
310
|
+
construct<uintptr_t>();
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
#endif
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compileOnSave": true,
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"declaration": false,
|
|
5
|
+
"experimentalDecorators": true,
|
|
6
|
+
"lib": ["es5", "es2015.collection"],
|
|
7
|
+
"module": "commonjs",
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"noImplicitAny": true,
|
|
10
|
+
"noImplicitThis": true,
|
|
11
|
+
"noImplicitUseStrict": true,
|
|
12
|
+
"outDir": "../../dist/bundle",
|
|
13
|
+
"removeComments": false,
|
|
14
|
+
"sourceMap": false,
|
|
15
|
+
"strictNullChecks": true,
|
|
16
|
+
"target": "es5"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"emscripten.d.ts",
|
|
20
|
+
"em-api.ts"
|
|
21
|
+
]
|
|
22
|
+
}
|
package/src/nbind.gypi
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
|
|
3
|
+
"variables": {
|
|
4
|
+
"asmjs%": 0
|
|
5
|
+
},
|
|
6
|
+
|
|
7
|
+
"target_name": "nbind",
|
|
8
|
+
"type": "loadable_module",
|
|
9
|
+
"sources": [
|
|
10
|
+
"common.cc",
|
|
11
|
+
"reflect.cc"
|
|
12
|
+
],
|
|
13
|
+
"include_dirs": [
|
|
14
|
+
"../include"
|
|
15
|
+
],
|
|
16
|
+
|
|
17
|
+
"conditions": [
|
|
18
|
+
['asmjs==1', {
|
|
19
|
+
|
|
20
|
+
"product_name": "nbind.js",
|
|
21
|
+
"type": "executable",
|
|
22
|
+
"sources": [ "em/Binding.cc" ],
|
|
23
|
+
"ldflags": [ "<@(_cflags)" ],
|
|
24
|
+
|
|
25
|
+
"copies": [{"destination": "<(INTERMEDIATE_DIR)", "files": ["pre.js", "post.js", "../dist/em-api.js"]}],
|
|
26
|
+
"prejs_path": "<(INTERMEDIATE_DIR)/pre.js",
|
|
27
|
+
"postjs_path": "<(INTERMEDIATE_DIR)/post.js",
|
|
28
|
+
"jslib_path": "<(INTERMEDIATE_DIR)/em-api.js",
|
|
29
|
+
|
|
30
|
+
"cflags": [
|
|
31
|
+
"-O3",
|
|
32
|
+
"--pre-js", "<(_prejs_path)",
|
|
33
|
+
"--post-js", "<(_postjs_path)",
|
|
34
|
+
"--js-library", "<(_jslib_path)",
|
|
35
|
+
"-s", "NO_FILESYSTEM=1",
|
|
36
|
+
"-s", "EXPORTED_FUNCTIONS=[\"_nbind_init\",\"_nbind_value\"]",
|
|
37
|
+
"-s", "DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[\"nbind_value\",\"\\$$Browser\"]"
|
|
38
|
+
],
|
|
39
|
+
|
|
40
|
+
"cflags_cc": [
|
|
41
|
+
"-std=c++11",
|
|
42
|
+
"-fno-exceptions"
|
|
43
|
+
],
|
|
44
|
+
|
|
45
|
+
"xcode_settings": {
|
|
46
|
+
"GCC_GENERATE_DEBUGGING_SYMBOLS": "NO",
|
|
47
|
+
"OTHER_CFLAGS": [ "<@(_cflags)" ],
|
|
48
|
+
"OTHER_CPLUSPLUSFLAGS": [ "<@(_cflags_cc)" ],
|
|
49
|
+
"OTHER_LDFLAGS": [ "<@(_cflags)" ]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
}, {
|
|
53
|
+
|
|
54
|
+
"copies": [{"destination": "<(INTERMEDIATE_DIR)", "files": ["symbols.txt"]}],
|
|
55
|
+
"symbols_path": "<(INTERMEDIATE_DIR)/symbols.txt",
|
|
56
|
+
|
|
57
|
+
"sources": [
|
|
58
|
+
"v8/Buffer.cc",
|
|
59
|
+
"v8/Binding.cc"
|
|
60
|
+
],
|
|
61
|
+
|
|
62
|
+
"cflags": [
|
|
63
|
+
"-O3",
|
|
64
|
+
"-fPIC"
|
|
65
|
+
],
|
|
66
|
+
|
|
67
|
+
"cflags_cc": [
|
|
68
|
+
"-std=c++20",
|
|
69
|
+
"-fexceptions",
|
|
70
|
+
"-fPIC"
|
|
71
|
+
],
|
|
72
|
+
|
|
73
|
+
"msbuild_settings": {
|
|
74
|
+
"ClCompile": {
|
|
75
|
+
"RuntimeTypeInfo": "false",
|
|
76
|
+
"ExceptionHandling": "Sync", # /EHsc
|
|
77
|
+
"MultiProcessorCompilation": "true"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
"xcode_settings": {
|
|
82
|
+
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
|
83
|
+
"CLANG_CXX_LANGUAGE_STANDARD": "c++20",
|
|
84
|
+
"MACOSX_DEPLOYMENT_TARGET": "10.7",
|
|
85
|
+
"OTHER_CFLAGS": [ "<@(_cflags)" ],
|
|
86
|
+
"OTHER_CPLUSPLUSFLAGS": [
|
|
87
|
+
"<@(_cflags_cc)",
|
|
88
|
+
"-stdlib=libc++"
|
|
89
|
+
],
|
|
90
|
+
"OTHER_LDFLAGS": [
|
|
91
|
+
"-stdlib=libc++",
|
|
92
|
+
"-exported_symbols_list", "<(_symbols_path)"
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
}]
|
|
97
|
+
]
|
|
98
|
+
}
|
package/src/post.js
ADDED
package/src/pre.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// This file is a public domain UMD wrapper for nbind asm.js output.
|
|
2
|
+
// Returns a wrapper function with parameters:
|
|
3
|
+
// - (Optional) initial asm.js module object, use {} or pass additional options.
|
|
4
|
+
// - Node.js style callback, fires on error or when nbind is ready for use.
|
|
5
|
+
|
|
6
|
+
// Export wrapper function for different module loaders.
|
|
7
|
+
(function(root, wrapper) {
|
|
8
|
+
// AMD.
|
|
9
|
+
if(typeof(define) == 'function' && define.amd) define([], function() { return(wrapper); });
|
|
10
|
+
// Node.js style CommonJS.
|
|
11
|
+
else if(typeof(module) == 'object' && module.exports) module.exports = wrapper;
|
|
12
|
+
// Browser global.
|
|
13
|
+
else (root.nbind = root.nbind || {}).init = wrapper;
|
|
14
|
+
|
|
15
|
+
// Define wrapper function, the main export from this module.
|
|
16
|
+
}(this, function(Module, cb) {
|
|
17
|
+
if(typeof(Module) == 'function') {
|
|
18
|
+
cb = Module;
|
|
19
|
+
Module = {};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Set up nbind in asm.js runtime ready hook.
|
|
23
|
+
Module.onRuntimeInitialized = (function(init, cb) {
|
|
24
|
+
return(function() {
|
|
25
|
+
// Call any previous runtime ready hook.
|
|
26
|
+
if(init) init.apply(this, arguments);
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
// Init the C++ side.
|
|
30
|
+
Module.ccall('nbind_init');
|
|
31
|
+
} catch(err) {
|
|
32
|
+
// Report failure.
|
|
33
|
+
cb(err);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Report success through callback passed to wrapper function.
|
|
38
|
+
cb(null, {
|
|
39
|
+
bind: Module._nbind_value,
|
|
40
|
+
reflect: Module.NBind.reflect,
|
|
41
|
+
queryType: Module.NBind.queryType,
|
|
42
|
+
toggleLightGC: Module.toggleLightGC,
|
|
43
|
+
lib: Module
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
})(Module.onRuntimeInitialized, cb);
|
|
47
|
+
|
|
48
|
+
// Emscripten-generated asm.js code begins.
|