-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmath_operations.py
120 lines (75 loc) · 2.89 KB
/
math_operations.py
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
115
116
117
118
119
120
from command import Command
from queue import (
QueueFrameBase,
RegisterQueueBase,
QQueueBase
)
class BinOpBase:
def execute(self, env):
self.get_queue(env)
l, r = self.pop(env), self.pop(env)
self.push(env, type(l)(self.op(l.value, r.value)))
self.return_queue(env)
class AddBase(BinOpBase):
op = lambda self, l, r: l + r
class Add(Command, AddBase, QueueFrameBase): pass
class RAdd(Command, AddBase, RegisterQueueBase): pass
class QAdd(Command, AddBase, QQueueBase): pass
class SubBase(BinOpBase):
op = lambda self, l, r: l - r
class Sub(Command, SubBase, QueueFrameBase): pass
class RSub(Command, SubBase, RegisterQueueBase): pass
class QSub(Command, SubBase, QQueueBase): pass
class MulBase(BinOpBase):
op = lambda self, l, r: l * r
class Mul(Command, MulBase, QueueFrameBase): pass
class RMul(Command, MulBase, RegisterQueueBase): pass
class QMul(Command, MulBase, QQueueBase): pass
class DivBase(BinOpBase):
op = lambda self, l, r: l / r
class Div(Command, DivBase, QueueFrameBase): pass
class RDiv(Command, DivBase, RegisterQueueBase): pass
class QDiv(Command, DivBase, QQueueBase): pass
class ModBase(BinOpBase):
op = lambda self, l, r: l % r
class Mod(Command, ModBase, QueueFrameBase): pass
class RMod(Command, ModBase, RegisterQueueBase): pass
class QMod(Command, ModBase, QQueueBase): pass
class ExpBase(BinOpBase):
op = lambda self, l, r: l ** r
class Exp(Command, ExpBase, QueueFrameBase): pass
class RExp(Command, ExpBase, RegisterQueueBase): pass
class QExp(Command, ExpBase, QQueueBase): pass
class BitAndBase(BinOpBase):
op = lambda self, l, r: l & r
class BitAnd(Command, BitAndBase, QueueFrameBase): pass
class RBitAnd(Command, BitAndBase, RegisterQueueBase): pass
class QBitAnd(Command, BitAndBase, QQueueBase): pass
class BitOrBase(BinOpBase):
op = lambda self, l, r: l | r
class BitOr(Command, BitOrBase, QueueFrameBase): pass
class RBitOr(Command, BitOrBase, RegisterQueueBase): pass
class QBitOr(Command, BitOrBase, QQueueBase): pass
class BitXorBase(BinOpBase):
op = lambda self, l, r: l ^ r
class BitXor(Command, BitXorBase, QueueFrameBase): pass
class RBitXor(Command, BitXorBase, RegisterQueueBase): pass
class QBitXor(Command, BitXorBase, QQueueBase): pass
class IncBase:
def execute(self, env):
self.get_queue(env)
v = self.pop(env)
self.push(env, type(v)(v.value + 1))
self.return_queue(env)
class Inc(Command, IncBase, QueueFrameBase): pass
class RInc(Command, IncBase, RegisterQueueBase): pass
class QInc(Command, IncBase, QQueueBase): pass
class DecBase:
def execute(self, env):
self.get_queue(env)
v = self.pop(env)
self.push(env, type(v)(v.value - 1))
self.return_queue(env)
class Dec(Command, DecBase, QueueFrameBase): pass
class RDec(Command, DecBase, RegisterQueueBase): pass
class QDec(Command, DecBase, QQueueBase): pass