@@ -90,6 +90,12 @@ typedef enum mvm_TeType {
90
90
VM_T_END ,
91
91
} mvm_TeType ;
92
92
93
+ // Prefix to attach to exported microvium API functions. If a user doesn't
94
+ // specify this, we just set it up as the empty macro.
95
+ #ifndef MVM_EXPORT
96
+ #define MVM_EXPORT
97
+ #endif
98
+
93
99
typedef struct mvm_VM mvm_VM ;
94
100
95
101
typedef mvm_TeError (* mvm_TfHostFunction )(mvm_VM * vm , mvm_HostFunctionID hostFunctionID , mvm_Value * result , mvm_Value * args , uint8_t argCount );
@@ -169,12 +175,12 @@ extern "C" {
169
175
* @param context Any value. The context for a VM can be retrieved later using
170
176
* `mvm_getContext`. It can be used to attach user-defined data to a VM.
171
177
*/
172
- mvm_TeError mvm_restore (mvm_VM * * result , MVM_LONG_PTR_TYPE snapshotBytecode , size_t bytecodeSize , void * context , mvm_TfResolveImport resolveImport );
178
+ MVM_EXPORT mvm_TeError mvm_restore (mvm_VM * * result , MVM_LONG_PTR_TYPE snapshotBytecode , size_t bytecodeSize , void * context , mvm_TfResolveImport resolveImport );
173
179
174
180
/**
175
181
* Free all memory associated with a VM. The VM must not be used again after freeing.
176
182
*/
177
- void mvm_free (mvm_VM * vm );
183
+ MVM_EXPORT void mvm_free (mvm_VM * vm );
178
184
179
185
/**
180
186
* Call a function in the VM
@@ -189,21 +195,21 @@ void mvm_free(mvm_VM* vm);
189
195
* MVM_E_UNCAUGHT_EXCEPTION and the exception value will be put into
190
196
* `out_result`
191
197
*/
192
- mvm_TeError mvm_call (mvm_VM * vm , mvm_Value func , mvm_Value * out_result , mvm_Value * args , uint8_t argCount );
198
+ MVM_EXPORT mvm_TeError mvm_call (mvm_VM * vm , mvm_Value func , mvm_Value * out_result , mvm_Value * args , uint8_t argCount );
193
199
194
- void * mvm_getContext (mvm_VM * vm );
200
+ MVM_EXPORT void * mvm_getContext (mvm_VM * vm );
195
201
196
- void mvm_initializeHandle (mvm_VM * vm , mvm_Handle * handle ); // Handle must be released by mvm_releaseHandle
197
- void mvm_cloneHandle (mvm_VM * vm , mvm_Handle * target , const mvm_Handle * source ); // Target must be released by mvm_releaseHandle
198
- mvm_TeError mvm_releaseHandle (mvm_VM * vm , mvm_Handle * handle );
199
- static inline mvm_Value mvm_handleGet (const mvm_Handle * handle ) { return handle -> _value ; }
200
- static inline void mvm_handleSet (mvm_Handle * handle , mvm_Value value ) { handle -> _value = value ; }
202
+ MVM_EXPORT void mvm_initializeHandle (mvm_VM * vm , mvm_Handle * handle ); // Handle must be released by mvm_releaseHandle
203
+ MVM_EXPORT void mvm_cloneHandle (mvm_VM * vm , mvm_Handle * target , const mvm_Handle * source ); // Target must be released by mvm_releaseHandle
204
+ MVM_EXPORT mvm_TeError mvm_releaseHandle (mvm_VM * vm , mvm_Handle * handle );
205
+ MVM_EXPORT static inline mvm_Value mvm_handleGet (const mvm_Handle * handle ) { return handle -> _value ; }
206
+ MVM_EXPORT static inline void mvm_handleSet (mvm_Handle * handle , mvm_Value value ) { handle -> _value = value ; }
201
207
202
208
/**
203
209
* Roughly like the `typeof` operator in JS, except with distinct values for
204
210
* null and arrays
205
211
*/
206
- mvm_TeType mvm_typeOf (mvm_VM * vm , mvm_Value value );
212
+ MVM_EXPORT mvm_TeType mvm_typeOf (mvm_VM * vm , mvm_Value value );
207
213
208
214
/**
209
215
* Converts the value to a string encoded as UTF-8.
@@ -226,21 +232,21 @@ mvm_TeType mvm_typeOf(mvm_VM* vm, mvm_Value value);
226
232
* [memory-management.md](https://github.com/coder-mike/microvium/blob/master/doc/native-vm/memory-management.md)
227
233
* for details.
228
234
*/
229
- const char * mvm_toStringUtf8 (mvm_VM * vm , mvm_Value value , size_t * out_sizeBytes );
235
+ MVM_EXPORT const char * mvm_toStringUtf8 (mvm_VM * vm , mvm_Value value , size_t * out_sizeBytes );
230
236
231
237
/**
232
238
* Convert the value to a bool based on its truthiness.
233
239
*
234
240
* See https://developer.mozilla.org/en-US/docs/Glossary/Truthy
235
241
*/
236
- bool mvm_toBool (mvm_VM * vm , mvm_Value value );
242
+ MVM_EXPORT bool mvm_toBool (mvm_VM * vm , mvm_Value value );
237
243
238
244
/**
239
245
* Converts the value to a 32-bit signed integer.
240
246
*
241
247
* The result of this should be the same as `value|0` in JavaScript code.
242
248
*/
243
- int32_t mvm_toInt32 (mvm_VM * vm , mvm_Value value );
249
+ MVM_EXPORT int32_t mvm_toInt32 (mvm_VM * vm , mvm_Value value );
244
250
245
251
#if MVM_SUPPORT_FLOAT
246
252
/**
@@ -250,7 +256,7 @@ int32_t mvm_toInt32(mvm_VM* vm, mvm_Value value);
250
256
*
251
257
* For efficiency, use mvm_toInt32 instead if your value is an integer.
252
258
*/
253
- MVM_FLOAT64 mvm_toFloat64 (mvm_VM * vm , mvm_Value value );
259
+ MVM_EXPORT MVM_FLOAT64 mvm_toFloat64 (mvm_VM * vm , mvm_Value value );
254
260
255
261
/**
256
262
* Create a number value in the VM.
@@ -260,23 +266,23 @@ MVM_FLOAT64 mvm_toFloat64(mvm_VM* vm, mvm_Value value);
260
266
* Design note: mvm_newNumber creates a number *from* a float64, so it's named
261
267
* `newNumber` and not `newFloat64`
262
268
*/
263
- mvm_Value mvm_newNumber (mvm_VM * vm , MVM_FLOAT64 value );
269
+ MVM_EXPORT mvm_Value mvm_newNumber (mvm_VM * vm , MVM_FLOAT64 value );
264
270
#endif
265
271
266
- bool mvm_isNaN (mvm_Value value );
272
+ MVM_EXPORT bool mvm_isNaN (mvm_Value value );
267
273
268
274
extern const mvm_Value mvm_undefined ;
269
275
extern const mvm_Value mvm_null ;
270
- mvm_Value mvm_newBoolean (bool value );
271
- mvm_Value mvm_newInt32 (mvm_VM * vm , int32_t value );
276
+ MVM_EXPORT mvm_Value mvm_newBoolean (bool value );
277
+ MVM_EXPORT mvm_Value mvm_newInt32 (mvm_VM * vm , int32_t value );
272
278
273
279
/**
274
280
* Create a new string in Microvium memory.
275
281
*
276
282
* @param valueUtf8 The a pointer to the string content.
277
283
* @param sizeBytes The size in bytes of the string, excluding any null terminator.
278
284
*/
279
- mvm_Value mvm_newString (mvm_VM * vm , const char * valueUtf8 , size_t sizeBytes );
285
+ MVM_EXPORT mvm_Value mvm_newString (mvm_VM * vm , const char * valueUtf8 , size_t sizeBytes );
280
286
281
287
/**
282
288
* A Uint8Array in Microvium is an efficient buffer of bytes. It is mutable but
@@ -288,7 +294,7 @@ mvm_Value mvm_newString(mvm_VM* vm, const char* valueUtf8, size_t sizeBytes);
288
294
*
289
295
* See also: mvm_uint8ArrayToBytes
290
296
*/
291
- mvm_Value mvm_uint8ArrayFromBytes (mvm_VM * vm , const uint8_t * data , size_t size );
297
+ MVM_EXPORT mvm_Value mvm_uint8ArrayFromBytes (mvm_VM * vm , const uint8_t * data , size_t size );
292
298
293
299
/**
294
300
* Given a Uint8Array, this will give a pointer to its data and its size (in
@@ -302,7 +308,7 @@ mvm_Value mvm_uint8ArrayFromBytes(mvm_VM* vm, const uint8_t* data, size_t size);
302
308
*
303
309
* See also: mvm_newUint8Array
304
310
*/
305
- mvm_TeError mvm_uint8ArrayToBytes (mvm_VM * vm , mvm_Value uint8ArrayValue , uint8_t * * out_data , size_t * out_size );
311
+ MVM_EXPORT mvm_TeError mvm_uint8ArrayToBytes (mvm_VM * vm , mvm_Value uint8ArrayValue , uint8_t * * out_data , size_t * out_size );
306
312
307
313
/**
308
314
* Resolves (finds) the values exported by the VM, identified by ID.
@@ -315,7 +321,7 @@ mvm_TeError mvm_uint8ArrayToBytes(mvm_VM* vm, mvm_Value uint8ArrayValue, uint8_t
315
321
* captured by a mvm_Handle. In typical usage, exports will each be function
316
322
* values, but any value type is valid.
317
323
*/
318
- mvm_TeError mvm_resolveExports (mvm_VM * vm , const mvm_VMExportID * ids , mvm_Value * results , uint8_t count );
324
+ MVM_EXPORT mvm_TeError mvm_resolveExports (mvm_VM * vm , const mvm_VMExportID * ids , mvm_Value * results , uint8_t count );
319
325
320
326
/**
321
327
* Run a garbage collection cycle.
@@ -327,12 +333,12 @@ mvm_TeError mvm_resolveExports(mvm_VM* vm, const mvm_VMExportID* ids, mvm_Value*
327
333
* of needed as the amount of space used after the last compaction, and then
328
334
* adding blocks as-necessary.
329
335
*/
330
- void mvm_runGC (mvm_VM * vm , bool squeeze );
336
+ MVM_EXPORT void mvm_runGC (mvm_VM * vm , bool squeeze );
331
337
332
338
/**
333
339
* Compares two values for equality. The same semantics as JavaScript `===`
334
340
*/
335
- bool mvm_equal (mvm_VM * vm , mvm_Value a , mvm_Value b );
341
+ MVM_EXPORT bool mvm_equal (mvm_VM * vm , mvm_Value a , mvm_Value b );
336
342
337
343
/**
338
344
* The current bytecode address being executed (relative to the beginning of the
@@ -341,12 +347,12 @@ bool mvm_equal(mvm_VM* vm, mvm_Value a, mvm_Value b);
341
347
* This value can be looked up in the map file generated by the CLI flag
342
348
* `--map-file`
343
349
*/
344
- uint16_t mvm_getCurrentAddress (mvm_VM * vm );
350
+ MVM_EXPORT uint16_t mvm_getCurrentAddress (mvm_VM * vm );
345
351
346
352
/**
347
353
* Get stats about the VM memory
348
354
*/
349
- void mvm_getMemoryStats (mvm_VM * vm , mvm_TsMemoryStats * out_stats );
355
+ MVM_EXPORT void mvm_getMemoryStats (mvm_VM * vm , mvm_TsMemoryStats * out_stats );
350
356
351
357
#if MVM_INCLUDE_SNAPSHOT_CAPABILITY
352
358
/**
@@ -368,7 +374,7 @@ void mvm_getMemoryStats(mvm_VM* vm, mvm_TsMemoryStats* out_stats);
368
374
* Note: The result is malloc'd on the host heap, and so needs to be freed with
369
375
* a call to *free*.
370
376
*/
371
- void * mvm_createSnapshot (mvm_VM * vm , size_t * out_size );
377
+ MVM_EXPORT void * mvm_createSnapshot (mvm_VM * vm , size_t * out_size );
372
378
#endif // MVM_INCLUDE_SNAPSHOT_CAPABILITY
373
379
374
380
#if MVM_INCLUDE_DEBUG_CAPABILITY
@@ -389,12 +395,12 @@ void* mvm_createSnapshot(mvm_VM* vm, size_t* out_size);
389
395
* Setting a breakpoint a second time on the same address of an existing active
390
396
* breakpoint will have no effect.
391
397
*/
392
- void mvm_dbg_setBreakpoint (mvm_VM * vm , uint16_t bytecodeAddress );
398
+ MVM_EXPORT void mvm_dbg_setBreakpoint (mvm_VM * vm , uint16_t bytecodeAddress );
393
399
394
400
/**
395
401
* Remove a breakpoint added by mvm_dbg_setBreakpoint
396
402
*/
397
- void mvm_dbg_removeBreakpoint (mvm_VM * vm , uint16_t bytecodeAddress );
403
+ MVM_EXPORT void mvm_dbg_removeBreakpoint (mvm_VM * vm , uint16_t bytecodeAddress );
398
404
399
405
/**
400
406
* Set the function to be called when any breakpoint is hit.
@@ -412,7 +418,7 @@ void mvm_dbg_removeBreakpoint(mvm_VM* vm, uint16_t bytecodeAddress);
412
418
* still active. This should *NOT* be used to continue execution, but could
413
419
* theoretically be used to evaluate debug watch expressions.
414
420
*/
415
- void mvm_dbg_setBreakpointCallback (mvm_VM * vm , mvm_TfBreakpointCallback cb );
421
+ MVM_EXPORT void mvm_dbg_setBreakpointCallback (mvm_VM * vm , mvm_TfBreakpointCallback cb );
416
422
#endif // MVM_INCLUDE_DEBUG_CAPABILITY
417
423
418
424
#ifdef __cplusplus
0 commit comments