mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge branch 'master' into pluggable_struct
This commit is contained in:
+8
-8
@@ -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
|
||||
|
||||
+4
-1
@@ -11,8 +11,11 @@ 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 '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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 */
|
||||
+10
-12
@@ -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
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
MRuby::Gem::Specification.new('mruby-math') do |spec|
|
||||
spec.license = 'MIT'
|
||||
spec.authors = 'mruby developers'
|
||||
end
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,4 @@
|
||||
MRuby::Gem::Specification.new('mruby-struct') do |spec|
|
||||
spec.license = 'MIT'
|
||||
spec.authors = 'mruby developers'
|
||||
end
|
||||
@@ -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 */
|
||||
@@ -1,4 +1,4 @@
|
||||
MRuby::Gem::Specification.new('mruby-time') do |spec|
|
||||
spec.license = 'MIT'
|
||||
spec.authors = 'mruby team'
|
||||
spec.authors = 'mruby developers'
|
||||
end
|
||||
+39
-38
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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,16 +47,9 @@ 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
|
||||
|
||||
@@ -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 */
|
||||
|
||||
+1
-1
@@ -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':
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);]
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
+1
-2
@@ -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?
|
||||
|
||||
-125
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user