我正在尝试从 AS3 代码调用 Tamarin 的 ESC 编译器。我已经在 Flash Player 中加载了 ESC 编译器字节码,但是当我调用它时,ESC 编译器总是返回相同的无操作字节码,无论我提供什么源代码。人类可读的 ESC 代码如下所示:
function compileStringToBytes(input, context="(string)", start_line=1) {
let [_,_,res] = compile( (function () input),
(function (abc) abc.getBytes()),
context,
start_line );
return res;
}
我使用以下 AS3 代码调用它:
var compile:Function = getDefinitionByName("ESC::compileStringToBytes") as Function;
var array:ByteArray = compile( function():String { return "trace(\"hi\");" },
"test" );
但无论我输入什么源代码,它总是返回两个函数的字节码,一个调用另一个,两个函数都不做任何事情。
这是它返回的字节码(元数据被剥离,转换为人类可读):
script0
const <#internal test>::internal:Namespace = <#internal test> /* slot_id 0 */
const <#internal test>::public:Namespace = /* slot_id 0 */
var Function:* /* slot_id 0 */
function script0$init():* /* disp_id 0*/
{
// local_count=2 max_scope=1 max_stack=2 code_len=11
0 getlocal0
1 pushscope
2 findpropstrict Function
4 newfunction function ():* /* disp_id 0*/
6 setproperty Function
8 getlocal1
9 returnvalue
10 returnvoid
}
function ():* /* disp_id 0*/
{
// local_count=1 max_scope=0 max_stack=0 code_len=1
0 returnvoid
}
提前致谢!我知道这是一个核心问题,但我希望一些核心编码器可以阐明它!
最佳答案
找到了我自己问题的答案。
以下站点使用最新的 Tamarin ESC 编译器 ABC 位通过 Flash 动态运行代码(左侧面板显示运行编译器的源代码):
http://wonderfl.net/c/2pBs/read
它实际上使用 Mercurial http 接口(interface)下载器获取 Tamarin Redux 位:http://hg.mozilla.org/tamarin-redux/raw-file/db3ebe261f68/esc/bin/
wonderfl 代码依次使用 Claus Wahlers 的 codeazur as3swf 包装 ABC 位以加载到 Flash(编译器本身和编译后的位):
https://github.com/claus/as3swf
谢谢 Claus 和 wonderfl!开源代码摇滚。
关于actionscript-3 - 如何从 AS3 代码调用 Tamarin ESC 编译器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5845439/