ruby: some more updates for x64, fix df_flagarray size

develop
jj 2016-10-28 16:40:14 +02:00
parent d62d263793
commit c640006069
3 changed files with 30 additions and 52 deletions

@ -577,10 +577,14 @@ sub render_global_objects {
# define friendlier accessors, eg df.world -> DFHack::GlobalObjects.new._at(0).world # define friendlier accessors, eg df.world -> DFHack::GlobalObjects.new._at(0).world
indent_rb { indent_rb {
push @lines_rb, "Global = GlobalObjects.new._at(0)"; push @lines_rb, "Global = GlobalObjects.new._at(0)";
for my $obj (@global_objects) for my $oname (@global_objects)
{ {
push @lines_rb, "def self.$obj ; Global.$obj ; end"; push @lines_rb, "if DFHack.get_global_address('$oname') != 0";
push @lines_rb, "def self.$obj=(v) ; Global.$obj = v ; end"; indent_rb {
push @lines_rb, "def self.$oname ; Global.$oname ; end";
push @lines_rb, "def self.$oname=(v) ; Global.$oname = v ; end";
};
push @lines_rb, "end";
} }
}; };
} }
@ -743,7 +747,7 @@ sub sizeof {
} elsif ($subtype eq 'df-linked-list') { } elsif ($subtype eq 'df-linked-list') {
return 3 * $SIZEOF_PTR; return 3 * $SIZEOF_PTR;
} elsif ($subtype eq 'df-flagarray') { } elsif ($subtype eq 'df-flagarray') {
return 4 + $SIZEOF_PTR; return 2 * $SIZEOF_PTR; # XXX length may be 4 on windows?
} elsif ($subtype eq 'df-static-flagarray') { } elsif ($subtype eq 'df-static-flagarray') {
return $field->getAttribute('count'); return $field->getAttribute('count');
} elsif ($subtype eq 'df-array') { } elsif ($subtype eq 'df-array') {

@ -214,17 +214,13 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
if (!onupdate_active) if (!onupdate_active)
return CR_OK; return CR_OK;
using namespace df::global; if (df::global::cur_year && *df::global::cur_year < onupdate_minyear)
if (cur_year && (*cur_year < onupdate_minyear))
return CR_OK; return CR_OK;
if (cur_year && cur_year_tick && onupdate_minyeartick >= 0 && if (df::global::cur_year_tick && onupdate_minyeartick >= 0 &&
(*cur_year == onupdate_minyear && *df::global::cur_year_tick < onupdate_minyeartick)
*cur_year_tick < onupdate_minyeartick))
return CR_OK; return CR_OK;
if (cur_year && cur_year_tick_advmode && onupdate_minyeartickadv >= 0 && if (df::global::cur_year_tick_advmode && onupdate_minyeartickadv >= 0 &&
(*cur_year == onupdate_minyear && *df::global::cur_year_tick_advmode < onupdate_minyeartickadv)
*cur_year_tick_advmode < onupdate_minyeartickadv))
return CR_OK; return CR_OK;
return plugin_eval_ruby(out, "DFHack.onupdate"); return plugin_eval_ruby(out, "DFHack.onupdate");
@ -283,21 +279,13 @@ static command_result df_rubyeval(color_ostream &out, std::vector <std::string>
// - ruby.h with gcc -m32 on linux 64 is broken // - ruby.h with gcc -m32 on linux 64 is broken
// so we dynamically load libruby with dlopen/LoadLibrary // so we dynamically load libruby with dlopen/LoadLibrary
// lib path is hardcoded here, and by default downloaded by cmake // lib path is hardcoded here, and by default downloaded by cmake
// this code should work with ruby1.9, but ruby1.9 doesn't like running
// in a dedicated non-main thread, so use ruby1.8 binaries only for now
typedef uintptr_t VALUE; typedef uintptr_t VALUE;
typedef uintptr_t ID; typedef uintptr_t ID;
static struct { static VALUE Qfalse = 0;
int major; static VALUE Qtrue = 2;
int minor; static VALUE Qnil = 4;
int teeny;
} libruby_version;
static VALUE Qfalse;
static VALUE Qtrue;
static VALUE Qnil;
#define INT2FIX(i) ((VALUE)((((intptr_t)i) << 1) | 1)) #define INT2FIX(i) ((VALUE)((((intptr_t)i) << 1) | 1))
#define FIX2INT(i) (((intptr_t)i) >> 1) #define FIX2INT(i) (((intptr_t)i) >> 1)
@ -345,26 +333,6 @@ static int df_loadruby(void)
return 0; return 0;
} }
const char *ruby_version = (const char*)LookupPlugin(libruby_handle, "ruby_version");
if (!ruby_version)
return 0;
sscanf(ruby_version, "%d.%d.%d",
&libruby_version.major, &libruby_version.minor, &libruby_version.teeny);
if (libruby_version.major >= 2 && sizeof(VALUE) >= sizeof(double))
{
// USE_FLONUM defined on x64
Qfalse = (VALUE)0;
Qtrue = (VALUE)0x14;
Qnil = (VALUE)0x08;
}
else
{
Qfalse = (VALUE)0;
Qtrue = (VALUE)2;
Qnil = (VALUE)4;
}
// ruby_sysinit is optional (ruby1.9 only) // ruby_sysinit is optional (ruby1.9 only)
ruby_sysinit = (decltype(ruby_sysinit))LookupPlugin(libruby_handle, "ruby_sysinit"); ruby_sysinit = (decltype(ruby_sysinit))LookupPlugin(libruby_handle, "ruby_sysinit");
#define rbloadsym(s) if (!(s = (decltype(s))LookupPlugin(libruby_handle, #s))) return 0 #define rbloadsym(s) if (!(s = (decltype(s))LookupPlugin(libruby_handle, #s))) return 0
@ -465,6 +433,11 @@ static void df_rubythread(void *p)
r_result = CR_OK; r_result = CR_OK;
r_type = RB_IDLE; r_type = RB_IDLE;
// initialize ruby constants (may depend on libruby compilation flags/version)
Qnil = rb_eval_string_protect("nil", &state);
Qtrue = rb_eval_string_protect("true", &state);
Qfalse = rb_eval_string_protect("false", &state);
// load the default ruby-level definitions in the background // load the default ruby-level definitions in the background
state=0; state=0;
rb_eval_string_protect("require './hack/ruby/ruby'", &state); rb_eval_string_protect("require './hack/ruby/ruby'", &state);
@ -1085,8 +1058,8 @@ static VALUE rb_dfmemory_set_clear(VALUE self, VALUE set)
/* call an arbitrary object virtual method */ /* call an arbitrary object virtual method */
#if defined(_WIN32) && !defined(_WIN64) #if defined(_WIN32) && !defined(_WIN64)
__declspec(naked) static int raw_vcall(void *that, void *fptr, unsigned long a0, __declspec(naked) static intptr_t raw_vcall(void *that, void *fptr, uintptr_t a0,
unsigned long a1, unsigned long a2, unsigned long a3, unsigned long a4, unsigned long a5) uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5)
{ {
// __thiscall requires that the callee cleans up the stack // __thiscall requires that the callee cleans up the stack
// here we dont know how many arguments it will take, so // here we dont know how many arguments it will take, so
@ -1112,11 +1085,11 @@ __declspec(naked) static int raw_vcall(void *that, void *fptr, unsigned long a0,
} }
} }
#else #else
static int raw_vcall(void *that, void *fptr, unsigned long a0, static intptr_t raw_vcall(void *that, void *fptr, uintptr_t a0,
unsigned long a1, unsigned long a2, unsigned long a3, unsigned long a4, unsigned long a5) uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5)
{ {
int (*t_fptr)(void *me, unsigned long, unsigned long, unsigned long, intptr_t (*t_fptr)(void *me, uintptr_t, uintptr_t, uintptr_t,
unsigned long, unsigned long, unsigned long); uintptr_t, uintptr_t, uintptr_t);
t_fptr = (decltype(t_fptr))fptr; t_fptr = (decltype(t_fptr))fptr;
return t_fptr(that, a0, a1, a2, a3, a4, a5); return t_fptr(that, a0, a1, a2, a3, a4, a5);
} }

@ -109,13 +109,14 @@ module DFHack
def onupdate def onupdate
@onupdate_list ||= [] @onupdate_list ||= []
y = cur_year y = yt = 0
y = cur_year rescue 0
ytmax = TICKS_PER_YEAR ytmax = TICKS_PER_YEAR
if df.gamemode == :ADVENTURE and df.respond_to?(:cur_year_tick_advmode) if df.gamemode == :ADVENTURE and df.respond_to?(:cur_year_tick_advmode)
yt = cur_year_tick_advmode yt = cur_year_tick_advmode
ytmax *= 144 ytmax *= 144
else else
yt = cur_year_tick yt = cur_year_tick rescue 0
end end
@onupdate_list.each { |o| @onupdate_list.each { |o|