70
|
1
|
110
|
2 def Enum(**enums):
|
|
3 return type('Enum', (), enums)
|
|
4
|
155
|
5 class Instruction:
|
104
|
6 """ Base class for all instructions. """
|
70
|
7 pass
|
|
8
|
|
9 class CallInstruction(Instruction):
|
110
|
10 def __init__(self, callee, arguments):
|
|
11 super().__init__()
|
|
12 self.callee = callee
|
|
13 self.arguments = arguments
|
|
14
|
|
15 BinOps = Enum(Add=1, Sub=2, Mul=3)
|
70
|
16
|
|
17 class BinaryOperator(Instruction):
|
104
|
18 def __init__(self, operation, value1, value2):
|
110
|
19 assert value1
|
|
20 assert value2
|
157
|
21 #print('operation is in binops:', operation in BinOps)
|
104
|
22 # Check types of the two operands:
|
|
23 self.value1 = value1
|
|
24 self.value2 = value2
|
|
25 self.operation = operation
|
70
|
26
|
157
|
27 class AddInstruction(BinaryOperator):
|
|
28 def __init__(self, a, b):
|
|
29 super().__init__('add', a, b)
|
70
|
30
|
157
|
31 class ImmLoadInstruction(Instruction):
|
|
32 def __init__(self, value):
|
|
33 self.value = value
|
|
34
|