Permalink
Browse files

WIP

  • Loading branch information...
1 parent 9781155 commit 32899b93eca8c64940e083f4e3febb93b80b1af5 @chrisdone chrisdone committed Sep 23, 2012
Showing with 34 additions and 22 deletions.
  1. +9 −4 fay.cabal
  2. +0 −5 js/runtime.js
  3. +2 −0 src/Language/Fay.hs
  4. +21 −4 src/Language/Fay/Core.hs
  5. +2 −9 src/Language/Fay/Print.hs
View
@@ -165,7 +165,9 @@ library
process,
filepath,
directory,
- groom
+ groom,
+ ghc,
+ split
if flag(devel)
build-depends:
@@ -205,7 +207,8 @@ executable fay
filepath,
groom,
options,
- haskeline
+ haskeline,
+ ghc
executable fay-tests
if !flag(devel)
@@ -238,7 +241,8 @@ executable fay-tests
groom,
test-framework,
test-framework-hunit,
- test-framework-th
+ test-framework-th,
+ ghc
executable fay-docs
if !flag(devel)
@@ -271,4 +275,5 @@ executable fay-docs
data-default,
safe,
language-ecmascript,
- groom
+ groom,
+ ghc
View
@@ -37,11 +37,6 @@ $.prototype.force = function(nocache) {
(this.value = this.value(), this.forced = true, this.value));
};
-// Eval in the context of the Haskell bindings.
-function Fay$$eval(str){
- return eval(str);
-}
-
/*******************************************************************************
* Monad.
*/
View
@@ -1223,3 +1223,5 @@ parseResult fail ok result =
-- | Get a config option.
config :: (CompileConfig -> a) -> Compile a
config f = gets (f . stateConfig)
+
+instance IsString Name where fromString = Ident
View
@@ -5,12 +5,14 @@ module Language.Fay.Core where
import Control.Monad
import Control.Monad.Identity
import Data.Generics.Text.Extra
+import Data.List
import Data.String
+import Encoding
import Language.Core.Core
import Language.Core.ParseGlue
import Language.Core.Parser
import Language.Fay.Print ()
-import Language.Fay.Types (JsExp(..),JsStmt(..),JsName,printJS)
+import Language.Fay.Types (JsExp(..),JsStmt(..),JsName,JsLit(..),printJS)
import Prelude hiding (exp)
import System.Process.Extra
@@ -25,6 +27,7 @@ compileFile fp = do
-- | Print the JS compiled from a file.
printCompileFile :: FilePath -> IO ()
printCompileFile fp = do
+ readFile fp >>= putStrLn
js <- compileFile fp
putStrLn $ printJS $ js
@@ -80,7 +83,7 @@ qualToName = fromString . qualToString
-- | Convert a qualified thing to a string.
qualToString :: Qual String -> String
qualToString (name,var) =
- show name ++ "." ++ var
+ maybe "" (zDecodeString . show) name ++ "." ++ zDecodeString var
-- | Compile an expression.
compileExp :: Exp -> Compile JsExp
@@ -94,12 +97,26 @@ compileExp exp =
-- | Compile a literal.
compileLit :: Lit -> Compile JsExp
-compileLit lit =
- return JsNull
+compileLit (Literal lit _) = return $ JsLit $
+ case lit of
+ Lstring str -> JsStr str
+ Lchar char -> JsChar char
+ Lrational rat -> JsFloating (fromRational rat)
+ Lint i -> JsInt (fromInteger i)
-- | Compile a function application.
compileApp :: Exp -> Exp -> Compile JsExp
compileApp op arg = do
o <- compileExp op
a <- compileExp arg
return (JsApp o [a])
+
+fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
+
+greedy :: Integer -> Integer
+greedy n = last $ takeWhile (<= n) fibs
+
+zeckendorf :: Integer -> [Integer]
+zeckendorf n = reverse $ rec n where
+ rec 0 = []
+ rec x = g : rec (n - g) where g = greedy n
View
@@ -17,6 +17,7 @@ module Language.Fay.Print where
import Language.Fay.Types
+import Encoding
import Data.Aeson.Encode
import qualified Data.ByteString.Lazy.UTF8 as UTF8
import Data.List
@@ -198,15 +199,7 @@ jsEncodeName name = normalize name
-- | Normalize the given name to JavaScript-valid names.
normalize :: [Char] -> [Char]
-normalize name =
- concatMap encodeChar name
-
- where
- encodeChar c | c `elem` allowed = [c]
- | otherwise = escapeChar c
- allowed = ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'] ++ "_"
- escapeChar c = "$" ++ charId c ++ "$"
- charId c = show (fromEnum c)
+normalize name = zEncodeString name
-- | Helpful for writing qualified symbols (Fay.*).
instance IsString ModuleName where

0 comments on commit 32899b9

Please sign in to comment.