Question

I'm trying to call Tamarin's ESC Compiler from AS3 code. I've got the ESC Compiler byte code loaded in Flash Player, but when I call it, the ESC Compiler always returns the same do nothing byte code, no matter what source code I feed it. The human readable ESC code looks like this:

function compileStringToBytes(input, context="(string)", start_line=1) {
    let [_,_,res] = compile( (function () input),
                             (function (abc) abc.getBytes()),
                             context,
                             start_line );
    return res;
}

I'm calling it using the following AS3 code:

var compile:Function = getDefinitionByName("ESC::compileStringToBytes") as Function;
var array:ByteArray = compile( function():String { return "trace(\"hi\");" },
                "test" );

But no matter what source code I feed it, it always returns byte code of two functions, one that calls the other, with neither function doing anything.

This is the byte code it returns (metadata stripped out, converted to human readable):

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      
}

Thanks in advance! I know this is hardcore question but I hope some hardcore coder can shed some light on it!

Was it helpful?

Solution

Found an answer to my own question.

The following site uses the newest Tamarin ESC Compiler ABC bits to dynamically run code through Flash (the panel on the left shows the source code which runs the compiler):

http://wonderfl.net/c/2pBs/read

It actually grabs the Tamarin Redux bits using the Mercurial http interface downloader: http://hg.mozilla.org/tamarin-redux/raw-file/db3ebe261f68/esc/bin/

The wonderfl code in turns uses Claus Wahlers' codeazur as3swf to wrap the ABC bits to load into Flash (both the compiler itself and the compiled bits):

https://github.com/claus/as3swf

Thank you Claus and wonderfl! Open sourced code rocks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top