diff --git a/.gitignore b/.gitignore index 76400796..cfa8616e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ /out/main.c /.DS_Store /Carp.prof +dist/ diff --git a/CarpHask.cabal b/CarpHask.cabal index 200fea3c..1d02ba9b 100644 --- a/CarpHask.cabal +++ b/CarpHask.cabal @@ -17,7 +17,7 @@ library hs-source-dirs: src exposed-modules: Obj, Parsing, - Infer, + Infer, Emit, ColorText, Constraints, @@ -35,7 +35,7 @@ library Polymorphism, Concretize, ArrayTemplates - + build-depends: base >= 4.7 && < 5 , parsec == 3.1.* , mtl @@ -43,7 +43,7 @@ library , process , directory , split - + default-language: Haskell2010 executable carp @@ -53,6 +53,7 @@ executable carp build-depends: base , CarpHask , containers + , haskeline , process default-language: Haskell2010 diff --git a/README.md b/README.md index 49d42bd3..68f9fe29 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ To build this example, save it to a file called 'example.carp' and load it with * Reini Urban * Anes Lihovac * Jonas Granquist +* Veit Heller ## License diff --git a/app/Main.hs b/app/Main.hs index 089eec98..186cd37c 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,8 +1,10 @@ module Main where import Control.Monad +import Control.Monad.IO.Class +import System.Console.Haskeline (getInputLine, InputT, runInputT, defaultSettings) import qualified System.Environment as SystemEnvironment -import System.IO (hFlush, stdout) +import System.IO (stdout) import System.Info (os) import qualified Data.Map as Map import ColorText @@ -25,16 +27,19 @@ defaultProject = Project { projectTitle = "Untitled" , projectPrompt = if os == "darwin" then "鲮 " else "> " } -repl :: Context -> String -> IO () +repl :: Context -> String -> InputT IO () repl context readSoFar = - do putStrWithColor Yellow (if null readSoFar then (projectPrompt (contextProj context)) else " ") -- 鲤 / 鲮 - hFlush stdout - input <- fmap (\s -> readSoFar ++ s ++ "\n") getLine - case balance input of - 0 -> do let input' = if input == "\n" then contextLastInput context else input - context' <- executeString context input' "REPL" - repl (context' { contextLastInput = input' }) "" - _ -> repl context input + do let prompt = strWithColor Yellow (if null readSoFar then (projectPrompt (contextProj context)) else " ") -- 鲤 / 鲮 + input <- (getInputLine prompt) + case input of + Nothing -> return () + Just i -> do + let concat = readSoFar ++ i ++ "\n" + case balance concat of + 0 -> do let input' = if concat == "\n" then contextLastInput context else concat + context' <- liftIO $ executeString context input' "REPL" + repl (context' { contextLastInput = input' }) "" + _ -> repl context concat arrayModule :: Env arrayModule = Env { envBindings = bindings, envParent = Nothing, envModuleName = Just "Array", envUseModules = [], envMode = ExternalEnv } @@ -101,5 +106,5 @@ main = do putStrLn "Welcome to Carp 0.2.0" context <- foldM executeCommand (Context startingGlobalEnv (TypeEnv startingTypeEnv) [] projectWithCarpDir "") (map Load (preludeModules (projectCarpDir projectWithCarpDir))) context' <- foldM executeCommand context (map Load args) - repl context' "" - + runInputT defaultSettings (repl context' "") + diff --git a/docs/Presentation.md b/docs/Presentation.md index 04f2fb4b..ab838eac 100644 --- a/docs/Presentation.md +++ b/docs/Presentation.md @@ -1,3 +1,5 @@ + + # Introduction to Carp --- @@ -413,9 +415,9 @@ Will allocate new memory and leave the old data as-is. ``` (let [xs [1 2 3 4 5]] - (transform Int.str &xs)) + (copy-map Int.str &xs)) -transform : (λ [(λ [a] b) (Ref (Array a))] (Array b)) ;; This type might be buggy!!! +copy-map : (λ [(λ [a] b) (Ref (Array a))] (Array b)) ;; This type might be buggy!!! ``` --- @@ -423,10 +425,10 @@ transform : (λ [(λ [a] b) (Ref (Array a))] (Array b)) ;; This type might be bu ``` (let [xs [1 2 3 4 5]] - (map square xs)) + (endo-map square xs)) ``` -Ownership of 'xs' is passed to the map function, which will mutate the array and return it. +Ownership of 'xs' is passed to the 'endo-map' function, which will mutate the array and return it. --- # Behind the scenes diff --git a/docs/Todo.md b/docs/Todo.md index c7b92b38..b1561a33 100644 --- a/docs/Todo.md +++ b/docs/Todo.md @@ -32,6 +32,7 @@ * Splicing in macros * Pattern matching on arguments in macros? * 'not=' function/macro +* Some lists and similar things generated by built in dynamic functions like 'cons' etc don't create proper Info for their XObjs ## Language Design Considerations * What's the correct type of the variable in a set!-form, i.e. (set! &x value) or (set! x value) @@ -51,7 +52,6 @@ * Enable printing of typed AST:s at the REPL to help debug unresolved type variables etc. * Proper error handling when defining invalid struct types (right now it crashes) * Stop evalutaion of forms after errors to avoid "Trying to refer to undefined symbol" error -* Built in REPL history (without using rlwrap) * Preserve whitespace to allow saving forms back to disk * Refactorings at the REPL. Rename, extract function, add/remove parameter? * Hide instances of templates/generic functions when printing the environment (by default, allow it as a setting)