Appearance
| 1 | namespace IR.Values is | |
| 2 | use TypeTyped = Semantic.Types.Typed; | |
| 3 | use Semantic.Types.Type; | |
| 4 | ||
| 5 | class COMPARE_ORDER_TO_ZERO: Value, TypeTyped is | |
| 6 | value: Value; | |
| 7 | actual_operation: string?; | |
| 8 | type: Type; | |
| 9 | ||
| 10 | is_value_type: bool => true; | |
| 11 | ||
| 12 | init(value: Value, actual_operation: string?, type: Type) is | |
| 13 | super.init(); | |
| 14 | ||
| 15 | self.value = value; | |
| 16 | self.actual_operation = actual_operation; | |
| 17 | self.type = type; | |
| 18 | si | |
| 19 | ||
| 20 | gen(context: IR.CONTEXT) is | |
| 21 | let instruction: string mut; | |
| 22 | let needs_not mut = false; | |
| 23 | ||
| 24 | if actual_operation =~ ">" then | |
| 25 | instruction = "cgt"; | |
| 26 | elif actual_operation =~ ">=" then | |
| 27 | instruction = "clt"; | |
| 28 | needs_not = true; | |
| 29 | elif actual_operation =~ "<" then | |
| 30 | instruction = "clt"; | |
| 31 | elif actual_operation =~ "<=" then | |
| 32 | instruction = "cgt"; | |
| 33 | needs_not = true; | |
| 34 | else | |
| 35 | throw System.Exception("unexpected compare order operation: {actual_operation}"); | |
| 36 | fi | |
| 37 | ||
| 38 | Value.gen(value, context); | |
| 39 | ||
| 40 | context.write_line("ldc.i4 0"); | |
| 41 | context.write_line(instruction); | |
| 42 | ||
| 43 | if needs_not then | |
| 44 | context.write_line("ldc.i4 0"); | |
| 45 | context.write_line("ceq"); | |
| 46 | fi | |
| 47 | si | |
| 48 | ||
| 49 | to_string() -> string => | |
| 50 | "compare-order-to-zero[{actual_operation}]({value})"; | |
| 51 | si | |
| 52 | si |