简体   繁体   English

使用Node运行GHCJS程序的变量太多

[英]Too many variables to run GHCJS program with Node

I'm trying to run a program built with GHCJS using node.js. 我正在尝试使用node.js运行使用GHCJS构建的程序。 However, I get the following error: 但是,我收到以下错误:

SyntaxError: Too many variables declared (only 131071 allowed)
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3
  1. Is it possible to increase the number of allowed variables in node? 是否可以增加节点中允许的变量数量?
  2. Is there a better utility for running JS files which would allow for more variables 是否有更好的实用程序来运行JS文件,这将允许更多的变量
  3. Are there optimization tools which could automatically reduce the number of variables? 是否有可以自动减少变量数量的优化工具?

Note that this is machine generated JS, so I have no desire to go through by hand and reduce the number of variables. 请注意,这是机器生成的JS,因此我不希望手动完成并减少变量的数量。

Any ideas are welcome. 欢迎任何想法。

Must be a pretty big program :) 必须是一个非常大的程序:)

I have run into the variables limit on very old node versions (32k) but not yet into the new raised limit. 我已经遇到了非常旧的节点版本(32k)的变量限制,但尚未进入新的上升限制。 The problem is similar to the Windows DLL symbols limit causing problems with dynamic linking, and possibly just as annoying. 问题类似于Windows DLL符号限制导致动态链接问题,可能同样令人讨厌。

GHCJS emits all generated code as top-level functions and variables for efficiency and simplicity (closures are handled by the STG implementation, so nested functions are not necessary here). GHCJS将所有生成的代码作为顶级函数和变量发出,以提高效率和简单性(闭包由STG实现处理,因此这里不需要嵌套函数)。

The limit only applies to local (function) scopes. 该限制仅适用于本地(函数)范围。 Unfortunately, node.js uses a module system, and loads all code implicitly into a local scope. 遗憾的是,node.js使用模块系统,并将所有代码隐式加载到本地范围中。

Fortunately JavaScript gives us a way to still declare global names from a local scope, you just need to remove the var keyword! 幸运的是,JavaScript为我们提供了一种从本地范围声明全局名称的方法,您只需要删除var关键字! I think you should be able to run the script if you replace all var h$ at the beginning of a line with h$ . 我想你应该可以,如果你更换所有运行的脚本var h$在与行的开头h$

Alternatively you can try running the script with the SpiderMonkey JS shell or in a browser, but these give you a more limited environment (no filesystem access, cannot start or interact with other processes). 或者,您可以尝试使用SpiderMonkey JS shell或在浏览器中运行脚本,但这些会为您提供更有限的环境(无文件系统访问,无法启动或与其他进程交互)。

If the variable limit remains a problem for you, please open a ticket at https://github.com/ghcjs/ghcjs/issues so we can try to find a more permanent solution (probably by adjusting the link-time transformation step to divide the generated code into multiple modules). 如果变量限制仍然是您的问题,请在https://github.com/ghcjs/ghcjs/issues打开一张票,这样我们就可以尝试找到一个更永久的解决方案(可能通过调整链接时转换步骤来划分将生成的代码分成多个模块)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM