actionscript-3 - 如何从 AS3 代码调用 Tamarin ESC 编译器?

标签 actionscript-3 compiler-construction eval ecmascript-5

我正在尝试从 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/

相关文章:

actionscript-3 - ActionScript 3 TransformGestureEvent 不适用于 SWF MovieClip

bash - 带参数和 eval 的条件构造

flash - 加载crossdomain.xml策略文件时出现网络故障怎么办?

apache-flex - 更改 textfield() 鼠标悬停的光标

actionscript-3 - 检查 child 是否存在

c++ - VS2010 未在预处理器条件下正确处理 "includes"

c++ - C++ 编译器如何创建对象?

Scala 不处理 ':' 函数的非显式类型闭包

javascript - 解析 JSON - eval() 或函数对象?

jQuery 的 getScript - 将文件包含到主范围中?