2017-02-09 20:02:59 +00:00
|
|
|
#ifndef VM_H_C4OZU8CQ
|
|
|
|
#define VM_H_C4OZU8CQ
|
|
|
|
|
|
|
|
#include "datatypes.h"
|
2017-02-22 23:19:46 +00:00
|
|
|
#include "value.h"
|
2017-02-09 20:02:59 +00:00
|
|
|
|
|
|
|
/* Exit from the VM normally */
|
2017-02-16 02:02:00 +00:00
|
|
|
#define gst_exit(vm, r) ((vm)->ret = (r), longjmp((vm)->jump, 1))
|
2017-02-09 20:02:59 +00:00
|
|
|
|
2017-02-23 22:21:13 +00:00
|
|
|
/* Bail from the VM with an error string. */
|
2017-02-22 23:19:46 +00:00
|
|
|
#define gst_error(vm, e) ((vm)->error = gst_load_cstring((vm), (e)), longjmp((vm)->jump, 2))
|
2017-02-09 20:02:59 +00:00
|
|
|
|
2017-02-09 23:50:47 +00:00
|
|
|
/* Crash. Not catchable, unlike error. */
|
2017-02-22 23:19:46 +00:00
|
|
|
#define gst_crash(vm, e) ((vm)->crash = (e), longjmp((vm)->jump, 3))
|
2017-02-09 23:50:47 +00:00
|
|
|
|
2017-02-09 20:02:59 +00:00
|
|
|
/* Error if the condition is false */
|
2017-02-16 02:02:00 +00:00
|
|
|
#define gst_assert(vm, cond, e) do \
|
|
|
|
{ if (!(cond)) { gst_error((vm), (e)); } } while (0)
|
2017-02-09 20:02:59 +00:00
|
|
|
|
2017-02-12 20:16:55 +00:00
|
|
|
/* Type assertion */
|
2017-02-16 02:02:00 +00:00
|
|
|
#define gst_assert_type(vm, f, t) \
|
|
|
|
gst_assert((vm), (f).type == (t), "Expected a different type.")
|
2017-02-12 20:16:55 +00:00
|
|
|
|
2017-02-09 20:02:59 +00:00
|
|
|
/* Initialize the VM */
|
2017-02-16 02:02:00 +00:00
|
|
|
void gst_init(Gst * vm);
|
2017-02-09 20:02:59 +00:00
|
|
|
|
|
|
|
/* Deinitialize the VM */
|
2017-02-16 02:02:00 +00:00
|
|
|
void gst_deinit(Gst * vm);
|
2017-02-09 20:02:59 +00:00
|
|
|
|
|
|
|
/* Load a function to be run on the VM */
|
2017-02-16 02:02:00 +00:00
|
|
|
void gst_load(Gst * vm, GstValue func);
|
2017-02-09 20:02:59 +00:00
|
|
|
|
|
|
|
/* Start running the VM */
|
2017-02-16 02:02:00 +00:00
|
|
|
int gst_start(Gst * vm);
|
2017-02-09 20:02:59 +00:00
|
|
|
|
|
|
|
/* Run garbage collection */
|
2017-02-16 02:02:00 +00:00
|
|
|
void gst_collect(Gst * vm);
|
2017-02-09 20:02:59 +00:00
|
|
|
|
|
|
|
/* Collect garbage if enough memory has been allocated since
|
|
|
|
* the previous collection */
|
2017-02-16 02:02:00 +00:00
|
|
|
void gst_maybe_collect(Gst * vm);
|
2017-02-09 20:02:59 +00:00
|
|
|
|
2017-02-09 23:50:47 +00:00
|
|
|
/* Allocate memory */
|
2017-02-16 02:02:00 +00:00
|
|
|
void * gst_alloc(Gst * vm, uint32_t amount);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Allocate zeroed memory */
|
2017-02-16 02:02:00 +00:00
|
|
|
void * gst_zalloc(Gst * vm, uint32_t amount);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
2017-02-10 04:28:11 +00:00
|
|
|
/* Get an argument from the stack */
|
2017-02-16 02:02:00 +00:00
|
|
|
GstValue gst_arg(Gst * vm, uint16_t index);
|
2017-02-10 04:28:11 +00:00
|
|
|
|
|
|
|
/* Put a value on the stack */
|
2017-02-16 02:02:00 +00:00
|
|
|
void gst_set_arg(Gst * vm, uint16_t index, GstValue x);
|
2017-02-10 04:28:11 +00:00
|
|
|
|
2017-02-11 19:01:06 +00:00
|
|
|
/* Get the number of arguments on the stack */
|
2017-02-16 02:02:00 +00:00
|
|
|
uint16_t gst_count_args(Gst * vm);
|
2017-02-11 19:01:06 +00:00
|
|
|
|
2017-02-09 20:02:59 +00:00
|
|
|
#endif /* end of include guard: VM_H_C4OZU8CQ */
|