Commit fcb5107c authored by Andrew Gibiansky's avatar Andrew Gibiansky

Adding static-canvas support; adding 7.6.3 bugfix N+1 for travis

parent ef3a4612
Copyright (c) 2015 Andrew Gibiansky
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import Distribution.Simple
main = defaultMain
-- Initial ihaskell-static-canvas.cabal generated by cabal init. For
-- further documentation, see http://haskell.org/cabal/users-guide/
-- The name of the package.
name: ihaskell-static-canvas
-- The package version. See the Haskell package versioning policy (PVP)
-- for standards guiding when and how versions should be incremented.
-- http://www.haskell.org/haskellwiki/Package_versioning_policy
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version: 0.1.0.0
-- A short (one-line) description of the package.
synopsis: IHaskell display for static-canvas
-- A longer description of the package.
-- description:
-- URL for the project homepage or repository.
homepage: http://www.github.com/gibiansky/IHaskell
-- The license under which the package is released.
license: MIT
-- The file containing the license text.
license-file: LICENSE
-- The package author(s).
author: Andrew Gibiansky
-- An email address to which users can send suggestions, bug reports, and
-- patches.
maintainer: andrew.gibiansky@gmail.com
-- A copyright notice.
-- copyright:
-- category:
build-type: Simple
-- Extra files to be distributed with the package, such as examples or a
-- README.
-- extra-source-files:
-- Constraint on the version of Cabal needed to build this package.
cabal-version: >=1.10
library
-- Modules exported by the library.
exposed-modules: IHaskell.Display.StaticCanvas
-- Modules included in this library but not exported.
-- other-modules:
-- LANGUAGE extensions used by modules in this package.
-- other-extensions:
-- Other library packages from which modules are imported.
build-depends: base >=4.7 && <4.8,
ihaskell >= 0.5,
static-canvas >= 0.2,
text >= 1.2
-- Directories containing source files.
hs-source-dirs: src
-- Base language which the package is written in.
default-language: Haskell2010
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
module IHaskell.Display.StaticCanvas (Canvas(..)) where
import Data.Text.Lazy.Builder (toLazyText)
import Data.Text.Lazy (unpack)
import Data.Text (pack, Text)
import System.IO.Unsafe
import Control.Concurrent.MVar
import Graphics.Static
import IHaskell.Display
{-# NOINLINE uniqueCounter #-}
uniqueCounter :: MVar Int
uniqueCounter = unsafePerformIO $ newMVar 0
getUniqueName :: IO Text
getUniqueName = do
val <- takeMVar uniqueCounter
let val' = val + 1
putMVar uniqueCounter val'
return $ pack $ "ihaskellStaticCanvasUniqueID" ++ show val
data Canvas = Canvas { width :: Int
, height :: Int
, canvas :: CanvasFree ()
}
instance IHaskellDisplay Canvas where
display cnv = do
name <- getUniqueName
let script = buildScript' (width cnv) (height cnv) name (canvas cnv)
return $ Display [html $ unpack $ toLazyText script]
...@@ -78,7 +78,7 @@ data ErrorOccurred = Success | Failure deriving (Show, Eq) ...@@ -78,7 +78,7 @@ data ErrorOccurred = Success | Failure deriving (Show, Eq)
-- | Enable debugging output -- | Enable debugging output
debug :: Bool debug :: Bool
debug = False debug = False
-- | Set GHC's verbosity for debugging -- | Set GHC's verbosity for debugging
ghcVerbosity :: Maybe Int ghcVerbosity :: Maybe Int
...@@ -193,8 +193,11 @@ initializeImports = do ...@@ -193,8 +193,11 @@ initializeImports = do
importFmt = "import IHaskell.Display.%s" importFmt = "import IHaskell.Display.%s"
dropFirstAndLast :: [a] -> [a]
dropFirstAndLast = reverse . drop 1 . reverse . drop 1
toImportStmt :: String -> String toImportStmt :: String -> String
toImportStmt = printf importFmt . concat . map capitalize . (drop 1) . split "-" toImportStmt = printf importFmt . concat . map capitalize . dropFirstAndLast . split "-"
displayImports = map toImportStmt displayPackages displayImports = map toImportStmt displayPackages
......
...@@ -318,8 +318,13 @@ cleanUpDuplicateInstances = modifySession $ \hscEnv -> ...@@ -318,8 +318,13 @@ cleanUpDuplicateInstances = modifySession $ \hscEnv ->
where where
instEq :: ClsInst -> ClsInst -> Bool instEq :: ClsInst -> ClsInst -> Bool
instEq ClsInst{is_tvs = tpl_tvs,is_tys = tpl_tys} ClsInst{is_tys = tpl_tys'} = instEq ClsInst{is_tvs = tpl_tvs,is_tys = tpl_tys} ClsInst{is_tys = tpl_tys'} =
#if MIN_VERSION_ghc(7,8,0)
-- Only support replacing instances on GHC 7.8 and up
let tpl_tv_set = mkVarSet tpl_tvs let tpl_tv_set = mkVarSet tpl_tvs
in isJust $ tcMatchTys tpl_tv_set tpl_tys tpl_tys' in isJust $ tcMatchTys tpl_tv_set tpl_tys tpl_tys'
#else
False
#endif
-- | Get the type of an expression and convert it to a string. -- | Get the type of an expression and convert it to a string.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment