@@ -33,7 +33,6 @@ import Language.PureScript.Names
3333import Language.PureScript.Declarations
3434import Language.PureScript.Options
3535import Language.PureScript.CodeGen.JS.AST as AST
36−import Language.PureScript.Types
3736import Language.PureScript.Optimizer
3837import Language.PureScript.CodeGen.Common
3938import Language.PureScript.Environment
@@ -228,10 +227,6 @@ valueToJs opts m e (Let ds val) = do
228227valueToJs opts m e (Abs (Left arg) val) = do
229228 ret <- valueToJs opts m e val
230229 return $ JSFunction Nothing [identToJs arg] (JSBlock [JSReturn ret])
231−valueToJs opts m e (TypedValue _ (Abs (Left arg) val) ty) | optionsPerformRuntimeTypeChecks opts = do
232− let arg' = identToJs arg
233− ret <- valueToJs opts m e val
234− return $ JSFunction Nothing [arg'] (JSBlock $ runtimeTypeChecks arg' ty ++ [JSReturn ret])
235230valueToJs _ m _ (Var ident) = return $ varToJs m ident
236231valueToJs opts m e (TypedValue _ val _) = valueToJs opts m e val
237232valueToJs opts m e (PositionedValue _ val) = valueToJs opts m e val
@@ -257,38 +252,6 @@ extendObj obj sts = do
257252 extend = map stToAssign sts
258253 return $ JSApp (JSFunction Nothing [] block) []
259254
260−-- |
261−-- Generate code in the simplified Javascript intermediate representation for runtime type checks.
262−--
263−runtimeTypeChecks :: String -> Type -> [JS]
264−runtimeTypeChecks arg ty =
265− let
266− argTy = getFunctionArgumentType ty
267− in
268− maybe [] (argumentCheck (JSVar arg)) argTy
269− where
270− getFunctionArgumentType :: Type -> Maybe Type
271− getFunctionArgumentType (TypeApp (TypeApp t funArg) _) | t == tyFunction = Just funArg
272− getFunctionArgumentType (ForAll _ ty' _) = getFunctionArgumentType ty'
273− getFunctionArgumentType _ = Nothing
274− argumentCheck :: JS -> Type -> [JS]
275− argumentCheck val t | t == tyNumber = [typeCheck val "number"]
276− argumentCheck val t | t == tyString = [typeCheck val "string"]
277− argumentCheck val t | t == tyBoolean = [typeCheck val "boolean"]
278− argumentCheck val (TypeApp t _) | t == tyArray = [arrayCheck val]
279− argumentCheck val (TypeApp t row) | t == tyObject =
280− let
281− (pairs, _) = rowToList row
282− in
283− typeCheck val "object" : concatMap (\(prop, ty') -> argumentCheck (accessorString prop val) ty') pairs
284− argumentCheck val (TypeApp (TypeApp t _) _) | t == tyFunction = [typeCheck val "function"]
285− argumentCheck val (ForAll _ ty' _) = argumentCheck val ty'
286− argumentCheck _ _ = []
287− typeCheck :: JS -> String -> JS
288− typeCheck js ty' = JSIfElse (JSBinary NotEqualTo (JSTypeOf js) (JSStringLiteral ty')) (JSBlock [JSThrow (JSStringLiteral $ ty' ++ " expected")]) Nothing
289− arrayCheck :: JS -> JS
290− arrayCheck js = JSIfElse (JSUnary Not (JSApp (JSAccessor "isArray" (JSVar "Array")) [js])) (JSBlock [JSThrow (JSStringLiteral "Array expected")]) Nothing
291−
292255-- |
293256-- Generate code in the simplified Javascript intermediate representation for a reference to a
294257-- variable.