From ba52787271b246255b8788942cdb74560f840bfe Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Mon, 6 Sep 2021 02:24:56 -0700 Subject: Chapter 19.1 - 19.2 --- clox/src/object.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 clox/src/object.h (limited to 'clox/src/object.h') 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 -- cgit v1.2.3-54-g00ecf