Last active
December 15, 2015 07:48
-
-
Save reactormonk/5225756 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Generated by the Nimrod Compiler v0.9.1 */ | |
| /* (c) 2013 Andreas Rumpf */ | |
| var Globals = this; | |
| var framePtr = null; | |
| var excHandler = null; | |
| var NTI842 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; | |
| var NTI808 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; | |
| var NTI140 = {size: 0,kind: 28,base: null,node: null,finalizer: null}; | |
| var NTI142 = {size: 0,kind: 29,base: null,node: null,finalizer: null}; | |
| var NTI893 = {size: 0,kind: 22,base: null,node: null,finalizer: null}; | |
| var NTI824 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; | |
| var NTI828 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; | |
| var NTI840 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; | |
| var NTI844 = {size: 0, kind: 17, base: null, node: null, finalizer: null}; | |
| var NNI844 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []}; | |
| NTI844.node = NNI844; | |
| var NNI840 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []}; | |
| NTI840.node = NNI840; | |
| var NNI828 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []}; | |
| NTI828.node = NNI828; | |
| NTI893.base = NTI824; | |
| var NNI824 = {kind: 2, len: 4, offset: 0, typ: null, name: null, sons: [{kind: 1, offset: "parent", len: 0, typ: NTI893, name: "parent", sons: null}, | |
| {kind: 1, offset: "name", len: 0, typ: NTI142, name: "name", sons: null}, | |
| {kind: 1, offset: "message", len: 0, typ: NTI140, name: "msg", sons: null}, | |
| {kind: 1, offset: "trace", len: 0, typ: NTI140, name: "trace", sons: null}]}; | |
| NTI824.node = NNI824; | |
| var NNI808 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []}; | |
| NTI808.node = NNI808; | |
| NTI824.base = NTI808; | |
| NTI828.base = NTI824; | |
| NTI840.base = NTI828; | |
| NTI844.base = NTI840; | |
| var NNI842 = {kind: 2, len: 0, offset: 0, typ: null, name: null, sons: []}; | |
| NTI842.node = NNI842; | |
| NTI842.base = NTI840; | |
| var nim_program_result = 0; | |
| var globalraisehook_5241 = null; | |
| var localraisehook_5246 = null; | |
| var outofmemhook_5249 = null; | |
| function cstrToNimstr(c_5950) { | |
| var result = []; | |
| for (var i = 0; i < c_5950.length; ++i) { | |
| result[i] = c_5950.charCodeAt(i); | |
| } | |
| result[result.length] = 0; // terminating zero | |
| return result; | |
| } | |
| function eqStrings(a_6006, b_6007) { | |
| if (a_6006 == b_6007) return true; | |
| if ((!a_6006) || (!b_6007)) return false; | |
| var alen = a_6006.length; | |
| if (alen != b_6007.length) return false; | |
| for (var i = 0; i < alen; ++i) | |
| if (a_6006[i] != b_6007[i]) return false; | |
| return true; | |
| } | |
| function add_5263(x_5266, x_5266_Idx, y_5267) { | |
| var len = x_5266[0].length-1; | |
| for (var i = 0; i < y_5267.length; ++i) { | |
| x_5266[0][len] = y_5267.charCodeAt(i); | |
| ++len; | |
| } | |
| x_5266[0][len] = 0 | |
| } | |
| function toJSStr(s_5954) { | |
| var len = s_5954.length-1; | |
| var result = new Array(len); | |
| var fcc = String.fromCharCode; | |
| for (var i = 0; i < len; ++i) { | |
| result[i] = fcc(s_5954[i]); | |
| } | |
| return result.join(""); | |
| } | |
| function raiseException(e_5762, ename_5763) { | |
| e_5762.name = ename_5763; | |
| if (!((excHandler == null))) { | |
| excHandler.exc = e_5762; | |
| }else { | |
| var buf_5775 = [cstrToNimstr("")]; | |
| if ((!(eqStrings(e_5762.message, null)) && !((e_5762.message[0] == 0)))) { | |
| buf_5775[0] = (buf_5775[0].slice(0,-1)).concat(cstrToNimstr("Error: unhandled exception: ")); | |
| buf_5775[0] = (buf_5775[0].slice(0,-1)).concat(e_5762.message); | |
| }else { | |
| buf_5775[0] = (buf_5775[0].slice(0,-1)).concat(cstrToNimstr("Error: unhandled exception")); | |
| } | |
| buf_5775[0] = (buf_5775[0].slice(0,-1)).concat(cstrToNimstr(" [")); | |
| add_5263(buf_5775, 0, ename_5763); | |
| buf_5775[0] = (buf_5775[0].slice(0,-1)).concat(cstrToNimstr("]\x0A")); | |
| console.log(toJSStr(buf_5775[0])); | |
| } | |
| throw e_5762;} | |
| function raiseOverflow() { | |
| raiseException(function () {var e_5839 = null; | |
| e_5839 = {m_type: NTI844, parent: null, name: null, message: null, trace: null}; | |
| ; | |
| e_5839.message = cstrToNimstr("over- or underflow"); | |
| return e_5839; }(), "EOverflow"); | |
| } | |
| function raiseDivByZero() { | |
| raiseException(function () {var e_5861 = null; | |
| e_5861 = {m_type: NTI842, parent: null, name: null, message: null, trace: null}; | |
| ; | |
| e_5861.message = cstrToNimstr("divison by zero"); | |
| return e_5861; }(), "EDivByZero"); | |
| } | |
| function newseq_9007(len_9010) { | |
| var result_9012 = null; | |
| result_9012 = new Array(len_9010); for (var i=0;i<len_9010;++i) {result_9012[i]=null;}; | |
| return result_9012; | |
| } | |
| var a_9039 = newseq_9007(0); | |
| var i_9076 = 0; | |
| var i_9099 = 0; | |
| if ((i_9099 <= 3)) { | |
| L1: while (1) { | |
| i_9076 = [1, 2, 3, 4][i_9099]; | |
| var j_9077 = i_9076; | |
| function X3Aanonymous_9078() { | |
| var result_9080 = 0; | |
| result_9080 = j_9077; | |
| return result_9080; | |
| } | |
| ; | |
| var fun_9081 = X3Aanonymous_9078; | |
| a_9039.push(fun_9081); | |
| if ((3 <= i_9099)) { | |
| break L1; | |
| } | |
| i_9099 += 1; | |
| } | |
| } | |
| function rawEcho() { | |
| var buf = ""; | |
| for (var i = 0; i < arguments.length; ++i) { | |
| buf += toJSStr(arguments[i]); | |
| } | |
| console.log(buf); | |
| } | |
| var fun_9133 = null; | |
| var i_9135 = 0; | |
| while ((i_9135 < a_9039.length)) { | |
| fun_9133 = a_9039[i_9135]; | |
| rawEcho(cstrToNimstr((fun_9133())+"")); | |
| i_9135 += 1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- test.js | |
| +++ test.js | |
| @@ -119,13 +119,15 @@ | |
| L1: while (1) { | |
| i_9076 = [1, 2, 3, 4][i_9099]; | |
| var j_9077 = i_9076; | |
| - function X3Aanonymous_9078() { | |
| + var X3Aanonymous_9078 = function(j) { | |
| + return function () { | |
| var result_9080 = 0; | |
| - result_9080 = j_9077; | |
| + result_9080 = j; | |
| return result_9080; | |
| } | |
| ; | |
| - var fun_9081 = X3Aanonymous_9078; | |
| + } | |
| + var fun_9081 = X3Aanonymous_9078(j_9077); | |
| a_9039.push(fun_9081); | |
| if ((3 <= i_9099)) { | |
| break L1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- a/test.js | |
| +++ b/test.js | |
| @@ -119,14 +119,16 @@ | |
| L1: while (1) { | |
| i_9076 = [1, 2, 3, 4][i_9099]; | |
| var j_9077 = i_9076; | |
| + (function(i) { | |
| function X3Aanonymous_9078() { | |
| var result_9080 = 0; | |
| - result_9080 = j_9077; | |
| + result_9080 = i; | |
| return result_9080; | |
| } | |
| ; | |
| var fun_9081 = X3Aanonymous_9078; | |
| a_9039.push(fun_9081); | |
| + })(j_9077); | |
| if ((3 <= i_9099)) { | |
| break L1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this is the proper fix: