Fixed the behaviour of the right-shift operator to match how it should work in occam
This commit is contained in:
parent
5807c59edf
commit
0f437dcf0e
|
@ -263,6 +263,15 @@ cgetScalarType A.Timer = Just "Time"
|
|||
cgetScalarType A.Time = Just "Time"
|
||||
cgetScalarType _ = Nothing
|
||||
|
||||
cgetUnsignedType :: A.Type -> Maybe String
|
||||
cgetUnsignedType t | elem t [A.Byte, A.UInt16, A.UInt32, A.UInt64] = cgetScalarType t
|
||||
cgetUnsignedType A.Int8 = cgetScalarType A.Byte
|
||||
cgetUnsignedType A.Int = cgetScalarType A.UInt32
|
||||
cgetUnsignedType A.Int16 = cgetScalarType A.UInt16
|
||||
cgetUnsignedType A.Int32 = cgetScalarType A.UInt32
|
||||
cgetUnsignedType A.Int64 = cgetScalarType A.UInt64
|
||||
cgetUnsignedType _ = Nothing
|
||||
|
||||
-- | Generate the C type corresponding to a variable being declared.
|
||||
-- It must be possible to use this in arrays.
|
||||
cgenType :: A.Type -> CGen ()
|
||||
|
@ -827,7 +836,18 @@ cgenDyadic _ A.Plus e f = call genSimpleDyadic "+" e f
|
|||
cgenDyadic _ A.Minus e f = call genSimpleDyadic "-" e f
|
||||
cgenDyadic _ A.Times e f = call genSimpleDyadic "*" e f
|
||||
cgenDyadic _ A.LeftShift e f = call genSimpleDyadic "<<" e f
|
||||
cgenDyadic _ A.RightShift e f = call genSimpleDyadic ">>" e f
|
||||
cgenDyadic m A.RightShift e f
|
||||
= do t <- typeOfExpression e
|
||||
(normalT, unsignedT) <- case (cgetScalarType t, cgetUnsignedType t) of
|
||||
(Just x, Just y) -> return (x,y)
|
||||
_ -> diePC m $ formatCode "Attempting to shift non-integer type: %" t
|
||||
if (normalT == unsignedT)
|
||||
then call genSimpleDyadic ">>" e f
|
||||
else do tell ["((", normalT, ")(((", unsignedT, ")"]
|
||||
call genExpression e
|
||||
tell [") >> "]
|
||||
call genExpression f
|
||||
tell ["))"]
|
||||
cgenDyadic _ A.BitAnd e f = call genSimpleDyadic "&" e f
|
||||
cgenDyadic _ A.BitOr e f = call genSimpleDyadic "|" e f
|
||||
cgenDyadic _ A.BitXor e f = call genSimpleDyadic "^" e f
|
||||
|
|
Loading…
Reference in New Issue
Block a user