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.
This commit is contained in:
raichoo 2015-08-12 00:49:28 +02:00
parent 8c283520f3
commit ac7c313fe6
3 changed files with 12 additions and 7 deletions

View File

@ -2,7 +2,6 @@ var i$putStr = function(s) {
console.log(s);
};
var i$systemInfo = function(index) {
switch(index) {
case 0:

View File

@ -104,3 +104,14 @@ var i$fromCharCode = function(chr) {
else
return String.fromCharCode(chr);
}
var i$RUN = function () {
for (var i = 0; i < 1000 && i$callstack.length; i++) {
var func = i$callstack.pop();
var args = i$callstack.pop();
func.apply(this,args);
};
if (i$callstack.length)
setTimeout(i$RUN, 0);
}

View File

@ -250,12 +250,7 @@ codegenJS_all target definitions includes libs filename outputType = do
, JSApp (
JSIdent (translateName (sMN 0 "runMain"))
) [JSNew "i$POINTER" [JSNum (JSInt 0)]]
, JSWhile (JSProj jsCALLSTACK "length") (
JSSeq [ JSAlloc "func" (Just jsPOP)
, JSAlloc "args" (Just jsPOP)
, JSApp (JSProj (JSIdent "func") "apply") [JSThis, JSIdent "args"]
]
)
, JSApp (JSIdent "i$RUN") []
]
invokeMain :: T.Text