on master help sign in
javascript: unlimited callstacks
commit312f83f971abd2487da5e6b0b3b52b2b33fbbb05 authorraichoo <raichoo@googlemail.com> dateMon 23 Jun 2014, 03:20 (12 years ago) parentdaac606
2 files changed+11−3
jsrts/Runtime-common.js+4−1 src/IRTS/CodegenJavaScript.hs+7−2
jsrts/Runtime-common.js+4−1
@@ -6,6 +6,8 @@ var i$VM = function() {
66
77 this.ret = null;
88 this.reg1 = null;
9+
10+ this.callstack = [];
911}
1012
1113/** @constructor */
@@ -27,7 +29,8 @@ var i$PROJECT = function(vm,val,loc,arity) {
2729}
2830
2931var i$CALL = function(vm,fun,args) {
30− fun.apply(this,args);
32+ vm.callstack.push(args);
33+ vm.callstack.push(fun);
3134}
3235
3336var __IDRRT__charCode = function(str) {
src/IRTS/CodegenJavaScript.hs+7−2
@@ -332,6 +332,12 @@ codegenJS_all target definitions includes filename outputType = do
332332 ) [ JSIdent "vm"
333333 , JSNum (JSInt 0)
334334 ]
335+ , JSWhile (JSProj (JSProj (JSIdent ("vm")) "callstack") "length") (
336+ JSSeq [ JSAlloc "func" (Just (JSApp (JSProj (JSProj (JSIdent ("vm")) "callstack") "pop") []))
337+ , JSAlloc "args" (Just (JSApp (JSProj (JSProj (JSIdent ("vm")) "callstack") "pop") []))
338+ , JSApp (JSProj (JSIdent "func") "apply") [JSThis, JSIdent "args"]
339+ ]
340+ )
335341 ]
336342 )
337343
@@ -377,8 +383,7 @@ splitFunction (JSAlloc name (Just (JSFunction args body@(JSSeq _)))) = do
377383 put (depth + 1)
378384 new <- splitFunction (newFun rest)
379385 tell [(depth, new)]
380− {-return $ JSSeq (pre ++ [newCall depth, call])-}
381− return $ JSSeq (pre ++ (call : [newCall depth]))
386+ return $ JSSeq (pre ++ (newCall depth : [call]))
382387
383388 splitSequence js = return js
384389