on master help sign in
javascript: schedule continuation every 1000 calls

using stdout with node has a curious side effect. It allocates memory that will only be reclaimed after a new event has been scheduled. Therefore we set a timeout every 1000 calls that will execute the remaining code.

commitac7c313fe63da500e129b27d0f4c5091d79327c1 authorraichoo <raichoo@googlemail.com> dateWed 12 Aug 2015, 00:49 (11 years ago) parent8c28352
3 files changed+12−7
jsrts/Runtime-browser.js−1 jsrts/Runtime-common.js+11 src/IRTS/CodegenJavaScript.hs+1−6
jsrts/Runtime-browser.js−1
@@ -2,7 +2,6 @@ var i$putStr = function(s) {
22 console.log(s);
33};
44
5−
65var i$systemInfo = function(index) {
76 switch(index) {
87 case 0:
jsrts/Runtime-common.js+11
@@ -104,3 +104,14 @@ var i$fromCharCode = function(chr) {
104104 else
105105 return String.fromCharCode(chr);
106106}
107+
108+var i$RUN = function () {
109+ for (var i = 0; i < 1000 && i$callstack.length; i++) {
110+ var func = i$callstack.pop();
111+ var args = i$callstack.pop();
112+ func.apply(this,args);
113+ };
114+
115+ if (i$callstack.length)
116+ setTimeout(i$RUN, 0);
117+}
src/IRTS/CodegenJavaScript.hs+1−6
@@ -250,12 +250,7 @@ codegenJS_all target definitions includes libs filename outputType = do
250250 , JSApp (
251251 JSIdent (translateName (sMN 0 "runMain"))
252252 ) [JSNew "i$POINTER" [JSNum (JSInt 0)]]
253− , JSWhile (JSProj jsCALLSTACK "length") (
254− JSSeq [ JSAlloc "func" (Just jsPOP)
255− , JSAlloc "args" (Just jsPOP)
256− , JSApp (JSProj (JSIdent "func") "apply") [JSThis, JSIdent "args"]
257− ]
258− )
253+ , JSApp (JSIdent "i$RUN") []
259254 ]
260255
261256 invokeMain :: T.Text