Skip to content

Commit

Permalink
Merge branch 'pr/606'
Browse files Browse the repository at this point in the history
  • Loading branch information
process-bot committed May 1, 2014
2 parents fd05744 + 32306c5 commit adaa65f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
3 changes: 2 additions & 1 deletion compiler/Generate/JavaScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ include alias moduleName =

internalImports :: String -> Statement ()
internalImports name =
VarDeclStmt ()
VarDeclStmt ()
[ varDecl "_N" (obj "Elm.Native")
, include "_U" "_N.Utils"
, include "_L" "_N.List"
, include "_A" "_N.Array"
, include "_E" "_N.Error"
, varDecl "$moduleName" (string name)
]
Expand Down
23 changes: 15 additions & 8 deletions compiler/Generate/JavaScript/Ports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ inc tipe x =

Data "Json.Value" [] ->
obj "Native.Json.fromJS" <| x

Data ctor []
| ctor == "Int" -> from JSNumber
| ctor == "Float" -> from JSNumber
Expand All @@ -55,8 +55,12 @@ inc tipe x =

| ctor == "_List" ->
check x JSArray (obj "_L.fromArray" <| array)
where
array = DotRef () x (var "map") <| incoming t

| ctor == "Array.Array" ->
check x JSArray (obj "_A.fromJSArray" <| array)

where
array = DotRef () x (var "map") <| incoming t

Data ctor ts
| Help.isTuple ctor -> check x JSArray tuple
Expand All @@ -67,10 +71,10 @@ inc tipe x =
, inc t (BracketRef () x (IntLit () n)))

Data _ _ ->
error "bad ADT got to port generation code"
error "bad ADT got to incoming port generation code"

Record _ (Just _) ->
error "bad record got to port generation code"
error "bad record got to incoming port generation code"

Record fields Nothing ->
check x (JSObject (map fst fields)) object
Expand Down Expand Up @@ -117,16 +121,19 @@ out tipe x =
| ctor == "_List" ->
DotRef () (obj "_L.toArray" <| x) (var "map") <| outgoing t

| ctor == "Array.Array" ->
DotRef () (obj "_A.toJSArray" <| x) (var "map") <| outgoing t

Data ctor ts
| Help.isTuple ctor ->
let convert n t = out t $ DotRef () x $ var ('_':show n)
in ArrayLit () $ zipWith convert [0..] ts

Data _ _ ->
error "bad ADT got to port generation code"
error "bad ADT got to outgoing port generation code"

Record _ (Just _) ->
error "bad record got to port generation code"
error "bad record got to outgoing port generation code"

Record fields Nothing ->
ObjectLit () keys
Expand Down
5 changes: 2 additions & 3 deletions compiler/Type/ExtraChecks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ portTypes rules expr =
| otherwise -> err' True "an unsupported type"
where
primitives =
["Int","Float","String","Bool","Maybe.Maybe","_List","Json.Value"]

["Int","Float","String","Bool","Maybe.Maybe","_List","Array.Array","Json.Value"]
validConstructor =
ctor `elem` primitives || Help.isTuple ctor

Expand Down Expand Up @@ -102,7 +101,7 @@ portTypes rules expr =
, txt [ "It contains ", kind, ":\n" ]
, (P.nest 4 . SPP.pretty $ Alias.realias rules tipe) <> P.text "\n"
, txt [ "Acceptable values for ", dir "incoming" "outgoing", " ports include:" ]
, txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Tuples," ]
, txt [ " Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples," ]
, txt [ " Json.Values, ", dir "" "first-order functions, ", "and concrete records." ]
] ++ if couldBeAlias then aliasWarning else []

Expand Down
6 changes: 2 additions & 4 deletions libraries/Native/Error.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Elm.Native.Error.make = function(elm) {
elm.Native.Error = elm.Native.Error || {};
if (elm.Native.Error.values) return elm.Native.Error.values;

var fromString = Elm.Native.JavaScript.make(elm).fromString;

function indent(lines) {
var msg = '';
for (var i = 0; i < lines.length; ++i) {
Expand All @@ -26,7 +24,7 @@ Elm.Native.Error.make = function(elm) {
throw new Error('Runtime error in module ' + moduleName + ' (' + span + '):' + msg);
}

function raise(str) { throw new Error(fromString(str)); }
function raise(str) { throw new Error(str); }

return elm.Native.Error.values = { Case: Case, If: If, raise: raise };
};
};

0 comments on commit adaa65f

Please sign in to comment.