-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogictypes.cpp
More file actions
70 lines (58 loc) · 2.88 KB
/
logictypes.cpp
File metadata and controls
70 lines (58 loc) · 2.88 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "logic.h"
namespace Logic {
std::vector<NodeType> nodeTypes {
NodeType(
"base/goal", {tAny},
[](Node *node, Object *obj) -> ValueType { return node->argNodes[0]->resolve(obj); }
),
#define LR_OPERATOR(MATHOP) [](Node *node, Object *obj) -> ValueType {\
return std::get<bool>(node->argNodes[0]->resolve(obj)) MATHOP std::get<bool>(node->argNodes[1]->resolve(obj));\
}
#define R_OPERATOR(MATHOP) [](Node *node, Object *obj) -> ValueType {\
return MATHOP std::get<bool>(node->argNodes[0]->resolve(obj));\
}
NodeType("math/add", {{tInt, tFloat}, {tInt, tFloat}}, LR_OPERATOR(+)),
NodeType("math/subtract", {{tInt, tFloat}, {tInt, tFloat}}, LR_OPERATOR(-)),
NodeType("math/multiply", {{tInt, tFloat}, {tInt, tFloat}}, LR_OPERATOR(*)),
NodeType("math/divide", {{tInt, tFloat}, {tInt, tFloat}}, LR_OPERATOR(/)),
NodeType("math/negate", {{tInt, tFloat}}, R_OPERATOR(-)),
NodeType("gate/and", {{tBool}, {tBool}}, LR_OPERATOR(&&)),
NodeType("gate/or", {{tBool}, {tBool}}, LR_OPERATOR(||)),
NodeType("gate/xor", {{tBool}, {tBool}}, LR_OPERATOR(^)),
NodeType("gate/not", {{tBool}}, R_OPERATOR(!)),
NodeType(
"branch/if", {tAny, {tBool}},
[](Node *node, Object *obj) -> ValueType {
if (std::get<bool>(node->argNodes[1]->resolve(obj)))
return node->argNodes[0]->resolve(obj);
else
return NullValue();
}
),
NodeType(
"branch/while", {tAny, {tBool}},
[](Node *node, Object *obj) -> ValueType {
while (std::get<bool>(node->argNodes[1]->resolve(obj))) {
node->argNodes[0]->resolve(obj);
}
return NullValue();
}
),
NodeType(
"branch/until", {tAny, {tBool}},
[](Node *node, Object *obj) -> ValueType {
while (!std::get<bool>(node->argNodes[1]->resolve(obj))) {
node->argNodes[0]->resolve(obj);
}
return NullValue();
}
),
#define NODE_CONSTANT [](Node *node, Object *obj) -> ValueType { return node->value; }
NodeType("constant/bool", {}, NODE_CONSTANT),
NodeType("constant/int", {}, NODE_CONSTANT),
NodeType("constant/float", {}, NODE_CONSTANT),
NodeType("constant/null", {}, NODE_CONSTANT),
NodeType("constant/string", {}, NODE_CONSTANT),
NodeType("constant/vector2", {}, NODE_CONSTANT)
};
}