git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #472 from purescript/remove-bindnames
4fc5a0dPhil Freeman
src/Language/PureScript/CodeGen/JS.hs+2−18
@@ -171,7 +171,7 @@ valueToJs opts m e (Let ds val) = do
171 ret <- valueToJs opts m e val
171 ret <- valueToJs opts m e val
172 return $ JSApp (JSFunction Nothing [] (JSBlock (decls ++ [JSReturn ret]))) []
172 return $ JSApp (JSFunction Nothing [] (JSBlock (decls ++ [JSReturn ret]))) []
173valueToJs opts m e (Abs (Left arg) val) = do
173valueToJs opts m e (Abs (Left arg) val) = do
174− ret <- valueToJs opts m (bindName m arg e) val
174+ ret <- valueToJs opts m e val
175 return $ JSFunction Nothing [identToJs arg] (JSBlock [JSReturn ret])
175 return $ JSFunction Nothing [identToJs arg] (JSBlock [JSReturn ret])
176valueToJs opts m e (TypedValue _ (Abs (Left arg) val) ty) | optionsPerformRuntimeTypeChecks opts = do
176valueToJs opts m e (TypedValue _ (Abs (Left arg) val) ty) | optionsPerformRuntimeTypeChecks opts = do
177 let arg' = identToJs arg
177 let arg' = identToJs arg
@@ -201,22 +201,6 @@ extendObj obj sts = do
201 stToAssign (s, js) = JSAssignment (JSAccessor s jsNewObj) js
201 stToAssign (s, js) = JSAssignment (JSAccessor s jsNewObj) js
202 extend = map stToAssign sts
202 extend = map stToAssign sts
203 return $ JSApp (JSFunction Nothing [] block) []
203 return $ JSApp (JSFunction Nothing [] block) []
204− where
205−
206−-- |
207−-- Temporarily extends the environment with a single local variable name
208−--
209−bindName :: ModuleName -> Ident -> Environment -> Environment
210−bindName m ident = bindNames m [ident]
211−
212−-- |
213−-- Temporarily extends the environment to include local variable names introduced by lambda
214−-- abstractions or case statements
215−--
216−bindNames :: ModuleName -> [Ident] -> Environment -> Environment
217−bindNames m idents env = env { names = M.fromList [ ((m, ident), (noType, LocalVariable)) | ident <- idents ] `M.union` names env }
218− where
219− noType = error "Temporary lambda variable type was read"
220
204
221-- |
205-- |
222-- Generate code in the simplified Javascript intermediate representation for runtime type checks.
206-- Generate code in the simplified Javascript intermediate representation for runtime type checks.
@@ -274,7 +258,7 @@ bindersToJs :: (Functor m, Applicative m, Monad m) => Options -> ModuleName -> E
274bindersToJs opts m e binders vals = do
258bindersToJs opts m e binders vals = do
275 valNames <- replicateM (length vals) freshName
259 valNames <- replicateM (length vals) freshName
276 jss <- forM binders $ \(CaseAlternative bs grd result) -> do
260 jss <- forM binders $ \(CaseAlternative bs grd result) -> do
277− ret <- valueToJs opts m (bindNames m (concatMap binderNames bs) e) result
261+ ret <- valueToJs opts m e result
278 go valNames [JSReturn ret] bs grd
262 go valNames [JSReturn ret] bs grd
279 return $ JSApp (JSFunction Nothing valNames (JSBlock (concat jss ++ [JSThrow (JSStringLiteral "Failed pattern match")])))
263 return $ JSApp (JSFunction Nothing valNames (JSBlock (concat jss ++ [JSThrow (JSStringLiteral "Failed pattern match")])))
280 vals
264 vals