on master help sign in
javascript: add jsPOP and jsPUSH utility functions
503b055raichoo
src/IRTS/CodegenJavaScript.hs+8−2
@@ -347,8 +347,8 @@ codegenJS_all target definitions includes filename outputType = do
347 JSIdent (translateName (sMN 0 "runMain"))
347 JSIdent (translateName (sMN 0 "runMain"))
348 ) [JSNum (JSInt 0)]
348 ) [JSNum (JSInt 0)]
349 , JSWhile (JSProj jsCALLSTACK "length") (
349 , JSWhile (JSProj jsCALLSTACK "length") (
350− JSSeq [ JSAlloc "func" (Just (JSApp (JSProj jsCALLSTACK "pop") []))
350+ JSSeq [ JSAlloc "func" (Just jsPOP)
351− , JSAlloc "args" (Just (JSApp (JSProj jsCALLSTACK "pop") []))
351+ , JSAlloc "args" (Just jsPOP)
352 , JSApp (JSProj (JSIdent "func") "apply") [JSThis, JSIdent "args"]
352 , JSApp (JSProj (JSIdent "func") "apply") [JSThis, JSIdent "args"]
353 ]
353 ]
354 )
354 )
@@ -1358,6 +1358,12 @@ jsTOP :: Int -> JS
1358jsTOP 0 = JSIndex jsSTACK jsSTACKTOP
1358jsTOP 0 = JSIndex jsSTACK jsSTACKTOP
1359jsTOP n = JSIndex jsSTACK (JSBinOp "+" jsSTACKTOP (JSNum (JSInt n)))
1359jsTOP n = JSIndex jsSTACK (JSBinOp "+" jsSTACKTOP (JSNum (JSInt n)))
1360
1360
1361+jsPUSH :: [JS] -> JS
1362+jsPUSH args = JSApp (JSProj jsCALLSTACK "push") args
1363+
1364+jsPOP :: JS
1365+jsPOP = JSApp (JSProj jsCALLSTACK "pop") []
1366+
1361translateBC :: CompileInfo -> BC -> JS
1367translateBC :: CompileInfo -> BC -> JS
1362translateBC info bc
1368translateBC info bc
1363 | ASSIGN r1 r2 <- bc = jsASSIGN info r1 r2
1369 | ASSIGN r1 r2 <- bc = jsASSIGN info r1 r2