-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbool.cpp
114 lines (92 loc) · 3.16 KB
/
bool.cpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "bool.h"
#include "int.h"
#include "float.h"
#include "assert.h"
#include "str.h"
#include "list.h"
value make$bool_(bool v) {
value ret;
ret.type = value::BOOL;
ret.boolval = v;
return ret;
}
value __eq__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return make$bool_(x.boolval == y.boolval);
}
value __ne__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return make$bool_(x.boolval != y.boolval);
}
value __lt__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return make$bool_(x.boolval < y.boolval);
}
value __le__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return make$bool_(x.boolval <= y.boolval);
}
value __ge__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return make$bool_(x.boolval >= y.boolval);
}
value __gt__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return make$bool_(x.boolval > y.boolval);
}
value __add__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return __add__$int_$int_(__int__$bool_(x), __int__$bool_(y));
}
value __truediv__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return __truediv__$int_$int_(__int__$bool_(x), __int__$bool_(y));
}
value __sub__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return __sub__$int_$int_(__int__$bool_(x), __int__$bool_(y));
}
value __mul__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return __mul__$int_$int_(__int__$bool_(x), __int__$bool_(y));
}
value __mod__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return __mod__$int_$int_(__int__$bool_(x), __int__$bool_(y));
}
value __lshift__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return __lshift__$int_$int_(__int__$bool_(x), __int__$bool_(y));
}
value __rshift__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return __rshift__$int_$int_(__int__$bool_(x), __int__$bool_(y));
}
value __invert__$bool_(value x) {
assert(x.type == value::BOOL);
return __invert__$int_(__int__$bool_(x));
}
value __bool__$bool_(value self) {
assert(self.type == value::BOOL);
return self;
}
value __int__$bool_(value self) {
assert(self.type == value::BOOL);
return make$int_(self.boolval? 1: 0);
}
value __float__$bool_(value self) {
assert(self.type == value::BOOL);
return make$float_(self.boolval? 1.0: 0.0);
}
value __and__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return make$bool_(x.boolval & y.boolval);
}
value __or__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return make$bool_(x.boolval | y.boolval);
}
value __xor__$bool_$bool_(value x, value y) {
assert(x.type == value::BOOL && y.type == value::BOOL);
return make$bool_(x.boolval ^ y.boolval);
}