5

From the AVM2 Overview PDF I encountered references to two types of stacks - Scope Stack and Operand Stack.

1) I assume these are two different memory stacks, each handling different things. Are there even more stacks?

2) pushstring "hello" - this would push a start of memory address where "hello" string is located onto Operand Stack. Right?

3) setlocal 0 - this would store a value from the stack (above) into register0 by popping it off. Right?

4) PushScope() - hmm, docs say pop value of stack, push value onto Scope Stack. Why?

I know a little bit of NASM but ABC seems more complex than that. Especially I'm confused about Scope Stack and the whole concept of multiple stacks.

cdlane
  • 40,441
  • 5
  • 32
  • 81
Ska
  • 6,658
  • 14
  • 53
  • 74

1 Answers1

5

I am no AVM2 expert, but here's what I know:

  1. There are only 2 stacks, the two you mention: scope and operand.
  2. Yes, pushstring "hello" will push the string onto the operand stack.
  3. Also, correct. setlocal0 will pop "hello" off the stack and store it in reg 0.
  4. The scope stack is used by all operations that require a name lookup for scope, for instance closures and exceptions. Often in ASM code you'll see getlocal_0 immediately followed by a pushscope. This is pretty common. You can kind of think of it as adding the "this" object to the scope stack for future reference in method calls, scope for closures, etc.

I highly recommend downloading the Tamarin source and playing with the decompiler there. Also, Yogda looks to be pretty handy for learning: http://www.yogda.com/

svoisen
  • 3,292
  • 1
  • 18
  • 8
  • Wohooo, Yogda looks epic. Thanks for other answers as well, I was seeing the use of PushScope and NewActivation - being unused later, done by Adobe complier, so I was really confused. I guess those cases were just a bit of a sloppiness from their side. – Ska Mar 29 '11 at 02:38
  • Yeah, I noticed the compiler does that frequently when it isn't always necessary. Many people have complained about mxmlc, for instance Joa Ebert. He's much more of an expert on AVM2. Definitely take a look at the apparat framework that he's been working on: http://code.google.com/p/apparat/ – svoisen Mar 29 '11 at 20:22
  • The more I'm looking at the ABC that gets generated, the more unused operations I notice. For example (this is too funny): Dup, SetLocal 2, PushScope, PopScope, Kill 2, I'm looking at apparat also, thanks. As for Yogda, it seems EXACTLY the tool I need, but ... it's Windows only :( – Ska Apr 01 '11 at 13:46