summaryrefslogtreecommitdiff
path: root/val.h
diff options
context:
space:
mode:
Diffstat (limited to 'val.h')
-rw-r--r--val.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/val.h b/val.h
index 4ee76d2..90b60f2 100644
--- a/val.h
+++ b/val.h
@@ -7,13 +7,16 @@
typedef struct _val Val;
typedef struct _obj Obj;
+typedef struct _state State;
+typedef Val (*CFunc)(State *S, int nargs, Val *args);
typedef enum {
TY_NIL,
TY_NUM,
TY_BOOL,
TY_OBJ,
+ TY_CFUNC,
} ValTy;
typedef struct _val {
@@ -22,6 +25,7 @@ typedef struct _val {
double d;
bool b;
Obj *o;
+ CFunc f;
} as;
} Val;
@@ -71,6 +75,7 @@ ObjFunc *objfunc_new(State *S, uint8_t arity);
#define IS_NUM(x) (x.ty == TY_NUM)
#define IS_BOOL(x) (x.ty == TY_BOOL)
#define IS_OBJ(x) (x.ty == TY_OBJ)
+#define IS_CFUNC(x) (x.ty == TY_CFUNC)
#define IS_STRING(x) (is_obj_ty((x), OTY_STRING))
#define IS_FUNC(x) (is_obj_ty((x), OTY_FUNC))
@@ -78,6 +83,7 @@ ObjFunc *objfunc_new(State *S, uint8_t arity);
#define AS_NUM(x) (x.as.d)
#define AS_BOOL(x) (x.as.b)
#define AS_OBJ(x) (x.as.o)
+#define AS_CFUNC(x) (x.as.f)
#define AS_STRING(x) ((ObjString*)AS_OBJ(x))
#define AS_CSTRING(x) (AS_STRING(x)->d)
@@ -89,6 +95,7 @@ ObjFunc *objfunc_new(State *S, uint8_t arity);
#define VAL_TRUE VAL_BOOL(1)
#define VAL_FALSE VAL_BOOL(0)
#define VAL_OBJ(x) ((Val){.ty=TY_OBJ, .as.o=(Obj*)(x) })
+#define VAL_CFUNC(x) ((Val){.ty=TY_CFUNC, .as.f=(CFunc)(x)})
static inline bool is_obj_ty(Val v, ObjTy t) {
return IS_OBJ(v) && (AS_OBJ(v)->oty == t);