Skip to content
Browse files

Merge branch 'master' into iij

Conflicts:
	src/string.c
  • Loading branch information...
2 parents 0f18a92 + 913faa4 commit e0052a6900d10b3aceeb92e0dad3b249028113e5 @tsahara tsahara committed Feb 6, 2013
View
4 Rakefile
@@ -64,9 +64,9 @@ task :all => depfiles do
end
desc "run all mruby tests"
-task :test => MRuby.targets.values.map { |t| t.exefile("#{t.build_dir}/test/mrbtest") } do
+task :test => MRuby.targets.values.map { |t| t.build_mrbtest_lib_only? ? t.libfile("#{t.build_dir}/test/mrbtest") : t.exefile("#{t.build_dir}/test/mrbtest") } do
MRuby.each_target do
- run_test
+ run_test unless build_mrbtest_lib_only?
end
end
View
2 build_config.rb
@@ -82,6 +82,8 @@
#
# conf.cc.flags << "-m32"
# conf.linker.flags << "-m32"
+#
+# conf.build_mrbtest_lib_only
#
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
# end
View
10 doc/compile/README.md
@@ -160,6 +160,16 @@ Integrate GEMs in the build process.
# Integrate GEM without additional configuration
conf.gem 'path/to/another/gem'
+
+### Mrbtest
+
+Configuration Mrbtest build process.
+
+If you want mrbtest.a only, You should set ```conf.build_mrbtest_lib_only```
+
+ conf.build_mrbtest_lib_only
+
+
## Cross-Compilation
mruby can also be cross-compiled from one platform to another. To
View
4 include/mruby.h
@@ -317,10 +317,6 @@ typedef enum call_type {
CALL_TYPE_MAX
} call_type;
-/* compar.c */
-void mrb_cmperr(mrb_state *mrb, mrb_value x, mrb_value y);
-int mrb_cmpint(mrb_state *mrb, mrb_value val, mrb_value a, mrb_value b);
-
#ifndef ANYARGS
# ifdef __cplusplus
# define ANYARGS ...
View
1 include/mruby/compile.h
@@ -104,7 +104,6 @@ struct mrb_parser_state {
struct mrb_parser_state* mrb_parser_new(mrb_state*);
void mrb_parser_free(struct mrb_parser_state*);
-const char *mrb_parser_filename(struct mrb_parser_state*, const char*);
void mrb_parser_parse(struct mrb_parser_state*,mrbc_context*);
/* utility functions */
View
3 include/mruby/hash.h
@@ -27,7 +27,6 @@ void mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val);
mrb_value mrb_hash_get(mrb_state *mrb, mrb_value hash, mrb_value key);
mrb_value mrb_hash_fetch(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value def);
mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key);
-mrb_value mrb_hash(mrb_state *mrb, mrb_value obj);
mrb_value mrb_hash_keys(mrb_state *mrb, mrb_value hash);
mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash);
@@ -41,8 +40,6 @@ struct kh_ht * mrb_hash_tbl(mrb_state *mrb, mrb_value hash);
#define MRB_HASH_PROC_DEFAULT 256
#define MRB_RHASH_PROCDEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_PROC_DEFAULT)
-mrb_value mrb_obj_is_proc(mrb_value proc);
-
/* GC functions */
void mrb_gc_mark_ht(mrb_state*, struct RHash*);
size_t mrb_gc_mark_ht_size(mrb_state*, struct RHash*);
View
1 include/mruby/string.h
@@ -72,7 +72,6 @@ mrb_value mrb_str_to_inum(mrb_state *mrb, mrb_value str, int base, int badcheck)
double mrb_str_to_dbl(mrb_state *mrb, mrb_value str, int badcheck);
mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str);
mrb_int mrb_str_hash(mrb_state *mrb, mrb_value str);
-int mrb_str_hash_cmp(mrb_state *mrb, mrb_value str1, mrb_value str2);
mrb_value mrb_str_buf_append(mrb_state *mrb, mrb_value str, mrb_value str2);
mrb_value mrb_str_inspect(mrb_state *mrb, mrb_value str);
int mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2);
View
60 src/codegen.c
@@ -962,6 +962,48 @@ readint_float(codegen_scope *s, const char *p, int base)
return f;
}
+static mrb_int
+readint_mrb_int(codegen_scope *s, const char *p, int base, int neg, int *overflow)
+{
+ const char *e = p + strlen(p);
+ mrb_int result = 0;
+ int n;
+
+ if (*p == '+') p++;
+ while (p < e) {
+ char c = *p;
+ c = tolower((unsigned char)c);
+ for (n=0; n<base; n++) {
+ if (mrb_digitmap[n] == c) {
+ break;
+ }
+ }
+ if (n == base) {
+ codegen_error(s, "malformed readint input");
+ }
+
+ if (neg) {
+ if ((MRB_INT_MIN + n)/base > result) {
+ *overflow = TRUE;
+ return 0;
+ }
+ result *= base;
+ result -= n;
+ }
+ else {
+ if ((MRB_INT_MAX - n)/base < result) {
+ *overflow = TRUE;
+ return 0;
+ }
+ result *= base;
+ result += n;
+ }
+ p++;
+ }
+ *overflow = FALSE;
+ return result;
+}
+
static void
codegen(codegen_scope *s, node *tree, int val)
{
@@ -1736,18 +1778,18 @@ codegen(codegen_scope *s, node *tree, int val)
if (val) {
char *p = (char*)tree->car;
int base = (intptr_t)tree->cdr->car;
- double f;
mrb_int i;
mrb_code co;
+ int overflow;
- f = readint_float(s, p, base);
- if (!FIXABLE(f)) {
+ i = readint_mrb_int(s, p, base, FALSE, &overflow);
+ if (overflow) {
+ double f = readint_float(s, p, base);
int off = new_lit(s, mrb_float_value(f));
genop(s, MKOP_ABx(OP_LOADL, cursp(), off));
}
else {
- i = (mrb_int)f;
if (i < MAXARG_sBx && i > -MAXARG_sBx) {
co = MKOP_AsBx(OP_LOADI, cursp(), i);
}
@@ -1792,18 +1834,18 @@ codegen(codegen_scope *s, node *tree, int val)
{
char *p = (char*)tree->car;
int base = (intptr_t)tree->cdr->car;
- mrb_float f;
mrb_int i;
mrb_code co;
+ int overflow;
- f = readint_float(s, p, base);
- if (!FIXABLE(f)) {
+ i = readint_mrb_int(s, p, base, TRUE, &overflow);
+ if (overflow) {
+ double f = readint_float(s, p, base);
int off = new_lit(s, mrb_float_value(-f));
-
+
genop(s, MKOP_ABx(OP_LOADL, cursp(), off));
}
else {
- i = (mrb_int)-f;
if (i < MAXARG_sBx && i > -MAXARG_sBx) {
co = MKOP_AsBx(OP_LOADI, cursp(), i);
}
View
5 src/hash.c
@@ -823,8 +823,9 @@ mrb_hash_empty_p(mrb_state *mrb, mrb_value self)
if (h) {
if (kh_size(h) == 0)
return mrb_true_value();
+ return mrb_false_value();
}
- return mrb_false_value();
+ return mrb_true_value();
}
/* 15.2.13.4.11 */
@@ -1125,7 +1126,7 @@ hash_equal(mrb_state *mrb, mrb_value hash1, mrb_value hash2, int eql)
}
h1 = RHASH_TBL(hash1);
h2 = RHASH_TBL(hash2);
- if (!h2) {
+ if (!h1) {
if (!h2) return mrb_true_value();
return mrb_false_value();
}
View
2 src/numeric.c
@@ -1160,7 +1160,7 @@ fix_minus(mrb_state *mrb, mrb_value self)
mrb_value
mrb_fix2str(mrb_state *mrb, mrb_value x, int base)
{
- char buf[64], *b = buf + sizeof buf;
+ char buf[sizeof(mrb_int)*CHAR_BIT+2], *b = buf + sizeof buf;
mrb_int val = mrb_fixnum(x);
int neg = 0;
View
1 src/string.c
@@ -2278,6 +2278,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
else
tmp = mrb_str_subseq(mrb, str, BEG(idx), END(idx)-BEG(idx));
mrb_ary_push(mrb, result, tmp);
+ mrb_gc_arena_restore(mrb, ai);
}
if (lim > 0 && lim <= ++i) break;
}
View
4 tasks/mrbgem_spec.rake
@@ -77,8 +77,8 @@ module MRuby
"#{build.build_dir}/mrbgems/#{name}"
end
- def testlib
- libfile("#{build_dir}/libmrb-#{name}-gem-test")
+ def test_rbireps
+ "#{build_dir}/gem_test.c"
end
def funcname
View
11 tasks/mrbgems_test.rake
@@ -2,15 +2,10 @@ MRuby.each_target do
dir = File.dirname(__FILE__).relative_path_from(root)
gems.each do |g|
- test_rbc = "#{g.build_dir}/gem_test.c"
- test_rbobj = test_rbc.ext(exts.object)
+ test_rbobj = g.test_rbireps.ext(exts.object)
- file g.testlib => [g.test_objs, test_rbobj].flatten do |t|
- g.build.archiver.run t.name, t.prerequisites
- end
-
- file test_rbobj => test_rbc
- file test_rbc => [g.test_rbfiles].flatten + [g.build.mrbcfile, libfile("#{build_dir}/lib/libmruby")] do |t|
+ file test_rbobj => g.test_rbireps
+ file g.test_rbireps => [g.test_rbfiles].flatten + [g.build.mrbcfile, libfile("#{build_dir}/lib/libmruby")] do |t|
open(t.name, 'w') do |f|
g.print_gem_init_header(f)
g.build.mrbc.run f, g.test_preload, "gem_test_irep_#{g.funcname}_preload"
View
9 tasks/mruby_build.rake
@@ -78,6 +78,7 @@ module MRuby
@bins = %w(mruby mrbc mirb)
@gems, @libmruby = [], []
+ @build_mrbtest_lib_only = false
MRuby.targets[@name] = self
end
@@ -149,6 +150,14 @@ module MRuby
end
end
+ def build_mrbtest_lib_only
+ @build_mrbtest_lib_only = true
+ end
+
+ def build_mrbtest_lib_only?
+ @build_mrbtest_lib_only
+ end
+
def run_test
puts ">>> Test #{name} <<<"
mrbtest = exefile("#{build_dir}/test/mrbtest")
View
23 tasks/toolchains/androideabi.rake
@@ -0,0 +1,23 @@
+# Download and unarchive latest Android NDK from https://developer.android.com/tools/sdk/ndk/index.html
+# Make custom standalone toolchain as described here (android_ndk/docs/STANDALONE-TOOLCHAIN.html)
+# Please export custom standalone toolchain path
+# export ANDROID_STANDALONE_TOOLCHAIN=/tmp/android-14-toolchain
+
+# Add to your build_config.rb
+# MRuby::CrossBuild.new('androideabi') do |conf|
+# toolchain :androideabi
+# end
+
+MRuby::Toolchain.new(:androideabi) do |conf|
+ toolchain :gcc
+
+ ANDROID_STANDALONE_TOOLCHAIN = ENV['ANDROID_STANDALONE_TOOLCHAIN'] + '/bin/arm-linux-androideabi-'
+ SYSROOT = ENV['ANDROID_STANDALONE_TOOLCHAIN'] + '/sysroot'
+
+ [conf.cc, conf.cxx, conf.objc, conf.asm].each do |cc|
+ cc.command = ENV['CC'] || ANDROID_STANDALONE_TOOLCHAIN + 'gcc'
+ cc.flags = [ENV['CFLAGS'] || ['--sysroot ' + SYSROOT]]
+ end
+ conf.linker.command = ENV['LD'] || ANDROID_STANDALONE_TOOLCHAIN + 'gcc'
+ conf.archiver.command = ENV['AR'] || ANDROID_STANDALONE_TOOLCHAIN + 'ar'
+end
View
23 test/mrbtest.rake
@@ -10,20 +10,27 @@ MRuby.each_target do
catrb = "#{build_dir}/#{dir}/mrbtest.rb"
catmrb = "#{build_dir}/#{dir}/mrbtest.mrb"
- objs = [objfile("#{build_dir}/#{dir}/driver"), mlib].flatten
+ mrbtest_lib = libfile("#{build_dir}/#{dir}/mrbtest")
+ file mrbtest_lib => [mlib, gems.map(&:test_objs), gems.map { |g| g.test_rbireps.ext(exts.object) }].flatten do |t|
+ archiver.run t.name, t.prerequisites
+ end
- file exec => objs + gems.map(&:testlib).flatten + [libfile("#{build_dir}/lib/libmruby")] do |t|
- gem_flags = gems.map { |g| g.linker.flags }
- gem_flags_before_libraries = gems.map { |g| g.linker.flags_before_libraries }
- gem_flags_after_libraries = gems.map { |g| g.linker.flags_after_libraries }
- gem_libraries = gems.map { |g| g.linker.libraries }
- gem_library_paths = gems.map { |g| g.linker.library_paths }
- linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags, gem_flags_before_libraries
+ unless build_mrbtest_lib_only?
+ driver_obj = objfile("#{build_dir}/#{dir}/driver")
+ file exec => [driver_obj, mrbtest_lib, libfile("#{build_dir}/lib/libmruby")] do |t|
+ gem_flags = gems.map { |g| g.linker.flags }
+ gem_flags_before_libraries = gems.map { |g| g.linker.flags_before_libraries }
+ gem_flags_after_libraries = gems.map { |g| g.linker.flags_after_libraries }
+ gem_libraries = gems.map { |g| g.linker.libraries }
+ gem_library_paths = gems.map { |g| g.linker.library_paths }
+ linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags, gem_flags_before_libraries
+ end
end
file mlib => [clib, catmrb]
file clib => [mrbcfile, init, asslib] + mrbs do |t|
_pp "GEN", "*.rb", "#{clib}"
+ FileUtils.mkdir_p File.dirname(clib)
open(clib, 'w') do |f|
f.puts IO.read(init)
mrbc.run f, [asslib] + mrbs, 'mrbtest_irep'

0 comments on commit e0052a6

Please sign in to comment.
Something went wrong with that request. Please try again.