@@ -15,6 +15,8 @@ import Data.Char
1515import Data.Function (on)
1616import qualified Data.Vector.Unboxed as V
1717
18+import Debug.Trace
19+
1820data Prim = Prim { p_name :: Name,
1921 p_type :: Type,
2022 p_arity :: Int,
@@ -165,6 +167,8 @@ primitives =
165167 (2, LStrIndex) partial,
166168 Prim (sUN "prim__strRev") (ty [StrType] StrType) 1 (p_strRev)
167169 (1, LStrRev) total,
170+ Prim (sUN "prim__strSubstr") (ty [AType (ATInt ITNative), AType (ATInt ITNative), StrType] StrType) 3 (p_strSubstr)
171+ (3, LStrSubstr) total,
168172
169173 Prim (sUN "prim__readString") (ty [WorldType] StrType) 1 (p_cantreduce)
170174 (1, LReadStr) total, -- total is okay, because we have 'WorldType'
@@ -493,7 +497,7 @@ p_floatSqrt = p_fPrim sqrt
493497p_floatFloor = p_fPrim (fromInteger . floor)
494498p_floatCeil = p_fPrim (fromInteger . ceiling)
495499
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
497501p_strLen [Str xs] = Just $ I (length xs)
498502p_strLen _ = Nothing
499503p_strHead [Str (x:xs)] = Just $ Ch x
@@ -507,6 +511,9 @@ p_strCons [Ch x, Str xs] = Just $ Str (x:xs)
507511p_strCons _ = Nothing
508512p_strRev [Str xs] = Just $ Str (reverse xs)
509513p_strRev _ = Nothing
514+p_strSubstr [I offset, I length, Str input] = Just $ Str (take length (drop offset input))
515+p_strSubstr _ = Nothing
516+
510517
511518p_cantreduce :: a -> Maybe b
512519p_cantreduce _ = Nothing