diff options
Diffstat (limited to 'clox/src/object.h')
-rw-r--r-- | clox/src/object.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/clox/src/object.h b/clox/src/object.h new file mode 100644 index 0000000..7ab8f3a --- /dev/null +++ b/clox/src/object.h @@ -0,0 +1,32 @@ +#ifndef OBJECT_H +#define OBJECT_H + +#include "common.h" +#include "value.h" + +#define OBJ_TYPE(value) (AS_OBJ(value)->type) + +#define IS_STRING(value) isObjType(value, OBJ_STRING) + +#define AS_STRING(value) ((ObjString *)AS_OBJ(value)) +#define AS_CSTRING(value) (((ObjString *)AS_OBJ(value))->chars) + +typedef enum { + OBJ_STRING, +} ObjType; + +struct Obj { + ObjType type; +}; + +struct ObjString { + Obj obj; + int length; + char *chars; +}; + +static inline bool isObjType(Value value, ObjType type) { + return IS_OBJ(value) && AS_OBJ(value)->type == type; +} + +#endif |