Many amenities can be mapped as areas.
[potlatch2.git] / it / sephiroth / expr / SWFContext.as
1 package it.sephiroth.expr
2 {
3         import hxasm.Context;
4         import hxasm.OpCode;
5         
6         public class SWFContext
7         {
8                 private var _stack: int;
9                 private var _max_stack: int;
10                 private var _context: Context;
11                 private var _regs: Object;
12                 
13                 public function SWFContext( context: Context )
14                 {
15                         _stack = 0;
16                         _max_stack = 0;
17                         _regs = new Object();
18                         _context = context;
19                 }
20                 
21                 public function get ctx(): Context
22                 {
23                         return _context;
24                 }
25                 
26                 public function get maxStack(): int
27                 {
28                         return _max_stack;
29                 }
30                 
31                 public function addStack( i: int ): void
32                 {
33                         _stack += i;
34                         _max_stack = Math.max( _stack, _max_stack );
35                 }
36                 
37                 public function subStack( i: int ): void
38                 {
39                         _stack -= i;
40                         _max_stack = Math.max( _stack, _max_stack );
41                 }
42                 
43                 public function storeReg( name: String ): void
44                 {
45                         var reg: int = _context.allocRegister();
46                         
47                         _context.op( OpCode.OThis );
48                         _context.op( OpCode.OGetProp( _context.property( name ) ) );
49                         _context.op( OpCode.OSetReg( reg ) );
50                         
51                         _regs[ name ] = reg;
52                         
53                         addStack( 1 );
54                 }
55                 
56                 public function getReg( name: String ): int
57                 {
58                         return _regs[ name ];
59                 }
60
61         }
62 }