2017-02-09 23:50:47 +00:00
|
|
|
#ifndef ds_h_INCLUDED
|
|
|
|
#define ds_h_INCLUDED
|
|
|
|
|
|
|
|
#include "datatypes.h"
|
|
|
|
|
2017-02-15 01:45:34 +00:00
|
|
|
/*
|
|
|
|
* Data type flags
|
|
|
|
*/
|
2017-02-16 02:02:00 +00:00
|
|
|
#define GST_DS_LOCKED 0x01
|
2017-02-15 01:45:34 +00:00
|
|
|
|
2017-02-09 23:50:47 +00:00
|
|
|
/****/
|
|
|
|
/* Buffer functions */
|
|
|
|
/****/
|
|
|
|
|
|
|
|
/* Create a new buffer */
|
2017-02-16 02:02:00 +00:00
|
|
|
GstBuffer *gst_buffer(Gst *vm, uint32_t capacity);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Ensure the buffer has enough capacity */
|
2017-02-16 02:02:00 +00:00
|
|
|
void gst_buffer_ensure(Gst *vm, GstBuffer *buffer, uint32_t capacity);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Get a value from the buffer */
|
2017-02-16 02:02:00 +00:00
|
|
|
int gst_buffer_get(GstBuffer *buffer, uint32_t index);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Push a value to the buffer */
|
2017-02-16 02:02:00 +00:00
|
|
|
void gst_buffer_push(Gst *vm, GstBuffer *buffer, uint8_t c);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Append a piece of memory to the buffer */
|
2017-02-16 02:02:00 +00:00
|
|
|
void gst_buffer_append(Gst *vm, GstBuffer *buffer, uint8_t *string, uint32_t length);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Convert the buffer to a string */
|
2017-02-16 02:02:00 +00:00
|
|
|
uint8_t *gst_buffer_to_string(Gst * vm, GstBuffer * buffer);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Define a push function for pushing a certain type to the buffer */
|
2017-02-16 02:02:00 +00:00
|
|
|
#define BUFFER_DEFINE(name, type) \
|
|
|
|
static void gst_buffer_push_##name(Gst * vm, GstBuffer * buffer, type x) { \
|
2017-02-09 23:50:47 +00:00
|
|
|
union { type t; uint8_t bytes[sizeof(type)]; } u; \
|
2017-02-16 02:02:00 +00:00
|
|
|
u.t = x; gst_buffer_append(vm, buffer, u.bytes, sizeof(type)); \
|
2017-02-09 23:50:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****/
|
|
|
|
/* Array functions */
|
|
|
|
/****/
|
|
|
|
|
|
|
|
/* Create a new Array */
|
2017-02-16 02:02:00 +00:00
|
|
|
GstArray *gst_array(Gst *vm, uint32_t capacity);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Get a value of an array with bounds checking. Returns nil if
|
|
|
|
* outside bounds. */
|
2017-02-16 02:02:00 +00:00
|
|
|
GstValue gst_array_get(GstArray *array, uint32_t index);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Set a value in the array. Does bounds checking but will not grow
|
|
|
|
* or shrink the array */
|
2017-02-16 02:02:00 +00:00
|
|
|
int gst_array_set(GstArray *array, uint32_t index, GstValue x);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Ensure that the internal memory hash enough space for capacity items */
|
2017-02-16 02:02:00 +00:00
|
|
|
void gst_array_ensure(Gst *vm, GstArray *array, uint32_t capacity);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Set a value in an array. Will also append to the array if the index is
|
|
|
|
* greater than the current max index. */
|
2017-02-16 02:02:00 +00:00
|
|
|
void gst_array_push(Gst *vm, GstArray *array, GstValue x);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Pop the last item in the array, or return NIL if empty */
|
2017-02-16 02:02:00 +00:00
|
|
|
GstValue gst_array_pop(GstArray *array);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Look at the top most item of an Array */
|
2017-02-16 02:02:00 +00:00
|
|
|
GstValue ArrayPeek(GstArray *array);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/****/
|
2017-02-16 02:02:00 +00:00
|
|
|
/* Object functions */
|
2017-02-09 23:50:47 +00:00
|
|
|
/****/
|
|
|
|
|
2017-02-16 02:02:00 +00:00
|
|
|
/* Create a new object */
|
|
|
|
GstObject *gst_object(Gst *vm, uint32_t capacity);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Get a value out of the dictionary */
|
2017-02-16 02:02:00 +00:00
|
|
|
GstValue gst_object_get(GstObject *obj, GstValue key);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Get a Value from the dictionary, but remove it at the same
|
|
|
|
* time. */
|
2017-02-16 02:02:00 +00:00
|
|
|
GstValue gst_object_remove(Gst *vm, GstObject *obj, GstValue key);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
/* Put a value into the dictionary. Returns 1 if successful, 0 if out of memory.
|
|
|
|
* The VM pointer is needed for memory allocation. */
|
2017-02-16 02:02:00 +00:00
|
|
|
void gst_object_put(Gst *vm, GstObject *obj, GstValue key, GstValue value);
|
2017-02-09 23:50:47 +00:00
|
|
|
|
|
|
|
#endif // ds_h_INCLUDED
|