diff options
| -rw-r--r-- | INSTALL | 10 | ||||
| -rw-r--r-- | examples/targets/IntelGalileo.rb | 90 | ||||
| -rw-r--r-- | include/mruby/version.h | 23 | ||||
| -rw-r--r-- | mrbgems/mruby-random/src/mt19937ar.c | 1 | ||||
| -rw-r--r-- | mrbgems/mruby-random/src/mt19937ar.h | 3 | ||||
| -rw-r--r-- | mrbgems/mruby-random/src/random.c | 62 | ||||
| -rw-r--r-- | src/class.c | 15 | ||||
| -rw-r--r-- | src/numeric.c | 5 | ||||
| -rw-r--r-- | tasks/toolchains/gcc.rake | 2 | ||||
| -rw-r--r-- | travis_config.rb | 2 |
10 files changed, 166 insertions, 47 deletions
@@ -1,6 +1,6 @@ * Prerequisites - - 1. Make sure you have bison (http://www.gnu.org/software/bison/) installed in your system. + + 1. Make sure you have bison (http://www.gnu.org/software/bison/) installed in your system. 2. Make sure you have ruby installed in your system (required to build). * Compilation and Installation @@ -8,10 +8,10 @@ 1. Run make in the top directory. This command will create a build directory with a directory for the host environment - and one for each crossbuild environment based on the settings in the build_config.rb + and one for each crossbuild environment based on the settings in the build_config.rb file. - Assuming a default build, each of the environment directories will have the following + Assuming a default build, each of the environment directories will have the following important directories: * bin - The binary executables for this environment @@ -19,7 +19,7 @@ You can find the header files in the include directory at the root of the project. - You can directory invoke 'minirake' as the following. + You can directly invoke 'minirake' with the following command: $ ruby ./minirake diff --git a/examples/targets/IntelGalileo.rb b/examples/targets/IntelGalileo.rb new file mode 100644 index 000000000..0ee073344 --- /dev/null +++ b/examples/targets/IntelGalileo.rb @@ -0,0 +1,90 @@ +# Cross Compiling configuration for Intel Galileo on Arduino environment +# http://arduino.cc/en/ArduinoCertified/IntelGalileo +# +# Requires Arduino IDE for Intel Galileo + +MRuby::CrossBuild.new("Galileo") do |conf| + toolchain :gcc + + # Mac OS X + # Assume you renamed Arduino.app to Arduino_Galileo.app + GALILEO_ARDUINO_PATH = '/Applications/Arduino_Galileo.app/Contents/Resources/Java' + # GNU Linux + #ARDUINO_GALILEO_PATH = '/opt/arduino' + + GALILEO_BIN_PATH = "#{GALILEO_ARDUINO_PATH}/hardware/tools/x86/i386-pokysdk-darwin/usr/bin/i586-poky-linux-uclibc" + GALILEO_SYSROOT = "#{GALILEO_ARDUINO_PATH}/hardware/tools/x86/i586-poky-linux-uclibc" + GALILEO_X86_PATH = "#{GALILEO_ARDUINO_PATH}/hardware/arduino/x86" + + + conf.cc do |cc| + cc.command = "#{GALILEO_BIN_PATH}/i586-poky-linux-uclibc-gcc" + cc.include_paths << ["#{GALILEO_X86_PATH}/cores/arduino", "#{GALILEO_X86_PATH}/variants/galileo_fab_d"] + cc.flags = %w(-m32 -march=i586 -c -g -Os -w + -ffunction-sections -fdata-sections -MMD -DARDUINO=153) + cc.flags << "--sysroot=#{GALILEO_SYSROOT}" + cc.compile_options = "%{flags} -o %{outfile} -c %{infile}" + end + + conf.cxx do |cxx| + cxx.command = "#{GALILEO_BIN_PATH}/i586-poky-linux-uclibc-g++" + cxx.include_paths = conf.cc.include_paths.dup + cxx.include_paths << "#{GALILEO_ARDUINO_PATH}/hardware/tools/x86/i586-poky-linux-uclibc/usr/include/c++" + cxx.include_paths << "#{GALILEO_ARDUINO_PATH}/hardware/tools/x86/i586-poky-linux-uclibc/usr/include/c++/i586-poky-linux-uclibc" + cxx.flags = conf.cc.flags.dup + cxx.defines = conf.cc.defines.dup + cxx.compile_options = conf.cc.compile_options.dup + end + + conf.archiver do |archiver| + archiver.command = "#{GALILEO_BIN_PATH}/i586-poky-linux-uclibc-ar" + archiver.archive_options = 'rcs %{outfile} %{objs}' + end + + conf.linker do |linker| + linker.command = "#{GALILEO_BIN_PATH}/i586-poky-linux-uclibc-g++" + linker.flags = %w(-m32 -march=i586) + linker.flags << "--sysroot=#{GALILEO_SYSROOT}" + linker.flags << %w(-Os -Wl,--gc-sections) + linker.libraries = %w(m pthread) + end + + #no executables + conf.bins = [] + + #do not build executable test + conf.build_mrbtest_lib_only + + #official mrbgems + conf.gem :core => "mruby-sprintf" + conf.gem :core => "mruby-print" + conf.gem :core => "mruby-math" + conf.gem :core => "mruby-time" + conf.gem :core => "mruby-struct" + conf.gem :core => "mruby-enum-ext" + conf.gem :core => "mruby-string-ext" + conf.gem :core => "mruby-numeric-ext" + conf.gem :core => "mruby-array-ext" + conf.gem :core => "mruby-hash-ext" + conf.gem :core => "mruby-range-ext" + conf.gem :core => "mruby-proc-ext" + conf.gem :core => "mruby-symbol-ext" + conf.gem :core => "mruby-random" + conf.gem :core => "mruby-object-ext" + conf.gem :core => "mruby-objectspace" + conf.gem :core => "mruby-fiber" + conf.gem :core => "mruby-toplevel-ext" + + #lightweigh regular expression + conf.gem :github => "masamitsu-murase/mruby-hs-regexp", :branch => "master" + + #Arduino API + #conf.gem :github =>"kyab/mruby-arduino", :branch => "master" do |g| + # g.cxx.include_paths << "#{GALILEO_X86_PATH}/libraries/Wire" + # g.cxx.include_paths << "#{GALILEO_X86_PATH}/libraries/Servo" + + #enable unsupported Servo class + # g.cxx.defines << "MRUBY_ARDUINO_GALILEO_ENABLE_SERVO" + #end + +end
\ No newline at end of file diff --git a/include/mruby/version.h b/include/mruby/version.h index 3abbb87b1..d451dfb31 100644 --- a/include/mruby/version.h +++ b/include/mruby/version.h @@ -18,16 +18,17 @@ #define MRUBY_AUTHOR "mruby developers" -#define STRINGIZE0(expr) #expr -#define STRINGIZE(expr) STRINGIZE0(expr) - -#define MRUBY_DESCRIPTION \ - "mruby " MRUBY_VERSION \ - " (" MRUBY_RELEASE_DATE ") " -#define MRUBY_COPYRIGHT \ - "mruby - Copyright (c) " \ - STRINGIZE(MRUBY_BIRTH_YEAR)"-" \ - STRINGIZE(MRUBY_RELEASE_YEAR)" " \ - MRUBY_AUTHOR +#define MRB_STRINGIZE0(expr) #expr +#define MRB_STRINGIZE(expr) MRB_STRINGIZE0(expr) + +#define MRUBY_DESCRIPTION \ + "mruby " MRUBY_VERSION \ + " (" MRUBY_RELEASE_DATE ") " \ + +#define MRUBY_COPYRIGHT \ + "mruby - Copyright (c) " \ + MRB_STRINGIZE(MRUBY_BIRTH_YEAR)"-" \ + MRB_STRINGIZE(MRUBY_RELEASE_YEAR)" " \ + MRUBY_AUTHOR \ #endif /* MRUBY_VERSION_H */ diff --git a/mrbgems/mruby-random/src/mt19937ar.c b/mrbgems/mruby-random/src/mt19937ar.c index 41ed2c00d..2c22b23ad 100644 --- a/mrbgems/mruby-random/src/mt19937ar.c +++ b/mrbgems/mruby-random/src/mt19937ar.c @@ -4,6 +4,7 @@ ** See Copyright Notice in mruby.h */ +#include "mruby.h" #include "mt19937ar.h" /* Period parameters */ diff --git a/mrbgems/mruby-random/src/mt19937ar.h b/mrbgems/mruby-random/src/mt19937ar.h index d59bd8748..504355193 100644 --- a/mrbgems/mruby-random/src/mt19937ar.h +++ b/mrbgems/mruby-random/src/mt19937ar.h @@ -13,6 +13,9 @@ typedef struct { unsigned long gen_int; double gen_dbl; }; + + mrb_int seed; + mrb_bool has_seed; } mt_state; void mrb_random_init_genrand(mt_state *, unsigned long); diff --git a/mrbgems/mruby-random/src/random.c b/mrbgems/mruby-random/src/random.c index 0d71ce2df..ac8f24a18 100644 --- a/mrbgems/mruby-random/src/random.c +++ b/mrbgems/mruby-random/src/random.c @@ -13,13 +13,8 @@ #include <time.h> -#define GLOBAL_RAND_SEED_KEY "$mrb_g_rand_seed" -#define GLOBAL_RAND_SEED_KEY_CSTR_LEN 16 - -#define INSTANCE_RAND_SEED_KEY "$mrb_i_rand_seed" -#define INSTANCE_RAND_SEED_KEY_CSTR_LEN 16 - -#define MT_STATE_KEY "$mrb_i_mt_state" +static char const GLOBAL_RAND_SEED_KEY[] = "$mrb_g_rand_seed"; +static char const MT_STATE_KEY[] = "$mrb_i_mt_state"; static const struct mrb_data_type mt_state_type = { MT_STATE_KEY, mrb_free, @@ -143,7 +138,7 @@ mrb_random_g_rand_seed(mrb_state *mrb) { mrb_value seed; - seed = mrb_gv_get(mrb, mrb_intern(mrb, GLOBAL_RAND_SEED_KEY, GLOBAL_RAND_SEED_KEY_CSTR_LEN)); + seed = mrb_gv_get(mrb, mrb_intern_lit(mrb, GLOBAL_RAND_SEED_KEY)); if (mrb_nil_p(seed)) { mrb_random_mt_g_srand(mrb, mrb_nil_value()); } @@ -167,8 +162,8 @@ mrb_random_g_srand(mrb_state *mrb, mrb_value self) seed = get_opt(mrb); seed = mrb_random_mt_g_srand(mrb, seed); - old_seed = mrb_gv_get(mrb, mrb_intern(mrb, GLOBAL_RAND_SEED_KEY, GLOBAL_RAND_SEED_KEY_CSTR_LEN)); - mrb_gv_set(mrb, mrb_intern(mrb, GLOBAL_RAND_SEED_KEY, GLOBAL_RAND_SEED_KEY_CSTR_LEN), seed); + old_seed = mrb_gv_get(mrb, mrb_intern_lit(mrb, GLOBAL_RAND_SEED_KEY)); + mrb_gv_set(mrb, mrb_intern_lit(mrb, GLOBAL_RAND_SEED_KEY), seed); return old_seed; } @@ -192,7 +187,14 @@ mrb_random_init(mrb_state *mrb, mrb_value self) seed = get_opt(mrb); seed = mrb_random_mt_srand(mrb, t, seed); - mrb_iv_set(mrb, self, mrb_intern(mrb, INSTANCE_RAND_SEED_KEY, INSTANCE_RAND_SEED_KEY_CSTR_LEN), seed); + if (mrb_nil_p(seed)) { + t->has_seed = FALSE; + } + else { + mrb_assert(mrb_fixnum_p(seed)); + t->has_seed = TRUE; + t->seed = mrb_fixnum(seed); + } DATA_PTR(self) = t; @@ -200,13 +202,9 @@ mrb_random_init(mrb_state *mrb, mrb_value self) } static void -mrb_random_rand_seed(mrb_state *mrb, mrb_value self) +mrb_random_rand_seed(mrb_state *mrb, mt_state *t) { - mrb_value seed; - mt_state *t = DATA_PTR(self); - - seed = mrb_iv_get(mrb, self, mrb_intern(mrb, INSTANCE_RAND_SEED_KEY, INSTANCE_RAND_SEED_KEY_CSTR_LEN)); - if (mrb_nil_p(seed)) { + if (!t->has_seed) { mrb_random_mt_srand(mrb, t, mrb_nil_value()); } } @@ -218,7 +216,7 @@ mrb_random_rand(mrb_state *mrb, mrb_value self) mt_state *t = DATA_PTR(self); max = get_opt(mrb); - mrb_random_rand_seed(mrb, self); + mrb_random_rand_seed(mrb, t); return mrb_random_mt_rand(mrb, t, max); } @@ -231,8 +229,15 @@ mrb_random_srand(mrb_state *mrb, mrb_value self) seed = get_opt(mrb); seed = mrb_random_mt_srand(mrb, t, seed); - old_seed = mrb_iv_get(mrb, self, mrb_intern(mrb, INSTANCE_RAND_SEED_KEY, INSTANCE_RAND_SEED_KEY_CSTR_LEN)); - mrb_iv_set(mrb, self, mrb_intern(mrb, INSTANCE_RAND_SEED_KEY, INSTANCE_RAND_SEED_KEY_CSTR_LEN), seed); + old_seed = t->has_seed? mrb_fixnum_value(t->seed) : mrb_nil_value(); + if (mrb_nil_p(seed)) { + t->has_seed = FALSE; + } + else { + mrb_assert(mrb_fixnum_p(seed)); + t->has_seed = TRUE; + t->seed = mrb_fixnum(seed); + } return old_seed; } @@ -248,17 +253,16 @@ static mrb_value mrb_ary_shuffle_bang(mrb_state *mrb, mrb_value ary) { mrb_int i; - mrb_value random = mrb_nil_value(); + mt_state *random = NULL; if (RARRAY_LEN(ary) > 1) { - mrb_get_args(mrb, "|o", &random); + mrb_get_args(mrb, "|d", &random, &mt_state_type); - if (mrb_nil_p(random)) { - mrb_random_g_rand_seed(mrb); + if (random) { + mrb_random_rand_seed(mrb, random); } else { - mrb_data_check_type(mrb, random, &mt_state_type); - mrb_random_rand_seed(mrb, random); + mrb_random_g_rand_seed(mrb); } mrb_ary_modify(mrb, mrb_ary_ptr(ary)); @@ -267,11 +271,11 @@ mrb_ary_shuffle_bang(mrb_state *mrb, mrb_value ary) mrb_int j; mrb_value tmp; - if (mrb_nil_p(random)) { - j = mrb_fixnum(mrb_random_mt_g_rand(mrb, mrb_fixnum_value(RARRAY_LEN(ary)))); + if (random) { + j = mrb_fixnum(mrb_random_mt_rand(mrb, random, mrb_fixnum_value(RARRAY_LEN(ary)))); } else { - j = mrb_fixnum(mrb_random_mt_rand(mrb, DATA_PTR(random), mrb_fixnum_value(RARRAY_LEN(ary)))); + j = mrb_fixnum(mrb_random_mt_g_rand(mrb, mrb_fixnum_value(RARRAY_LEN(ary)))); } tmp = RARRAY_PTR(ary)[i]; diff --git a/src/class.c b/src/class.c index 11a21f7a7..2c1145ed3 100644 --- a/src/class.c +++ b/src/class.c @@ -14,6 +14,7 @@ #include "mruby/string.h" #include "mruby/variable.h" #include "mruby/error.h" +#include "mruby/data.h" KHASH_DEFINE(mt, mrb_sym, struct RProc*, 1, kh_int_hash_func, kh_int_hash_equal) @@ -406,6 +407,7 @@ to_hash(mrb_state *mrb, mrb_value val) i: Integer [mrb_int] b: Boolean [mrb_bool] n: Symbol [mrb_sym] + d: Data [void*,mrb_data_type const] 2nd argument will be used to check data type so it won't be modified &: Block [mrb_value] *: rest argument [mrb_value*,int] Receive the rest of the arguments as an array. |: optional Next argument of '|' and later are optional. @@ -658,6 +660,19 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) } } break; + case 'd': + { + void** datap; + struct mrb_data_type const* type; + + datap = va_arg(ap, void**); + type = va_arg(ap, struct mrb_data_type const*); + if (i < argc) { + *datap = mrb_data_get_ptr(mrb, *sp++, type); + ++i; + } + } + break; case '&': { diff --git a/src/numeric.c b/src/numeric.c index ec7f05b97..e081cf80a 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -19,9 +19,11 @@ #define ceil(f) ceilf(f) #define fmod(x,y) fmodf(x,y) #define FLO_MAX_DIGITS 7 +#define FLO_MAX_SIGN_LENGTH 3 #define FLO_EPSILON FLT_EPSILON #else #define FLO_MAX_DIGITS 14 +#define FLO_MAX_SIGN_LENGTH 10 #define FLO_EPSILON DBL_EPSILON #endif @@ -159,6 +161,7 @@ mrb_flo_to_str(mrb_state *mrb, mrb_value flo) } } if (beg >= 0) length = end - beg; + if (length > FLO_MAX_SIGN_LENGTH) length = FLO_MAX_SIGN_LENGTH; } if (abs(exp) + length >= FLO_MAX_DIGITS) { @@ -166,7 +169,7 @@ mrb_flo_to_str(mrb_state *mrb, mrb_value flo) e = TRUE; n = n / pow(10.0, exp); if (isinf(n)) { - if (s[0] == '-') { + if (s < c) { /* s[0] == '-' */ return mrb_str_new_lit(mrb, "-0.0"); } else { diff --git a/tasks/toolchains/gcc.rake b/tasks/toolchains/gcc.rake index b1827bcc5..a25f840c5 100644 --- a/tasks/toolchains/gcc.rake +++ b/tasks/toolchains/gcc.rake @@ -1,7 +1,7 @@ MRuby::Toolchain.new(:gcc) do |conf| [conf.cc, conf.objc, conf.asm].each do |cc| cc.command = ENV['CC'] || 'gcc' - cc.flags = [ENV['CFLAGS'] || %w(-g -std=gnu99 -O3 -Wall -Werror-implicit-function-declaration -Wdeclaration-after-statement -Werror=declaration-after-statement)] + cc.flags = [ENV['CFLAGS'] || %w(-g -std=gnu99 -O3 -Wall -Werror-implicit-function-declaration -Wdeclaration-after-statement)] cc.include_paths = ["#{MRUBY_ROOT}/include"] cc.defines = %w(DISABLE_GEMS) cc.option_include_path = '-I%s' diff --git a/travis_config.rb b/travis_config.rb index 6f406ae37..ffa0a75d4 100644 --- a/travis_config.rb +++ b/travis_config.rb @@ -4,6 +4,7 @@ MRuby::Build.new('debug') do |conf| # include all core GEMs conf.gembox 'full-core' + conf.cc.flags += %w(-Werror=declaration-after-statement) conf.cc.defines += %w(MRB_GC_FIXED_ARENA) end @@ -12,6 +13,7 @@ MRuby::Build.new do |conf| # include all core GEMs conf.gembox 'full-core' + conf.cc.flags += %w(-Werror=declaration-after-statement) conf.cc.defines = %w(MRB_DEBUG MRB_GC_FIXED_ARENA) conf.enable_bintest = true end |
