@@ -33,7 +33,6 @@ import Language.PureScript.Names
33import Language.PureScript.Declarations
33import Language.PureScript.Declarations
34import Language.PureScript.Options
34import Language.PureScript.Options
35import Language.PureScript.CodeGen.JS.AST as AST
35import Language.PureScript.CodeGen.JS.AST as AST
36−import Language.PureScript.Types
37import Language.PureScript.Optimizer
36import Language.PureScript.Optimizer
38import Language.PureScript.CodeGen.Common
37import Language.PureScript.CodeGen.Common
39import Language.PureScript.Environment
38import Language.PureScript.Environment
@@ -228,10 +227,6 @@ valueToJs opts m e (Let ds val) = do
228valueToJs opts m e (Abs (Left arg) val) = do
227valueToJs opts m e (Abs (Left arg) val) = do
229 ret <- valueToJs opts m e val
228 ret <- valueToJs opts m e val
230 return $ JSFunction Nothing [identToJs arg] (JSBlock [JSReturn ret])
229 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])
235valueToJs _ m _ (Var ident) = return $ varToJs m ident
230valueToJs _ m _ (Var ident) = return $ varToJs m ident
236valueToJs opts m e (TypedValue _ val _) = valueToJs opts m e val
231valueToJs opts m e (TypedValue _ val _) = valueToJs opts m e val
237valueToJs opts m e (PositionedValue _ val) = valueToJs opts m e val
232valueToJs opts m e (PositionedValue _ val) = valueToJs opts m e val
@@ -257,38 +252,6 @@ extendObj obj sts = do
257 extend = map stToAssign sts
252 extend = map stToAssign sts
258 return $ JSApp (JSFunction Nothing [] block) []
253 return $ JSApp (JSFunction Nothing [] block) []
261−-- Generate code in the simplified Javascript intermediate representation for runtime type checks.
263−runtimeTypeChecks :: String -> Type -> [JS]
264−runtimeTypeChecks arg ty =
266− argTy = getFunctionArgumentType ty
268− maybe [] (argumentCheck (JSVar arg)) argTy
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 =
281− (pairs, _) = rowToList row
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
293-- Generate code in the simplified Javascript intermediate representation for a reference to a
256-- Generate code in the simplified Javascript intermediate representation for a reference to a
294-- variable.
257-- variable.