as3-commons-bytecode: How to use object's property on method body's definition?

134 views
Skip to first unread message

Rodrigo Hamuy Aquino

unread,
Feb 7, 2014, 7:31:27 PM2/7/14
to as3-commons...@googlegroups.com
I'm getting started using the "Introduction to the emit API" on as3-commons-bytecode:

Defining a method body, how do you use an object's property?

On the documentation they give this example:

methodBuilder.addOpcode(Opcode.getlocal_0)
             .addOpcode(Opcode.pushscope)
             .addOpcode(Opcode.getlocal_1)
             .addOpcode(Opcode.pushint, [100])
             .addOpcode(Opcode.multiply)
             .addOpcode(Opcode.setlocal_1)
             .addOpcode(Opcode.getlocal_1)
             .addOpcode(Opcode.returnvalue);

As3 equivalent is:

public function multiplyByHundred(value:int):int {
  value = (value * 100);
  return value;
}

What'll be the equivalent to:

public function multiplyPropertyByHundred():int {
  someProperty = (someProperty * 100);
  return someProperty;
}

Where someProperty is an object's property?

I have already create two properties:
- one from the same class, 
- and another inhered from parent .as3 class (thanks to http://manamark.blogspot.com/2013/11/mxcorebitmapasset-and-as3commonsbytecode.html )

Thanks for any answer!

Roland Zwaga

unread,
Feb 8, 2014, 4:29:48 AM2/8/14
to as3-commons...@googlegroups.com
Hi there,

as mentioned in the docs, you can refer to this PDF: http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/actionscript/articles/avm2overview.pdf
for a full list of all opcodes and their meaning.
What can help you as well is the swfdump utility, located in the the bin folder of your Flex SDK, and use that to dump a SWF's contents.
All method bodies will be in this file as well, that way you can compare the opcode output with your source code and get an idea of how all the moving parts correspond.

good luck,

Roland

Rodrigo Hamuy Aquino

unread,
Feb 8, 2014, 5:35:28 AM2/8/14
to as3-commons...@googlegroups.com
Thanks Roland, I did it. Sorry for not give more feedback on my question from the beginning. Here is what I get so far...

Using swfdump, I translate some method with objects properties, this is what I get:

00015) + 0:1 getlex <q>[public]::jumpHeight

where jumpHeight is an object property.

In the Adobe docs describe this instruction as "Find and get a property". (Just what I need). 

But how I use getlex instruction in this API? 

getlex, getproperty and others Opcodes const from the API requires a BaseMultiname property.
getlex = new Opcode(0x60, "getlex", [BaseMultiname, AbcSpec.U30]);

Again, a BaseMultiname use a MultinameKind parameter in his constructor, and MultinameKind's constructor is:

MultinameKind(byteValue:int, descriptionValue:String)

I dont know how to translate this assemply output in the as3-commons-bytecode's API format.

Short version. In method body definition, on:

.addOpcode(Opcode.getlex[
   /* how I writte <q>[public]::jumpHeight  ?*/
])

Thanks again!

Rodrigo Hamuy Aquino

unread,
Feb 8, 2014, 4:51:04 PM2/8/14
to as3-commons...@googlegroups.com
Tried defining method bodies using a string source. No luck.

var source:String = (<![CDATA[
getlocal_0
pushscope
getlocal_1
pushint 100
multiply
setlocal_1
getlocal_1
returnvalue
]]>).toString();

methodBuilder.addAsmSource(source);

I'm getting this error:

TypeError: Error #1034: Error converting []@504ec69 to __AS3__.vec.Vector.<org.as3commons.bytecode.abc::Op>.
at org.as3commons.bytecode.emit.impl::MethodBodyBuilder/addAsmSource()[C:\Users\Rodrigo\Downloads\Flash\as3commons-bytecode\as3-commons.googlecode.com\src\main\actionscript\org\as3commons\bytecode\emit\impl\MethodBodyBuilder.as:397]
at org.as3commons.bytecode.emit.impl::MethodBuilder/addAsmSource()[C:\Users\Rodrigo\Downloads\Flash\as3commons-bytecode\as3-commons.googlecode.com\src\main\actionscript\org\as3commons\bytecode\emit\impl\MethodBuilder.as:153]

Rodrigo Hamuy Aquino

unread,
Feb 9, 2014, 9:25:22 PM2/9/14
to as3-commons...@googlegroups.com
The conversion problem is a library issue. To convert Array to Vector, use Vector.<Type>(arrayObject)

But still cant figured out how to get an object property on method body definition.

Rodrigo Hamuy Aquino

unread,
Feb 10, 2014, 9:50:57 AM2/10/14
to as3-commons...@googlegroups.com
Solution:

Using:
var source:String = (<![CDATA[
   getlocal_0
   pushscope
   getlex jumpHeight
   pushint 100
   multiply
   setlocal_1
   getlocal_1
   returnvalue
]]>).toString();

methodBuilder.addAsmSource(source);

Works after some modifications to the bytecode API. You could commit those fix in the next commit (if'll be any):

On org.as3commons.bytecode.emit.impl.MethodBodyBuilder
Line 397
Change: addOpcodes(result[0]);
for: addOpcodes(Vector.<Op>(result[0]));

Line: 431
Chage:_backpatches = _backpatches.concat(newBackpatches);
for: _backpatches = _backpatches.concat(Vector.<JumpTargetData>(newBackpatches));

Thanks very much for the help Roland!

Roland Zwaga

unread,
Feb 10, 2014, 11:43:35 AM2/10/14
to as3-commons...@googlegroups.com
Hi Rodrigo,

sorry for not getting back earlier.
Currently I am moving away from AS3 in my daily projects, so its hard for me to devote a lot
of time to any opensource work in that area.

You seem to be getting a hang for the library though, so if you're interested I can make you
a committer for the as3commons-bytecode repository.
Any advice on how the code base is structred etc, I'll be happy to help you with. I don't think
I'll be able to spend much time doign actual coding though. (I'm basically working 7 days a week
on my current project).

So, if you're interested, let me know which gmail address of yours I should use to add you to the
committer list.

I'm sorry to have to give you this dissatisfying answer, I'll do my best to help you where possible though.

cheers,

Roland

Roland Zwaga

unread,
Feb 10, 2014, 12:15:00 PM2/10/14
to as3-commons...@googlegroups.com
Hey,

as for the proeprty retrieval (sorry, its been a while since I've been working on this stuff, its a bit hazy now for me as well...)

If I take a look at this class:
org.as3commons.bytecode.proxy.impl.MethodProxyFactory in the addMethodBody() method.

I think you can just retrieve the property using this:

addOpcode(Opcode.findpropstrict, [bytecodeQname]) //
addOpcode(Opcode.getproperty, [bytecodeQname]) //

I'm not intimately familiar with the whole getlex business anymore, I'm not sure
what the difference is anymore...

cheers,

Roland

Rodrigo Hamuy Aquino

unread,
Feb 10, 2014, 12:50:44 PM2/10/14
to as3-commons...@googlegroups.com
Thanks Roland, 

You are rigth, getlex is the equivalent to use findprospstrict and get property. Eitherway, I just dont know what to put in [bytecodeQname] (a BaseMultiname parameter is required). 

Fortunately defining the method body using string source, is as simple as put the name of the property. So I'm using it this way for now.

About being a committer, I would love to help. This is my primary mail. I'm trying this API for my ingeniering thesis, so if it fits my needs, I will be heavily working whit it.

cheers,
Rodrigo

Roland Zwaga

unread,
Feb 10, 2014, 1:36:26 PM2/10/14
to as3-commons...@googlegroups.com
Hi Rodrigo,

I've added you to the committers list, you should have write access to the repository now.
The parameter is a BaseMultiname, but like the name implies, that's just a base class,
you'll find all of the classes inheriting from this in the namespace org.as3commons.bytecode.abc.
In the case of the property, I'm guessing you can just construct a QualifiedName, those classes
aren't that complicated.
But, if for now using string source works for you, go that route :)
Good luck, and welcome to the as3commons team I guess :)

cheers,

Roland

Rodrigo Hamuy Aquino

unread,
Feb 10, 2014, 1:47:44 PM2/10/14
to as3-commons...@googlegroups.com
Thanks! :P


--
You received this message because you are subscribed to the Google Groups "as3-commons-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to as3-commons-devel...@googlegroups.com.
To post to this group, send email to as3-commons...@googlegroups.com.
Visit this group at http://groups.google.com/group/as3-commons-developers.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages