From 1ea13483cb3a5d6e0007b49b0ab9cfdb3e9055eb Mon Sep 17 00:00:00 2001 From: Kouki Ooyatsu Date: Thu, 28 Feb 2013 10:56:58 +0900 Subject: [PATCH 01/13] Regexp: %r notation bug fix. close #85. be able to parse any delimiters. variable expansion isn't supported yet. * sample code ``` def matchpath(str) puts "#{str} is ..." if %r!img/! =~ str then puts "match" else puts "not match" end end matchpath("img/a.png") # => match matchpath("/usr/local/bin") # => not match matchpath("book/img/local") # => match ``` --- src/parse.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parse.y b/src/parse.y index 365bc5f18..2c5690ea3 100644 --- a/src/parse.y +++ b/src/parse.y @@ -4440,7 +4440,7 @@ parser_yylex(parser_state *p) p->lex_strterm = new_strterm(p, str_regexp, term, paren); #endif p->regexp = 1; - p->sterm = '/'; + p->sterm = term; return tREGEXP_BEG; case 's': From 1f692ab0ba1def0291bf63cd8c295180d8fcc0e3 Mon Sep 17 00:00:00 2001 From: "Xuejie \"Rafael\" Xiao" Date: Wed, 27 Feb 2013 21:29:49 -0500 Subject: [PATCH 02/13] Do not generate test_args_hash variable if it is not used --- tasks/mrbgems_test.rake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tasks/mrbgems_test.rake b/tasks/mrbgems_test.rake index 6d40d092a..6ca5eaef2 100644 --- a/tasks/mrbgems_test.rake +++ b/tasks/mrbgems_test.rake @@ -18,7 +18,11 @@ MRuby.each_target do f.puts %Q[void GENERATED_TMP_mrb_#{g.funcname}_gem_test(mrb_state *mrb) {] unless g.test_rbfiles.empty? f.puts %Q[ mrb_state *mrb2;] - f.puts %Q[ mrb_value val1, val2, ary1, ary2, test_args_hash;] + if g.test_args.empty? + f.puts %Q[ mrb_value val1, val2, ary1, ary2;] + else + f.puts %Q[ mrb_value val1, val2, ary1, ary2, test_args_hash;] + end f.puts %Q[ int ai;] g.test_rbfiles.count.times do |i| f.puts %Q[ ai = mrb_gc_arena_save(mrb);] From f4485ee1eb6c8f586ca5313b1085e4f354db19d1 Mon Sep 17 00:00:00 2001 From: Yuichiro MASUI Date: Thu, 28 Feb 2013 11:55:22 +0900 Subject: [PATCH 03/13] s/mgem/mrbgem/ --- build_config.rb | 2 +- {mgems => mrbgems}/mruby-time/mrbgem.rake | 2 +- {mgems => mrbgems}/mruby-time/src/time.c | 0 {mgems => mrbgems}/mruby-time/test/time.rb | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename {mgems => mrbgems}/mruby-time/mrbgem.rake (69%) rename {mgems => mrbgems}/mruby-time/src/time.c (100%) rename {mgems => mrbgems}/mruby-time/test/time.rb (100%) diff --git a/build_config.rb b/build_config.rb index a66dab6ac..a296ce705 100644 --- a/build_config.rb +++ b/build_config.rb @@ -12,7 +12,7 @@ MRuby::Build.new do |conf| # conf.gem :git => 'git@github.com:masuidrive/mrbgems-example.git', :branch => 'master', :options => '-v' # Use standard Time class - conf.gem 'mgems/mruby-time' + conf.gem 'mrbgems/mruby-time' # Generate binaries # conf.bins = %w(mrbc mruby mirb) diff --git a/mgems/mruby-time/mrbgem.rake b/mrbgems/mruby-time/mrbgem.rake similarity index 69% rename from mgems/mruby-time/mrbgem.rake rename to mrbgems/mruby-time/mrbgem.rake index 2cd3fd354..0f0b4899d 100644 --- a/mgems/mruby-time/mrbgem.rake +++ b/mrbgems/mruby-time/mrbgem.rake @@ -1,4 +1,4 @@ MRuby::Gem::Specification.new('mruby-time') do |spec| spec.license = 'MIT' - spec.authors = 'mruby team' + spec.authors = 'mruby developers' end diff --git a/mgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c similarity index 100% rename from mgems/mruby-time/src/time.c rename to mrbgems/mruby-time/src/time.c diff --git a/mgems/mruby-time/test/time.rb b/mrbgems/mruby-time/test/time.rb similarity index 100% rename from mgems/mruby-time/test/time.rb rename to mrbgems/mruby-time/test/time.rb From 473abbd0ff7c32f449f4d20ec04adebf951c4edf Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 28 Feb 2013 17:39:38 +0900 Subject: [PATCH 04/13] Cleanup Regexp codes --- src/init.c | 2 -- src/re.c | 42 ------------------------------------------ 2 files changed, 44 deletions(-) delete mode 100644 src/re.c diff --git a/src/init.c b/src/init.c index a5727561d..c5235396b 100644 --- a/src/init.c +++ b/src/init.c @@ -22,7 +22,6 @@ void mrb_init_numeric(mrb_state*); void mrb_init_range(mrb_state*); void mrb_init_struct(mrb_state*); void mrb_init_gc(mrb_state*); -void mrb_init_regexp(mrb_state*); void mrb_init_print(mrb_state*); void mrb_init_math(mrb_state*); void mrb_init_mrblib(mrb_state*); @@ -53,7 +52,6 @@ mrb_init_core(mrb_state *mrb) mrb_init_struct(mrb); DONE; #endif mrb_init_gc(mrb); DONE; - mrb_init_regexp(mrb); DONE; #ifdef ENABLE_STDIO mrb_init_print(mrb); DONE; #endif diff --git a/src/re.c b/src/re.c deleted file mode 100644 index 744732e58..000000000 --- a/src/re.c +++ /dev/null @@ -1,42 +0,0 @@ -/* -** re.c - Regexp class -** -** See Copyright Notice in mruby.h -*/ - -#include "mruby.h" -#include -#include "mruby/string.h" -#include "re.h" -#include "mruby/array.h" -#include "mruby/class.h" -#include "error.h" - -/* - * Document-class: RegexpError - * - * Raised when given an invalid regexp expression. - * - * Regexp.new("?") - * - * raises the exception: - * - * RegexpError: target of repeat operator is not specified: /?/ - */ - -/* - * Document-class: Regexp - * - * A Regexp holds a regular expression, used to match a pattern - * against strings. Regexps are created using the /.../ and - * %r{...} literals, and by the Regexp::new - * constructor. - * - * :include: doc/re.rdoc - */ - -void -mrb_init_regexp(mrb_state *mrb) -{ - //mrb_define_class(mrb, REGEXP_CLASS, mrb->object_class); -} From 6bee2fd193b94f00c7f4025fc3d62282f867e60d Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 28 Feb 2013 17:52:18 +0900 Subject: [PATCH 05/13] Pluggable Math --- build_config.rb | 3 +++ include/mrbconf.h | 4 ---- mgems/mruby-math/mrbgem.rake | 4 ++++ {src => mgems/mruby-math/src}/math.c | 9 ++++++--- {test/t => mgems/mruby-math/test}/math.rb | 0 src/init.c | 3 --- 6 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 mgems/mruby-math/mrbgem.rake rename {src => mgems/mruby-math/src}/math.c (99%) rename {test/t => mgems/mruby-math/test}/math.rb (100%) diff --git a/build_config.rb b/build_config.rb index a66dab6ac..99761a795 100644 --- a/build_config.rb +++ b/build_config.rb @@ -11,6 +11,9 @@ MRuby::Build.new do |conf| # conf.gem :github => 'masuidrive/mrbgems-example', :branch => 'master' # conf.gem :git => 'git@github.com:masuidrive/mrbgems-example.git', :branch => 'master', :options => '-v' + # Use standard Math module + conf.gem 'mgems/mruby-math' + # Use standard Time class conf.gem 'mgems/mruby-time' diff --git a/include/mrbconf.h b/include/mrbconf.h index 092e02d11..45e3d6034 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -45,7 +45,6 @@ /* -DDISABLE_XXXX to drop following features */ //#define DISABLE_SPRINTF /* Kernel.sprintf method */ -//#define DISABLE_MATH /* Math functions */ //#define DISABLE_STRUCT /* Struct class */ //#define DISABLE_STDIO /* use of stdio */ @@ -85,9 +84,6 @@ typedef short mrb_sym; #ifndef DISABLE_SPRINTF #define ENABLE_SPRINTF #endif -#ifndef DISABLE_MATH -#define ENABLE_MATH -#endif #ifndef DISABLE_STRUCT #define ENABLE_STRUCT #endif diff --git a/mgems/mruby-math/mrbgem.rake b/mgems/mruby-math/mrbgem.rake new file mode 100644 index 000000000..4b0fa40fd --- /dev/null +++ b/mgems/mruby-math/mrbgem.rake @@ -0,0 +1,4 @@ +MRuby::Gem::Specification.new('mruby-math') do |spec| + spec.license = 'MIT' + spec.authors = 'mruby developers' +end diff --git a/src/math.c b/mgems/mruby-math/src/math.c similarity index 99% rename from src/math.c rename to mgems/mruby-math/src/math.c index 782b75c97..9955d9862 100644 --- a/src/math.c +++ b/mgems/mruby-math/src/math.c @@ -7,7 +7,6 @@ #include "mruby.h" #include "mruby/array.h" -#ifdef ENABLE_MATH #include #define domain_error(msg) \ @@ -630,7 +629,7 @@ math_erfc(mrb_state *mrb, mrb_value obj) /* ------------------------------------------------------------------------*/ void -mrb_init_math(mrb_state *mrb) +mrb_mruby_math_gem_init(mrb_state* mrb) { struct RClass *mrb_math; mrb_math = mrb_define_module(mrb, "Math"); @@ -685,4 +684,8 @@ mrb_init_math(mrb_state *mrb) mrb_define_module_function(mrb, mrb_math, "erf", math_erf, ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_math, "erfc", math_erfc, ARGS_REQ(1)); } -#endif /* ENABLE_MATH */ + +void +mrb_mruby_math_gem_final(mrb_state* mrb) +{ +} diff --git a/test/t/math.rb b/mgems/mruby-math/test/math.rb similarity index 100% rename from test/t/math.rb rename to mgems/mruby-math/test/math.rb diff --git a/src/init.c b/src/init.c index a5727561d..a630a3307 100644 --- a/src/init.c +++ b/src/init.c @@ -56,9 +56,6 @@ mrb_init_core(mrb_state *mrb) mrb_init_regexp(mrb); DONE; #ifdef ENABLE_STDIO mrb_init_print(mrb); DONE; -#endif -#ifdef ENABLE_MATH - mrb_init_math(mrb); DONE; #endif mrb_init_mrblib(mrb); DONE; #ifndef DISABLE_GEMS From bdd908c92e04970e72e4d468ddefb81243767ee8 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 28 Feb 2013 10:30:30 +0000 Subject: [PATCH 06/13] Rake respects verbose flag also for test and clean target --- Rakefile | 7 +++---- tasks/mruby_build.rake | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index 1c65321f5..33967b07b 100644 --- a/Rakefile +++ b/Rakefile @@ -32,7 +32,6 @@ load "#{MRUBY_ROOT}/tools/mirb/mirb.rake" load "#{MRUBY_ROOT}/tasks/mrbgems_test.rake" load "#{MRUBY_ROOT}/test/mrbtest.rake" - ############################## # generic build targets, rules task :default => :all @@ -42,7 +41,7 @@ depfiles = MRuby.targets['host'].bins.map do |bin| source_path = MRuby.targets['host'].exefile("#{MRuby.targets['host'].build_dir}/bin/#{bin}") file install_path => source_path do |t| - FileUtils.cp t.prerequisites.first, t.name + FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose } end install_path @@ -72,8 +71,8 @@ end desc "clean all built and in-repo installed artifacts" task :clean do MRuby.each_target do |t| - FileUtils.rm_rf t.build_dir + FileUtils.rm_rf t.build_dir, { :verbose => $verbose } end - FileUtils.rm_f depfiles + FileUtils.rm_f depfiles, { :verbose => $verbose } puts "Cleaned up build folder" end diff --git a/tasks/mruby_build.rake b/tasks/mruby_build.rake index 4d28b1d95..812e861a7 100644 --- a/tasks/mruby_build.rake +++ b/tasks/mruby_build.rake @@ -163,7 +163,7 @@ module MRuby def run_test puts ">>> Test #{name} <<<" mrbtest = exefile("#{build_dir}/test/mrbtest") - sh "#{filename mrbtest.relative_path}" + sh "#{filename mrbtest.relative_path}#{$verbose ? ' -v' : ''}" puts end From 12af04011fcaa80c6aa70da0586e39046613b3cf Mon Sep 17 00:00:00 2001 From: Yukihiro Matz Matsumoto Date: Thu, 28 Feb 2013 22:41:08 +0900 Subject: [PATCH 07/13] mv mrgems/mruby-math to mrbgems --- build_config.rb | 2 +- {mgems => mrbgems}/mruby-math/mrbgem.rake | 0 {mgems => mrbgems}/mruby-math/src/math.c | 0 {mgems => mrbgems}/mruby-math/test/math.rb | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename {mgems => mrbgems}/mruby-math/mrbgem.rake (100%) rename {mgems => mrbgems}/mruby-math/src/math.c (100%) rename {mgems => mrbgems}/mruby-math/test/math.rb (100%) diff --git a/build_config.rb b/build_config.rb index d2f9597a0..c0a6eacc6 100644 --- a/build_config.rb +++ b/build_config.rb @@ -12,7 +12,7 @@ MRuby::Build.new do |conf| # conf.gem :git => 'git@github.com:masuidrive/mrbgems-example.git', :branch => 'master', :options => '-v' # Use standard Math module - conf.gem 'mgems/mruby-math' + conf.gem 'mrbgems/mruby-math' # Use standard Time class conf.gem 'mrbgems/mruby-time' diff --git a/mgems/mruby-math/mrbgem.rake b/mrbgems/mruby-math/mrbgem.rake similarity index 100% rename from mgems/mruby-math/mrbgem.rake rename to mrbgems/mruby-math/mrbgem.rake diff --git a/mgems/mruby-math/src/math.c b/mrbgems/mruby-math/src/math.c similarity index 100% rename from mgems/mruby-math/src/math.c rename to mrbgems/mruby-math/src/math.c diff --git a/mgems/mruby-math/test/math.rb b/mrbgems/mruby-math/test/math.rb similarity index 100% rename from mgems/mruby-math/test/math.rb rename to mrbgems/mruby-math/test/math.rb From 3d3ebbc9cd3c7b745e98fd3232044fa0f97fd891 Mon Sep 17 00:00:00 2001 From: Carson McDonald Date: Thu, 28 Feb 2013 09:24:08 -0500 Subject: [PATCH 08/13] Fix arena size check. --- src/gc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gc.c b/src/gc.c index 58326d396..5cc794fd9 100644 --- a/src/gc.c +++ b/src/gc.c @@ -314,7 +314,7 @@ mrb_free_heap(mrb_state *mrb) static void gc_protect(mrb_state *mrb, struct RBasic *p) { - if (mrb->arena_idx > MRB_ARENA_SIZE) { + if (mrb->arena_idx >= MRB_ARENA_SIZE) { /* arena overflow error */ mrb->arena_idx = MRB_ARENA_SIZE - 4; /* force room in arena */ mrb_raise(mrb, E_RUNTIME_ERROR, "arena overflow error"); From 81f96cb9af239d2bf3ff97bcc5f511dad1d51985 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 28 Feb 2013 15:20:46 +0000 Subject: [PATCH 09/13] Move Math::TOLERANCE to mruby-math --- mrbgems/mruby-math/test/math.rb | 249 +++++++++++++++++--------------- test/assert.rb | 3 +- 2 files changed, 131 insertions(+), 121 deletions(-) diff --git a/mrbgems/mruby-math/test/math.rb b/mrbgems/mruby-math/test/math.rb index 780b805d2..1cc3a20b0 100644 --- a/mrbgems/mruby-math/test/math.rb +++ b/mrbgems/mruby-math/test/math.rb @@ -1,125 +1,136 @@ ## # Math Test -if Object.const_defined?(:Math) - assert('Math.sin 0') do - check_float(Math.sin(0), 0) - end - - assert('Math.sin PI/2') do - check_float(Math.sin(Math::PI / 2), 1) - end - - assert('Fundamental trig identities') do - result = true - N = 13 - N.times do |i| - a = Math::PI / N * i - ca = Math::PI / 2 - a - s = Math.sin(a) - c = Math.cos(a) - t = Math.tan(a) - result &= check_float(s, Math.cos(ca)) - result &= check_float(t, 1 / Math.tan(ca)) - result &= check_float(s ** 2 + c ** 2, 1) - result &= check_float(t ** 2 + 1, (1/c) ** 2) - result &= check_float((1/t) ** 2 + 1, (1/s) ** 2) - end - result - end - - assert('Math.erf 0') do - check_float(Math.erf(0), 0) - end - - assert('Math.exp 0') do - check_float(Math.exp(0), 1.0) - end - - assert('Math.exp 1') do - check_float(Math.exp(1), 2.718281828459045) - end - - assert('Math.exp 1.5') do - check_float(Math.exp(1.5), 4.4816890703380645) - end - - assert('Math.log 1') do - check_float(Math.log(1), 0) - end - - assert('Math.log E') do - check_float(Math.log(Math::E), 1.0) - end - - assert('Math.log E**3') do - check_float(Math.log(Math::E**3), 3.0) - end - - assert('Math.log2 1') do - check_float(Math.log2(1), 0.0) - end - - assert('Math.log2 2') do - check_float(Math.log2(2), 1.0) - end - - assert('Math.log10 1') do - check_float(Math.log10(1), 0.0) - end - - assert('Math.log10 10') do - check_float(Math.log10(10), 1.0) - end - - assert('Math.log10 10**100') do - check_float(Math.log10(10**100), 100.0) - end - - assert('Math.sqrt') do - num = [0.0, 1.0, 2.0, 3.0, 4.0] - sqr = [0, 1, 4, 9, 16] - result = true - sqr.each_with_index do |v,i| - result &= check_float(Math.sqrt(v), num[i]) - end - result - end - - assert('Math.cbrt') do - num = [-2.0, -1.0, 0.0, 1.0, 2.0] - cub = [-8, -1, 0, 1, 8] - result = true - cub.each_with_index do |v,i| - result &= check_float(Math.cbrt(v), num[i]) - end - result - end - - assert('Math.hypot') do - check_float(Math.hypot(3, 4), 5.0) - end - - assert('Math.frexp 1234') do - n = 1234 - fraction, exponent = Math.frexp(n) - check_float(Math.ldexp(fraction, exponent), n) - end - - assert('Math.erf 1') do - check_float(Math.erf(1), 0.842700792949715) - end - - assert('Math.erfc 1') do - check_float(Math.erfc(1), 0.157299207050285) - end - - assert('Math.erf -1') do - check_float(Math.erf(-1), -0.8427007929497148) - end - - assert('Math.erfc -1') do - check_float(Math.erfc(-1), 1.8427007929497148) +## +# Performs fuzzy check for equality on methods returning floats +# on the basis of the Math::TOLERANCE constant. +def check_float(a, b) + tolerance = Math::TOLERANCE + a = a.to_f + b = b.to_f + if a.finite? and b.finite? + (a-b).abs < tolerance + else + true end end +assert('Math.sin 0') do + check_float(Math.sin(0), 0) +end + +assert('Math.sin PI/2') do + check_float(Math.sin(Math::PI / 2), 1) +end + +assert('Fundamental trig identities') do + result = true + N = 13 + N.times do |i| + a = Math::PI / N * i + ca = Math::PI / 2 - a + s = Math.sin(a) + c = Math.cos(a) + t = Math.tan(a) + result &= check_float(s, Math.cos(ca)) + result &= check_float(t, 1 / Math.tan(ca)) + result &= check_float(s ** 2 + c ** 2, 1) + result &= check_float(t ** 2 + 1, (1/c) ** 2) + result &= check_float((1/t) ** 2 + 1, (1/s) ** 2) + end + result +end + +assert('Math.erf 0') do + check_float(Math.erf(0), 0) +end + +assert('Math.exp 0') do + check_float(Math.exp(0), 1.0) +end + +assert('Math.exp 1') do + check_float(Math.exp(1), 2.718281828459045) +end + +assert('Math.exp 1.5') do + check_float(Math.exp(1.5), 4.4816890703380645) +end + +assert('Math.log 1') do + check_float(Math.log(1), 0) +end + +assert('Math.log E') do + check_float(Math.log(Math::E), 1.0) +end + +assert('Math.log E**3') do + check_float(Math.log(Math::E**3), 3.0) +end + +assert('Math.log2 1') do + check_float(Math.log2(1), 0.0) +end + +assert('Math.log2 2') do + check_float(Math.log2(2), 1.0) +end + +assert('Math.log10 1') do + check_float(Math.log10(1), 0.0) +end + +assert('Math.log10 10') do + check_float(Math.log10(10), 1.0) +end + +assert('Math.log10 10**100') do + check_float(Math.log10(10**100), 100.0) +end + +assert('Math.sqrt') do + num = [0.0, 1.0, 2.0, 3.0, 4.0] + sqr = [0, 1, 4, 9, 16] + result = true + sqr.each_with_index do |v,i| + result &= check_float(Math.sqrt(v), num[i]) + end + result +end + +assert('Math.cbrt') do + num = [-2.0, -1.0, 0.0, 1.0, 2.0] + cub = [-8, -1, 0, 1, 8] + result = true + cub.each_with_index do |v,i| + result &= check_float(Math.cbrt(v), num[i]) + end + result +end + +assert('Math.hypot') do + check_float(Math.hypot(3, 4), 5.0) +end + +assert('Math.frexp 1234') do + n = 1234 + fraction, exponent = Math.frexp(n) + check_float(Math.ldexp(fraction, exponent), n) +end + +assert('Math.erf 1') do + check_float(Math.erf(1), 0.842700792949715) +end + +assert('Math.erfc 1') do + check_float(Math.erfc(1), 0.157299207050285) +end + +assert('Math.erf -1') do + check_float(Math.erf(-1), -0.8427007929497148) +end + +assert('Math.erfc -1') do + check_float(Math.erfc(-1), 1.8427007929497148) +end diff --git a/test/assert.rb b/test/assert.rb index 269c435a7..86e99db5c 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -151,9 +151,8 @@ end ## # Performs fuzzy check for equality on methods returning floats -# on the basis of the Math::TOLERANCE constant. def check_float(a, b) - tolerance = Math::TOLERANCE + tolerance = 1e-12 a = a.to_f b = b.to_f if a.finite? and b.finite? From f6c9e40d48db5ae667451687c8b2ad36bd184ac2 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 1 Mar 2013 00:34:05 +0800 Subject: [PATCH 10/13] Modification of CONTRIBUTING.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some minor fixes of the  CONTRIBUTING.md file. --- CONTRIBUTING.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 08995978f..99bd55962 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # How to contribute -mruby is an open-source project which is looking forward to each contribution. +mruby is an open-source project which is looking forward to each contribution. ## Your Pull Request @@ -8,10 +8,10 @@ To make it easy to review and understand your change please keep the following things in mind before submitting your pull request: * Work on the latest possible state of **mruby/master** -* Test your changes before creating a pull request (**make test**) +* Create a branch which is dedicated to your change +* Test your changes before creating a pull request (```./minirake test```) * If possible write a test case which confirms your change * Don't mix several features or bug-fixes in one pull request -* Create a branch which is dedicated to your change * Create a meaningful commit message * Explain your change (i.e. with a link to the issue you are fixing) @@ -27,16 +27,16 @@ C code: #### Comply with C99 (ISO/IEC 9899:1999) -mruby should be highly portable to other systems and compilers. For that it is +mruby should be highly portable to other systems and compilers. For this it is recommended to keep your code as close as possible to the C99 standard (http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf). -Although we target C99, VC is also an important target for mruby, so that we -avoid local variable declaration in the middle. +Although we target C99, Visual C++ is also an important target for mruby, so +you should local variable declarations in the middle. #### Reduce library dependencies to a minimum -The dependencies to libraries should be put to an absolute minimum. This +The dependencies to libraries should be kept to an absolute minimum. This increases the portability but makes it also easier to cut away parts of mruby on-demand. @@ -56,7 +56,7 @@ Use C++ style comments only for temporary comment e.g. commenting out some code ### Ruby code -Parts of the standard library of mruby is written in the Ruby programming language +Parts of the standard library of mruby are written in the Ruby programming language itself. Please note the following hints for your Ruby code: #### Comply with the Ruby standard (ISO/IEC 30170:2012) From cdc1c5b5d0ce02c3490a98b89fb5c4cfa44fd30f Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 1 Mar 2013 01:19:10 +0800 Subject: [PATCH 11/13] Fix styleguide based on @cremno's input --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 99bd55962..b8db5a7dc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,8 +31,8 @@ mruby should be highly portable to other systems and compilers. For this it is recommended to keep your code as close as possible to the C99 standard (http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf). -Although we target C99, Visual C++ is also an important target for mruby, so -you should local variable declarations in the middle. +Although we target C99, Visual C++ is also an important target for mruby. For this +reason a declaration of a local variable has to be at the beginning of a scope block. #### Reduce library dependencies to a minimum From e66de39a02433933c0966c91864650220c6f80d5 Mon Sep 17 00:00:00 2001 From: MATSUMOTO Ryosuke Date: Thu, 28 Feb 2013 15:24:36 -0800 Subject: [PATCH 12/13] Adjust space --- src/class.c | 77 +++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/src/class.c b/src/class.c index e70bd7e73..c2def3e8c 100644 --- a/src/class.c +++ b/src/class.c @@ -1777,9 +1777,9 @@ mrb_init_class(mrb_state *mrb) /* name basic classes */ mrb_define_const(mrb, bob, "BasicObject", mrb_obj_value(bob)); mrb_define_const(mrb, obj, "BasicObject", mrb_obj_value(bob)); - mrb_define_const(mrb, obj, "Object", mrb_obj_value(obj)); - mrb_define_const(mrb, obj, "Module", mrb_obj_value(mod)); - mrb_define_const(mrb, obj, "Class", mrb_obj_value(cls)); + mrb_define_const(mrb, obj, "Object", mrb_obj_value(obj)); + mrb_define_const(mrb, obj, "Module", mrb_obj_value(mod)); + mrb_define_const(mrb, obj, "Class", mrb_obj_value(cls)); /* name each classes */ mrb_name_class(mrb, bob, mrb_intern(mrb, "BasicObject")); @@ -1789,43 +1789,44 @@ mrb_init_class(mrb_state *mrb) mrb_undef_method(mrb, mod, "new"); MRB_SET_INSTANCE_TT(cls, MRB_TT_CLASS); - mrb_define_method(mrb, bob, "initialize", mrb_bob_init, ARGS_NONE()); - mrb_define_method(mrb, bob, "!", mrb_bob_not, ARGS_NONE()); - mrb_define_method(mrb, bob, "method_missing", mrb_bob_missing, ARGS_ANY()); /* 15.3.1.3.30 */ - mrb_define_class_method(mrb, cls, "new", mrb_class_new_class, ARGS_ANY()); - mrb_define_method(mrb, cls, "superclass", mrb_class_superclass, ARGS_NONE()); /* 15.2.3.3.4 */ - mrb_define_method(mrb, cls, "new", mrb_instance_new, ARGS_ANY()); /* 15.2.3.3.3 */ - mrb_define_method(mrb, cls, "inherited", mrb_bob_init, ARGS_REQ(1)); - mrb_define_method(mrb, mod, "class_variable_defined?", mrb_mod_cvar_defined, ARGS_REQ(1)); /* 15.2.2.4.16 */ - mrb_define_method(mrb, mod, "class_variable_get", mrb_mod_cvar_get, ARGS_REQ(1)); /* 15.2.2.4.17 */ - mrb_define_method(mrb, mod, "class_variable_set", mrb_mod_cvar_set, ARGS_REQ(2)); /* 15.2.2.4.18 */ - mrb_define_method(mrb, mod, "extend_object", mrb_mod_extend_object, ARGS_REQ(1)); /* 15.2.2.4.25 */ - mrb_define_method(mrb, mod, "extended", mrb_bob_init, ARGS_REQ(1)); /* 15.2.2.4.26 */ - mrb_define_method(mrb, mod, "include", mrb_mod_include, ARGS_ANY()); /* 15.2.2.4.27 */ - mrb_define_method(mrb, mod, "include?", mrb_mod_include_p, ARGS_REQ(1)); /* 15.2.2.4.28 */ - mrb_define_method(mrb, mod, "append_features", mrb_mod_append_features, ARGS_REQ(1)); /* 15.2.2.4.10 */ - mrb_define_method(mrb, mod, "class_eval", mrb_mod_module_eval, ARGS_ANY()); /* 15.2.2.4.15 */ - mrb_define_method(mrb, mod, "included", mrb_bob_init, ARGS_REQ(1)); /* 15.2.2.4.29 */ - mrb_define_method(mrb, mod, "included_modules", mrb_mod_included_modules, ARGS_NONE()); /* 15.2.2.4.30 */ - mrb_define_method(mrb, mod, "instance_methods", mrb_mod_instance_methods, ARGS_ANY()); /* 15.2.2.4.33 */ - mrb_define_method(mrb, mod, "method_defined?", mrb_mod_method_defined, ARGS_REQ(1)); /* 15.2.2.4.34 */ - mrb_define_method(mrb, mod, "module_eval", mrb_mod_module_eval, ARGS_ANY()); /* 15.2.2.4.35 */ - mrb_define_method(mrb, mod, "remove_class_variable", mrb_mod_remove_cvar, ARGS_REQ(1)); /* 15.2.2.4.39 */ - mrb_define_method(mrb, mod, "remove_method", mrb_mod_remove_method, ARGS_ANY()); /* 15.2.2.4.41 */ + mrb_define_method(mrb, bob, "initialize", mrb_bob_init, ARGS_NONE()); + mrb_define_method(mrb, bob, "!", mrb_bob_not, ARGS_NONE()); + mrb_define_method(mrb, bob, "method_missing", mrb_bob_missing, ARGS_ANY()); /* 15.3.1.3.30 */ - mrb_define_method(mrb, mod, "to_s", mrb_mod_to_s, ARGS_NONE()); - mrb_define_method(mrb, mod, "inspect", mrb_mod_to_s, ARGS_NONE()); - mrb_define_method(mrb, mod, "alias_method", mrb_mod_alias, ARGS_ANY()); /* 15.2.2.4.8 */ - mrb_define_method(mrb, mod, "ancestors", mrb_mod_ancestors, ARGS_NONE()); /* 15.2.2.4.9 */ - mrb_define_method(mrb, mod, "undef_method", mrb_mod_undef, ARGS_ANY()); /* 15.2.2.4.41 */ - mrb_define_method(mrb, mod, "const_defined?", mrb_mod_const_defined, ARGS_REQ(1)); /* 15.2.2.4.20 */ - mrb_define_method(mrb, mod, "const_get", mrb_mod_const_get, ARGS_REQ(1)); /* 15.2.2.4.21 */ - mrb_define_method(mrb, mod, "const_set", mrb_mod_const_set, ARGS_REQ(2)); /* 15.2.2.4.23 */ - mrb_define_method(mrb, mod, "remove_const", mrb_mod_remove_const, ARGS_REQ(1)); /* 15.2.2.4.40 */ - mrb_define_method(mrb, mod, "define_method", mod_define_method, ARGS_REQ(1)); - mrb_define_method(mrb, mod, "class_variables", mrb_mod_class_variables, ARGS_NONE()); /* 15.2.2.4.19 */ + mrb_define_class_method(mrb, cls, "new", mrb_class_new_class, ARGS_ANY()); + mrb_define_method(mrb, cls, "superclass", mrb_class_superclass, ARGS_NONE()); /* 15.2.3.3.4 */ + mrb_define_method(mrb, cls, "new", mrb_instance_new, ARGS_ANY()); /* 15.2.3.3.3 */ + mrb_define_method(mrb, cls, "inherited", mrb_bob_init, ARGS_REQ(1)); + + mrb_define_method(mrb, mod, "class_variable_defined?", mrb_mod_cvar_defined, ARGS_REQ(1)); /* 15.2.2.4.16 */ + mrb_define_method(mrb, mod, "class_variable_get", mrb_mod_cvar_get, ARGS_REQ(1)); /* 15.2.2.4.17 */ + mrb_define_method(mrb, mod, "class_variable_set", mrb_mod_cvar_set, ARGS_REQ(2)); /* 15.2.2.4.18 */ + mrb_define_method(mrb, mod, "extend_object", mrb_mod_extend_object, ARGS_REQ(1)); /* 15.2.2.4.25 */ + mrb_define_method(mrb, mod, "extended", mrb_bob_init, ARGS_REQ(1)); /* 15.2.2.4.26 */ + mrb_define_method(mrb, mod, "include", mrb_mod_include, ARGS_ANY()); /* 15.2.2.4.27 */ + mrb_define_method(mrb, mod, "include?", mrb_mod_include_p, ARGS_REQ(1)); /* 15.2.2.4.28 */ + mrb_define_method(mrb, mod, "append_features", mrb_mod_append_features, ARGS_REQ(1)); /* 15.2.2.4.10 */ + mrb_define_method(mrb, mod, "class_eval", mrb_mod_module_eval, ARGS_ANY()); /* 15.2.2.4.15 */ + mrb_define_method(mrb, mod, "included", mrb_bob_init, ARGS_REQ(1)); /* 15.2.2.4.29 */ + mrb_define_method(mrb, mod, "included_modules", mrb_mod_included_modules, ARGS_NONE()); /* 15.2.2.4.30 */ + mrb_define_method(mrb, mod, "instance_methods", mrb_mod_instance_methods, ARGS_ANY()); /* 15.2.2.4.33 */ + mrb_define_method(mrb, mod, "method_defined?", mrb_mod_method_defined, ARGS_REQ(1)); /* 15.2.2.4.34 */ + mrb_define_method(mrb, mod, "module_eval", mrb_mod_module_eval, ARGS_ANY()); /* 15.2.2.4.35 */ + mrb_define_method(mrb, mod, "remove_class_variable", mrb_mod_remove_cvar, ARGS_REQ(1)); /* 15.2.2.4.39 */ + mrb_define_method(mrb, mod, "remove_method", mrb_mod_remove_method, ARGS_ANY()); /* 15.2.2.4.41 */ + mrb_define_method(mrb, mod, "to_s", mrb_mod_to_s, ARGS_NONE()); + mrb_define_method(mrb, mod, "inspect", mrb_mod_to_s, ARGS_NONE()); + mrb_define_method(mrb, mod, "alias_method", mrb_mod_alias, ARGS_ANY()); /* 15.2.2.4.8 */ + mrb_define_method(mrb, mod, "ancestors", mrb_mod_ancestors, ARGS_NONE()); /* 15.2.2.4.9 */ + mrb_define_method(mrb, mod, "undef_method", mrb_mod_undef, ARGS_ANY()); /* 15.2.2.4.41 */ + mrb_define_method(mrb, mod, "const_defined?", mrb_mod_const_defined, ARGS_REQ(1)); /* 15.2.2.4.20 */ + mrb_define_method(mrb, mod, "const_get", mrb_mod_const_get, ARGS_REQ(1)); /* 15.2.2.4.21 */ + mrb_define_method(mrb, mod, "const_set", mrb_mod_const_set, ARGS_REQ(2)); /* 15.2.2.4.23 */ + mrb_define_method(mrb, mod, "remove_const", mrb_mod_remove_const, ARGS_REQ(1)); /* 15.2.2.4.40 */ + mrb_define_method(mrb, mod, "define_method", mod_define_method, ARGS_REQ(1)); + mrb_define_method(mrb, mod, "class_variables", mrb_mod_class_variables, ARGS_NONE()); /* 15.2.2.4.19 */ + mrb_define_method(mrb, mod, "===", mrb_mod_eqq, ARGS_REQ(1)); - mrb_define_method(mrb, mod, "===", mrb_mod_eqq, ARGS_REQ(1)); mrb_undef_method(mrb, cls, "append_features"); mrb_undef_method(mrb, cls, "extend_object"); } From 138ecf4723078cf8ef4342fb3995db23003eff01 Mon Sep 17 00:00:00 2001 From: mattn Date: Fri, 1 Mar 2013 13:37:46 +0900 Subject: [PATCH 13/13] Pluggable Struct --- include/mrbconf.h | 4 --- include/mruby/struct.h | 27 ------------------- include/mruby/value.h | 22 +++++++-------- mrbgems/mruby-struct/mrbgem.rake | 4 +++ {src => mrbgems/mruby-struct/src}/struct.c | 18 ++++++++----- .../t => mrbgems/mruby-struct/test}/struct.rb | 0 src/etc.c | 1 - src/gc.c | 3 --- src/init.c | 4 --- src/object.c | 1 - 10 files changed, 25 insertions(+), 59 deletions(-) delete mode 100644 include/mruby/struct.h create mode 100644 mrbgems/mruby-struct/mrbgem.rake rename {src => mrbgems/mruby-struct/src}/struct.c (98%) rename {test/t => mrbgems/mruby-struct/test}/struct.rb (100%) diff --git a/include/mrbconf.h b/include/mrbconf.h index 45e3d6034..c84480af7 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -45,7 +45,6 @@ /* -DDISABLE_XXXX to drop following features */ //#define DISABLE_SPRINTF /* Kernel.sprintf method */ -//#define DISABLE_STRUCT /* Struct class */ //#define DISABLE_STDIO /* use of stdio */ /* -DENABLE_XXXX to enable following features */ @@ -84,9 +83,6 @@ typedef short mrb_sym; #ifndef DISABLE_SPRINTF #define ENABLE_SPRINTF #endif -#ifndef DISABLE_STRUCT -#define ENABLE_STRUCT -#endif #ifndef DISABLE_STDIO #define ENABLE_STDIO #endif diff --git a/include/mruby/struct.h b/include/mruby/struct.h deleted file mode 100644 index cfe6df135..000000000 --- a/include/mruby/struct.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -** mruby/struct.h - Struct class -** -** See Copyright Notice in mruby.h -*/ - -#ifndef MRUBY_STRUCT_H -#define MRUBY_STRUCT_H - -#if defined(__cplusplus) -extern "C" { -#endif - -struct RStruct { - struct RBasic basic; - long len; - mrb_value *ptr; -}; -#define RSTRUCT(st) ((struct RStruct*)((st).value.p)) -#define RSTRUCT_LEN(st) ((int)(RSTRUCT(st)->len)) -#define RSTRUCT_PTR(st) (RSTRUCT(st)->ptr) - -#if defined(__cplusplus) -} /* extern "C" { */ -#endif - -#endif /* MRUBY_STRUCT_H */ diff --git a/include/mruby/value.h b/include/mruby/value.h index 17f51db94..1dfa7b975 100644 --- a/include/mruby/value.h +++ b/include/mruby/value.h @@ -29,12 +29,11 @@ enum mrb_vtype { MRB_TT_HASH, /* 16 */ MRB_TT_STRING, /* 17 */ MRB_TT_RANGE, /* 18 */ - MRB_TT_STRUCT, /* 19 */ - MRB_TT_EXCEPTION, /* 20 */ - MRB_TT_FILE, /* 21 */ - MRB_TT_ENV, /* 22 */ - MRB_TT_DATA, /* 23 */ - MRB_TT_MAXDEFINE /* 24 */ + MRB_TT_EXCEPTION, /* 19 */ + MRB_TT_FILE, /* 20 */ + MRB_TT_ENV, /* 21 */ + MRB_TT_DATA, /* 22 */ + MRB_TT_MAXDEFINE /* 23 */ }; typedef struct mrb_value { @@ -89,12 +88,11 @@ enum mrb_vtype { MRB_TT_HASH, /* 17 */ MRB_TT_STRING, /* 18 */ MRB_TT_RANGE, /* 19 */ - MRB_TT_STRUCT, /* 20 */ - MRB_TT_EXCEPTION, /* 21 */ - MRB_TT_FILE, /* 22 */ - MRB_TT_ENV, /* 23 */ - MRB_TT_DATA, /* 24 */ - MRB_TT_MAXDEFINE /* 25 */ + MRB_TT_EXCEPTION, /* 20 */ + MRB_TT_FILE, /* 21 */ + MRB_TT_ENV, /* 22 */ + MRB_TT_DATA, /* 23 */ + MRB_TT_MAXDEFINE /* 24 */ }; #ifdef MRB_ENDIAN_BIG diff --git a/mrbgems/mruby-struct/mrbgem.rake b/mrbgems/mruby-struct/mrbgem.rake new file mode 100644 index 000000000..476e990da --- /dev/null +++ b/mrbgems/mruby-struct/mrbgem.rake @@ -0,0 +1,4 @@ +MRuby::Gem::Specification.new('mruby-struct') do |spec| + spec.license = 'MIT' + spec.authors = 'mruby developers' +end diff --git a/src/struct.c b/mrbgems/mruby-struct/src/struct.c similarity index 98% rename from src/struct.c rename to mrbgems/mruby-struct/src/struct.c index d7b63259e..131702e9c 100644 --- a/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -4,18 +4,23 @@ ** See Copyright Notice in mruby.h */ -#include "mruby.h" -#ifdef ENABLE_STRUCT #include -#include "error.h" -#include "mruby/struct.h" -#include "mruby/array.h" #include - +#include "mruby.h" +#include "mruby/array.h" #include "mruby/string.h" #include "mruby/class.h" #include "mruby/variable.h" +struct RStruct { + struct RBasic basic; + long len; + mrb_value *ptr; +}; + +#define RSTRUCT(st) ((struct RStruct*)((st).value.p)) +#define RSTRUCT_LEN(st) ((int)(RSTRUCT(st)->len)) +#define RSTRUCT_PTR(st) (RSTRUCT(st)->ptr) static struct RClass * struct_class(mrb_state *mrb) @@ -778,4 +783,3 @@ mrb_init_struct(mrb_state *mrb) mrb_define_method(mrb, st, "eql?", mrb_struct_eql, ARGS_REQ(1)); /* 15.2.18.4.12(x) */ } -#endif /* ENABLE_STRUCT */ diff --git a/test/t/struct.rb b/mrbgems/mruby-struct/test/struct.rb similarity index 100% rename from test/t/struct.rb rename to mrbgems/mruby-struct/test/struct.rb diff --git a/src/etc.c b/src/etc.c index 6a43ddd31..644465c80 100644 --- a/src/etc.c +++ b/src/etc.c @@ -170,7 +170,6 @@ mrb_obj_id(mrb_value obj) case MRB_TT_ARRAY: case MRB_TT_HASH: case MRB_TT_RANGE: - case MRB_TT_STRUCT: case MRB_TT_EXCEPTION: case MRB_TT_FILE: case MRB_TT_DATA: diff --git a/src/gc.c b/src/gc.c index 5cc794fd9..c48e6949a 100644 --- a/src/gc.c +++ b/src/gc.c @@ -86,9 +86,6 @@ typedef struct { struct RArray array; struct RHash hash; struct RRange range; -#ifdef ENABLE_STRUCT - struct RStruct strct; -#endif struct RData data; struct RProc proc; } as; diff --git a/src/init.c b/src/init.c index fa2d5d305..0d1a24881 100644 --- a/src/init.c +++ b/src/init.c @@ -20,7 +20,6 @@ void mrb_init_array(mrb_state*); void mrb_init_hash(mrb_state*); void mrb_init_numeric(mrb_state*); void mrb_init_range(mrb_state*); -void mrb_init_struct(mrb_state*); void mrb_init_gc(mrb_state*); void mrb_init_print(mrb_state*); void mrb_init_math(mrb_state*); @@ -48,9 +47,6 @@ mrb_init_core(mrb_state *mrb) mrb_init_hash(mrb); DONE; mrb_init_numeric(mrb); DONE; mrb_init_range(mrb); DONE; -#ifdef ENABLE_STRUCT - mrb_init_struct(mrb); DONE; -#endif mrb_init_gc(mrb); DONE; #ifdef ENABLE_STDIO mrb_init_print(mrb); DONE; diff --git a/src/object.c b/src/object.c index e087c35c0..6707fc6e4 100644 --- a/src/object.c +++ b/src/object.c @@ -379,7 +379,6 @@ static const struct types { {MRB_TT_HASH, "Hash"}, {MRB_TT_STRING, "String"}, {MRB_TT_RANGE, "Range"}, - {MRB_TT_STRUCT, "Struct"}, // {MRB_TT_BIGNUM, "Bignum"}, {MRB_TT_FILE, "File"}, {MRB_TT_DATA, "Data"}, /* internal use: wrapped C pointers */