Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Elimination of duplicate definitions.

  • Loading branch information...
commit 0bb0eee94a233755d130f33e41f6cd2bebc13692 1 parent a04e831
Sebastiaan Visser authored
View
8 src/Compiler/LiftDefinitions.hs
@@ -3,9 +3,8 @@ module Compiler.LiftDefinitions
, Definition
, DefinitionsA (..)
, Definitions
-, inline
-, collect
, lift
+, eliminiateDoubles
, dump
)
where
@@ -13,7 +12,7 @@ where
import Compiler.Generics
import Compiler.Raw
import Control.Arrow hiding (app)
-import Data.List (intercalate)
+import Data.List (intercalate, nubBy)
data DefinitionA a = Def
{ defName :: String
@@ -51,6 +50,9 @@ collect = reduce defs
lift :: Arrow (~>) => Expr ~> Definitions
lift = arr (\e -> Defs (collect e ++ [Def "__main" (inline e)]))
+eliminiateDoubles :: Arrow (~>) => Definitions ~> Definitions
+eliminiateDoubles = arr (Defs . nubBy (\a b -> defName a == defName b) . unDefs)
+
dump :: Arrow (~>) => Definitions ~> String
dump = arr (intercalate "\n" . map one . unDefs)
where
View
1  src/Compiler/Pipeline.hs
@@ -12,6 +12,7 @@ compiler :: Val l i -> IO String
compiler = runKleisli
$ Lambdas.instantiate
>>> Definitions.lift
+ >>> Definitions.eliminiateDoubles
>>> FreeVariables.annotateDefinitions
>>> ClosedApplications.lift
>>> Definitions.dump
View
11 src/test.js
@@ -2,23 +2,12 @@ var mul = /* mul */ function (v1) { return function (v2) { return v1 * v2; }; }
var fix = /* fix */ function (v1) { return fix = arguments.callee, v1(function (i) { return fix(v1)(i) }); }
var list = /* list */ function (v3) { return function (v4) { return function (v5) { return v5.nil ? v3 : v4(v5.head)(v5.tail); }; }; }
var add = /* add */ function (v5) { return function (v6) { return v5 + v6; }; }
-var fix = /* fix */ function (v1) { return fix = arguments.callee, v1(function (i) { return fix(v1)(i) }); }
-var list = /* list */ function (v3) { return function (v4) { return function (v5) { return v5.nil ? v3 : v4(v5.head)(v5.tail); }; }; }
-var fix = /* fix */ function (v3) { return fix = arguments.callee, v3(function (i) { return fix(v3)(i) }); }
var bool = /* bool */ function (v5) { return function (v6) { return function (v7) { return v7 ? v5(/*force*/) : v6(/*force*/); }; }; }
var cons = /* cons */ function (v6) { return function (v7) { return { head : v6, tail : v7 }; }; }
var sub = /* sub */ function (v6) { return function (v7) { return v6 - v7; }; }
var eq = /* eq */ function (v5) { return function (v6) { return v5 == v6; }; }
-var cons = /* cons */ function (v5) { return function (v6) { return { head : v5, tail : v6 }; }; }
-var fix = /* fix */ function (v1) { return fix = arguments.callee, v1(function (i) { return fix(v1)(i) }); }
-var bool = /* bool */ function (v3) { return function (v4) { return function (v5) { return v5 ? v3(/*force*/) : v4(/*force*/); }; }; }
-var cons = /* cons */ function (v4) { return function (v5) { return { head : v4, tail : v5 }; }; }
-var sub = /* sub */ function (v4) { return function (v5) { return v4 - v5; }; }
-var eq = /* eq */ function (v3) { return function (v4) { return v3 == v4; }; }
var maybe = /* maybe */ function (v1) { return function (v2) { return function (v3) { return v3.nothing ? v1 : v2(v3.just); }; }; }
-var mul = /* mul */ function (v2) { return function (v3) { return v2 * v3; }; }
var just = /* just */ function (v1) { return { just : v1 }; }
-var sub = /* sub */ function (v1) { return function (v2) { return v1 - v2; }; }
var c1 = list(0)
var c2 = fix(function (v1) { return function (v2) { return c1(function (v3) { return function (v4) { return add(v3)(v1(v4)); }; })(v2); }; })
var c3 = function (v6) { return function (v7) { return v6; }; }({ nil : 1 })
Please sign in to comment.
Something went wrong with that request. Please try again.