diff options
| -rw-r--r-- | CONTRIBUTING.md | 16 | ||||
| -rw-r--r-- | Rakefile | 7 | ||||
| -rw-r--r-- | build_config.rb | 5 | ||||
| -rw-r--r-- | include/mrbconf.h | 8 | ||||
| -rw-r--r-- | include/mruby/struct.h | 27 | ||||
| -rw-r--r-- | include/mruby/value.h | 22 | ||||
| -rw-r--r-- | mrbgems/mruby-math/mrbgem.rake | 4 | ||||
| -rw-r--r-- | mrbgems/mruby-math/src/math.c (renamed from src/math.c) | 9 | ||||
| -rw-r--r-- | mrbgems/mruby-math/test/math.rb | 136 | ||||
| -rw-r--r-- | mrbgems/mruby-struct/mrbgem.rake | 4 | ||||
| -rw-r--r-- | mrbgems/mruby-struct/src/struct.c (renamed from src/struct.c) | 18 | ||||
| -rw-r--r-- | mrbgems/mruby-struct/test/struct.rb (renamed from test/t/struct.rb) | 0 | ||||
| -rw-r--r-- | mrbgems/mruby-time/mrbgem.rake (renamed from mgems/mruby-time/mrbgem.rake) | 2 | ||||
| -rw-r--r-- | mrbgems/mruby-time/src/time.c (renamed from mgems/mruby-time/src/time.c) | 0 | ||||
| -rw-r--r-- | mrbgems/mruby-time/test/time.rb (renamed from mgems/mruby-time/test/time.rb) | 0 | ||||
| -rw-r--r-- | src/class.c | 81 | ||||
| -rw-r--r-- | src/etc.c | 1 | ||||
| -rw-r--r-- | src/gc.c | 2 | ||||
| -rw-r--r-- | src/init.c | 9 | ||||
| -rw-r--r-- | src/object.c | 1 | ||||
| -rw-r--r-- | src/parse.y | 2 | ||||
| -rw-r--r-- | src/re.c | 42 | ||||
| -rw-r--r-- | tasks/mrbgems_test.rake | 6 | ||||
| -rw-r--r-- | tasks/mruby_build.rake | 2 | ||||
| -rw-r--r-- | test/assert.rb | 3 | ||||
| -rw-r--r-- | test/t/math.rb | 125 |
26 files changed, 237 insertions, 295 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 08995978f..b8db5a7dc 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. 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 -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) @@ -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/build_config.rb b/build_config.rb index a66dab6ac..c0a6eacc6 100644 --- a/build_config.rb +++ b/build_config.rb @@ -11,8 +11,11 @@ MRuby::Build.new do |conf| # conf.gem :github => 'masuidrive/mrbgems-example', :branch => 'master' # conf.gem :git => '[email protected]:masuidrive/mrbgems-example.git', :branch => 'master', :options => '-v' + # Use standard Math module + conf.gem 'mrbgems/mruby-math' + # 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/include/mrbconf.h b/include/mrbconf.h index 092e02d11..c84480af7 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -45,8 +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 */ /* -DENABLE_XXXX to enable following features */ @@ -85,12 +83,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 #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-math/mrbgem.rake b/mrbgems/mruby-math/mrbgem.rake new file mode 100644 index 000000000..4b0fa40fd --- /dev/null +++ b/mrbgems/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/mrbgems/mruby-math/src/math.c index 782b75c97..9955d9862 100644 --- a/src/math.c +++ b/mrbgems/mruby-math/src/math.c @@ -7,7 +7,6 @@ #include "mruby.h" #include "mruby/array.h" -#ifdef ENABLE_MATH #include <math.h> #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/mrbgems/mruby-math/test/math.rb b/mrbgems/mruby-math/test/math.rb new file mode 100644 index 000000000..1cc3a20b0 --- /dev/null +++ b/mrbgems/mruby-math/test/math.rb @@ -0,0 +1,136 @@ +## +# Math Test + +## +# 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/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 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 <string.h> -#include "error.h" -#include "mruby/struct.h" -#include "mruby/array.h" #include <stdarg.h> - +#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 index d79b30c0e..d79b30c0e 100644 --- a/test/t/struct.rb +++ b/mrbgems/mruby-struct/test/struct.rb diff --git a/mgems/mruby-time/mrbgem.rake b/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 index ed40c5279..ed40c5279 100644 --- a/mgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c diff --git a/mgems/mruby-time/test/time.rb b/mrbgems/mruby-time/test/time.rb index f92459d5e..f92459d5e 100644 --- a/mgems/mruby-time/test/time.rb +++ b/mrbgems/mruby-time/test/time.rb 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, 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, 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, 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_undef_method(mrb, cls, "append_features"); mrb_undef_method(mrb, cls, "extend_object"); } @@ -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: @@ -310,7 +310,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"); diff --git a/src/init.c b/src/init.c index a5727561d..0d1a24881 100644 --- a/src/init.c +++ b/src/init.c @@ -20,9 +20,7 @@ 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_regexp(mrb_state*); void mrb_init_print(mrb_state*); void mrb_init_math(mrb_state*); void mrb_init_mrblib(mrb_state*); @@ -49,17 +47,10 @@ 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; - 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 mrb_init_mrbgems(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 */ 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': 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 <string.h> -#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("?") - * - * <em>raises the exception:</em> - * - * RegexpError: target of repeat operator is not specified: /?/ - */ - -/* - * Document-class: Regexp - * - * A <code>Regexp</code> holds a regular expression, used to match a pattern - * against strings. Regexps are created using the <code>/.../</code> and - * <code>%r{...}</code> literals, and by the <code>Regexp::new</code> - * constructor. - * - * :include: doc/re.rdoc - */ - -void -mrb_init_regexp(mrb_state *mrb) -{ - //mrb_define_class(mrb, REGEXP_CLASS, mrb->object_class); -} 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);] 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 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? diff --git a/test/t/math.rb b/test/t/math.rb deleted file mode 100644 index 780b805d2..000000000 --- a/test/t/math.rb +++ /dev/null @@ -1,125 +0,0 @@ -## -# 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) - end -end - |
