Skip to content

Commit

Permalink
Merge pull request #590 from HigherOrderCO/update
Browse files Browse the repository at this point in the history
Update Reduce and adjusting operator parsing
  • Loading branch information
VictorTaelin authored Oct 7, 2024
2 parents 558ebed + 37280a4 commit 5a7d727
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Kind/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ parseOper = P.choice
, P.try (string "*") >> return MUL
, P.try (string "/") >> return DIV
, P.try (string "%") >> return MOD
, P.try (string "<<") >> return LSH
, P.try (string ">>") >> return RSH
, P.try (string "<=") >> return LTE
, P.try (string ">=") >> return GTE
, P.try (string "<") >> return LT
Expand All @@ -356,8 +358,6 @@ parseOper = P.choice
, P.try (string "&") >> return AND
, P.try (string "|") >> return OR
, P.try (string "^") >> return XOR
, P.try (string "<<") >> return LSH
, P.try (string ">>") >> return RSH
]

parseBook :: Parser Book
Expand Down
7 changes: 6 additions & 1 deletion src/Kind/Reduce.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Kind.Reduce where

import Prelude hiding (EQ, LT, GT)
import Data.Bits ( (.&.), (.|.), xor, shiftL, shiftR )
import Data.Char (ord)
import Debug.Trace

import Kind.Type
import Kind.Show

Expand Down Expand Up @@ -67,6 +67,11 @@ reduce book fill lv term = red term where
op2 GT (Num fst) (Num snd) = Num (if fst > snd then 1 else 0)
op2 LTE (Num fst) (Num snd) = Num (if fst <= snd then 1 else 0)
op2 GTE (Num fst) (Num snd) = Num (if fst >= snd then 1 else 0)
op2 AND (Num fst) (Num snd) = Num (fst .&. snd)
op2 OR (Num fst) (Num snd) = Num (fst .|. snd)
op2 XOR (Num fst) (Num snd) = Num (fst `xor` snd)
op2 LSH (Num fst) (Num snd) = Num (shiftL fst (fromIntegral snd))
op2 RSH (Num fst) (Num snd) = Num (shiftR fst (fromIntegral snd))
op2 opr fst snd = Op2 opr fst snd

ref nam | lv > 0 = case M.lookup nam book of
Expand Down

0 comments on commit 5a7d727

Please sign in to comment.