From 8f26b393d14762e57c3b7a2fe0976855ae406de8 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Fri, 12 Apr 2024 16:40:10 +0200 Subject: [PATCH] nodes: add a TrueDivision node making use of the explicit IRDiv ir item --- compiler/nodes.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/compiler/nodes.py b/compiler/nodes.py index 84f426f..f0288a7 100644 --- a/compiler/nodes.py +++ b/compiler/nodes.py @@ -199,6 +199,23 @@ class Product(Node): return list(self.values) +class TrueDivision(Node): + def intermediate_representation(self) -> list[ir.IRItem]: + result: list[ir.IRAction] = [] + + values_results = Node._prepare_sources_ir(result=result, values=self.values) + dest = ir.IRRegister(location=self.location()) + result += [ir.IRDiv(self.location(), dest, *values_results)] + return result + + def __init__(self, *values: Value): + super().__init__() + self.values = values + + def _values(self) -> list[Node | Any]: + return list(self.values) + + class Division(Node): def intermediate_representation(self) -> list[ir.IRItem]: result: list[ir.IRAction] = [] @@ -228,7 +245,7 @@ class Division(Node): return [self.first_value] + list(self.values) -BinaryOperation = Sum | Sub | Product | Division +BinaryOperation = Sum | Sub | Product | Division | TrueDivision @typecheck