format.abc: OP_newactivation used in method without NEED_ACTIVATION flag

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

format.abc: OP_newactivation used in method without NEED_ACTIVATION flag

alstrup
Hi,

Using format.abc, I run into the error in the subject when I try to generate a SWF file with a method using the ONewBlock instruction. I fail to see how to set that flag for a method. I have tried

   var t = untyped ctx.curFunction.f;
   t.newBlock = true;

but it does not help. Any ideas?

See the attached, and produce the final Test.swf with:

  haxe -main Main -neko main.n -lib format
  neko main.n
  haxe -main SwfRunner -swf Test.swf -swf-version 10 -swf-lib Main.swf

Regards,
Asger
P.s. I have tried hxswfml as well, but I can not get it to produce a SWF file similar to what I do in the zip file.


--
haXe - an open source web programming language
http://haxe.org

activation.zip (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: format.abc: OP_newactivation used in method without NEED_ACTIVATION flag

Nicolas Cannasse
Le 23/08/2011 09:40, Asger Ottar Alstrup a écrit :

> Hi,
>
> Using format.abc, I run into the error in the subject when I try to
> generate a SWF file with a method using the ONewBlock instruction. I
> fail to see how to set that flag for a method. I have tried
>
>     var t = untyped ctx.curFunction.f;
>     t.newBlock = true;
>
> but it does not help. Any ideas?

Try to check what the haXe compiler is doing in genswf9.ml when there
are "captured" variables.

Nicolas


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: format.abc: OP_newactivation used in method without NEED_ACTIVATION flag

alstrup
Hi,

Yes, I know how to find out when to use the newBlock instructions (when there are free variables that needs to be captured in a closure), but the question is how to produce the correct SWF bytecodes for this.

Looking at 


line 731, it says

                        hlmt_new_block = hasblock;

and that value is sent along to the SWF writer. Where can I find out what effect that hlmt_new_block field has in terms of the bytecode? It seems that you need to tell Flash that the method needs that capability, but I fail to see how to produce that.

Thanks,
Asger

On Tue, Aug 23, 2011 at 10:13 AM, Nicolas Cannasse <[hidden email]> wrote:
Le 23/08/2011 09:40, Asger Ottar Alstrup a écrit :

Hi,

Using format.abc, I run into the error in the subject when I try to
generate a SWF file with a method using the ONewBlock instruction. I
fail to see how to set that flag for a method. I have tried

   var t = untyped ctx.curFunction.f;
   t.newBlock = true;

but it does not help. Any ideas?

Try to check what the haXe compiler is doing in genswf9.ml when there are "captured" variables.

Nicolas


--
haXe - an open source web programming language
http://haxe.org



--
Asger Ottar Alstrup, SVP - Research & Development
Area9, Nyhavn 63d, 3, DK-1052 København K
Phone: +45 33 11 00 90, cell (DK): +45 26 16 79 03, cell (US): 630 995 9277

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: format.abc: OP_newactivation used in method without NEED_ACTIVATION flag

Nicolas Cannasse
In reply to this post by alstrup
Le 23/08/2011 09:40, Asger Ottar Alstrup a écrit :

> Hi,
>
> Using format.abc, I run into the error in the subject when I try to
> generate a SWF file with a method using the ONewBlock instruction. I
> fail to see how to set that flag for a method. I have tried
>
>     var t = untyped ctx.curFunction.f;
>     t.newBlock = true;
>
> but it does not help. Any ideas?

You need to somehow pass the "extra" parameter to beginFunction which is
a MethodTypeExtra with newBlock = true

The current Context api does not allow it but you can subclass it to add
such access.

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: format.abc: OP_newactivation used in method without NEED_ACTIVATION flag

Jan_Flanders
In reply to this post by alstrup


On Tue, Aug 23, 2011 at 9:40 AM, Asger Ottar Alstrup <[hidden email]> wrote:
Hi,

Using format.abc, I run into the error in the subject when I try to generate a SWF file with a method using the ONewBlock instruction. I fail to see how to set that flag for a method. I have tried

   var t = untyped ctx.curFunction.f;
   t.newBlock = true;

but it does not help. Any ideas?

See the attached, and produce the final Test.swf with:

  haxe -main Main -neko main.n -lib format
  neko main.n
  haxe -main SwfRunner -swf Test.swf -swf-version 10 -swf-lib Main.swf

Regards,
Asger
P.s. I have tried hxswfml as well, but I can not get it to produce a SWF file similar to what I do in the zip file.


--
haXe - an open source web programming language
http://haxe.org

With some adjustments to your example it works:

import format.abc.Data;
import format.swf.Data;
import neko.Sys;
import neko.Lib;
import neko.FileSystem;
import neko.io.File;
class Main
{
    public static function main()
    {
        var ctx = new format.abc.Context();
        var cl = ctx.beginClass('Swf', false);
        
        var f=ctx.beginMethod('Swf', [], ctx.type('*'), false, false, false, true, KNormal);
        cl.constructor = f.type;
        ctx.ops([
            OThis,
            OScope,
            OThis,
            OConstructSuper(0),
            ORetVoid]);
        f.maxStack = f.maxScope = 1;

        f=ctx.beginMethod('test', [], ctx.type('int'), false, false, false, false, KNormal,
        {native:false, variableArgs:false, argumentsDefined : false, usesDXNS:false, newBlock:true,
        unused:false, debugName:ctx.string(''), defaultParameters:null, paramNames:null});
        ctx.ops([
            ONewBlock,
            OPop,
            OInt(666),
            ORet]);
        f.maxStack = f.maxScope = 1;
        
        ctx.endClass(true);

        var abcOutput = new haxe.io.BytesOutput();
        new format.abc.Writer(abcOutput).write(ctx.getData());
        var swfFile =
        {
            header: {version:10, compressed:false, width:800, height:600, fps:30, nframes:1},
            tags:
            [
                TSandBox({useDirectBlit :false, useGPU:false, hasMetaData:false, actionscript3:true, useNetWork:true}),
                TActionScript3(abcOutput.getBytes()),
                TShowFrame
            ]
        };
        var swfOutput = new haxe.io.BytesOutput();
        new format.swf.Writer(swfOutput).write(swfFile);
        var file = File.write("Main.swf",true);
        file.write(swfOutput.getBytes());
        file.close();
    }
}


class SwfRunner {
    public static function main() {
        var swfClass = Type.resolveClass("Swf");
        var swf = Type.createInstance(swfClass, []);
        trace(Reflect.callMethod(swf, Reflect.field(swf, "test"), []));//666
    }
}

Also attached in the zip.

Jan

--
haXe - an open source web programming language
http://haxe.org

activation.zip (89K) Download Attachment