@@ -135,7 +135,6 @@ valueToJs opts m e (IfThenElse cond th el) = JSConditional (valueToJs opts m e c
135valueToJs opts m e (Accessor prop val) = JSAccessor prop (valueToJs opts m e val)
135valueToJs opts m e (Accessor prop val) = JSAccessor prop (valueToJs opts m e val)
136valueToJs opts m e (App val arg) = JSApp (valueToJs opts m e val) [valueToJs opts m e arg]
136valueToJs opts m e (App val arg) = JSApp (valueToJs opts m e val) [valueToJs opts m e arg]
137valueToJs opts m e (Abs (Left arg) val) = JSFunction Nothing [identToJs arg] (JSBlock [JSReturn (valueToJs opts m (bindName m arg e) val)])
137valueToJs opts m e (Abs (Left arg) val) = JSFunction Nothing [identToJs arg] (JSBlock [JSReturn (valueToJs opts m (bindName m arg e) val)])
138−valueToJs opts m e (TypedValue _ (Abs (Left arg) val) ty) | optionsPerformRuntimeTypeChecks opts = let arg' = identToJs arg in JSFunction Nothing [arg'] (JSBlock $ runtimeTypeChecks arg' ty ++ [JSReturn (valueToJs opts m e val)])
139valueToJs _ m _ (Var ident) = varToJs m ident
138valueToJs _ m _ (Var ident) = varToJs m ident
140valueToJs opts m e (TypedValue _ val _) = valueToJs opts m e val
139valueToJs opts m e (TypedValue _ val _) = valueToJs opts m e val
141valueToJs _ _ _ (TypeClassDictionary _ _) = error "Type class dictionary was not replaced"
140valueToJs _ _ _ (TypeClassDictionary _ _) = error "Type class dictionary was not replaced"
@@ -173,39 +172,6 @@ bindNames m idents env = env { names = M.fromList [ ((m, ident), (noType, LocalV
174 noType = error "Temporary lambda variable type was read"
173 noType = error "Temporary lambda variable type was read"
178−-- Generate code in the simplified Javascript intermediate representation for runtime type checks.
180−runtimeTypeChecks :: String -> Type -> [JS]
181−runtimeTypeChecks arg ty =
183− argTy = getFunctionArgumentType ty
185− maybe [] (argumentCheck (JSVar arg)) argTy
187− getFunctionArgumentType :: Type -> Maybe Type
188− getFunctionArgumentType (TypeApp (TypeApp t funArg) _) | t == tyFunction = Just funArg
189− getFunctionArgumentType (ForAll _ ty' _) = getFunctionArgumentType ty'
190− getFunctionArgumentType _ = Nothing
191− argumentCheck :: JS -> Type -> [JS]
192− argumentCheck val t | t == tyNumber = [typeCheck val "number"]
193− argumentCheck val t | t == tyString = [typeCheck val "string"]
194− argumentCheck val t | t == tyBoolean = [typeCheck val "boolean"]
195− argumentCheck val (TypeApp t _) | t == tyArray = [arrayCheck val]
196− argumentCheck val (Object row) =
198− (pairs, _) = rowToList row
200− typeCheck val "object" : concatMap (\(prop, ty') -> argumentCheck (JSAccessor prop val) ty') pairs
201− argumentCheck val (TypeApp (TypeApp t _) _) | t == tyFunction = [typeCheck val "function"]
202− argumentCheck val (ForAll _ ty' _) = argumentCheck val ty'
203− argumentCheck _ _ = []
204− typeCheck :: JS -> String -> JS
205− typeCheck js ty' = JSIfElse (JSBinary NotEqualTo (JSTypeOf js) (JSStringLiteral ty')) (JSBlock [JSThrow (JSStringLiteral $ ty' ++ " expected")]) Nothing
206− arrayCheck :: JS -> JS
207− arrayCheck js = JSIfElse (JSUnary Not (JSApp (JSAccessor "isArray" (JSVar "Array")) [js])) (JSBlock [JSThrow (JSStringLiteral "Array expected")]) Nothing
210-- Generate code in the simplified Javascript intermediate representation for a reference to a
176-- Generate code in the simplified Javascript intermediate representation for a reference to a
211-- variable.
177-- variable.