crafting-interpreters/clox/src/object.h

33 lines
556 B
C
Raw Normal View History

2021-09-06 02:24:56 -07:00
#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