diff options
| -rw-r--r-- | Rakefile | 24 | ||||
| -rw-r--r-- | build_config.rb | 3 | ||||
| -rw-r--r-- | mrbgems/mruby-string-ext/mrbgem.rake | 4 | ||||
| -rw-r--r-- | mrbgems/mruby-string-ext/src/string.c | 30 | ||||
| -rw-r--r-- | mrbgems/mruby-string-ext/test/string.rb | 15 | ||||
| -rw-r--r-- | tasks/mrbgem_spec.rake | 8 | ||||
| -rw-r--r-- | tasks/mruby_build.rake | 5 |
7 files changed, 87 insertions, 2 deletions
@@ -48,6 +48,30 @@ depfiles = MRuby.targets['host'].bins.map do |bin| install_path end +MRuby.each_target do + gems.map do | gem | + current_dir = gem.dir.relative_path_from(Dir.pwd) + relative_from_root = gem.dir.relative_path_from(MRUBY_ROOT) + current_build_dir = "#{build_dir}/#{relative_from_root}" + + gem.bins.each do | bin | + exec = exefile("#{build_dir}/bin/#{bin}") + objs = Dir.glob("#{current_dir}/tool/#{bin}/*.c").map { |f| objfile(f.pathmap("#{current_build_dir}/tool/#{bin}/%n")) } + + file exec => objs + [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 + + depfiles += [ exec ] + end + end +end + depfiles += MRuby.targets.reject { |n, t| n == 'host' }.map { |n, t| [t.libfile("#{t.build_dir}/lib/libmruby")] + t.bins.map { |bin| t.exefile("#{t.build_dir}/bin/#{bin}") } }.flatten diff --git a/build_config.rb b/build_config.rb index 3c089d8cc..c54c9d323 100644 --- a/build_config.rb +++ b/build_config.rb @@ -23,6 +23,9 @@ MRuby::Build.new do |conf| # Use standard Kernel#sprintf method conf.gem 'mrbgems/mruby-sprintf' + # Use extensional String class + conf.gem 'mrbgems/mruby-string-ext' + # Generate binaries # conf.bins = %w(mrbc mruby mirb) diff --git a/mrbgems/mruby-string-ext/mrbgem.rake b/mrbgems/mruby-string-ext/mrbgem.rake new file mode 100644 index 000000000..83db97eb4 --- /dev/null +++ b/mrbgems/mruby-string-ext/mrbgem.rake @@ -0,0 +1,4 @@ +MRuby::Gem::Specification.new('mruby-string-ext') do |spec| + spec.license = 'MIT' + spec.authors = 'mruby developers' +end diff --git a/mrbgems/mruby-string-ext/src/string.c b/mrbgems/mruby-string-ext/src/string.c new file mode 100644 index 000000000..175426638 --- /dev/null +++ b/mrbgems/mruby-string-ext/src/string.c @@ -0,0 +1,30 @@ +#include "mruby.h" +#include "mruby/string.h" + +static mrb_value +mrb_str_getbyte(mrb_state *mrb, mrb_value str) +{ + mrb_int pos; + mrb_get_args(mrb, "i", &pos); + + if (pos < 0) + pos += RSTRING_LEN(str); + if (pos < 0 || RSTRING_LEN(str) <= pos) + return mrb_nil_value(); + + return mrb_fixnum_value((unsigned char)RSTRING_PTR(str)[pos]); +} + + +void +mrb_mruby_string_ext_gem_init(mrb_state* mrb) +{ + struct RClass * s = mrb->string_class; + + mrb_define_method(mrb, s, "getbyte", mrb_str_getbyte, ARGS_REQ(1)); +} + +void +mrb_mruby_string_ext_gem_final(mrb_state* mrb) +{ +} diff --git a/mrbgems/mruby-string-ext/test/string.rb b/mrbgems/mruby-string-ext/test/string.rb new file mode 100644 index 000000000..9a7579131 --- /dev/null +++ b/mrbgems/mruby-string-ext/test/string.rb @@ -0,0 +1,15 @@ +## +# String(Ext) Test + +assert('String#getbyte') do + str1 = "hello" + bytes1 = [104, 101, 108, 108, 111] + assert_equal bytes1[0], str1.getbyte(0) + assert_equal bytes1[-1], str1.getbyte(-1) + assert_equal bytes1[6], str1.getbyte(6) + + str2 = "\xFF" + bytes2 = [0xFF] + assert_equal bytes2[0], str2.getbyte(0) +end + diff --git a/tasks/mrbgem_spec.rake b/tasks/mrbgem_spec.rake index 5b01bc79b..649f99d0e 100644 --- a/tasks/mrbgem_spec.rake +++ b/tasks/mrbgem_spec.rake @@ -28,6 +28,8 @@ module MRuby attr_accessor :test_objs, :test_rbfiles, :test_args attr_accessor :test_preload + attr_accessor :bins + attr_block MRuby::Build::COMMANDS def initialize(name, &block) @@ -59,6 +61,8 @@ module MRuby @test_preload = 'test/assert.rb' @test_args = {} + @bins = [] + instance_eval(&@initializer) if !name || !licenses || !authors @@ -76,6 +80,10 @@ module MRuby define_gem_init_builder end + def self.bin=(bin) + @bins = [bin].flatten + end + def build_dir "#{build.build_dir}/mrbgems/#{name}" end diff --git a/tasks/mruby_build.rake b/tasks/mruby_build.rake index 812e861a7..10125701e 100644 --- a/tasks/mruby_build.rake +++ b/tasks/mruby_build.rake @@ -174,8 +174,9 @@ module MRuby puts " Binaries: #{@bins.join(', ')}" unless @bins.empty? unless @gems.empty? puts " Included Gems:" - @gems.map(&:name).each do |name| - puts " #{name}" + @gems.map do |gem| + puts " #{gem.name}" + puts " - Binaries: #{gem.bins.join(', ')}" unless gem.bins.empty? end end puts "================================================" |
