on master help sign in
Update to newest head
ab5baf6Christian Widera
compiler/Generate/Cases.hs+14−11
@@ -13,7 +13,6 @@ import qualified SourceSyntax.Pattern as P
13import qualified SourceSyntax.Variable as V
13import qualified SourceSyntax.Variable as V
14import Transform.Substitute
14import Transform.Substitute
15
15
16−
17toMatch :: [(P.Pattern, Expr)] -> State Int (String, Match)
16toMatch :: [(P.Pattern, Expr)] -> State Int (String, Match)
18toMatch patterns = do
17toMatch patterns = do
19 v <- newVar
18 v <- newVar
@@ -37,16 +36,19 @@ data Clause =
37 deriving Show
36 deriving Show
38
37
39matchSubst :: [(String,String)] -> Match -> Match
38matchSubst :: [(String,String)] -> Match -> Match
40−matchSubst _ Break = Break
39+matchSubst pairs match =
40+ case match of
41+ Break -> Break
41−matchSubst _ Fail = Fail
42+ Fail -> Fail
42−matchSubst pairs (Seq ms) = Seq (map (matchSubst pairs) ms)
43+ Seq ms -> Seq (map (matchSubst pairs) ms)
43−matchSubst pairs (Other (A a e)) =
44+ Other (A a e) ->
44− Other . A a $ foldr ($) e $ map (\(x,y) -> subst x (rawVar y)) pairs
45+ Other . A a $ foldr ($) e $ map (\(x,y) -> subst x (rawVar y)) pairs
45−matchSubst pairs (Match n cs m) =
46+ Match n cs m ->
46− Match (varSubst n) (map clauseSubst cs) (matchSubst pairs m)
47+ Match (varSubst n) (map clauseSubst cs) (matchSubst pairs m)
48+ where
47− where varSubst v = fromMaybe v (lookup v pairs)
49+ varSubst v = fromMaybe v (lookup v pairs)
48− clauseSubst (Clause c vs m) =
50+ clauseSubst (Clause c vs m) =
49− Clause c (map varSubst vs) (matchSubst pairs m)
51+ Clause c (map varSubst vs) (matchSubst pairs m)
50
52
51isCon (p:_, _) =
53isCon (p:_, _) =
52 case p of
54 case p of
@@ -68,6 +70,7 @@ match vs@(v:_) cs def
68 where
70 where
69 cs' = map (dealias v) cs
71 cs' = map (dealias v) cs
70
72
73+dealias :: String -> ([P.Pattern],Expr) -> ([P.Pattern],Expr)
71dealias v c@(p:ps, A a e) =
74dealias v c@(p:ps, A a e) =
72 case p of
75 case p of
73 P.Alias x pattern -> (pattern:ps, A a $ subst x (rawVar v) e)
76 P.Alias x pattern -> (pattern:ps, A a $ subst x (rawVar v) e)
compiler/Generate/JavaScript.hs+8−5
@@ -55,6 +55,7 @@ expression :: Expr -> State Int (Expression ())
55expression (A region expr) =
55expression (A region expr) =
56 case expr of
56 case expr of
57 Var (V.Raw x) -> return $ obj x
57 Var (V.Raw x) -> return $ obj x
58+
58 Literal lit -> return $ literal lit
59 Literal lit -> return $ literal lit
59
60
60 Range lo hi ->
61 Range lo hi ->
@@ -215,19 +216,19 @@ definition (Definition pattern expr@(A region _) _) = do
215 decl x n = varDecl x (dotSep ["$","_" ++ show n])
216 decl x n = varDecl x (dotSep ["$","_" ++ show n])
216 setup vars
217 setup vars
217 | Help.isTuple name = assign "$" : vars
218 | Help.isTuple name = assign "$" : vars
218− | otherwise = assign "$raw" : safeAssign : vars
219+ | otherwise = assign "_raw" : safeAssign : vars
219
220
220− safeAssign = varDecl "$" (CondExpr () if' (obj "$raw") exception)
221+ safeAssign = varDecl "$" (CondExpr () if' (obj "_raw") exception)
221− if' = InfixExpr () OpStrictEq (obj "$raw.ctor") (string name)
222+ if' = InfixExpr () OpStrictEq (obj "_raw.ctor") (string name)
222 exception = obj "_E.Case" `call` [ref "$moduleName", string (renderPretty region)]
223 exception = obj "_E.Case" `call` [ref "$moduleName", string (renderPretty region)]
223
224
224 _ ->
225 _ ->
225 do defs' <- concat <$> mapM toDef vars
226 do defs' <- concat <$> mapM toDef vars
226− return (VarDeclStmt () [assign "$"] : defs')
227+ return (VarDeclStmt () [assign "_"] : defs')
227 where
228 where
228 vars = P.boundVarList pattern
229 vars = P.boundVarList pattern
229 mkVar = A region . rawVar
230 mkVar = A region . rawVar
230− toDef y = let expr = A region $ Case (mkVar "$") [(pattern, mkVar y)]
231+ toDef y = let expr = A region $ Case (mkVar "_") [(pattern, mkVar y)]
231 in definition $ Definition (P.Var y) expr Nothing
232 in definition $ Definition (P.Var y) expr Nothing
232
233
233match :: Region -> Case.Match -> State Int [Statement ()]
234match :: Region -> Case.Match -> State Int [Statement ()]
@@ -254,9 +255,11 @@ match region mtch =
254 return [ ExprStmt () (obj "_E.Case" `call` [ref "$moduleName", string (renderPretty region)]) ]
255 return [ ExprStmt () (obj "_E.Case" `call` [ref "$moduleName", string (renderPretty region)]) ]
255
256
256 Case.Break -> return [BreakStmt () Nothing]
257 Case.Break -> return [BreakStmt () Nothing]
258+
257 Case.Other e ->
259 Case.Other e ->
258 do e' <- expression e
260 do e' <- expression e
259 return [ ret e' ]
261 return [ ret e' ]
262+
260 Case.Seq ms -> concat <$> mapM (match region) (dropEnd [] ms)
263 Case.Seq ms -> concat <$> mapM (match region) (dropEnd [] ms)
261 where
264 where
262 dropEnd acc [] = acc
265 dropEnd acc [] = acc
libraries/Array.elm+19−3
@@ -1,8 +1,8 @@
1module Array where
1module Array where
2
2
3−{-| A library for manipulating arrays of elements. The elements in an
3+{-| A library for immutable arrays. The elements in an array must have the same
4−array must have the same type. The arrays are implemented in Relaxed
4+type. The arrays are implemented in Relaxed Radix Balanced-Trees for fast
5−Radix Balanced-Trees for fast updating and concating.
5+reads, updates, and concatenation.
6
6
7If you use more then one map or zip function on an array, consider turning it
7If you use more then one map or zip function on an array, consider turning it
8into a list before operating on it, and then turning it back into an array.
8into a list before operating on it, and then turning it back into an array.
@@ -133,10 +133,18 @@ get = Native.Array.get
133 getMaybe 2 (A.fromList [3,2,1]) == Just 2
133 getMaybe 2 (A.fromList [3,2,1]) == Just 2
134 getMaybe 5 (A.fromList [3,2,1]) == Nothing
134 getMaybe 5 (A.fromList [3,2,1]) == Nothing
135-}
135-}
136+<<<<<<< HEAD
136getMaybe : Int -> Array a -> Maybe a
137getMaybe : Int -> Array a -> Maybe a
137getMaybe i array = if Native.Array.length array > i
138getMaybe i array = if Native.Array.length array > i
138 then Just (Native.Array.get i array)
139 then Just (Native.Array.get i array)
139 else Nothing
140 else Nothing
141+=======
142+safeGet : Int -> Array a -> Maybe a
143+safeGet i array =
144+ if i < Native.Array.length array
145+ then Just (Native.Array.get i array)
146+ else Nothing
147+>>>>>>> dev
140
148
141{-| Get the element at the index. If the index is out of range, the given default
149{-| Get the element at the index. If the index is out of range, the given default
142element is returned.
150element is returned.
@@ -144,9 +152,17 @@ element is returned.
144 getSafe 0 2 (A.fromList [3,2,1]) == 1
152 getSafe 0 2 (A.fromList [3,2,1]) == 1
145 getSafe 0 5 (A.fromList [3,2,1]) == 0
153 getSafe 0 5 (A.fromList [3,2,1]) == 0
146-}
154-}
155+<<<<<<< HEAD
147getSafe : a -> Int -> Array a -> a
156getSafe : a -> Int -> Array a -> a
148getSafe default i array = if Native.Array.length array > i
157getSafe default i array = if Native.Array.length array > i
149 then Native.Array.get i array else default
158 then Native.Array.get i array else default
159+=======
160+getWithDefault : a -> Int -> Array a -> a
161+getWithDefault default i array =
162+ if i < Native.Array.length array
163+ then Native.Array.get i array
164+ else default
165+>>>>>>> dev
150
166
151{-| Set the element at the index. Returns the updated array, or if the index is
167{-| Set the element at the index. Returns the updated array, or if the index is
152out of range, the unaltered array.
168out of range, the unaltered array.
libraries/Native/Graphics/Input.js+9−9
@@ -12,7 +12,7 @@ Elm.Native.Graphics.Input.make = function(elm) {
12 var Text = Elm.Native.Text.make(elm);
12 var Text = Elm.Native.Text.make(elm);
13 var Signal = Elm.Signal.make(elm);
13 var Signal = Elm.Signal.make(elm);
14 var newElement = Elm.Graphics.Element.make(elm).newElement;
14 var newElement = Elm.Graphics.Element.make(elm).newElement;
15− var JS = Elm.Native.JavaScript.make(elm);
15+ var List = Elm.Native.List.make(elm);
16 var Utils = Elm.Native.Utils.make(elm);
16 var Utils = Elm.Native.Utils.make(elm);
17 var Tuple2 = Utils.Tuple2;
17 var Tuple2 = Utils.Tuple2;
18
18
@@ -23,14 +23,14 @@ Elm.Native.Graphics.Input.make = function(elm) {
23
23
24 function renderDropDown(signal, values) {
24 function renderDropDown(signal, values) {
25 return function(_) {
25 return function(_) {
26− var entries = JS.fromList(values);
26+ var entries = List.toArray(values);
27
27
28 var drop = newNode('select');
28 var drop = newNode('select');
29 drop.style.border = '0 solid';
29 drop.style.border = '0 solid';
30 drop.style.pointerEvents = 'auto';
30 drop.style.pointerEvents = 'auto';
31 for (var i = 0; i < entries.length; ++i) {
31 for (var i = 0; i < entries.length; ++i) {
32 var option = newNode('option');
32 var option = newNode('option');
33− var name = JS.fromString(entries[i]._0);
33+ var name = entries[i]._0;
34 option.value = name;
34 option.value = name;
35 option.innerHTML = name;
35 option.innerHTML = name;
36 drop.appendChild(option);
36 drop.appendChild(option);
@@ -91,7 +91,7 @@ Elm.Native.Graphics.Input.make = function(elm) {
91 type: 'Button',
91 type: 'Button',
92 render: renderButton,
92 render: renderButton,
93 update: updateButton,
93 update: updateButton,
94− model: { signal:signal, value:value, text:JS.fromString(text) }
94+ model: { signal:signal, value:value, text:text }
95 });
95 });
96 }
96 }
97
97
@@ -266,8 +266,8 @@ Elm.Native.Graphics.Input.make = function(elm) {
266 field.style.pointerEvents = 'auto';
266 field.style.pointerEvents = 'auto';
267
267
268 field.type = model.type;
268 field.type = model.type;
269− field.placeholder = JS.fromString(model.placeHolder);
269+ field.placeholder = model.placeHolder;
270− field.value = JS.fromString(model.content.string);
270+ field.value = model.content.string;
271
271
272 field.elm_signal = model.signal;
272 field.elm_signal = model.signal;
273 field.elm_handler = model.handler;
273 field.elm_handler = model.handler;
@@ -287,7 +287,7 @@ Elm.Native.Graphics.Input.make = function(elm) {
287
287
288 elm.notify(field.elm_signal.id, field.elm_handler({
288 elm.notify(field.elm_signal.id, field.elm_handler({
289 _:{},
289 _:{},
290− string: JS.toString(next),
290+ string: next,
291 selection: {
291 selection: {
292 _:{},
292 _:{},
293 start: start,
293 start: start,
@@ -338,8 +338,8 @@ Elm.Native.Graphics.Input.make = function(elm) {
338 field.elm_handler = newModel.handler;
338 field.elm_handler = newModel.handler;
339
339
340 field.type = newModel.type;
340 field.type = newModel.type;
341− field.placeholder = JS.fromString(newModel.placeHolder);
341+ field.placeholder = newModel.placeHolder;
342− var value = JS.fromString(newModel.content.string);
342+ var value = newModel.content.string;
343 field.value = value;
343 field.value = value;
344 field.elm_old_value = value;
344 field.elm_old_value = value;
345 if (field.elm_hasFocus) {
345 if (field.elm_hasFocus) {