the hito embeddable programming language
at main 72 lines 1.3 kB view raw
1#ifndef value_h 2#define value_h 3 4#include "intern.h" 5#include "env.h" 6#include "syntax.h" 7#include "builtins.h" 8#include <stdbool.h> 9typedef struct env env_t; 10typedef struct value value_t; 11typedef struct gc gc_t; 12 13 14 15struct value { 16 enum { 17 VALUE_INT = 0, 18 VALUE_FLOAT, 19 VALUE_STRING, 20 VALUE_CONSTRUCTOR, 21 VALUE_CLOSURE, 22 VALUE_BUILTIN, 23 VALUE_ENV, 24 } tag; 25 union { 26 long integer; 27 double floating; 28 builtin_func_t *builtin; 29 struct { 30 char *string; 31 bool shared; 32 } string; 33 struct { 34 intern_t name; 35 value_t **args; 36 size_t num_args; 37 } constructor; 38 struct { 39 value_t *env; 40 expr_t *body; 41 size_t arity; 42 value_t *next; // should be another closure of the same arity 43 } closure; 44 env_t *env; 45 } as; 46 value_t *gc_next; 47}; 48 49 50/* allocate a gc arena */ 51gc_t *gc_alloc(void); 52 53/* free a gc arena -- ensure all values are collected first */ 54void gc_free(gc_t *); 55 56/* Allocation */ 57value_t *value_alloc(gc_t *gc); 58 59value_t *value_alloc_bool(gc_t *gc, bool); 60value_t *value_alloc_int(gc_t *gc, long); 61value_t *value_alloc_float(gc_t *gc, double); 62value_t *value_alloc_string(gc_t *gc, char *, bool shared); 63 64/* Mark as live for gc */ 65void value_mark_gc(value_t *); 66 67/* GC collection */ 68void gc(gc_t *gc); 69 70void value_debug_dump(value_t *it); 71 72#endif