on master help sign in
javascript: unlimited callstacks
312f83fraichoo
jsrts/Runtime-common.js+4−1
@@ -6,6 +6,8 @@ var i$VM = function() {
6
6
7 this.ret = null;
7 this.ret = null;
8 this.reg1 = null;
8 this.reg1 = null;
9+
10+ this.callstack = [];
9}
11}
10
12
11/** @constructor */
13/** @constructor */
@@ -27,7 +29,8 @@ var i$PROJECT = function(vm,val,loc,arity) {
27}
29}
28
30
29var i$CALL = function(vm,fun,args) {
31var i$CALL = function(vm,fun,args) {
30− fun.apply(this,args);
32+ vm.callstack.push(args);
33+ vm.callstack.push(fun);
31}
34}
32
35
33var __IDRRT__charCode = function(str) {
36var __IDRRT__charCode = function(str) {
src/IRTS/CodegenJavaScript.hs+7−2
@@ -332,6 +332,12 @@ codegenJS_all target definitions includes filename outputType = do
332 ) [ JSIdent "vm"
332 ) [ JSIdent "vm"
333 , JSNum (JSInt 0)
333 , JSNum (JSInt 0)
334 ]
334 ]
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+ )
335 ]
341 ]
336 )
342 )
337
343
@@ -377,8 +383,7 @@ splitFunction (JSAlloc name (Just (JSFunction args body@(JSSeq _)))) = do
377 put (depth + 1)
383 put (depth + 1)
378 new <- splitFunction (newFun rest)
384 new <- splitFunction (newFun rest)
379 tell [(depth, new)]
385 tell [(depth, new)]
380− {-return $ JSSeq (pre ++ [newCall depth, call])-}
386+ return $ JSSeq (pre ++ (newCall depth : [call]))
381− return $ JSSeq (pre ++ (call : [newCall depth]))
382
387
383 splitSequence js = return js
388 splitSequence js = return js
384
389