on master help sign in
Merge branch 'dev' of https://github.com/evancz/Elm into dev
commitecaa5bdb292896dd768e3023f3fe70b3d5468e7e authorevancz <info@elm-lang.org> dateWed 27 Mar 2013, 18:32 (14 years ago) parentc0a42867044dd5
2 files changed+29−10
Setup.hs+11−1 libraries/Native/List.js+18−9
Setup.hs+11−1
@@ -51,11 +51,15 @@ elm lbi = (buildDir lbi) </> "elm" </> "elm"
5151
5252
5353main :: IO ()
54−main = defaultMainWithHooks simpleUserHooks { buildHook = myBuild, postBuild = myPostBuild }
54+main = defaultMainWithHooks simpleUserHooks { {-- buildHook = myBuild, --} postBuild = myPostBuildWithTypes }
5555
5656
5757-- Build
5858
59+-- Not currently used. buildTypes is in 'myPostBuildWithTypes'
60+-- If using this again, change postBuild to 'myPostBuild'
61+-- Purpose is to make sure docs.json was built before elm exec was (as elm exec depended on it)
62+-- This is no longer true and the code below seems to affect cabal's build dependencies
5963myBuild :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO ()
6064myBuild pd lbi uh bf = do
6165 putStrLn $ "Custom build step started: compile " ++ elmDoc
@@ -97,6 +101,12 @@ buildTypes lbi = do
97101
98102-- Post Build
99103
104+myPostBuildWithTypes :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
105+myPostBuildWithTypes as bfs pd lbi = do
106+ putStrLn "Custom build step started: build docs.json"
107+ buildTypes lbi -- see note(1) below
108+ myPostBuild as bfs pd lbi
109+
100110myPostBuild :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
101111myPostBuild as bfs pd lbi = do
102112 putStrLn "Custom post build step started: build elm-runtime.js"
libraries/Native/List.js+18−9
@@ -6,6 +6,15 @@ Elm.Native.List = function(elm) {
66
77 var Utils = Elm.Native.Utils(elm);
88
9+ // TODO: Improve Nil handling
10+ // We can change places like: if (xs.ctor === 'Nil') ... to if (xs === Nil) ...
11+ // but only if we're confident Nil can only be defined once.
12+ // Currently (27Mar2013) each module can have different instantiations, so multiple Nil objects can exist
13+ // (and if they're used interchangeably then direct object comparison fails where ctor doesn't).
14+ // So, this can only be fixed when modules initialisation is also fixed.
15+ // The performance overhead of the .ctor calls is 5-10% according to jsperf (depending on fn + list size)
16+ // (on firefox 19)
17+
918 // freeze is universally supported and as a singleton introduces little performance penalty
1019 // for a small amount of object safety
1120 var Nil = Object.freeze({ ctor:'Nil' });
@@ -44,7 +53,7 @@ Elm.Native.List = function(elm) {
4453
4554 function append(xs,ys) {
4655 if (typeof xs === "string") { return xs.concat(ys); }
47− if (xs === Nil) { return ys; }
56+ if (xs.ctor === 'Nil') { return ys; }
4857 var root = Cons(xs._0, Nil);
4958 var curr = root;
5059 xs = xs._1;
@@ -57,11 +66,11 @@ Elm.Native.List = function(elm) {
5766 return root;
5867 }
5968
60− function head(v) { return v === Nil ? throwError('head') : v._0; }
61− function tail(v) { return v === Nil ? throwError('tail') : v._1; }
69+ function head(v) { return v.ctor === 'Nil' ? throwError('head') : v._0; }
70+ function tail(v) { return v.ctor === 'Nil' ? throwError('tail') : v._1; }
6271
6372 function last(xs) {
64− if (xs === Nil) { throwError('last'); }
73+ if (xs.ctor === 'Nil') { throwError('last'); }
6574 var out = xs._0;
6675 while (xs.ctor !== 'Nil') {
6776 out = xs._0;
@@ -100,11 +109,11 @@ Elm.Native.List = function(elm) {
100109 }
101110
102111 function foldl1(f, xs) {
103− return xs === Nil ? throwError('foldl1') : foldl(f, xs._0, xs._1);
112+ return xs.ctor === 'Nil' ? throwError('foldl1') : foldl(f, xs._0, xs._1);
104113 }
105114
106115 function foldr1(f, xs) {
107− if (xs === Nil) { throwError('foldr1'); }
116+ if (xs.ctor === 'Nil') { throwError('foldr1'); }
108117 var arr = toArray(xs);
109118 var acc = arr.pop();
110119 for (var i = arr.length; i--; ) {
@@ -124,7 +133,7 @@ Elm.Native.List = function(elm) {
124133 }
125134
126135 function scanl1(f, xs) {
127− return xs === Nil ? throwError('scanl1') : scanl(f, xs._0, xs._1);
136+ return xs.ctor === 'Nil' ? throwError('scanl1') : scanl(f, xs._0, xs._1);
128137 }
129138
130139 function filter(pred, xs) {
@@ -156,7 +165,7 @@ Elm.Native.List = function(elm) {
156165 function reverse(xs) { return fromArray(toArray(xs).reverse()); }
157166
158167 function concat(xss) {
159− if (xss === Nil) return xss;
168+ if (xss.ctor === 'Nil') return xss;
160169 var arr = toArray(xss);
161170 var xs = arr[arr.length-1];
162171 for (var i = arr.length-1; i--; ) {
@@ -228,7 +237,7 @@ Elm.Native.List = function(elm) {
228237 }
229238
230239 function join(sep, xss) {
231− if (xss === Nil) return Nil;
240+ if (xss.ctor === 'Nil') return Nil;
232241 var s = toArray(sep);
233242 var out = toArray(xss._0);
234243 xss = xss._1;