RTP.hs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. module RTP where
  2. import RTS
  3. import qualified RTN
  4. import qualified Prelude
  5. -- import qualified RTS
  6. undefined = Prelude.undefined
  7. data Bool = False | True
  8. type Float = Prelude.Double
  9. -- newtype Float = FloatT { unboxFloat :: Prelude.Float}
  10. newtype Char = CharT { unboxChar :: Prelude.Char }
  11. _Int = ()
  12. _Float = ()
  13. _String = ()
  14. _Char = ()
  15. _primShowBool :: Bool -> Prelude.String
  16. _primShowBool False = "False"
  17. _primShowBool True = "True"
  18. _primShowInt :: Prelude.Int -> Prelude.String
  19. _primShowInt = Prelude.show
  20. _primIntZero :: Prelude.Int
  21. _primIntZero = (0::Prelude.Int)
  22. _primIntOne :: Prelude.Int
  23. _primIntOne = (1::Prelude.Int)
  24. _primIntAdd :: Prelude.Int -> Prelude.Int -> Prelude.Int
  25. _primIntAdd = (Prelude.+)
  26. _primIntSub :: Prelude.Int -> Prelude.Int -> Prelude.Int
  27. _primIntSub = (Prelude.-)
  28. _primIntMul :: Prelude.Int -> Prelude.Int -> Prelude.Int
  29. _primIntMul = (Prelude.*)
  30. _primIntDiv :: Prelude.Int -> Prelude.Int -> Prelude.Int
  31. _primIntDiv = (Prelude.div)
  32. _primIntMod :: Prelude.Int -> Prelude.Int -> Prelude.Int
  33. _primIntMod = (Prelude.mod)
  34. _primIntEquals :: Prelude.Int -> Prelude.Int -> Prelude.Bool
  35. _primIntEquals = (Prelude.==)
  36. _primIntLess :: Prelude.Int -> Prelude.Int -> Prelude.Bool
  37. _primIntLess = (Prelude.<)
  38. _int = _primNatToInt
  39. _primNatToInt RTN.C2 = (0::Prelude.Int)
  40. _primNatToInt (RTN.C3 n) = ( _primIntAdd (1::Prelude.Int) ( (_primNatToInt(cast n))))
  41. _primIntToNat 0 = zero
  42. _primIntToNat n | (Prelude.>) n (0 :: Prelude.Int) = suc (cast (_primIntToNat ( _primIntSub n (1::Prelude.Int))))
  43. | Prelude.otherwise = _primIntToNat (_primIntSub 0 n)
  44. _abs = _primIntToNat
  45. _primShowFloat :: Float -> Prelude.String
  46. _primShowFloat f = Prelude.show f
  47. -- _primShowFloat (FloatT f) = Prelude.show f
  48. _primShowChar c = [ unboxChar c]
  49. _primStringAppend :: Prelude.String -> Prelude.String -> Prelude.String
  50. _primStringAppend = (Prelude.++)
  51. _primStringReverse = Prelude.reverse
  52. _primStringToList s = Prelude.map CharT s
  53. _primStringFromList s = Prelude.map unboxChar s
  54. _primNatPlus m n = _abs (_primIntAdd (_int m) (_int n))
  55. _primNatMinus m n = _abs (_primIntSub (_int m) (_int n))
  56. _primNatTimes m n = _abs (_primIntMul (_int m) (_int n))
  57. _primNatDivSuc m n= _abs (_primIntDiv (_int m) (_int n))
  58. _primNatModSuc m n = _abs (_primIntMod (_int m) (_int n))
  59. _primNatLess m n = _primIntLess (_int m) (_int n)
  60. _primNatEquals m n = _primIntEquals (_int m) (_int n)
  61. -- For tests
  62. zero = RTN.C2
  63. suc = RTN.C3
  64. one = suc zero
  65. two = suc one