-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValue.h
57 lines (48 loc) · 1.15 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
57
#pragma once
#include <string>
#include <unordered_map>
#include "Utils.h"
namespace lwscript
{
enum ValueKind : uint8_t
{
NIL,
INT,
REAL,
BOOL,
OBJECT,
};
struct LWSCRIPT_API Value
{
Value() noexcept;
Value(int64_t integer) noexcept;
Value(double number) noexcept;
Value(bool boolean) noexcept;
Value(struct Object *object) noexcept;
~Value() noexcept = default;
STD_STRING ToString() const;
void Mark() const;
void UnMark() const;
std::vector<uint8_t> Serialize() const;
void Deserialize(const std::vector<uint8_t> &data);
ValueKind kind;
Privilege privilege = Privilege::MUTABLE;
union
{
int64_t integer;
double realnum;
bool boolean;
struct Object *object;
};
};
LWSCRIPT_API bool operator==(const Value &left, const Value &right);
LWSCRIPT_API bool operator!=(const Value &left, const Value &right);
struct LWSCRIPT_API ValueHash
{
size_t operator()(const Value *v) const;
size_t operator()(const Value &v) const;
};
using ValueUnorderedMap = std::unordered_map<Value, Value, ValueHash>;
size_t HashValueList(Value *start, size_t count);
size_t HashValueList(Value *start, Value *end);
}