From d751deedfdc2ba5fbeb72ede5754587a1f677835 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 4 Mar 2025 21:33:56 +0100 Subject: Compile: Fix right-precedence of (*) --- src/Compile.hs | 4 ++-- src/Interpreter.hs | 2 +- src/Language.hs | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Compile.hs b/src/Compile.hs index 7a846d4..0e6eee7 100644 --- a/src/Compile.hs +++ b/src/Compile.hs @@ -170,9 +170,9 @@ printCExpr d = \case ,(">", (5, (6, 6))) ,("<=", (5, (6, 6))) ,(">=", (5, (6, 6))) - ,("+", (6, (6, 6))) + ,("+", (6, (6, 7))) ,("-", (6, (6, 7))) - ,("*", (7, (7, 7))) + ,("*", (7, (7, 8))) ,("/", (7, (7, 8))) ,("%", (7, (7, 8)))] diff --git a/src/Interpreter.hs b/src/Interpreter.hs index dd558fe..d80a76e 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -173,7 +173,7 @@ interpretOp op arg = case op of ORecip st -> floatingIsFractional st $ recip arg OExp st -> floatingIsFractional st $ exp arg OLog st -> floatingIsFractional st $ log arg - OIDiv st -> integralIsIntegral st $ uncurry div arg + OIDiv st -> integralIsIntegral st $ uncurry quot arg where styIsEq :: SScalTy t -> (Eq (Rep (TScal t)) => r) -> r styIsEq STI32 = id diff --git a/src/Language.hs b/src/Language.hs index 70cc4f9..810a889 100644 --- a/src/Language.hs +++ b/src/Language.hs @@ -182,9 +182,11 @@ not_ = oper ONot and_ :: NExpr env (TScal TBool) -> NExpr env (TScal TBool) -> NExpr env (TScal TBool) and_ = oper2 OAnd +infixr 3 `and_` or_ :: NExpr env (TScal TBool) -> NExpr env (TScal TBool) -> NExpr env (TScal TBool) or_ = oper2 OOr +infixr 2 `or_` -- | The first alternative is the True case; the second is the False case. if_ :: NExpr env (TScal TBool) -> NExpr env t -> NExpr env t -> NExpr env t @@ -198,3 +200,4 @@ toFloat_ = oper OToFl64 idiv :: (KnownScalTy t, ScalIsIntegral t ~ True) => NExpr env (TScal t) -> NExpr env (TScal t) -> NExpr env (TScal t) idiv = oper2 (OIDiv knownScalTy) +infixl 7 `idiv` -- cgit v1.2.3-70-g09d2