berp 0.0.1 → 0.0.2
raw patch · 5 files changed
+76/−27 lines, 5 filesdep −integerdep ~arraydep ~basedep ~containers
Dependencies removed: integer
Dependency ranges changed: array, base, containers, ghc, monads-tf, transformers
Files
- berp.cabal +12/−13
- src/Berp/Base/Hash.hs +6/−3
- src/Berp/Base/Unique.hs +38/−3
- src/Berp/Compile/Compile.hs +6/−5
- src/Berp/Interpreter/Input.hs +14/−3
berp.cabal view
@@ -1,5 +1,5 @@ name: berp-version: 0.0.1+version: 0.0.2 cabal-version: >= 1.6 synopsis: An implementation of Python 3. description: Berp is an implementation of Python 3, written in Haskell.@@ -32,14 +32,14 @@ base == 4.*, monads-tf == 0.1.*, transformers == 0.2.*,- containers == 0.2.*,+ containers < 0.4, language-python == 0.3.*, haskell-src-exts == 1.9.*, parseargs == 0.1.*, process == 1.0.*, filepath == 1.1.*, directory == 1.0.*,- ghc >= 6.10.4,+ ghc >= 6.10, haskeline == 0.6.*, ghc-paths == 0.1.*, extensible-exceptions == 0.1.*@@ -59,18 +59,17 @@ Library ghc-options: -Wall -fno-warn-name-shadowing -fno-warn-orphans include-dirs:- src/include + src/include hs-source-dirs:- src+ src build-depends:- base,- monads-tf,- transformers,- containers,- ghc-prim,- integer,- template-haskell,- array+ base == 4.*,+ monads-tf == 0.1.*,+ transformers == 0.2.*,+ containers < 0.4,+ ghc-prim,+ template-haskell,+ array < 0.4 exposed-modules: Berp.Base Berp.Base.Hash
src/Berp/Base/Hash.hs view
@@ -18,8 +18,6 @@ import Berp.Base.Mangle (mangle) import Language.Haskell.TH import Data.HashTable as HT (hashString)-import GHC.Integer (hashInteger)-import GHC.Types (Int (..)) type Hashed a = (Int, a) @@ -30,10 +28,15 @@ hash = fromIntegral . HT.hashString instance Hash Integer where- hash i = I# (hashInteger i)+ -- hash i = I# (hashInteger i)+ hash = hashInteger hashedStr :: String -> Q Exp hashedStr str = [| (n, mangle str) |] where n :: Int n = hash str++-- XXX May need to reconsider this. We'll want something which is fast.+hashInteger :: Integer -> Int+hashInteger i = fromInteger (i `mod` (toInteger (maxBound :: Int)))
src/Berp/Base/Unique.hs view
@@ -3,9 +3,10 @@ ----------------------------------------------------------------------------- -- | -- Module : Berp.Base--- Copyright : (c) 2010 Bernie Pope--- License : BSD-style--- Maintainer : florbitous@gmail.com+-- Copyright : (c) Copyright 2002, The University Court of the University +-- of Glasgow. All rights reserved. +-- License : See the GHC license below. +-- Maintainer : (of this branch) florbitous@gmail.com -- Stability : experimental -- Portability : ghc --@@ -13,6 +14,40 @@ -- Same as the version in GHC but with added show instance. -- -----------------------------------------------------------------------------++{-+The Glasgow Haskell Compiler License++Copyright 2002, The University Court of the University of Glasgow. +All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++- Redistributions of source code must retain the above copyright notice,+this list of conditions and the following disclaimer.+ +- Redistributions in binary form must reproduce the above copyright notice,+this list of conditions and the following disclaimer in the documentation+and/or other materials provided with the distribution.+ +- Neither name of the University nor the names of its contributors may be+used to endorse or promote products derived from this software without+specific prior written permission. ++THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY COURT OF THE UNIVERSITY OF+GLASGOW AND THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE+UNIVERSITY COURT OF THE UNIVERSITY OF GLASGOW OR THE CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH+DAMAGE.+-} module Berp.Base.Unique (
src/Berp/Compile/Compile.hs view
@@ -16,12 +16,13 @@ module Berp.Compile.Compile (compiler, Compilable (..)) where import Prelude hiding (read, init, mapM, putStrLn)+import Language.Python.Common.PrettyAST ()+import Language.Python.Common.Pretty (prettyText) import Language.Python.Common.AST as Py import Data.Traversable import Data.Foldable (foldrM) import Language.Haskell.Exts.Syntax as Hask import Language.Haskell.Exts.Build--- import Language.Haskell.Exts.Pretty import Control.Applicative import qualified Data.Set as Set import Data.Set ((\\))@@ -209,7 +210,7 @@ return (stmts1 ++ stmts2 ++ [newStmt]) compile (Break {}) = returnStmt Prim.break compile (Continue {}) = returnStmt Prim.continue- compile other = error $ "compile on " ++ show other ++ " unsupported"+ compile other = unsupported $ prettyText other docString :: SuiteSpan -> Exp docString (StmtExpr { stmt_expr = Strings { strings_strings = ss }} : _)@@ -301,7 +302,7 @@ return (stmts, newExpr) compile (Py.Paren { paren_expr = e }) = compile e compile (None {}) = returnExp Prim.none- compile other = unsupported $ "compile: " ++ show other+ compile other = unsupported $ prettyText other compileTailCall :: ExprSpan -> Compile ([Stmt], Exp) compileTailCall (Call { call_fun = fun, call_args = args }) = do@@ -315,7 +316,7 @@ instance Compilable ArgumentSpan where type (CompileResult ArgumentSpan) = ([Stmt], Exp) compile (ArgExpr { arg_expr = expr }) = compileExprObject expr- compile other = unsupported $ show other+ compile other = unsupported $ prettyText other newtype Block = Block [StatementSpan] newtype TopBlock = TopBlock [StatementSpan]@@ -405,7 +406,7 @@ (exprStmts, compiledExp) <- compileExprObject expr let newStmt = qualStmt $ infixApp (identToMangledVar ident) Prim.assignOp compiledExp return (exprStmts ++ [newStmt])-compileAssign e1 e2 = unsupported $ "assignment for " ++ show e1 ++ " and " ++ show e2 +compileAssign e1 e2 = unsupported $ unwords [prettyText e1, "=", prettyText e2] compileUnaryOp :: Py.OpSpan -> Hask.Exp compileUnaryOp (Plus {}) = Prim.unaryPlus
src/Berp/Interpreter/Input.hs view
@@ -12,6 +12,11 @@ -- Prompt for and read input lines. Handle input continuations for multi-line -- statemtents. --+-- Generally speaking this module is a pile of ugly hacks which approximate+-- what is supposed to happen. The need for hacks occurs because the lexer+-- isn't really cut out for what we want to do. At some point we'll need+-- to fix the lexer.+-- ----------------------------------------------------------------------------- module Berp.Interpreter.Input (getInputLines) where@@ -35,9 +40,10 @@ case maybeInput of Nothing -> return Nothing Just line- | null line -> return $ Just [] + | Right (tokens, _state) <- lexResult,+ null $ noComments tokens -> return $ Just [] | Right (tokens, state) <- lexResult,- lastTokenIsColon tokens -> do+ lastTokenIsColon $ noComments tokens -> do restLines <- getIndentContinueLines state [] return $ Just $ unlines (line:restLines) | Right (_tokens, state) <- lexResult,@@ -47,7 +53,12 @@ | otherwise -> return $ Just line where lexResult = runParser lexer $ lexState line+ noComments = filter (not . isComment) +isComment :: Token -> Bool+isComment (CommentToken {}) = True+isComment _other = False+ lastTokenIsColon :: [Token] -> Bool lastTokenIsColon [] = False lastTokenIsColon tokens = @@ -58,7 +69,7 @@ isColon _other = False nonEmptyParenStack :: ParseState -> Bool-nonEmptyParenStack state = not $ null $ parenStack state+nonEmptyParenStack = not . null . parenStack getIndentContinueLines :: ParseState -> [String] -> Repl [String] getIndentContinueLines state acc = do