All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
value.h
Go to the documentation of this file.
1 #ifndef uscript_value_h
2 #define uscript_value_h
3 #include <string>
4 
5 #include "tclass.h"
6 
7 namespace uscript {
8 
9 enum ValueType {
16 };
17 
18 struct ObjString {
19  const char *string;
20 };
21 
22 struct TClassInfo;
23 
24 struct ObjTInstance {
25  uint8_t *loc;
27 };
28 
29 struct Value {
31  union {
32  bool boolean;
33  double number;
34  int integer;
37  } as;
38  void Print() const;
39  void PrintObj() const;
40 
41  bool operator!() const;
42 };
43 } // end namespace
44 
45 #define BOOL_VAL(value) ((uscript::Value){ uscript::VAL_BOOL, { .boolean = value }})
46 #define NIL_VAL ((uscript::Value){ uscript::VAL_NIL, { .integer = 0 }})
47 #define NUMBER_VAL(value) ((uscript::Value){ uscript::VAL_NUMBER, { .number = value }})
48 #define INTEGER_VAL(value) ((uscript::Value){ uscript::VAL_INTEGER, { .integer = value }})
49 #define STRING_VAL(value) ((uscript::Value){ uscript::VAL_OBJ_STRING, { .string = (uscript::ObjString){ value } }})
50 #define TINSTANCE_VAL(value) ((uscript::Value){ uscript::VAL_OBJ_TINSTANCE, { .tinst = value }})
51 
52 #define AS_BOOL(value) ((value).as.boolean)
53 #define AS_NUMBER(value) ((value).as.number)
54 #define AS_INTEGER(value) ((value).as.integer)
55 #define AS_STRING(value) ((value).as.string)
56 #define AS_CSTRING(value) ((value).as.string.string)
57 #define AS_TINSTANCE(value) ((value).as.tinst)
58 
59 #define IS_NIL(value) ((value).val == uscript::VAL_NIL)
60 #define IS_BOOL(value) ((value).val == uscript::VAL_BOOL)
61 #define IS_NUMBER(value) ((value).val == uscript::VAL_NUMBER)
62 #define IS_INTEGER(value) ((value).val == uscript::VAL_INTEGER)
63 #define IS_STRING(value) ((value).val == uscript::VAL_OBJ_STRING)
64 #define IS_TINSTANCE(value) ((value).val == uscript::VAL_OBJ_TINSTANCE)
65 
66 #endif
ObjString string
Definition: value.h:35
uint8_t * loc
Definition: value.h:25
void PrintObj() const
bool operator!() const
Definition: value.cc:16
const char * string
Definition: value.h:19
double number
Definition: value.h:33
ObjTInstance tinst
Definition: value.h:36
ValueType val
Definition: value.h:30
void Print() const
Definition: value.cc:5
union uscript::Value::@3 as
int integer
Definition: value.h:34
bool boolean
Definition: value.h:32
ValueType
Definition: value.h:9