@@ -338,7 +338,7 @@ reduceJS program =
338338 map reduce candidates ++ map (reduceCall (map funNames candidates)) rest
339339 where findConstructors :: JS -> Bool
340340 findConstructors js
341− | (JSAlloc fun (Just (JSFunction [] (JSSeq body)))) <- js =
341+ | (JSAlloc fun (Just (JSFunction _ (JSSeq body)))) <- js =
342342 reducable $ last body
343343 | otherwise = False
344344 where reducable :: JS -> Bool
@@ -347,24 +347,26 @@ reduceJS program =
347347 reducable (JSArray fields) = and $ map reducable fields
348348 reducable (JSNum _) = True
349349 reducable JSNull = True
350+ reducable (JSIdent _) = True
350351 reducable _ = False
351352
352353 reduce :: JS -> JS
353− reduce (JSAlloc fun (Just (JSFunction [] (JSSeq body))))
354+ reduce (JSAlloc fun (Just (JSFunction _ (JSSeq body))))
354355 | JSReturn js <- last body = (JSAlloc fun (Just js))
355356
357+ reduce js = js
358+
356359 funNames :: JS -> String
357360 funNames (JSAlloc fun _) = fun
358361
359362 reduceCall :: [String] -> JS -> JS
360363 reduceCall funs (JSApp (JSIdent "__IDRRT__tailcall") [JSFunction [] (
361− JSReturn (JSApp (JSIdent ret) [])
364+ JSReturn (JSApp id@(JSIdent ret) _)
362365 )])
363− | ret `elem` funs = JSIdent ret
366+ | ret `elem` funs = id
364367
365− reduceCall funs js@(JSApp (JSIdent fun) [])
366− | fun `elem` funs = JSIdent fun
367− | otherwise = js
368+ reduceCall funs js@(JSApp id@(JSIdent fun) _)
369+ | fun `elem` funs = id
368370
369371 reduceCall funs (JSAlloc fun (Just body)) =
370372 JSAlloc fun (Just $ reduceCall funs body)
@@ -886,8 +888,8 @@ translateExpression patterncase
886888 (checkCon `jsAnd` checkTag, branch)
887889
888890 | TypeCase ty <- caseTy =
889− let checkTy = JSRaw var `jsInstanceOf` jsType
890− checkTag = jsTypeTag (JSRaw var) `jsEq` JSType ty in
891+ let checkTy = JSIdent var `jsInstanceOf` jsType
892+ checkTag = jsTypeTag (JSIdent var) `jsEq` JSType ty in
891893 (checkTy `jsAnd` checkTag, branch)
892894
893895translateExpression (SCon i name vars) =
@@ -899,7 +901,7 @@ translateExpression (SUpdate var e) =
899901 JSAssign (JSVar var) (translateExpression e)
900902
901903translateExpression (SProj var i) =
902− JSIndex (JSProj (JSVar var) "vars") (JSRaw $ show i)
904+ JSIndex (JSProj (JSVar var) "vars") (JSNum $ JSInt i)
903905
904906translateExpression SNothing = JSNull
905907
@@ -962,11 +964,11 @@ translateCaseCond var cse@(SConstCase ty _)
962964 matchHelper ty = (CaseCond $ TypeCase ty, translateCase Nothing cse)
963965
964966translateCaseCond var cse@(SConstCase cst@(BI _) _) =
965− let cond = jsMeth (JSRaw var) "equals" [translateConstant cst] in
967+ let cond = jsMeth (JSIdent var) "equals" [translateConstant cst] in
966968 (RawCond cond, translateCase Nothing cse)
967969
968970translateCaseCond var cse@(SConstCase cst _) =
969− let cond = JSRaw var `jsEq` translateConstant cst in
971+ let cond = JSIdent var `jsEq` translateConstant cst in
970972 (RawCond cond, translateCase Nothing cse)
971973
972974translateCaseCond var cse@(SConCase _ tag _ _ _) =
@@ -978,5 +980,5 @@ translateCase _ (SConstCase _ e) = translateExpression e
978980translateCase (Just var) (SConCase a _ _ vars e) =
979981 let params = map jsVar [a .. (a + length vars)] in
980982 jsMeth (JSFunction params (JSReturn $ translateExpression e)) "apply" [
981− JSThis, JSProj (JSRaw var) "vars"
983+ JSThis, JSProj (JSIdent var) "vars"
982984 ]