Permalink
Browse files

Compiler is (for now) JS specific.

  • Loading branch information...
1 parent 2cfeaa3 commit e7592d66c806f2bd4987c03965772878695d445c Sebastiaan Visser committed Dec 20, 2009
Showing with 17 additions and 17 deletions.
  1. +3 −3 src/Compiler/Pipeline.hs
  2. +14 −14 src/Lang/JavaScript.hs
View
@@ -2,7 +2,7 @@
module Compiler.Pipeline where
import Control.Arrow
-import Lang.Value (Val)
+import Lang.JavaScript
import Compiler.Expr
import Compiler.FreeVariables (DefinitionsFV)
import Compiler.LiftDefinitions (Definitions)
@@ -13,9 +13,9 @@ import qualified Compiler.LiftDefinitions as Definitions
type a :-> b = Kleisli IO a b
-compiler :: Val l i -> IO String
+compiler :: JavaScript a -> IO String
compiler = runKleisli
- $ ( Lambdas.instantiate :: Val l i :-> Expr )
+ $ ( Lambdas.instantiate :: JavaScript a :-> Expr )
>>> ( Definitions.lift :: Expr :-> Definitions )
>>> ( Definitions.eliminiateDoubles :: Definitions :-> Definitions )
>>> ( FreeVariables.annotateDefinitions :: Definitions :-> DefinitionsFV )
View
@@ -11,65 +11,65 @@ import Lang.Value
import Prelude ((++))
import qualified Prelude
-data JavaScript
-type Js a = Val JavaScript a
+data JS
+type JavaScript a = Val JS a
-- * JavaScript instances for AwesomePrelude datatypes.
-instance NameC (Val JavaScript) where
+instance NameC (Val JS) where
named s a = s `Name` a
-instance FunC (Val JavaScript) where
+instance FunC (Val JS) where
lam f = Lam f
app f g = App f g
fix f = fun1 "fix" (\[v] -> "fix = arguments.callee, " ++ v ++ "(function (i) { return fix(" ++ v ++ ")(i) })") (lam f)
-instance BoolC (Val JavaScript) where
+instance BoolC (Val JS) where
true = Con "true"
false = Con "false"
bool x y z = fun3 "bool" (\[t, e, b] -> b ++ " ? " ++ t ++ "(/*force*/) : " ++ e ++ "(/*force*/)") (lam (const x)) (lam (const y)) z
-instance NumC (Val JavaScript) where
+instance NumC (Val JS) where
(+) = fun2 "add" (\[a, b] -> a ++ " + " ++ b)
(-) = fun2 "sub" (\[a, b] -> a ++ " - " ++ b)
(*) = fun2 "mul" (\[a, b] -> a ++ " * " ++ b)
(/) = fun2 "div" (\[a, b] -> a ++ " / " ++ b)
num x = Con (Prelude.show x)
-instance MaybeC (Val JavaScript) where
+instance MaybeC (Val JS) where
nothing = Con "{ nothing : 1 }"
just = fun1 "just" (\[x] -> "{ just : " ++ x ++ " }")
maybe p q = fun3 "maybe" (\[n, j, m] -> m ++ ".nothing ? " ++ n ++ " : " ++ j ++ "(" ++ m ++ ".just)") p (lam q)
-instance TupleC (Val JavaScript) where
+instance TupleC (Val JS) where
mkTuple = fun2 "mkTuple" (\[a, b] -> "{ fst : " ++ a ++ ", snd : " ++ b ++ "}")
tuple p q = fun2 "tuple" (\[f, t] -> f ++ "(" ++ t ++ ".fst, " ++ t ++ ".snd)") (lam2 p) q
-instance EitherC (Val JavaScript) where
+instance EitherC (Val JS) where
left = fun1 "left" (\[l] -> "{ left : " ++ l ++ " }")
right = fun1 "right" (\[r] -> "{ right : " ++ r ++ " }")
either p q = fun3 "either" (\[l, r, e] -> e ++ ".left ? " ++ l ++ "(" ++ e ++ ".left) : " ++ r ++ "(" ++ e ++ ".right)") (lam p) (lam q)
-instance ListC (Val JavaScript) where
+instance ListC (Val JS) where
nil = Con "{ nil : 1 }"
cons = fun2 "cons" (\[x, xs] -> "{ head : " ++ x ++ ", tail : " ++ xs ++ " }")
list b f = fun3 "list" (\[n, c, xs] -> xs ++ ".nil ? " ++ n ++ " : " ++ c ++ "(" ++ xs ++ ".head)(" ++ xs ++ ".tail)") b (lam2 f)
-- * JavaScript instances of AwesomePrelude type classes.
-instance Eq (Val JavaScript) Bool where
+instance Eq (Val JS) Bool where
(==) = fun2 "eq" (\[a, b] -> a ++ " == " ++ b)
(/=) = fun2 "neq" (\[a, b] -> a ++ " /= " ++ b)
-instance Eq (Val JavaScript) Num where
+instance Eq (Val JS) Num where
(==) = fun2 "eq" (\[a, b] -> a ++ " == " ++ b)
(/=) = fun2 "neq" (\[a, b] -> a ++ " /= " ++ b)
-instance (Eq (Val JavaScript) a, Eq (Val JavaScript) b) => Eq (Val JavaScript) (a, b) where
+instance (Eq (Val JS) a, Eq (Val JS) b) => Eq (Val JS) (a, b) where
(==) = fun2 "eq" (\[a, b] -> a ++ " == " ++ b)
(/=) = fun2 "neq" (\[a, b] -> a ++ " /= " ++ b)
-instance Eq (Val JavaScript) a => Eq (Val JavaScript) [a] where
+instance Eq (Val JS) a => Eq (Val JS) [a] where
(==) = fun2 "eq" (\[a, b] -> a ++ " == " ++ b)
(/=) = fun2 "neq" (\[a, b] -> a ++ " /= " ++ b)

0 comments on commit e7592d6

Please sign in to comment.