-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathint.cpp
106 lines (86 loc) · 2.87 KB
/
int.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
#include "int.h"
#include "float.h"
#include "bool.h"
#include "assert.h"
value make$int_(long v) {
value ret;
ret.type = value::INT;
ret.intval = v;
return ret;
}
value __add__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$int_(x.intval + y.intval);
}
value __sub__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$int_(x.intval - y.intval);
}
value __truediv__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return __truediv__$float_$float_(__float__$int_(x), __float__$int_(y));
}
value __mul__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$int_(x.intval * y.intval);
}
value __mod__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$int_(x.intval % y.intval);
}
value __float__$int_(value self) {
assert(self.type == value::INT);
return make$float_(self.intval);
}
value __eq__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$bool_(x.intval == y.intval);
}
value __ne__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$bool_(x.intval != y.intval);
}
value __lt__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$bool_(x.intval < y.intval);
}
value __le__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$bool_(x.intval <= y.intval);
}
value __ge__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$bool_(x.intval >= y.intval);
}
value __gt__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$bool_(x.intval > y.intval);
}
value __bool__$int_(value self) {
assert(self.type == value::INT);
return make$bool_(self.intval != 0);
}
value __and__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$int_(x.intval & y.intval);
}
value __or__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$int_(x.intval | y.intval);
}
value __xor__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$int_(x.intval ^ y.intval);
}
value __invert__$int_(value self) {
assert(self.type == value::INT);
return make$int_(~self.intval);
}
value __lshift__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$int_(x.intval << y.intval);
}
value __rshift__$int_$int_(value x, value y) {
assert(x.type == value::INT && y.type == value::INT);
return make$int_(x.intval >> y.intval);
}