@@ -27,6 +27,7 @@ task name expr portType =
28data JSType
28data JSType
29 = JSNumber
29 = JSNumber
30 | JSBoolean
31 | JSBoolean
31 | JSString
32 | JSString
@@ -37,6 +38,7 @@ typeToString :: JSType -> String
37typeToString tipe =
38typeToString tipe =
38 case tipe of
39 case tipe of
39 JSNumber -> "a number"
40 JSNumber -> "a number"
41+ JSInt -> "an integer"
40 JSBoolean -> "a boolean (true or false)"
42 JSBoolean -> "a boolean (true or false)"
41 JSString -> "a string"
43 JSString -> "a string"
42 JSArray -> "an array"
44 JSArray -> "an array"
@@ -81,12 +83,31 @@ check x jsType continue =
83 case jsType of
85 case jsType of
84− JSNumber -> [typeof "number"]
87+ [typeof "number"]
90+ [jsFold OpLAnd intChecks]
85− JSBoolean -> [typeof "boolean"]
93+ [typeof "boolean"]
86− JSString -> [typeof "string", instanceof "String"]
96+ [typeof "string", instanceof "String"]
87− JSArray -> [instanceof "Array"]
99+ [instanceof "Array"]
88 JSObject fields ->
101 JSObject fields ->
89− [jsFold OpLAnd (typeof "object" : map member fields)]
102+ [jsFold OpLAnd (typeof "object" : map member fields)]
105+intChecks :: [Expression () -> Expression ()]
108+ , \x -> ref "isFinite" <| x
109+ , \x -> equal (obj ["Math","floor"] <| x) x
92-- INBOUND
113-- INBOUND
@@ -127,8 +148,8 @@ toType tipe x =
127 toType (T.dealias args t) x
148 toType (T.dealias args t) x
129 T.Type (Var.Canonical Var.BuiltIn name)
150 T.Type (Var.Canonical Var.BuiltIn name)
130− | name == "Int" -> from JSNumber
131 | name == "Float" -> from JSNumber
151 | name == "Float" -> from JSNumber
152+ | name == "Int" -> from JSInt
132 | name == "Bool" -> from JSBoolean
153 | name == "Bool" -> from JSBoolean
133 | name == "String" -> from JSString
154 | name == "String" -> from JSString