#ifndef _val_h #define _val_h #include struct _val; typedef struct _val Val; struct _obj; typedef struct _obj Obj; typedef enum { TY_NIL, TY_NUM, TY_BOOL, } ValTy; struct _val { ValTy ty; union { double d; bool b; Obj *o; } as; }; struct _obj { // some gc shit int foo; }; void print_val(Val v); void println_val(Val v); const char *valty_str(ValTy ty); #define IS_NUM(x) (x.ty == TY_NUM) #define IS_BOOL(x) (x.ty == TY_BOOL) #define IS_NIL(x) (x.ty == NIL) #define AS_NUM(x) (x.as.d) #define AS_BOOL(x) (x.as.b) #define VAL_NUM(x) ((Val){.ty=TY_NUM, .as.d=x}) #define VAL_BOOL(x) ((Val){.ty=TY_BOOL, .as.b=x}) #define VAL_NIL ((Val){.ty=TY_NIL}) #endif