@@ -225,12 +225,19 @@ vecOps ity@(ITVec elem count) =
225225 [ Prim (UN $ "prim__mk" ++ intTyName ity)
226226 (ty (replicate count . AType . ATInt . ITFixed $ elem) (AType . ATInt $ ity))
227227 count (mkVecCon elem count) (count, LMkVec elem count) total
228+ , Prim (UN $ "prim__index" ++ intTyName ity)
229+ (ty [AType . ATInt $ ity, AType (ATInt (ITFixed IT32))] (AType . ATInt . ITFixed $ elem))
230+ 2 (mkVecIndex count) (2, LIdxVec elem count) partial -- TODO: Ensure this reduces
231+ , Prim (UN $ "prim__update" ++ intTyName ity)
232+ (ty [AType . ATInt $ ity, AType (ATInt (ITFixed IT32)), AType . ATInt . ITFixed $ elem]
233+ (AType . ATInt $ ity))
234+ 3 (mkVecUpdate elem count) (3, LUpdateVec elem count) partial -- TODO: Ensure this reduces
228235 ] ++ intArith ity
229236
230−mkVecCon :: IntTy -> Int -> [Const] -> Const
231−mkVecCon ity count args = if length ints == count
232− then Just (mkVec ity count ints)
233− else error $ "Got: " ++ show args ++ " when expecting " ++ show count ++ " x " ++ show ity
237+mkVecCon :: NativeTy -> Int -> [Const] -> Maybe Const
238+mkVecCon ity count args
239+ | length ints == count = Just (mkVec ity count ints)
240+ | otherwise = Nothing
234241 where
235242 ints = getInt args
236243 mkVec :: NativeTy -> Int -> [Integer] -> Const
@@ -239,6 +246,23 @@ mkVecCon ity count args = if length ints == count
239246 mkVec IT32 len values = B32V $ V.generate len (fromInteger . (values !!))
240247 mkVec IT64 len values = B64V $ V.generate len (fromInteger . (values !!))
241248
249+mkVecIndex count [vec, B32 i] = Just (idxVec vec)
250+ where
251+ idxVec :: Const -> Const
252+ idxVec (B8V v) = B8 $ V.unsafeIndex v (fromIntegral i)
253+ idxVec (B16V v) = B16 $ V.unsafeIndex v (fromIntegral i)
254+ idxVec (B32V v) = B32 $ V.unsafeIndex v (fromIntegral i)
255+ idxVec (B64V v) = B64 $ V.unsafeIndex v (fromIntegral i)
256+mkVecIndex _ _ = Nothing
257+
258+mkVecUpdate ity count [vec, B32 i, newElem] = updateVec vec newElem
259+ where
260+ updateVec :: Const -> Const -> Maybe Const
261+ updateVec (B8V v) (B8 e) = Just . B8V $ V.unsafeUpdate v (V.singleton (fromIntegral i, e))
262+ updateVec (B16V v) (B16 e) = Just . B16V $ V.unsafeUpdate v (V.singleton (fromIntegral i, e))
263+ updateVec (B32V v) (B32 e) = Just . B32V $ V.unsafeUpdate v (V.singleton (fromIntegral i, e))
264+ updateVec (B64V v) (B64 e) = Just . B64V $ V.unsafeUpdate v (V.singleton (fromIntegral i, e))
265+
242266intTyName :: IntTy -> String
243267intTyName ITNative = "Int"
244268intTyName ITBig = "BigInt"
@@ -302,7 +326,7 @@ bsrem (ITVec IT8 _) [B8V x, B8V y]
302326 = Just . B8V $
303327 V.zipWith (\n d -> (fromIntegral (fromIntegral n `rem` fromIntegral d :: Int8))) x y
304328bsrem (ITVec IT16 _) [B16V x, B16V y]
305− = Just . VConstant . B16V $
329+ = Just . B16V $
306330 V.zipWith (\n d -> (fromIntegral (fromIntegral n `rem` fromIntegral d :: Int16))) x y
307331bsrem (ITVec IT32 _) [B32V x, B32V y]
308332 = Just . B32V $