Mercurial > lcfOS
comparison python/ppci/core/instruction.py @ 111:d3068efdf045
merge
author | Windel Bouwman |
---|---|
date | Fri, 04 Jan 2013 15:26:59 +0100 |
parents | 9e552d34bd60 |
children |
comparison
equal
deleted
inserted
replaced
109:ad14c7c52589 | 111:d3068efdf045 |
---|---|
1 | 1 |
2 from .value import Value | 2 from .value import Value |
3 | |
4 def Enum(**enums): | |
5 return type('Enum', (), enums) | |
3 | 6 |
4 class Instruction(Value): | 7 class Instruction(Value): |
5 """ Base class for all instructions. """ | 8 """ Base class for all instructions. """ |
6 pass | 9 pass |
7 | 10 |
8 class CallInstruction(Instruction): | 11 class CallInstruction(Instruction): |
9 pass | 12 def __init__(self, callee, arguments): |
13 super().__init__() | |
14 self.callee = callee | |
15 self.arguments = arguments | |
16 | |
17 BinOps = Enum(Add=1, Sub=2, Mul=3) | |
10 | 18 |
11 class BinaryOperator(Instruction): | 19 class BinaryOperator(Instruction): |
12 def __init__(self, operation, value1, value2): | 20 def __init__(self, operation, value1, value2): |
21 assert value1 | |
22 assert value2 | |
23 print('operation is in binops:', operation in BinOps) | |
13 # Check types of the two operands: | 24 # Check types of the two operands: |
14 self.value1 = value1 | 25 self.value1 = value1 |
15 self.value2 = value2 | 26 self.value2 = value2 |
16 self.operation = operation | 27 self.operation = operation |
17 | 28 |