diff options
author | Tom Willemse | 2021-09-06 02:24:56 -0700 |
---|---|---|
committer | Tom Willemse | 2021-09-06 02:24:56 -0700 |
commit | ba52787271b246255b8788942cdb74560f840bfe (patch) | |
tree | 85febc8cd97beb7fc498bc16e01bb496c3941b20 /clox/src/object.h | |
parent | c10cbcdf99824bf81fb0874deb258d5c8c7cb22d (diff) | |
download | crafting-interpreters-ba52787271b246255b8788942cdb74560f840bfe.tar.gz crafting-interpreters-ba52787271b246255b8788942cdb74560f840bfe.zip |
Chapter 19.1 - 19.2
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 |