summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--Rakefile10
-rw-r--r--build_config.rb2
-rw-r--r--include/mruby/khash.h2
-rw-r--r--mrbgems/mruby-array-ext/mrblib/array.rb31
-rw-r--r--mrbgems/mruby-array-ext/test/array.rb14
-rw-r--r--mrbgems/mruby-string-ext/mrblib/string.rb4
-rw-r--r--mrbgems/mruby-string-ext/test/string.rb5
-rw-r--r--mrbgems/mruby-string-utf8/test/string.rb42
-rw-r--r--mrbgems/mruby-struct/src/struct.c16
-rw-r--r--mrbgems/mruby-struct/test/struct.rb6
-rw-r--r--mrbgems/mruby-symbol-ext/mrblib/symbol.rb12
-rw-r--r--mrbgems/mruby-symbol-ext/test/symbol.rb7
-rw-r--r--src/dump.c10
-rw-r--r--tasks/mruby_build_commands.rake13
-rw-r--r--tasks/mruby_build_gem.rake14
16 files changed, 156 insertions, 33 deletions
diff --git a/AUTHORS b/AUTHORS
index 3791ad723..555cf7743 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -19,3 +19,4 @@ Original Authors "mruby developers" are:
Yuichi Nishiwaki
Tatsuhiko Kubo
Takeshi Watanabe
+ Yuki Kurihara
diff --git a/Rakefile b/Rakefile
index dbe2ed0a3..ad0e258b4 100644
--- a/Rakefile
+++ b/Rakefile
@@ -113,5 +113,13 @@ task :clean do
FileUtils.rm_rf t.build_dir, { :verbose => $verbose }
end
FileUtils.rm_f depfiles, { :verbose => $verbose }
- puts "Cleaned up build folder"
+ puts "Cleaned up target build folder"
+end
+
+desc "clean everything!"
+task :deep_clean => ["clean"] do
+ MRuby.each_target do |t|
+ FileUtils.rm_rf t.gem_clone_dir, { :verbose => $verbose }
+ end
+ puts "Cleaned up mrbgems build folder"
end
diff --git a/build_config.rb b/build_config.rb
index 3f8009047..795251486 100644
--- a/build_config.rb
+++ b/build_config.rb
@@ -16,7 +16,7 @@ MRuby::Build.new do |conf|
# g.cc.flags << '-g' # append cflags in this gem
# end
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
- # conf.gem :github => 'masuidrive/mrbgems-example', :branch => 'master'
+ # conf.gem :github => 'masuidrive/mrbgems-example', :checksum_hash => '76518e8aecd131d047378448ac8055fa29d974a9'
# conf.gem :git => '[email protected]:masuidrive/mrbgems-example.git', :branch => 'master', :options => '-v'
# include the default GEMs
diff --git a/include/mruby/khash.h b/include/mruby/khash.h
index bd33b7a6d..d2e87b8dd 100644
--- a/include/mruby/khash.h
+++ b/include/mruby/khash.h
@@ -180,7 +180,7 @@ kh_fill_flags(uint8_t *p, uint8_t c, size_t len)
return k; \
} \
} \
- else if (del_k != kh_end(h)) { \
+ else if (del_k == kh_end(h)) { \
del_k = k; \
} \
k = (k+(++step)) & khash_mask(h); \
diff --git a/mrbgems/mruby-array-ext/mrblib/array.rb b/mrbgems/mruby-array-ext/mrblib/array.rb
index 6c47235fe..43d77b5f6 100644
--- a/mrbgems/mruby-array-ext/mrblib/array.rb
+++ b/mrbgems/mruby-array-ext/mrblib/array.rb
@@ -425,4 +425,35 @@ class Array
def rotate!(count=1)
self.replace(self.rotate(count))
end
+
+ ##
+ # call-seq:
+ # ary.delete_if { |item| block } -> ary
+ # ary.delete_if -> Enumerator
+ #
+ # Deletes every element of +self+ for which block evaluates to +true+.
+ #
+ # The array is changed instantly every time the block is called, not after
+ # the iteration is over.
+ #
+ # See also Array#reject!
+ #
+ # If no block is given, an Enumerator is returned instead.
+ #
+ # scores = [ 97, 42, 75 ]
+ # scores.delete_if {|score| score < 80 } #=> [97]
+
+ def delete_if(&block)
+ return to_enum :delete_if unless block_given?
+
+ idx = 0
+ while idx < self.size do
+ if block.call(self[idx])
+ self.delete_at(idx)
+ else
+ idx += 1
+ end
+ end
+ self
+ end
end
diff --git a/mrbgems/mruby-array-ext/test/array.rb b/mrbgems/mruby-array-ext/test/array.rb
index d157a5b4d..1fdfabe49 100644
--- a/mrbgems/mruby-array-ext/test/array.rb
+++ b/mrbgems/mruby-array-ext/test/array.rb
@@ -169,3 +169,17 @@ assert("Array#rotate!") do
assert_equal ["c", "d", "a", "b"], a.rotate(10)
assert_equal [], [].rotate!
end
+
+assert("Array#delete_if") do
+ a = [1, 2, 3, 4, 5]
+ assert_equal [1, 2, 3, 4, 5], a.delete_if { false }
+ assert_equal [1, 2, 3, 4, 5], a
+
+ a = [1, 2, 3, 4, 5]
+ assert_equal [], a.delete_if { true }
+ assert_equal [], a
+
+ a = [1, 2, 3, 4, 5]
+ assert_equal [1, 2, 3], a.delete_if { |i| i > 3 }
+ assert_equal [1, 2, 3], a
+end
diff --git a/mrbgems/mruby-string-ext/mrblib/string.rb b/mrbgems/mruby-string-ext/mrblib/string.rb
index a517aa209..45c631b94 100644
--- a/mrbgems/mruby-string-ext/mrblib/string.rb
+++ b/mrbgems/mruby-string-ext/mrblib/string.rb
@@ -47,7 +47,9 @@ class String
# "abcdef".casecmp("ABCDEF") #=> 0
#
def casecmp(str)
- self.downcase <=> str.downcase
+ self.downcase <=> str.to_str.downcase
+ rescue NoMethodError
+ raise TypeError, "no implicit conversion of #{str.class} into String"
end
def partition(sep)
diff --git a/mrbgems/mruby-string-ext/test/string.rb b/mrbgems/mruby-string-ext/test/string.rb
index 90bb43c65..4c5620575 100644
--- a/mrbgems/mruby-string-ext/test/string.rb
+++ b/mrbgems/mruby-string-ext/test/string.rb
@@ -98,6 +98,11 @@ assert('String#casecmp') do
assert_equal 0, "aBcDeF".casecmp("abcdef")
assert_equal(-1, "abcdef".casecmp("abcdefg"))
assert_equal 0, "abcdef".casecmp("ABCDEF")
+ o = Object.new
+ def o.to_str
+ "ABCDEF"
+ end
+ assert_equal 0, "abcdef".casecmp(o)
end
assert('String#start_with?') do
diff --git a/mrbgems/mruby-string-utf8/test/string.rb b/mrbgems/mruby-string-utf8/test/string.rb
index 2cebfd7f3..ce99fba47 100644
--- a/mrbgems/mruby-string-utf8/test/string.rb
+++ b/mrbgems/mruby-string-utf8/test/string.rb
@@ -3,28 +3,28 @@
# String(utf8) Test
assert('String#[]') do
- assert_equal "ち", "こんにちわ世界"[3]
- assert_equal nil, "こんにちわ世界"[20]
- assert_equal "世", "こんにちわ世界"[-2]
- assert_equal "世界", "こんにちわ世界"[-2..-1]
- assert_equal "んに", "こんにちわ世界"[1,2]
- assert_equal "世", "こんにちわ世界"["世"]
+ assert_equal "ち", "こんにちは世界"[3]
+ assert_equal nil, "こんにちは世界"[20]
+ assert_equal "世", "こんにちは世界"[-2]
+ assert_equal "世界", "こんにちは世界"[-2..-1]
+ assert_equal "んに", "こんにちは世界"[1,2]
+ assert_equal "世", "こんにちは世界"["世"]
end
assert('String#reverse', '15.2.10.5.29') do
- a = 'こんにちわ世界!'
+ a = 'こんにちは世界!'
a.reverse
- assert_equal 'こんにちわ世界!', a
- assert_equal '!界世わちにんこ', 'こんにちわ世界!'.reverse
+ assert_equal 'こんにちは世界!', a
+ assert_equal '!界世はちにんこ', 'こんにちは世界!'.reverse
end
assert('String#reverse!', '15.2.10.5.30') do
- a = 'こんにちわ世界!'
+ a = 'こんにちは世界!'
a.reverse!
- assert_equal '!界世わちにんこ', a
- assert_equal '!界世わちにんこ', 'こんにちわ世界!'.reverse!
+ assert_equal '!界世はちにんこ', a
+ assert_equal '!界世はちにんこ', 'こんにちは世界!'.reverse!
end
assert('Invalid sequence') do
@@ -33,14 +33,14 @@ assert('Invalid sequence') do
end
assert('String#size') do
- str = 'こんにちわ世界!'
+ str = 'こんにちは世界!'
assert_equal 8, str.size
assert_not_equal str.bytesize, str.size
assert_equal 2, str[1, 2].size
end
assert('String#index') do
- str = "こんにちわ世界!\nこんにちわ世界!"
+ str = "こんにちは世界!\nこんにちは世界!"
assert_nil str.index('さ')
assert_equal 3, str.index('ち')
assert_equal 12, str.index('ち', 10)
@@ -48,20 +48,20 @@ assert('String#index') do
end
assert('String#ord') do
- got = "こんにちわ世界!".split('').map {|x| x.ord}
- expect = [0x3053,0x3093,0x306b,0x3061,0x308f,0x4e16,0x754c,0x21]
+ got = "こんにちは世界!".split('').map {|x| x.ord}
+ expect = [0x3053,0x3093,0x306b,0x3061,0x306f,0x4e16,0x754c,0x21]
assert_equal expect, got
end
assert('String#split') do
- got = "こんにちわ世界!".split('')
- assert_equal ['こ', 'ん', 'に', 'ち', 'わ', '世', '界', '!'], got
- got = "こんにちわ世界!".split('に')
- assert_equal ['こん', 'ちわ世界!'], got
+ got = "こんにちは世界!".split('')
+ assert_equal ['こ', 'ん', 'に', 'ち', 'は', '世', '界', '!'], got
+ got = "こんにちは世界!".split('に')
+ assert_equal ['こん', 'ちは世界!'], got
end
assert('String#rindex') do
- str = "こんにちわ世界!\nこんにちわ世界!"
+ str = "こんにちは世界!\nこんにちは世界!"
assert_nil str.index('さ')
assert_equal 12, str.rindex('ち')
assert_equal 3, str.rindex('ち', 10)
diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c
index 6932bb372..b5b498009 100644
--- a/mrbgems/mruby-struct/src/struct.c
+++ b/mrbgems/mruby-struct/src/struct.c
@@ -780,6 +780,19 @@ mrb_struct_eql(mrb_state *mrb, mrb_value s)
}
/*
+ * call-seq:
+ * struct.length -> Fixnum
+ * struct.size -> Fixnum
+ *
+ * Returns number of struct members.
+ */
+static mrb_value
+mrb_struct_len(mrb_state *mrb, mrb_value self)
+{
+ return mrb_fixnum_value(RSTRUCT_LEN(self));
+}
+
+/*
* A <code>Struct</code> is a convenient way to bundle a number of
* attributes together, using accessor methods, without having to write
* an explicit class.
@@ -811,6 +824,9 @@ mrb_mruby_struct_gem_init(mrb_state* mrb)
mrb_define_method(mrb, st, "inspect", mrb_struct_inspect, MRB_ARGS_NONE()); /* 15.2.18.4.10(x) */
mrb_define_alias(mrb, st, "to_s", "inspect"); /* 15.2.18.4.11(x) */
mrb_define_method(mrb, st, "eql?", mrb_struct_eql, MRB_ARGS_REQ(1)); /* 15.2.18.4.12(x) */
+
+ mrb_define_method(mrb, st, "size", mrb_struct_len, MRB_ARGS_NONE());
+ mrb_define_method(mrb, st, "length", mrb_struct_len, MRB_ARGS_NONE());
}
void
diff --git a/mrbgems/mruby-struct/test/struct.rb b/mrbgems/mruby-struct/test/struct.rb
index d647cd3a3..f4cb30b13 100644
--- a/mrbgems/mruby-struct/test/struct.rb
+++ b/mrbgems/mruby-struct/test/struct.rb
@@ -107,4 +107,10 @@ if Object.const_defined?(:Struct)
cc = c.new(1,2,3,4,5)
assert_equal "#<struct #{c.inspect} m1=1, m2=2, m3=3, m4=4, m5=5>", cc.inspect
end
+
+ assert('Struct#length, Struct#size') do
+ s = Struct.new(:f1, :f2).new(0, 1)
+ assert_equal 2, s.size
+ assert_equal 2, s.length
+ end
end
diff --git a/mrbgems/mruby-symbol-ext/mrblib/symbol.rb b/mrbgems/mruby-symbol-ext/mrblib/symbol.rb
index 78edf3cad..f4bf23cb1 100644
--- a/mrbgems/mruby-symbol-ext/mrblib/symbol.rb
+++ b/mrbgems/mruby-symbol-ext/mrblib/symbol.rb
@@ -1,4 +1,5 @@
class Symbol
+ include Comparable
def to_proc
->(obj,*args,&block) do
@@ -47,6 +48,17 @@ class Symbol
self.to_s.upcase.intern
end
+ ##
+ # call-seq:
+ # sym.casecmp(other) -> -1, 0, +1 or nil
+ #
+ # Case-insensitive version of <code>Symbol#<=></code>.
+
+ def casecmp(other)
+ return nil unless other.kind_of?(Symbol)
+ self.to_s.upcase <=> other.to_s.upcase
+ end
+
#
# call-seq:
# sym.empty? -> true or false
diff --git a/mrbgems/mruby-symbol-ext/test/symbol.rb b/mrbgems/mruby-symbol-ext/test/symbol.rb
index 35bb31aef..59df7ea9d 100644
--- a/mrbgems/mruby-symbol-ext/test/symbol.rb
+++ b/mrbgems/mruby-symbol-ext/test/symbol.rb
@@ -29,6 +29,13 @@ assert("Symbol#upcase") do
assert_equal :HELLO, :hEllO.upcase
end
+assert("Symbol#casecmp") do
+ assert_equal 0, :HELLO.casecmp(:hEllO)
+ assert_equal 1, :HELLO.casecmp(:hEllN)
+ assert_equal(-1, :HELLO.casecmp(:hEllP))
+ assert_nil :HELLO.casecmp("hEllO")
+end
+
assert("Symbol#empty?") do
assert_true :''.empty?
end
diff --git a/src/dump.c b/src/dump.c
index 2691aab3d..e3d1b779f 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -831,20 +831,20 @@ mrb_dump_irep_binary(mrb_state *mrb, mrb_irep *irep, int debug_info, FILE* fp)
return result;
}
-static int
+static mrb_bool
is_valid_c_symbol_name(const char *name)
{
const char *c = NULL;
- if (name == NULL || name[0] == '\0') return 0;
- if (!ISALPHA(name[0]) && name[0] != '_') return 0;
+ if (name == NULL || name[0] == '\0') return FALSE;
+ if (!ISALPHA(name[0]) && name[0] != '_') return FALSE;
c = &name[1];
for (; *c != '\0'; ++c) {
- if (!ISALNUM(*c) && *c != '_') return 0;
+ if (!ISALNUM(*c) && *c != '_') return FALSE;
}
- return 1;
+ return TRUE;
}
int
diff --git a/tasks/mruby_build_commands.rake b/tasks/mruby_build_commands.rake
index d64b20ff3..4beb7e743 100644
--- a/tasks/mruby_build_commands.rake
+++ b/tasks/mruby_build_commands.rake
@@ -228,14 +228,15 @@ module MRuby
class Command::Git < Command
attr_accessor :flags
- attr_accessor :clone_options, :pull_options
+ attr_accessor :clone_options, :pull_options, :checkout_options
def initialize(build)
super
@command = 'git'
- @flags = %w[--depth 1]
+ @flags = %w[]
@clone_options = "clone %{flags} %{url} %{dir}"
@pull_options = "pull"
+ @checkout_options = "checkout %{checksum_hash}"
end
def run_clone(dir, url, _flags = [])
@@ -250,6 +251,14 @@ module MRuby
_run pull_options
Dir.chdir root
end
+
+ def run_checkout(dir, checksum_hash)
+ root = Dir.pwd
+ Dir.chdir dir
+ _pp "GIT CHECKOUT", checksum_hash
+ _run checkout_options, { :checksum_hash => checksum_hash }
+ Dir.chdir root
+ end
end
class Command::Mrbc < Command
diff --git a/tasks/mruby_build_gem.rake b/tasks/mruby_build_gem.rake
index 42d0d6b89..766266680 100644
--- a/tasks/mruby_build_gem.rake
+++ b/tasks/mruby_build_gem.rake
@@ -59,6 +59,9 @@ module MRuby
url = params[:git]
gemdir = "#{gem_clone_dir}/#{url.match(/([-\w]+)(\.[-\w]+|)$/).to_a[1]}"
+ # by default the 'master' branch is used
+ branch = params[:branch] ? params[:branch] : 'master'
+
if File.exist?(gemdir)
if $pull_gems
git.run_pull gemdir, url
@@ -67,10 +70,19 @@ module MRuby
end
else
options = [params[:options]] || []
- options << "--branch \"#{params[:branch]}\"" if params[:branch]
+ options << "--branch \"#{branch}\""
+ options << "--depth 1" unless params[:checksum_hash]
FileUtils.mkdir_p "#{gem_clone_dir}"
git.run_clone gemdir, url, options
end
+
+ if params[:checksum_hash]
+ # Jump to the specified commit
+ git.run_checkout gemdir, params[:checksum_hash]
+ else
+ # Jump to the top of the branch
+ git.run_checkout gemdir, branch
+ end
else
fail "unknown gem option #{params}"
end