<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -11,7 +11,7 @@ module RedSun
       swf = nil
       Dir.chdir(File.dirname(__FILE__)) do
         Dir['RubyVMMain.swf'].each do |fname|
-          puts &quot;got name - #{fname}&quot;
+          #puts &quot;got name - #{fname}&quot;
           swf = Swf.new fname
         end
       end
@@ -28,12 +28,18 @@ module RedSun
       @swf.write
     end
 
-    def initialize(ruby_code)
+    def initialize(ruby_code=nil)
       @swf = vm_swf()
+      @abc = @swf.tag_select(Tags::DoABC)[0].abc_file
+      @cp = @abc.constant_pool
+      @f_ns = @abc.get_ns(ABC::Namespace::PackageNamespace, :&quot;&quot;)
+                                                                   
+      @qnil = @abc.get_qname(:Qnil, @f_ns)
+      translate_code(ruby_code) if ruby_code
+    end
+    
+    def translate_code(ruby_code)
       vm = RubyVM::InstructionSequence.compile(ruby_code).to_a
-      @abc = @swf.tags[8].abc_file
-      @f_ns = 1
-      @qnil = @abc.add_multiname(:Qnil, @f_ns)
       load_ruby_vm(vm)
     end
 
@@ -48,60 +54,67 @@ module RedSun
     def translate_top(vm, body)
       # loop over opcodes
       # need a new function for iseqs, blocks, procs, lambda, classes
-      translated_scope(vm, body)
+      translate_scope(vm, body)
     end
 
     def mn(sym)
-      @abc.add_multiname(sym, @f_ns)
+      @abc.get_qname(sym, @f_ns)
     end
 
+    # Translate the given iseq Array into the body of the given method
     def translate_scope(vm, body)
       iseq = vm[11]
-      labels = []
-      loc = 0
+      labels = {}
       codes = []
+      # Need to track max_stack and scope_depth
       iseq.each do |insn|
-        case insn.class.name
-        when :Integer
-          # debug line
-        when :Symbol
-          # label
-          labels[insn] = loc
-        when :Array
-          codes &lt;&lt; ABC::GetLocal1.new(@abc)
-          push_insn_ops(codes, insn)
-          codes &lt;&lt; ABC::CallPropVoid.new(@abc, mn(insn[0]), insn.length-1)
-        end
-        loc = loc+1
-          
+        push_insn(codes, insn, labels)
+      end
+      body.code.codes = codes
+    end
+
+    def push_insn(codes, insn, labels)
+      case insn.class.name
+      when &quot;Fixnum&quot;
+        # debug line
+      when &quot;Symbol&quot;
+        # label
+        labels[insn] = codes.length
+      when &quot;Array&quot;
+        codes &lt;&lt; ABC::GetLocal1.new(@abc)
+        push_insn_ops(codes, insn)
+        codes &lt;&lt; ABC::CallPropVoid.new(@abc, mn(insn[0]), insn.length-1)
       end
+      codes
     end
 
     def push_insn_ops(codes, insn)
       1.upto(insn.length-1) do |i|
         case insn[i].class.name
-        when :Symbol
-          codes &lt;&lt; ABC::PushString(@abc,@abc.add_string(insn[1]))
-        when :String
-          codes &lt;&lt; ABC::PushString(@abc,@abc.add_string(insn[1].to_sym))
-        when :NilClass
-          codes &lt;&lt; ABC::GetLocal1.new(@abc)
-          codes &lt;&lt; ABC::GetProperty.new(@abc, @qnil)
+        when &quot;Symbol&quot;
+          push_string(codes, insn[i])
+        when &quot;String&quot;
+          push_string(codes, insn[i])
+        when &quot;Fixnum&quot;
+          codes &lt;&lt; ABC::PushByte.new(@abc,insn[i])
+        when &quot;NilClass&quot;
+          push_nil(codes)
         end
       end
+      codes
     end
 
-    def push_sym(codes, sym)
-      codes &lt;&lt; ABC::PushString(@abc, @abc.add_string(sym))
-    end
     def push_string(codes, str)
-      codes &lt;&lt; ABC::PushString(@abc, @abc.add_string(str.to_sym))
+      str = str.to_sym if not str.is_a? Symbol
+      codes &lt;&lt; ABC::PushString.new(@abc, @cp.add_string(str))
     end
     def push_nil(codes)
+      codes &lt;&lt; ABC::GetLocal1.new(@abc)
+      codes &lt;&lt; ABC::GetProperty.new(@abc, @qnil)
     end
       
 
-    def setup_doc_constructor(vm)
+    def setup_doc_constructor(vm, iinit)
       code = iinit.body.code
       code.codes[16] = ABC::PushByte.new(@abc, vm[4][:local_size])
       code.codes[17] = ABC::PushByte.new(@abc, vm[4][:stack_max])
@@ -377,7 +390,7 @@ HERE
           gl = GetLex.new(self)
           match = clz_sym.to_s.match(/^(?:([\w.]+):)?(\w+)$/)
           package, name = match[1] || &quot;&quot;, match[2]
-          gl.index = get_qname(name, Namespace::PackageNamespace, package)
+          gl.index = get_qname(name, package, Namespace::PackageNamespace)
           codes &lt;&lt; gl
           codes &lt;&lt; PushScope.new(self)
         end
@@ -386,7 +399,7 @@ HERE
         clz_sym = hierarchy.last
         match = clz_sym.to_s.match(/^(?:([\w.]+):)?(\w+)$/)
         package, name = match[1] || &quot;&quot;, match[2]
-        gl.index = get_qname(name, Namespace::PackageNamespace, package)
+        gl.index = get_qname(name, package, Namespace::PackageNamespace)
         codes &lt;&lt; gl
 
         nc = NewClass.new(self)
@@ -500,12 +513,12 @@ HERE
         codes &lt;&lt; GetLocal0.new(self)
         codes &lt;&lt; PushScope.new(self)
 
-        prot_mn = get_multiname(:prototype, class_ns_set) if not methods.empty?
+        prot_mn = get_mn_nsset(:prototype, class_ns_set) if not methods.empty?
         # JPB
         methods.each do |index|
           name = @abc_methods[index].name.to_s
           name.match(/^(?:\w+\/)?(\w+)$/)
-          mn = get_multiname($1, class_ns_set)
+          mn = get_mn_nsset($1, class_ns_set)
           codes &lt;&lt; GetLex.new(self, prot_mn)
           codes &lt;&lt; NewFunction.new(self, index)
           codes &lt;&lt; SetProperty.new(self, mn)
@@ -580,7 +593,7 @@ HERE
               inc_stack.call
               codes &lt;&lt; PushString.new(self, @constant_pool.add_string(line[1].to_sym))
             when :getconstant
-              mn = get_multiname(line[1], class_ns_set)
+              mn = get_mn_nsset(line[1], class_ns_set)
               codes &lt;&lt; FindPropStrict.new(self, mn)
             when :getlocal
               case line[1]
@@ -655,7 +668,7 @@ HERE
                   ind &lt;&lt; get_ns(Namespace::PackageNamespace, package_name)
                   new_set = NsSet.new(ind, @constant_pool)
                   new_set_index = @constant_pool.add_ns_set(new_set)
-                  mn = get_multiname(class_name, new_set_index)
+                  mn = get_mn_nsset(class_name, new_set_index)
                   codes &lt;&lt; FindPropStrict.new(self, mn)
                   codes &lt;&lt; ConstructProp.new(self, mn, params)
                   codes &lt;&lt; CoerceA.new(self)
@@ -669,7 +682,7 @@ HERE
                 # (actually, this needs to delegate to the send() method, but
                 # this should work for now)
                 obj = codes[-params-1]
-                mn = get_multiname(line[1], class_ns_set)
+                mn = get_mn_nsset(line[1], class_ns_set)
                 if obj.opcode == PushNull::Opcode
                   if doing_get
                     fps = GetLex.new(self, mn)
@@ -744,8 +757,8 @@ HERE
         # Issue Flash::Display::Sprite
         # translate to flash.display.Sprite and know what that means
 
-        inst.name_index = get_qname(name, Namespace::PackageNamespace, package)
-        inst.super_name_index = get_qname(super_name, Namespace::PackageNamespace, super_package)
+        inst.name_index = get_qname(name, package, Namespace::PackageNamespace)
+        inst.super_name_index = get_qname(super_name, super_package, Namespace::PackageNamespace)
         inst.flags = Instance::ProtectedNamespace
 
         inst.protected_namespace_index = get_ns(Namespace::ProtectedNamespace, protected_namespace_name(name, package))
@@ -761,19 +774,29 @@ HERE
         @constant_pool.add_namespace(Namespace.new(kind, name_index, @constant_pool))
       end
 
-      def get_qname(name, ns_kind, namespace)
+      def get_qname(name, namespace, ns_kind=nil)
         name = name.to_sym if not name.is_a? Symbol
-        ns_index = get_ns(ns_kind, namespace)
+        if (namespace.is_a? Integer)
+          ns_index = namespace
+        else
+          ns_index = get_ns(ns_kind, namespace)
+        end
         name_index = @constant_pool.add_string(name)
         mn_index = @constant_pool.add_multiname(Multiname.new(Multiname::MultinameQName, name_index, ns_index, nil, @constant_pool))
       end
 
-      def get_multiname(name, ns_set_index)
+      def get_mn_nsset(name, ns_set_index)
         name = name.to_sym if not name.is_a? Symbol
         name_index = @constant_pool.add_string(name)
         mn_index = @constant_pool.add_multiname(Multiname.new(Multiname::MultinameC, name_index, nil, ns_set_index, @constant_pool))
       end
 
+      def get_mn_ns(name, ns_index)
+        name = name.to_sym if not name.is_a? Symbol
+        name_index = @constant_pool.add_string(name)
+        mn_index = @constant_pool.add_multiname(Multiname.new(Multiname::MultinameC, name_index, ns_index, nil, @constant_pool))
+      end
+
       def set_constructor(constr)
       end
 </diff>
      <filename>lib/redsun/generate.rb</filename>
    </modified>
    <modified>
      <diff>@@ -30,6 +30,7 @@ c=RubyVM::InstructionSequence.compile(IO.read('rf.rb'))
 @md = RedSun::Swf.new &quot;research/MethodDecompile.swf&quot;
 @sc = RedSun::Swf.new &quot;research/SeveralClasses.swf&quot;
 @t = RedSun::Swf.new &quot;research/Traits.swf&quot;
+@rvm = RedSun::Swf.new &quot;lib/redsun/RubyVMMain.swf&quot;
 # @t.tags[8].abc_file.instances[0].iinit.body.code.pretty_print;nil
 
 @af = RedSun::ABC::ABCFile.new
@@ -56,4 +57,6 @@ c=RubyVM::InstructionSequence.compile(IO.read('rf.rb'))
 @sc=RubyVM::InstructionSequence.compile(IO.read('research/scope.rb')).to_a
 # RedSun::ABC::ABCFile.pp_yarv(@sc)
 
-# RedSun::Translate.translate(&quot;r.swf&quot;, IO.read('research/scope.rb'))
+# RedSun::Translate.translate(&quot;r&quot;, IO.read('research/scope.rb'))
+
+</diff>
      <filename>research/ex.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,7 @@
-v = &quot;hi&quot;
-puts &quot;FAIL&quot; unless v
-puts &quot;SUCCESS&quot; if v
+#v = &quot;hi&quot;
+puts &quot;test&quot;
+#puts &quot;FAIL&quot; unless v
+#puts &quot;SUCCESS&quot; if v
 =begin
 v = nil
 puts &quot;FAIL&quot; if v</diff>
      <filename>research/scope.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,67 @@
 require 'redsun'
 require 'load_files'
 
+describe &quot;new generation&quot; do
+  before :each do
+    @tx = RedSun::Translate.new()
+  end
+  def frame_get_prop_op(op, sym)
+    op.class.should == RedSun::ABC::GetProperty
+    op.index.nil?.should == false
+    op.property.nil?.should == false
+    op.property.name.should == sym
+    op.property.ns.name.should == :&quot;&quot;
+  end
+  def frame_call_prop_op(op, sym)
+    op.class.should == RedSun::ABC::CallPropVoid
+    op.index.nil?.should == false
+    op.property.nil?.should == false
+    op.property.kind.should == RedSun::ABC::Multiname::MultinameQName
+    op.property.name.should == sym
+    op.property.ns.name.should == :&quot;&quot;
+  end
+  it &quot;should tx putnil to RubyFrame call&quot; do
+    r = @tx.push_insn([], [:putnil], [])
+    r[0].class.should == RedSun::ABC::GetLocal1
+    frame_call_prop_op(r[1], :putnil)
+    r.length.should == 2
+  end
+  it &quot;should tx no instruction operands&quot; do
+    r = @tx.push_insn_ops([], [:putnil])
+    r.length.should == 0
+  end
+  it &quot;should tx send instruction operands&quot; do
+    r = @tx.push_insn_ops([], [:send, :puts, 1, nil, 8, nil])
+    r[0].class.should == RedSun::ABC::PushString
+    r[0].string.should == :puts
+    r[1].class.should == RedSun::ABC::PushByte
+    r[1].value.should == 1
+    r[2].class.should == RedSun::ABC::GetLocal1
+    frame_get_prop_op(r[3], :Qnil)
+    r[4].class.should == RedSun::ABC::PushByte
+    r[4].value.should == 8
+    r[5].class.should == RedSun::ABC::GetLocal1
+    frame_get_prop_op(r[6], :Qnil)
+    r.length.should == 7
+  end
+  it &quot;should tx send to RubyFrame call with operands&quot; do
+    r = @tx.push_insn([], [:send, :puts, 1, nil, 8, nil], [])
+    r[0].class.should == RedSun::ABC::GetLocal1
+    r[1].class.should == RedSun::ABC::PushString
+    r[1].string.should == :puts
+    r[2].class.should == RedSun::ABC::PushByte
+    r[2].value.should == 1
+    r[3].class.should == RedSun::ABC::GetLocal1
+    frame_get_prop_op(r[4], :Qnil)
+    r[5].class.should == RedSun::ABC::PushByte
+    r[5].value.should == 8
+    r[6].class.should == RedSun::ABC::GetLocal1
+    frame_get_prop_op(r[7], :Qnil)
+    frame_call_prop_op(r[8], :send)
+    r.length.should == 9
+  end
+end
+
 describe RedSun::ABC::ABCFile do
   before(:each) do
     @empty_data = &quot;10002e000000000d0011456d7074795377662f456d70747953776608456d7074795377660d666c6173682e646973706c6179065370726974653d473a5c776f726b5c65636c697073655c61727469636c65735c44796e616d6963416374696f6e5363726970745c7372633b3b456d7074795377662e6173064f626a6563740c666c6173682e6576656e74730f4576656e74446973706174636865720d446973706c61794f626a65637411496e7465726163746976654f626a65637416446973706c61794f626a656374436f6e7461696e6572051601160418031608000807010307020507010707040907020a07020b07020c0300000100000002000000010000010102090300010000000102010104010003000101080903d030470000010101090a0ef106f007d030f008d04900f00947000002020101082bd030f106f0056500600330600430600530600630600730600230600258001d1d1d1d1d1d6801f106f003470000&quot;.pack_as_hex</diff>
      <filename>test/redsun_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>22eaea60a8538af0bde174e5ed4c7cfe0b97c5d3</id>
    </parent>
  </parents>
  <author>
    <name>Jonathan Branam</name>
    <email>github@jonathanbranam.net</email>
  </author>
  <url>http://github.com/jonathanbranam/redsun/commit/ba44d279754e3adac99e7feb44e344ba658b9b7f</url>
  <id>ba44d279754e3adac99e7feb44e344ba658b9b7f</id>
  <committed-date>2008-10-22T12:17:57-07:00</committed-date>
  <authored-date>2008-10-22T12:17:57-07:00</authored-date>
  <message>Ruby bytecode translation and tests.
Some successful Ruby bytecode translation tests.
However, re-opening the saved SWF from RubyVMMain.swf doesn't work in RedSun::Swf.
This appears to be true even if I don't change the SWF at all. Need to look into this
problem quickly.</message>
  <tree>c18cdd70c3cc6a72b4393addea89ca9f5133c87c</tree>
  <committer>
    <name>Jonathan Branam</name>
    <email>github@jonathanbranam.net</email>
  </committer>
</commit>
