Implement << and >>

This commit is contained in:
Adam Sampson 2007-04-25 17:48:16 +00:00
parent 6d419c92c7
commit f8fa60d1ed
5 changed files with 24 additions and 2 deletions

View File

@ -122,6 +122,7 @@ data DyadicOp =
Add | Subtr | Mul | Div | Rem
| Plus | Minus | Times
| BitAnd | BitOr | BitXor
| LeftShift | RightShift
| And | Or
| Eq | NotEq | Less | More | LessEq | MoreEq
| After

View File

@ -427,6 +427,8 @@ genDyadic m A.Rem e f = genFuncDyadic m "rem" e f
genDyadic _ A.Plus e f = genSimpleDyadic "+" e f
genDyadic _ A.Minus e f = genSimpleDyadic "-" e f
genDyadic _ A.Times e f = genSimpleDyadic "*" e f
genDyadic _ A.LeftShift e f = genSimpleDyadic "<<" e f
genDyadic _ A.RightShift e f = genSimpleDyadic ">>" e f
genDyadic _ A.BitAnd e f = genSimpleDyadic "&" e f
genDyadic _ A.BitOr e f = genSimpleDyadic "|" e f
genDyadic _ A.BitXor e f = genSimpleDyadic "^" e f

View File

@ -53,6 +53,8 @@ occamStyle
"/\\",
"\\/",
"><",
"<<",
">>",
"=",
"<>",
"<",
@ -788,6 +790,10 @@ expression
t <- typeOfExpression l
r <- operandOfType t
return $ A.Dyadic m o l r
<|> do m <- md
(l, o) <- tryVV operand shiftOperator
r <- operandOfType A.Int
return $ A.Dyadic m o l r
<|> do m <- md
(l, o) <- tryVV (noTypeContext operand) comparisonOperator
t <- typeOfExpression l
@ -862,6 +868,13 @@ dyadicOperator
<|> do { sOR; return A.Or }
<?> "dyadic operator"
-- These always need an INT on their right-hand side.
shiftOperator :: OccParser A.DyadicOp
shiftOperator
= do { reservedOp "<<"; return A.LeftShift }
<|> do { reservedOp ">>"; return A.RightShift }
<?> "shift operator"
-- These always return a BOOL, so we have to deal with them specially for type
-- context.
comparisonOperator :: OccParser A.DyadicOp

View File

@ -27,8 +27,6 @@ Add an option for whether to compile out overflow/bounds checks.
The indentation parser is way too simplistic.
Shift counts aren't implemented.
Record literals aren't implemented.
## Passes

View File

@ -0,0 +1,8 @@
PROC P ()
INT a:
SEQ
a := 42
a := a << 4
a := a >> 4
a := a >> (a - 40)
: