Skip to content

Commit

Permalink
Use 'arg' rather than 'funArg'.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Pike committed Jan 31, 2012
1 parent 483e7be commit 61fba52
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 54 deletions.
14 changes: 7 additions & 7 deletions src/Copilot/Language/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Copilot.Language.Analyze

import Copilot.Core (DropIdx)
import qualified Copilot.Core as C
import Copilot.Language.Stream (Stream (..), FunArg (..))
import Copilot.Language.Stream (Stream (..), Arg (..))
import Copilot.Language.Spec
import Copilot.Language.Error (badUsage)

Expand Down Expand Up @@ -90,8 +90,8 @@ analyzeTrigger refStreams (Trigger _ e0 args) =
analyzeExpr refStreams e0 >> mapM_ analyzeTriggerArg args

where
analyzeTriggerArg :: TriggerArg -> IO ()
analyzeTriggerArg (TriggerArg e) = analyzeExpr refStreams e
analyzeTriggerArg :: Arg -> IO ()
analyzeTriggerArg (Arg e) = analyzeExpr refStreams e

--------------------------------------------------------------------------------

Expand Down Expand Up @@ -130,7 +130,7 @@ analyzeExpr refStreams s = do
Nothing -> return ()
Just e -> go seenExt nodes' e
checkArgs = case seenExt of
NoExtern -> mapM_ (\(FunArg a) ->
NoExtern -> mapM_ (\(Arg a) ->
go SeenFun nodes' a) args
SeenFun -> throw NestedExternFun
SeenArr -> throw NestedArray
Expand Down Expand Up @@ -284,7 +284,7 @@ specExts refStreams spec = do
triggerExts :: ExternEnv -> Trigger -> IO ExternEnv
triggerExts env (Trigger _ guard args) = do
env' <- collectExts refStreams guard env
foldM (\env'' (TriggerArg arg_) -> collectExts refStreams arg_ env'')
foldM (\env'' (Arg arg_) -> collectExts refStreams arg_ env'')
env' args

collectExts :: C.Typed a => IORef Env -> Stream a -> ExternEnv -> IO ExternEnv
Expand Down Expand Up @@ -312,9 +312,9 @@ collectExts refStreams stream_ env_ = do
env' <- case me of
Nothing -> return env
Just e -> go nodes env e
env'' <- foldM (\env'' (FunArg arg_) -> go nodes env'' arg_)
env'' <- foldM (\env'' (Arg arg_) -> go nodes env'' arg_)
env' args
let argTypes = map (\(FunArg arg_) -> getSimpleType arg_) args
let argTypes = map (\(Arg arg_) -> getSimpleType arg_) args
let fun = (name, getSimpleType stream)
return env'' { externFunEnv = fun : externFunEnv env''
, externFunArgs = (name, argTypes) : externFunArgs env''
Expand Down
10 changes: 5 additions & 5 deletions src/Copilot/Language/Operators/Extern.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module Copilot.Language.Operators.Extern
, externI64
, externF
, externD
, FunArg
, externFun
, externArray
, externArrayB
Expand All @@ -31,7 +30,7 @@ module Copilot.Language.Operators.Extern
, externArrayI64
, externArrayF
, externArrayD
, funArg
, funArg -- ^ Deprecated.
) where

import Copilot.Core (Typed)
Expand All @@ -46,15 +45,16 @@ type Size = Int
extern :: Typed a => String -> Maybe [a] -> Stream a
extern = Extern

externFun :: Typed a => String -> [FunArg] -> Maybe (Stream a) -> Stream a
externFun :: Typed a => String -> [Arg] -> Maybe (Stream a) -> Stream a
externFun = ExternFun

externArray :: (Typed a, Typed b, Integral a)
=> String -> Stream a -> Size -> Maybe [[b]] -> Stream b
externArray = ExternArray

funArg :: Typed a => Stream a -> FunArg
funArg = FunArg
-- | Deprecated.
funArg :: Typed a => Stream a -> Arg
funArg = Arg

--------------------------------------------------------------------------------

Expand Down
10 changes: 5 additions & 5 deletions src/Copilot/Language/Reify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Copilot.Core (Typed, Type, Id, typeOf, impossible)
--import Copilot.Language.Reify.Sharing (makeSharingExplicit)
import Copilot.Language.Analyze (analyze)
import Copilot.Language.Spec
import Copilot.Language.Stream (Stream (..), FunArg (..))
import Copilot.Language.Stream (Stream (..), Arg (..))

import Prelude hiding (id)
import Data.IORef
Expand Down Expand Up @@ -83,8 +83,8 @@ mkTrigger refMkId refStreams refMap (Trigger name guard args) = do

where

mkTriggerArg :: TriggerArg -> IO Core.UExpr
mkTriggerArg (TriggerArg e) = do
mkTriggerArg :: Arg -> IO Core.UExpr
mkTriggerArg (Arg e) = do
w <- mkExpr refMkId refStreams refMap e
return $ Core.UExpr typeOf w

Expand Down Expand Up @@ -181,8 +181,8 @@ mkExpr refMkId refStreams refMap = go

------------------------------------------------------

mkFunArg :: FunArg -> IO Core.UExpr
mkFunArg (FunArg e) = do
mkFunArg :: Arg -> IO Core.UExpr
mkFunArg (Arg e) = do
w <- mkExpr refMkId refStreams refMap e
return $ Core.UExpr typeOf w

Expand Down
37 changes: 6 additions & 31 deletions src/Copilot/Language/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module Copilot.Language.Spec
, observer
, observers
, Trigger (..)
, TriggerArg (..)
, triggers
, trigger
, arg
Expand Down Expand Up @@ -67,50 +66,26 @@ data SpecItem
--------------------------------------------------------------------------------

data Observer where
Observer
:: Typed a
=> String
-> Stream a
-> Observer
Observer :: Typed a => String -> Stream a -> Observer

--------------------------------------------------------------------------------

observer
:: Typed a
=> String
-> Stream a
-> Spec
observer :: Typed a => String -> Stream a -> Spec
observer name e = tell [ObserverItem $ Observer name e]

--------------------------------------------------------------------------------

data Trigger where
Trigger
:: Core.Name
-> Stream Bool
-> [TriggerArg]
-> Trigger
Trigger :: Core.Name -> Stream Bool -> [Arg] -> Trigger

--------------------------------------------------------------------------------

data TriggerArg where
TriggerArg
:: Typed a
=> Stream a
-> TriggerArg

--------------------------------------------------------------------------------

trigger
:: String
-> Stream Bool
-> [TriggerArg]
-> Spec
trigger :: String -> Stream Bool -> [Arg] -> Spec
trigger name e args = tell [TriggerItem $ Trigger name e args]

--------------------------------------------------------------------------------

arg :: Typed a => Stream a -> TriggerArg
arg = TriggerArg
arg :: Typed a => Stream a -> Arg
arg = Arg

--------------------------------------------------------------------------------
12 changes: 6 additions & 6 deletions src/Copilot/Language/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
-- Copyright © 2011 National Institute of Aerospace / Galois, Inc.
--------------------------------------------------------------------------------

-- |
-- | Abstract syntax for streams and operators.

{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE Rank2Types #-}

module Copilot.Language.Stream
( Stream (..)
, FunArg (..)
( Stream (..)
, Arg (..)
) where

import Copilot.Core (Typed, typeOf)
Expand All @@ -30,7 +30,7 @@ data Stream :: * -> * where
Extern :: Typed a
=> String -> Maybe [a] -> Stream a
ExternFun :: Typed a
=> String -> [FunArg] -> Maybe (Stream a) -> Stream a
=> String -> [Arg] -> Maybe (Stream a) -> Stream a
ExternArray :: (Typed a, Typed b, Integral a)
=> String -> Stream a -> Int -> Maybe [[b]] -> Stream b
Local :: (Typed a, Typed b)
Expand All @@ -46,8 +46,8 @@ data Stream :: * -> * where

--------------------------------------------------------------------------------

data FunArg where
FunArg :: Typed a => Stream a -> FunArg
data Arg where
Arg :: Typed a => Stream a -> Arg

--------------------------------------------------------------------------------

Expand Down

0 comments on commit 61fba52

Please sign in to comment.