other arith
This commit is contained in:
@@ -19,6 +19,9 @@ data Expr = Var Name
|
|||||||
|
|
||||||
data Prim = IntP Int
|
data Prim = IntP Int
|
||||||
| IntAddP
|
| IntAddP
|
||||||
|
| IntSubP
|
||||||
|
| IntMulP
|
||||||
|
| IntDivP
|
||||||
| IntNegP
|
| IntNegP
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
||||||
|
|||||||
12
src/TI.hs
12
src/TI.hs
@@ -78,6 +78,9 @@ primitives :: [(Name, Prim)]
|
|||||||
primitives =
|
primitives =
|
||||||
[ ("negate#", IntNegP)
|
[ ("negate#", IntNegP)
|
||||||
, ("+#", IntAddP)
|
, ("+#", IntAddP)
|
||||||
|
, ("-#", IntSubP)
|
||||||
|
, ("*#", IntMulP)
|
||||||
|
, ("/#", IntDivP)
|
||||||
]
|
]
|
||||||
|
|
||||||
instantiate :: Expr -> TiHeap -> [(Name, Addr)] -> (TiHeap, Addr)
|
instantiate :: Expr -> TiHeap -> [(Name, Addr)] -> (TiHeap, Addr)
|
||||||
@@ -230,6 +233,9 @@ step st =
|
|||||||
arg = hLookupUnsafe argAddr h
|
arg = hLookupUnsafe argAddr h
|
||||||
|
|
||||||
primStep _ IntAddP st = primBinOp (+) st
|
primStep _ IntAddP st = primBinOp (+) st
|
||||||
|
primStep _ IntSubP st = primBinOp (-) st
|
||||||
|
primStep _ IntMulP st = primBinOp (*) st
|
||||||
|
primStep _ IntDivP st = primBinOp (div) st
|
||||||
|
|
||||||
primBinOp :: (Int -> Int -> Int) -> TiState -> TiState
|
primBinOp :: (Int -> Int -> Int) -> TiState -> TiState
|
||||||
primBinOp f (TiState s d h g sts) =
|
primBinOp f (TiState s d h g sts) =
|
||||||
@@ -356,6 +362,12 @@ negExample3 = Program
|
|||||||
"twice" :$ Prim IntNegP :$ Prim (IntP 3)
|
"twice" :$ Prim IntNegP :$ Prim (IntP 3)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
arithExample1 :: Program
|
||||||
|
arithExample1 = Program
|
||||||
|
[ ScDef "main" [] $
|
||||||
|
"+#" :$ (Prim $ IntP 3) :$ ("negate#" :$ (Prim $ IntP 2))
|
||||||
|
]
|
||||||
|
|
||||||
----------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------
|
||||||
|
|
||||||
instance Pretty TiState where
|
instance Pretty TiState where
|
||||||
|
|||||||
Reference in New Issue
Block a user