<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,5 @@
 #!/bin/sh
 
 cd shotgun; bash ./mkconfig.sh &quot;$*&quot;
-
+echo 
 echo &quot;Rubinius is configured.&quot;</diff>
      <filename>configure</filename>
    </modified>
    <modified>
      <diff>@@ -6,10 +6,10 @@ if ! test -f run; then
   cd config
 fi
 
-if test -f $name; then
-  exec ./$name
-fi
-
 cc -o $name $name.c
 
-exec ./$name
+./$name
+code=$?
+echo &quot;[CONFIG] $1: $?&quot;
+rm $name
+exit $code</diff>
      <filename>shotgun/config/run</filename>
    </modified>
    <modified>
      <diff>@@ -78,7 +78,7 @@ static inline uint32_t read_int_from_be(uint8_t *str) {
                   |  str[3]      );
 }
 
-void iseq_flip(STATE, OBJECT self) {
+void iseq_flip(STATE, OBJECT self, OBJECT output) {
   uint8_t *buf;
   uint32_t *ibuf;
   uint32_t val;
@@ -86,15 +86,12 @@ void iseq_flip(STATE, OBJECT self) {
   
   f = object_size(state, self);
   buf = (uint8_t*)bytearray_byte_address(state, self);
-  ibuf = (uint32_t*)bytearray_byte_address(state, self);
-  
-  /* The first thing can't be a noop */
-  sassert(*ibuf);
+  ibuf = (uint32_t*)bytearray_byte_address(state, output);
   
   /* A sanity check. The first thing is always an instruction,
    * and we've got less that 1024 instructions, so if it's less
    * it's already been flipped. */
-  if(*ibuf &lt; 1024) return;
+  if(*(uint32_t*)buf &lt; 1024) return;
 
   for(i = 0; i &lt; f; i += 4, ibuf++) {
     val = read_int_from_be(buf + i);</diff>
      <filename>shotgun/lib/bytearray.c</filename>
    </modified>
    <modified>
      <diff>@@ -13,4 +13,4 @@ OBJECT bytearray_new_dirty(STATE, int size);
 #define bytearray_bytes(st, self) BYTEARRAY_SIZE(self)
 
 OBJECT iseq_new(STATE, int fields);
-void iseq_flip(STATE, OBJECT self);
+void iseq_flip(STATE, OBJECT self, OBJECT output);</diff>
      <filename>shotgun/lib/bytearray.h</filename>
    </modified>
    <modified>
      <diff>@@ -165,7 +165,7 @@ OBJECT cpu_const_get(STATE, cpu c, OBJECT sym, OBJECT under);
 OBJECT cpu_const_set(STATE, cpu c, OBJECT sym, OBJECT val, OBJECT under);
 void cpu_run(STATE, cpu c, int setup);
 int cpu_dispatch(STATE, cpu c);
-void cpu_compile_instructions(STATE, OBJECT ba);
+void cpu_compile_instructions(STATE, OBJECT bc, OBJECT ba);
 OBJECT cpu_compile_method(STATE, OBJECT cm);
 OBJECT cpu_create_block_context(STATE, cpu c, OBJECT env, int sp);
 </diff>
      <filename>shotgun/lib/cpu.h</filename>
    </modified>
    <modified>
      <diff>@@ -340,22 +340,26 @@ static inline OBJECT cpu_locate_method(STATE, cpu c, OBJECT klass, OBJECT obj, O
 
 OBJECT cpu_compile_method(STATE, OBJECT cm) {
   OBJECT ba, bc;
+  int target_size;
+
   ba = cmethod_get_compiled(cm);
   bc = cmethod_get_bytecodes(cm);
-  if(NIL_P(ba) || BYTEARRAY_SIZE(ba) &lt; BYTEARRAY_SIZE(bc)) {
+
+  /* If we're direct threaded, the compiled version is an array of the pointer
+   * size. */
+#if DIRECT_THREADED
+  target_size = BYTEARRAY_SIZE(bc) * sizeof(uintptr_t);
+#else
+  target_size = BYTEARRAY_SIZE(bc);
+#endif
+
+  if(NIL_P(ba) || BYTEARRAY_SIZE(ba) &lt; target_size) {
     /* First time this method has been compiled, or size of current
        bytearray is insufficient to hold revised bytecode */
-    ba = bytearray_dup(state, bc);
+    ba = bytearray_new(state, target_size);
   }
-  else {
-    /* Method is being recompiled due to a change to the iseq.
-       Reuse the existing compiled bytearray so that we don't
-       need to reload all contexts that have a reference to this
-       compiled method. */
-    object_copy_body(state, bc, ba);
-  }
-  
-  cpu_compile_instructions(state, ba);
+
+  cpu_compile_instructions(state, bc, ba);
   cmethod_set_compiled(cm, ba);
 
   /* Allocate a tuple to hold the cache entries for method calls */
@@ -374,17 +378,15 @@ OBJECT cpu_compile_method(STATE, OBJECT cm) {
   return ba;
 }
 
-void cpu_compile_instructions(STATE, OBJECT ba) {
+void cpu_compile_instructions(STATE, OBJECT bc, OBJECT comp) {
   /* If this is not a big endian platform, we need to adjust
      the iseq to have the right order */
-#if !CONFIG_BIG_ENDIAN
-  iseq_flip(state, ba);
-#endif
-
+#if !CONFIG_BIG_ENDIAN &amp;&amp; !DIRECT_THREADED
+  iseq_flip(state, bc, comp);
+#elif DIRECT_THREADED
   /* If we're compiled with direct threading, then translate
      the compiled version into addresses. */
-#if DIRECT_THREADED
-  calculate_into_gotos(state, ba, _dt_addresses, _dt_size);
+  calculate_into_gotos(state, bc, comp, _dt_addresses, _dt_size);
 #endif
 }
 </diff>
      <filename>shotgun/lib/cpu_instructions.c</filename>
    </modified>
    <modified>
      <diff>@@ -75,30 +75,47 @@ class ShotgunInstructions
     code &lt;&lt; &quot;\n&quot;
     
     code &lt;&lt; &lt;&lt;-CODE
+
+    static inline uint32_t read_int_from_be(uint8_t *str) {
+      return (uint32_t)((str[0] &lt;&lt; 24)
+                      | (str[1] &lt;&lt; 16)
+                      | (str[2] &lt;&lt; 8 )
+                      |  str[3]      );
+    }
     
-    static void calculate_into_gotos(STATE, OBJECT iseq, void **addrs, int size) {
-      uint32_t *insn;
+    static void calculate_into_gotos(STATE, OBJECT iseq, OBJECT output, void* addrs[], int size) {
+      uint8_t *insn;
       uint32_t op;
-      void *addr;
-      int i, k, count;
-      
-      k = bytearray_bytes(state, iseq) / sizeof(uint32_t);
-      insn = (uint32_t*)bytearray_byte_address(state, iseq);
-      i = 0;
-      count = 0;
+      uintptr_t *compiled;
+
+      int i, f, offset, sz;
       
-      while(i &lt; k) {
-        op = insn[i];
+      f = bytearray_bytes(state, iseq);
+      insn = (uint8_t*)bytearray_byte_address(state, iseq);
+      compiled = (uintptr_t*)bytearray_byte_address(state, output);
+
+      offset = 0;
+      for(offset = 0; offset &lt; f; offset += 4) { 
+#if CONFIG_BIG_ENDIAN
+        op = *((uint32_t*)(insn + offset));
+#else
+        op = read_int_from_be(insn + offset);
+#endif
         /* Protect against errant data */
         if(op &gt; size) op = 0;
-        addr = addrs[op];
-        // printf(&quot;OC: %d =&gt; %p\\n&quot;, op, addr);
-        // assert(addr);
-        insn[i] = (uint32_t)addr;
-        i += _ip_size(op);
-        count++;
+        *compiled++ = (uintptr_t)addrs[op];
+        /* copy the instruction args */
+        sz = _ip_size(op) - 1;
+        for(i = 0; i &lt; sz; i++) {
+          offset += 4;
+#if CONFIG_BIG_ENDIAN
+          op = *((uint32_t*)(insn + offset));
+#else
+          op = read_int_from_be(insn + offset);
+#endif
+          *compiled++ = (uintptr_t)op;
+        }
       }
-      // printf(&quot;Calculated %d ops into %s\\n&quot;, count, _inspect(iseq));
     }
     
     CODE</diff>
      <filename>shotgun/lib/instructions.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2075,7 +2075,7 @@ class ShotgunPrimitives
 
     fc = FASTCTX(t1);
     if(fc-&gt;method-&gt;obj_type == CMethodType) {
-      cpu_compile_instructions(state, t2);
+      cpu_compile_method(state, fc-&gt;method);
       fc-&gt;data = BYTEARRAY_ADDRESS(t2);
     }
 </diff>
      <filename>shotgun/lib/primitives.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>105bad5f1517b52c9ff6a25702cfe372f383d5a8</id>
    </parent>
  </parents>
  <author>
    <name>Evan Phoenix</name>
    <email>evan@fallingsnow.net</email>
  </author>
  <url>http://github.com/evanphx/rubinius/commit/c488ccd524115699c12b1f8eb5f80e5916a8e999</url>
  <id>c488ccd524115699c12b1f8eb5f80e5916a8e999</id>
  <committed-date>2008-01-25T16:42:29-08:00</committed-date>
  <authored-date>2008-01-25T16:42:29-08:00</authored-date>
  <message>Rework DT compiling, fix configure subscripts</message>
  <tree>093903a4d34e12969e4de8aa7031a691b5ac5c57</tree>
  <committer>
    <name>Evan Phoenix</name>
    <email>evan@fallingsnow.net</email>
  </committer>
</commit>
