Skip to content

Commit 8b25b9f

Browse files
committed
Factored out lexer and parser, added high level API modules.
Updated bindings generator. Moved to /opt/arrayfire includes and lib dirs. Renaming of package.
1 parent 925373d commit 8b25b9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1034
-562
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ result/
33
/TAGS
44
/result
55
*~
6+
/ctags

fire.cabal renamed to arrayfire.cabal

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: fire
1+
name: arrayfire
22
version: 0.1.0.0
33
synopsis: Haskell bindings to ArrayFire
44
description: High-level Haskell bindings to ArrayFire
@@ -15,35 +15,55 @@ cabal-version: >=1.10
1515

1616
library
1717
exposed-modules:
18+
ArrayFire.Arith
19+
ArrayFire.Array
20+
ArrayFire.Backend
21+
ArrayFire.BLAS
22+
ArrayFire.Data
23+
ArrayFire.Device
24+
ArrayFire.Exception
25+
ArrayFire.Graphics
26+
ArrayFire.LAPACK
27+
ArrayFire.Random
28+
ArrayFire.Statistics
29+
ArrayFire.Util
1830
ArrayFire.Internal.Algorithm
1931
ArrayFire.Internal.Arith
2032
ArrayFire.Internal.Array
2133
ArrayFire.Internal.Backend
2234
ArrayFire.Internal.BLAS
23-
ArrayFire.Internal.Complex
24-
ArrayFire.Internal.CUDA
35+
-- ArrayFire.Internal.CUDA
2536
ArrayFire.Internal.Data
2637
ArrayFire.Internal.Defines
2738
ArrayFire.Internal.Device
2839
ArrayFire.Internal.Exception
2940
ArrayFire.Internal.Features
3041
ArrayFire.Internal.Graphics
31-
ArrayFire.Internal.Images
42+
ArrayFire.Internal.Image
3243
ArrayFire.Internal.Index
3344
ArrayFire.Internal.Internal
3445
ArrayFire.Internal.LAPACK
35-
ArrayFire.Internal.OpenCL
46+
-- ArrayFire.Internal.OpenCL
3647
ArrayFire.Internal.Random
37-
ArrayFire.Internal.Seq
48+
-- ArrayFire.Internal.Seq
3849
ArrayFire.Internal.Signal
3950
ArrayFire.Internal.Sparse
4051
ArrayFire.Internal.Statistics
52+
ArrayFire.Internal.Types
4153
ArrayFire.Internal.Util
4254
ArrayFire.Internal.Vision
4355
build-tools:
4456
hsc2hs
4557
include-dirs:
46-
include
58+
/opt/arrayfire/include
59+
extra-lib-dirs:
60+
/opt/arrayfire/lib
61+
ld-options:
62+
-rpath /opt/arrayfire/lib
63+
cc-options:
64+
-fPIC
65+
extra-libraries:
66+
af
4767
build-depends:
4868
base < 5
4969
hs-source-dirs:
@@ -57,7 +77,7 @@ executable main
5777
main-is:
5878
Main.hs
5979
build-depends:
60-
base < 5, fire
80+
base < 5, arrayfire
6181
default-language:
6282
Haskell2010
6383

@@ -70,3 +90,8 @@ executable gen
7090
base < 5, parsec, text, directory
7191
default-language:
7292
Haskell2010
93+
other-modules:
94+
Lex
95+
Parse
96+
Print
97+
Types

default.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
{ pkgs ? import <nixpkgs> {} }: pkgs.haskellPackages.callPackage ./pkg.nix {}
1+
{ pkgs ? import <nixpkgs> {} }:
2+
pkgs.haskellPackages.callPackage ./pkg.nix {}

exe/Main.hs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
11
module Main where
22

3-
main = print 4
3+
import Control.Concurrent
4+
5+
import ArrayFire.Internal.Defines
6+
7+
import ArrayFire.Util
8+
import ArrayFire.Exception
9+
import ArrayFire.Device
10+
import ArrayFire.Data
11+
import ArrayFire.Arith
12+
import ArrayFire.Array
13+
import ArrayFire.LAPACK
14+
import ArrayFire.Backend
15+
import ArrayFire.Statistics
16+
import ArrayFire.Random
17+
import ArrayFire.Graphics
18+
import ArrayFire.BLAS
19+
20+
main :: IO ()
21+
main = do
22+
-- Info things
23+
-- print =<< getVersion
24+
-- getInfo
25+
-- print =<< errorToString afErrNoMem
26+
-- putStrLn =<< getInfoString
27+
-- print =<< getDeviceCount
28+
-- print =<< getDevice
29+
-- print =<< getRevision
30+
31+
-- -- Create and print an array
32+
-- arr1 <- constant 1 1 1 f64
33+
-- arr2 <- constant 2 1 1 f64
34+
-- r <- addArray arr1 arr2 True
35+
-- printArray r
36+
37+
-- print =<< isLAPACKAvailable
38+
-- print =<< getActiveBackend
39+
40+
-- w <- createWindow 300 300 "hey"
41+
-- showWindow w
42+
-- threadDelay (secs 10)
43+
44+
a1 <- randn 1 1 1 f64
45+
a2 <- randn 1 1 1 f64
46+
a3 <- matmul a1 a2 afMatNone afMatNone
47+
printArray a3
48+
49+
-- x <- constant 10 1 1 f64
50+
-- printArray =<< mean x 0
51+
52+
secs :: Int -> Int
53+
secs = (*1000000)

gen/Lex.hs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module Lex where
3+
4+
import Control.Arrow
5+
import Data.Text (Text)
6+
import qualified Data.Text as T
7+
8+
import Data.Char
9+
import Types
10+
11+
symbols :: String
12+
symbols = " *();,"
13+
14+
lex :: Text -> [Token]
15+
lex = go NameMode
16+
where
17+
tokenize ' ' = []
18+
tokenize '*' = [Star]
19+
tokenize '(' = [LParen]
20+
tokenize ')' = [RParen]
21+
tokenize ';' = [Semi]
22+
tokenize ',' = [Comma]
23+
tokenize _ = []
24+
go TokenMode xs = do
25+
case T.uncons xs of
26+
Nothing -> []
27+
Just (c,cs)
28+
| isAlpha c -> go NameMode (T.cons c cs)
29+
| otherwise -> tokenize c ++ go TokenMode cs
30+
go NameMode xs = do
31+
let (match, rest) = partition xs
32+
if match == "const"
33+
then [] ++ go TokenMode rest
34+
else Id match : go TokenMode rest
35+
36+
partition :: Text -> (Text,Text)
37+
partition =
38+
T.takeWhile (`notElem` symbols) &&&
39+
T.dropWhile (`notElem` symbols)

0 commit comments

Comments
 (0)