forked from SMotaal/xs-wasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxsnap.h
146 lines (120 loc) · 4.26 KB
/
xsnap.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifndef __XSNAP__
#define __XSNAP__
#ifdef __wasm__
#include "xsnap-wasm.h"
#endif /* __wasm__ */
#include "xs.h"
typedef struct xsSnapshotRecord xsSnapshot;
struct xsSnapshotRecord {
char* signature;
int signatureLength;
xsCallback* callbacks;
int callbacksLength;
int (*read)(void* stream, void* address, size_t size);
int (*write)(void* stream, void* address, size_t size);
void* stream;
int error;
void* firstChunk;
void* firstProjection;
void* firstSlot;
int slotSize;
void* slots;
};
#define xsInitializeSharedCluster() \
fxInitializeSharedCluster()
#define xsTerminateSharedCluster() \
fxTerminateSharedCluster()
#ifdef mxMetering
#define xsBeginMetering(_THE, _CALLBACK, _STEP) \
do { \
xsJump __HOST_JUMP__; \
__HOST_JUMP__.nextJump = (_THE)->firstJump; \
__HOST_JUMP__.stack = (_THE)->stack; \
__HOST_JUMP__.scope = (_THE)->scope; \
__HOST_JUMP__.frame = (_THE)->frame; \
__HOST_JUMP__.environment = NULL; \
__HOST_JUMP__.code = (_THE)->code; \
__HOST_JUMP__.flag = 0; \
(_THE)->firstJump = &__HOST_JUMP__; \
if (setjmp(__HOST_JUMP__.buffer) == 0) { \
fxBeginMetering(_THE, _CALLBACK, _STEP)
#define xsEndMetering(_THE) \
fxEndMetering(_THE); \
} \
(_THE)->stack = __HOST_JUMP__.stack, \
(_THE)->scope = __HOST_JUMP__.scope, \
(_THE)->frame = __HOST_JUMP__.frame, \
(_THE)->code = __HOST_JUMP__.code, \
(_THE)->firstJump = __HOST_JUMP__.nextJump; \
break; \
} while(1)
#define xsGetCurrentMeter(_THE) \
fxGetCurrentMeter(_THE)
#define xsSetCurrentMeter(_THE, _VALUE) \
fxSetCurrentMeter(_THE, _VALUE)
#else
#define xsBeginMetering(_THE, _CALLBACK, _STEP)
#define xsEndMetering(_THE)
#define xsPatchHostFunction(_FUNCTION,_PATCH)
#define xsMeterHostFunction(_COUNT) (void)(_COUNT)
#define xsGetCurrentMeter(_THE) 0
#define xsSetCurrentMeter(_THE, _VALUE)
#endif
#define xsReadSnapshot(_SNAPSHOT, _NAME, _CONTEXT) \
fxReadSnapshot(_SNAPSHOT, _NAME, _CONTEXT)
#define xsWriteSnapshot(_THE, _SNAPSHOT) \
fxWriteSnapshot(_THE, _SNAPSHOT)
#define xsRunDebugger(_THE) \
fxRunDebugger(_THE)
#define xsRunModuleFile(_PATH) \
fxRunModuleFile(the, _PATH)
#define xsRunProgramFile(_PATH) \
fxRunProgramFile(the, _PATH)
#define xsRunLoop(_THE) \
fxRunLoop(_THE)
#define xsClearTimer() \
fxClearTimer(the)
#define xsSetTimer(_INTERVAL, _REPEAT) \
fxSetTimer(the, _INTERVAL, _REPEAT)
#define xsVersion(_BUFFER, _SIZE) \
fxVersion(_BUFFER, _SIZE)
#ifdef mxInstrument
#define xsDescribeInstrumentation(_THE,_COUNT,_NAMES,_UNITS) \
fxDescribeInstrumentation(_THE,_COUNT,_NAMES,_UNITS)
#define xsSampleInstrumentation(_THE,_COUNT,_VALUES) \
fxSampleInstrumentation(_THE,_COUNT,_VALUES)
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern void fxInitializeSharedCluster();
extern void fxTerminateSharedCluster();
#ifdef mxMetering
mxImport void fxBeginMetering(xsMachine* the, xsBooleanValue (*callback)(xsMachine*, xsUnsignedValue), xsUnsignedValue interval);
mxImport void fxEndMetering(xsMachine* the);
mxImport void fxMeterHostFunction(xsMachine* the, xsUnsignedValue count);
mxImport void fxPatchHostFunction(xsMachine* the, xsCallback patch);
mxImport xsUnsignedValue fxGetCurrentMeter(xsMachine* the);
mxImport void fxSetCurrentMeter(xsMachine* the, xsUnsignedValue value);
#endif
mxImport xsMachine* fxReadSnapshot(xsSnapshot* snapshot, xsStringValue theName, void* theContext);
mxImport int fxWriteSnapshot(xsMachine* the, xsSnapshot* snapshot);
mxImport void fxRunDebugger(xsMachine* the);
mxImport void fxRunModuleFile(xsMachine* the, xsStringValue path);
mxImport void fxRunProgramFile(xsMachine* the, xsStringValue path);
mxImport void fxRunLoop(xsMachine* the);
mxImport void fxClearTimer(xsMachine* the);
mxImport void fxSetTimer(xsMachine* the, xsNumberValue interval, xsBooleanValue repeat);
#ifdef mxInstrument
mxImport void fxDescribeInstrumentation(xsMachine* the, xsIntegerValue count, xsStringValue* names, xsStringValue* units);
mxImport void fxSampleInstrumentation(xsMachine* the, xsIntegerValue count, xsIntegerValue* values);
#endif
mxImport void fxVersion(xsStringValue theBuffer, xsUnsignedValue theSize);
mxImport void fx_lockdown(xsMachine* the);
mxImport void fx_harden(xsMachine* the);
mxImport void fx_petrify(xsMachine* the);
mxImport void fx_mutabilities(xsMachine* the);
#ifdef __cplusplus
}
#endif
#endif /* __XSNAP__ */