Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a bit more work on endian-ness of InstructionSequence's.

InstructionSequence#compile now lets the VM properly adjust an iseq so it can be run.
  • Loading branch information...
commit 26cd57a5b454917df3a16f09c663f4c72a6ce559 1 parent 0c7ac1b
Evan Phoenix evanphx authored
5 kernel/bootstrap/compiled_method.rb
View
@@ -90,6 +90,10 @@ def serial=(ser)
@serial = ser
end
+ def compile
+ @bytecodes.compile
+ end
+
def activate(recv, args, locals=nil, &prc)
sz = args.total
if prc
@@ -187,6 +191,7 @@ def location
def compiled_method
@method
end
+
end
class UnboundMethod
5 kernel/bootstrap/iseq.rb
View
@@ -0,0 +1,5 @@
+class InstructionSequence
+ def compile
+ Ruby.primitive :iseq_compile
+ end
+end
7 kernel/core/compile.rb
View
@@ -26,6 +26,7 @@ def self.compile_string(string)
def self.execute(string)
cm = compile_string(string)
+ cm.compile
cm.activate MAIN, []
end
end
@@ -76,7 +77,11 @@ def load(path)
# and store it
Marshal.dump_to_file cm, comp, Rubinius::CompiledMethodVersion
-
+
+ # since we just created it, 'compile it', ie, let the VM finish
+ # preparing it to be run
+ cm.compile
+
return cm.activate_as_script
end
2  lib/bytecode/primitive_names.rb
View
@@ -54,7 +54,7 @@ class Compiler
:gc_start,
:file_to_sexp,
:get_byte,
- nil, # :zlib_inflate,
+ :iseq_compile,
nil, # :zlib_deflate,
:fixnum_modulo,
:bytearray_size,
BIN  runtime/bootstrap.rba
View
Binary file not shown
BIN  runtime/compiler.rba
View
Binary file not shown
BIN  runtime/core.rba
View
Binary file not shown
20 shotgun/lib/bytearray.c
View
@@ -48,24 +48,22 @@ OBJECT iseq_new(STATE, int fields) {
return obj;
}
-static inline uint32_t read_int_big(uint8_t *str) {
- return (uint32_t)((str[0] << 24)
- | (str[1] << 16)
- | (str[2] << 8 )
- | str[3] );
-}
-static inline uint32_t read_int_little(uint8_t *str) {
+
+#if defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
+static inline uint32_t read_int(uint8_t *str) {
return (uint32_t)(str[0]
| (str[1] << 8 )
| (str[2] << 26)
| (str[3] << 24));
}
-
-#if defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
-#define read_int read_int_little
#else
-#define read_int read_int_big
+static inline uint32_t read_int(uint8_t *str) {
+ return (uint32_t)((str[0] << 24)
+ | (str[1] << 16)
+ | (str[2] << 8 )
+ | str[3] );
+}
#endif
void iseq_flip(STATE, OBJECT self) {
18 shotgun/lib/cpu_marshal.c
View
@@ -6,6 +6,7 @@
#include "tuple.h"
#include "bignum.h"
#include "float.h"
+#include "flags.h"
#include <string.h>
#include <stdlib.h>
#include <glib.h>
@@ -273,16 +274,12 @@ static OBJECT unmarshal_bytes(STATE, struct marshal_state *ms) {
static void marshal_iseq(STATE, OBJECT obj, GString *buf) {
int i;
append_c('I');
- /* Right now, an iseq is always stored as big endian, we need to
- figure out how it knows the iseq is in little to use this code. */
- append_c('b');
-/*
-#if defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN)
- append_c('b');
-#else
- append_c('l');
-#endif
-*/
+ if(FLAG2_SET_P(obj, IsLittleEndianFlag)) {
+ append_c('l');
+ } else {
+ append_c('b');
+ }
+
i = NUM_FIELDS(obj) * REFSIZE;
append_sz(i);
append_str(bytearray_byte_address(state, obj), i);
@@ -306,6 +303,7 @@ static OBJECT unmarshal_iseq(STATE, struct marshal_state *ms) {
if(endian != 'b') iseq_flip(state, obj);
#else
if(endian != 'l') iseq_flip(state, obj);
+ FLAG2_SET(obj, IsLittleEndianFlag);
#endif
return obj;
2  shotgun/lib/flags.h
View
@@ -17,5 +17,5 @@
#define IsTaintedFlag (1<<0)
#define IsFrozenFlag (1<<1)
-
+#define IsLittleEndianFlag (1<<2)
#endif
16 shotgun/lib/primitives.rb
View
@@ -2460,6 +2460,22 @@ def bignum_size(_ = bignum)
stack_push(bignum_size(state, self));
CODE
end
+
+ def iseq_compile
+ <<-CODE
+ self = stack_pop();
+ if(FLAG2_SET_P(self, IsLittleEndianFlag)) {
+ #if defined(__BIG_ENDIAN__)
+ iseq_flip(state, self);
+ FLAG2_SET(self, IsLittleEndianFlag);
+ #endif
+ } else {
+ #if !defined(__BIG_ENDIAN__)
+ iseq_flip(state, self);
+ #endif
+ }
+ CODE
+ end
end
prim = ShotgunPrimitives.new
Please sign in to comment.
Something went wrong with that request. Please try again.