@@ -15,6 +15,8 @@ import Data.Char
15import Data.Function (on)
15import Data.Function (on)
16import qualified Data.Vector.Unboxed as V
16import qualified Data.Vector.Unboxed as V
18data Prim = Prim { p_name :: Name,
20data Prim = Prim { p_name :: Name,
19 p_type :: Type,
21 p_type :: Type,
20 p_arity :: Int,
22 p_arity :: Int,
@@ -165,6 +167,8 @@ primitives =
165 (2, LStrIndex) partial,
167 (2, LStrIndex) partial,
166 Prim (sUN "prim__strRev") (ty [StrType] StrType) 1 (p_strRev)
168 Prim (sUN "prim__strRev") (ty [StrType] StrType) 1 (p_strRev)
167 (1, LStrRev) total,
169 (1, LStrRev) total,
170+ Prim (sUN "prim__strSubstr") (ty [AType (ATInt ITNative), AType (ATInt ITNative), StrType] StrType) 3 (p_strSubstr)
171+ (3, LStrSubstr) total,
169 Prim (sUN "prim__readString") (ty [WorldType] StrType) 1 (p_cantreduce)
173 Prim (sUN "prim__readString") (ty [WorldType] StrType) 1 (p_cantreduce)
170 (1, LReadStr) total, -- total is okay, because we have 'WorldType'
174 (1, LReadStr) total, -- total is okay, because we have 'WorldType'
@@ -493,7 +497,7 @@ p_floatSqrt = p_fPrim sqrt
493p_floatFloor = p_fPrim (fromInteger . floor)
497p_floatFloor = p_fPrim (fromInteger . floor)
494p_floatCeil = p_fPrim (fromInteger . ceiling)
498p_floatCeil = p_fPrim (fromInteger . ceiling)
496−p_strLen, p_strHead, p_strTail, p_strIndex, p_strCons, p_strRev :: [Const] -> Maybe Const
500+p_strLen, p_strHead, p_strTail, p_strIndex, p_strCons, p_strRev, p_strSubstr :: [Const] -> Maybe Const
497p_strLen [Str xs] = Just $ I (length xs)
501p_strLen [Str xs] = Just $ I (length xs)
498p_strLen _ = Nothing
502p_strLen _ = Nothing
499p_strHead [Str (x:xs)] = Just $ Ch x
503p_strHead [Str (x:xs)] = Just $ Ch x
@@ -507,6 +511,9 @@ p_strCons [Ch x, Str xs] = Just $ Str (x:xs)
507p_strCons _ = Nothing
511p_strCons _ = Nothing
508p_strRev [Str xs] = Just $ Str (reverse xs)
512p_strRev [Str xs] = Just $ Str (reverse xs)
509p_strRev _ = Nothing
513p_strRev _ = Nothing
514+p_strSubstr [I offset, I length, Str input] = Just $ Str (take length (drop offset input))
515+p_strSubstr _ = Nothing
511p_cantreduce :: a -> Maybe b
518p_cantreduce :: a -> Maybe b
512p_cantreduce _ = Nothing
519p_cantreduce _ = Nothing