-
Notifications
You must be signed in to change notification settings - Fork 0
/
value.h
56 lines (44 loc) · 1.11 KB
/
value.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef _VALUE_H
#define _VALUE_H
#include <iostream>
#include "object.h"
#define NIL_VALUE Value()
class Value {
public:
typedef enum { INT32, INT64, STRING, BOOL, NIL, OBJECT, CLASS } vtype;
union uval {
bool is_nil;
int i32val;
std::string* strval;
bool boolval;
Object* objval;
Class* classval;
};
union uval val;
vtype value_type;
Value();
Value(int);
Value(std::string);
Value(bool);
Value(Object* obj);
Value(Class* cl);
int getInt32() const;
int64_t getInt64() const;
bool getBool() const;
std::string getString() const;
Object* getObject() const;
Class* getClass() const;
bool is(vtype) const;
bool isNumeric() const;
bool isString() const;
bool isBool() const;
bool isNil() const;
bool isObject() const;
bool isClass() const;
Value operator+(const Value& v);
Value operator-(const Value& v);
Value operator*(const Value& v);
Value operator/(const Value& v);
};
std::ostream& operator<<(std::ostream& s, const Value &v);
#endif