Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion copilot-language/src/Copilot/Language/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ analyzeAppend refStreams dstn e b f = do
-- append.
analyzeDrop :: Int -> Stream a -> IO ()
analyzeDrop k (Append xs _ _)
| k >= length xs = throw DropIndexOverflow
| k > length xs = throw DropIndexOverflow
| k > fromIntegral (maxBound :: DropIdx) = throw DropMaxViolation
| otherwise = return ()
analyzeDrop _ _ = throw DropAppliedToNonAppend
Expand Down
16 changes: 9 additions & 7 deletions copilot-language/src/Copilot/Language/Operators/Temporal.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-- Copyright © 2011 National Institute of Aerospace / Galois, Inc.

{-# LANGUAGE Safe #-}

-- | Temporal stream transformations.
Expand All @@ -11,7 +10,7 @@ module Copilot.Language.Operators.Temporal
import Copilot.Core (Typed)
import Copilot.Language.Prelude
import Copilot.Language.Stream
import Prelude ()
import Prelude ((==))

infixr 1 ++

Expand All @@ -32,8 +31,11 @@ infixr 1 ++
-- elements. For most kinds of streams, you cannot drop elements without
-- prepending an equal or greater number of elements to them first, as it
-- could result in undefined samples.
drop :: Typed a => Int -> Stream a -> Stream a
drop 0 s = s
drop _ ( Const j ) = Const j
drop i ( Drop j s ) = Drop (fromIntegral i + j) s
drop i s = Drop (fromIntegral i) s
drop :: (Typed a) => Int -> Stream a -> Stream a
drop 0 s = s
-- Along with simplifying the Stream, this also avoids the invalid C code
-- generated from append (array) and drop (indexing) when their lengths are the same
drop i ( Append a _ s ) | i == length a = s
drop _ ( Const j ) = Const j
drop i ( Drop j s ) = Drop (fromIntegral i + j) s
drop i s = Drop (fromIntegral i) s