-
Notifications
You must be signed in to change notification settings - Fork 67
/
pThreadedFFIUtils.h
44 lines (37 loc) · 1.36 KB
/
pThreadedFFIUtils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef __UTILS__
#define __UTILS__
#include "pharovm/pharo.h"
void setHandler(sqInt anExternalObject, void* value);
void writeAddress(sqInt anExternalAddress, void* value);
char *readString(sqInt aString);
void *getAddressFromExternalAddressOrByteArray(sqInt anExternalAddressOrByteArray);
// meta
sqInt getAttributeOf(sqInt receiver, int index);
void *getHandlerOf(sqInt receiver, int index);
// arrays
sqInt arrayObjectAt(sqInt array, sqInt index);
sqInt arrayObjectAtPut(sqInt array, sqInt index, sqInt object);
sqInt arrayObjectSize(sqInt array);
// clean ending for a primitive
// Inline functions need to be defined in the file that uses them. Thus define them at the header level
static inline sqInt getReceiver() {
return stackValue(methodArgumentCount());
}
// these must be made static else they cause trouble with no-opt -O0 builds
// because the compiler doesn't inline them with -O0
static inline void primitiveEnd() {
//pop all execept receiver, which will be answered (^self)
pop(methodArgumentCount());
}
static inline void primitiveEndReturn(sqInt ret) {
//pop all including receiver, we are answering our own result
pop(methodArgumentCount() + 1);
push(ret);
}
static inline void primitiveEndReturnInteger(sqInt ret) {
pop(methodArgumentCount() + 1);
pushInteger(ret);
}
// others
sqInt newExternalAddress(void *address);
#endif