Permalink
Browse files

Update external functions example to work with latest release.

  • Loading branch information...
1 parent 4dd6a6d commit 1d2215ec8769f9c9de630a446ec7d9dd1935a461 @leepike committed Dec 30, 2011
Showing with 21 additions and 12 deletions.
  1. +21 −12 Examples/ExtFuns.hs
View
@@ -10,21 +10,34 @@ module Main where
import Language.Copilot
import qualified Copilot.Compile.C99 as C
+
--------------------------------------------------------------------------------
nats :: Stream Word16
nats = [0] ++ nats + 1
+---------------------------------------------------------------------------------
+-- Function func0 and it's environment for interpreting
+
func0 :: Stream Word16
-func0 = externFun "func0" [ funArg $ externW8 "x"
- , funArg nats]
+func0 = externFun "func0" [ funArg $ externW8 "x", funArg nats ]
+ (Just $ cast (externW8 "x") + nats)
+
+---------------------------------------------------------------------------------
+-- Function func0 with another set of args and it's environment for interpreting
+
+func2 :: Stream Word16
+func2 = externFun "func0" [ funArg $ constW8 3, funArg $ constW16 4 ]
+ (Just $ constW16 4 + 1)
+
+---------------------------------------------------------------------------------
+---------------------------------------------------------------------------------
+-- Function func1 and it's environment for interpreting
func1 :: Stream Bool
-func1 = externFun "func1" []
+func1 = externFun "func1" [] (Just $ [False] ++ not func1)
-func2 :: Stream Word16
-func2 = externFun "func0" [ funArg $ constW8 3
- , funArg $ constW16 4]
+---------------------------------------------------------------------------------
a :: Stream Word16
a = func0 + func0
@@ -36,12 +49,8 @@ spec = trigger "trigger" true [ arg func0
main :: IO ()
main = do
- reify spec >>= C.compile C.defaultParams
- -- Reference implementations of our functions
- interpret 10 [ func "func0" (cast (externW8 "x") + nats)
- , var "x" ([0..] :: [Word8])
- , func "func1" ([False] ++ not func1)
- ]
+-- reify spec >>= C.compile C.defaultParams
+ interpret 10 [ var "x" ([0..] :: [Word8]) ]
spec
--------------------------------------------------------------------------------

0 comments on commit 1d2215e

Please sign in to comment.