summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--build_config/cross-mingw.rb14
-rw-r--r--lib/mruby/build.rb3
-rw-r--r--lib/mruby/build/command.rb6
-rw-r--r--mrbgems/mruby-compiler/core/codegen.c14
-rw-r--r--mrbgems/mruby-complex/mrbgem.rake2
-rw-r--r--mrbgems/mruby-complex/mrblib/complex.rb8
-rw-r--r--mrbgems/mruby-complex/src/complex.c35
-rw-r--r--mrbgems/mruby-os-memsize/src/memsize.c19
-rw-r--r--mrbgems/mruby-rational/mrbgem.rake2
-rw-r--r--mrbgems/mruby-rational/src/rational.c3
-rw-r--r--tasks/mrbgems.rake2
11 files changed, 84 insertions, 24 deletions
diff --git a/build_config/cross-mingw.rb b/build_config/cross-mingw.rb
new file mode 100644
index 000000000..63d267d6a
--- /dev/null
+++ b/build_config/cross-mingw.rb
@@ -0,0 +1,14 @@
+#
+# Ubuntu 20.04 requires at least `gcc-mingw-w64-x86-64` package as a
+# cross compiler.
+#
+
+MRuby::CrossBuild.new("cross-mingw") do |conf|
+ conf.toolchain :gcc
+ conf.host_target = "x86_64-w64-mingw32" # required for `for_windows?` used by `mruby-socket` gem
+ conf.cc.command = "#{conf.host_target}-gcc-posix"
+ conf.linker.command = conf.cc.command
+ conf.archiver.command = "#{conf.host_target}-gcc-ar"
+ conf.exts.executable = ".exe"
+ conf.gembox "default"
+end
diff --git a/lib/mruby/build.rb b/lib/mruby/build.rb
index a99c0f507..f82eb9401 100644
--- a/lib/mruby/build.rb
+++ b/lib/mruby/build.rb
@@ -71,7 +71,7 @@ module MRuby
include Rake::DSL
include LoadGems
- attr_accessor :name, :bins, :exts, :file_separator, :build_dir, :gem_clone_dir
+ attr_accessor :name, :bins, :exts, :file_separator, :build_dir, :gem_clone_dir, :defines
attr_reader :products, :libmruby_core_objs, :libmruby_objs, :gems, :toolchains, :presym, :mrbc_build, :gem_dir_to_repo_url
alias libmruby libmruby_objs
@@ -97,6 +97,7 @@ module MRuby
@file_separator = '/'
@build_dir = "#{build_dir}/#{@name}"
@gem_clone_dir = "#{build_dir}/repos/#{@name}"
+ @defines = []
@cc = Command::Compiler.new(self, %w(.c), label: "CC")
@cxx = Command::Compiler.new(self, %w(.cc .cxx .cpp), label: "CXX")
@objc = Command::Compiler.new(self, %w(.m), label: "OBJC")
diff --git a/lib/mruby/build/command.rb b/lib/mruby/build/command.rb
index dbe3763d9..c93d08ea7 100644
--- a/lib/mruby/build/command.rb
+++ b/lib/mruby/build/command.rb
@@ -51,7 +51,7 @@ module MRuby
@flags = [ENV['CFLAGS'] || []]
@source_exts = source_exts
@include_paths = ["#{MRUBY_ROOT}/include"]
- @defines = %w()
+ @defines = []
@option_include_path = %q[-I"%s"]
@option_define = %q[-D"%s"]
@compile_options = %q[%{flags} -o "%{outfile}" -c "%{infile}"]
@@ -77,7 +77,7 @@ module MRuby
end
def all_flags(_defines=[], _include_paths=[], _flags=[])
- define_flags = [defines, _defines].flatten.map{ |d| option_define % d }
+ define_flags = [defines, _defines, build.defines].flatten.map{ |d| option_define % d }
include_path_flags = [include_paths, _include_paths].flatten.map do |f|
option_include_path % filename(f)
end
@@ -277,7 +277,7 @@ module MRuby
def initialize(build)
super
@command = 'git'
- @flags = %w[]
+ @flags = []
@clone_options = "clone %{flags} %{url} %{dir}"
@pull_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} pull"
@checkout_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} checkout %{checksum_hash}"
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index dc5b37260..857496f00 100644
--- a/mrbgems/mruby-compiler/core/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
@@ -592,7 +592,8 @@ pop_n_(codegen_scope *s, int n)
static int
new_litbn(codegen_scope *s, const char *p, int base, mrb_bool neg)
{
- int i, plen;
+ int i;
+ size_t plen;
mrb_pool_value *pv;
plen = strlen(p);
@@ -604,7 +605,7 @@ new_litbn(codegen_scope *s, const char *p, int base, mrb_bool neg)
pv = &s->pool[i];
if (pv->tt != IREP_TT_BIGINT) continue;
len = pv->u.str[0];
- if (len == strlen(p) && pv->u.str[1] == base && memcmp(pv->u.str+2, p, len) == 0)
+ if (len == plen && pv->u.str[1] == base && memcmp(pv->u.str+2, p, len) == 0)
return i;
}
@@ -617,14 +618,13 @@ new_litbn(codegen_scope *s, const char *p, int base, mrb_bool neg)
i = s->irep->plen++;
{
char *buf;
- mrb_int len = strlen(p);
pv->tt = IREP_TT_BIGINT;
- buf = (char*)codegen_realloc(s, NULL, len+3);
- buf[0] = len;
+ buf = (char*)codegen_realloc(s, NULL, plen+3);
+ buf[0] = (char)plen;
buf[1] = base;
if (neg) buf[1] = 0x80;
- memcpy(buf+2, p, len);
- buf[len+2] = '\0';
+ memcpy(buf+2, p, plen);
+ buf[plen+2] = '\0';
pv->u.str = buf;
}
return i;
diff --git a/mrbgems/mruby-complex/mrbgem.rake b/mrbgems/mruby-complex/mrbgem.rake
index 6c4b629ca..cd81ecd02 100644
--- a/mrbgems/mruby-complex/mrbgem.rake
+++ b/mrbgems/mruby-complex/mrbgem.rake
@@ -2,6 +2,6 @@ MRuby::Gem::Specification.new('mruby-complex') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'Complex class'
- spec.build.cc.defines << "MRB_USE_COMPLEX"
+ spec.build.defines << "MRB_USE_COMPLEX"
spec.add_dependency 'mruby-math', core: 'mruby-math'
end
diff --git a/mrbgems/mruby-complex/mrblib/complex.rb b/mrbgems/mruby-complex/mrblib/complex.rb
index 0b5fc8f73..1484ff394 100644
--- a/mrbgems/mruby-complex/mrblib/complex.rb
+++ b/mrbgems/mruby-complex/mrblib/complex.rb
@@ -52,14 +52,6 @@ class Complex < Numeric
end
alias_method :quo, :/
- def ==(rhs)
- if rhs.is_a? Complex
- real == rhs.real && imaginary == rhs.imaginary
- elsif rhs.is_a? Numeric
- imaginary == 0 && real == rhs
- end
- end
-
def abs
Math.hypot imaginary, real
end
diff --git a/mrbgems/mruby-complex/src/complex.c b/mrbgems/mruby-complex/src/complex.c
index 8960c0573..67ab9c33d 100644
--- a/mrbgems/mruby-complex/src/complex.c
+++ b/mrbgems/mruby-complex/src/complex.c
@@ -137,6 +137,40 @@ complex_to_c(mrb_state *mrb, mrb_value self)
return self;
}
+mrb_bool
+mrb_complex_eq(mrb_state *mrb, mrb_value x, mrb_value y)
+{
+ struct mrb_complex *p1 = complex_ptr(mrb, x);
+
+ switch (mrb_type(y)) {
+ case MRB_TT_COMPLEX:
+ {
+ struct mrb_complex *p2 = complex_ptr(mrb, y);
+
+ if (p1->real == p2->real && p1->imaginary == p2->imaginary) {
+ return TRUE;
+ }
+ return FALSE;
+ }
+ case MRB_TT_INTEGER:
+ if (p1->imaginary != 0) return FALSE;
+ return p1->real == mrb_integer(y);
+ case MRB_TT_FLOAT:
+ if (p1->imaginary != 0) return FALSE;
+ return p1->real == mrb_float(y);
+
+ default:
+ return mrb_equal(mrb, y, x);
+ }
+}
+
+static mrb_value
+complex_eq(mrb_state *mrb, mrb_value x)
+{
+ mrb_value y = mrb_get_arg1(mrb);
+ return mrb_bool_value(mrb_complex_eq(mrb, x, y));
+}
+
/* Arithmetic on (significand, exponent) pairs avoids premature overflow in
complex division */
struct float_pair {
@@ -289,6 +323,7 @@ void mrb_mruby_complex_gem_init(mrb_state *mrb)
mrb_define_method(mrb, comp, "to_i", complex_to_i, MRB_ARGS_NONE());
mrb_define_method(mrb, comp, "to_c", complex_to_c, MRB_ARGS_NONE());
mrb_define_method(mrb, comp, "__div__", complex_div, MRB_ARGS_REQ(1));
+ mrb_define_method(mrb, comp, "==", complex_eq, MRB_ARGS_REQ(1));
#ifndef MRB_USE_RATIONAL
mrb_define_method(mrb, mrb->integer_class, "/", int_div, MRB_ARGS_REQ(1)); /* overrride */
mrb_define_method(mrb, mrb->integer_class, "quo", int_quo, MRB_ARGS_REQ(1)); /* overrride */
diff --git a/mrbgems/mruby-os-memsize/src/memsize.c b/mrbgems/mruby-os-memsize/src/memsize.c
index abfd94268..9947512cf 100644
--- a/mrbgems/mruby-os-memsize/src/memsize.c
+++ b/mrbgems/mruby-os-memsize/src/memsize.c
@@ -126,8 +126,25 @@ os_memsize_of_object(mrb_state* mrb, mrb_value obj)
case MRB_TT_INTEGER:
if (mrb_immediate_p(obj))
break;
+ case MRB_TT_RATIONAL:
+#if defined(MRB_USE_RATIONAL)
+#if defined(MRB_INT64) && defined(MRB_32BIT)
+ size += sizeof(mrb_int)*2;
+#endif
+ size += mrb_objspace_page_slot_size();
+#endif
+ break;
+
+ case MRB_TT_COMPLEX:
+#if defined(MRB_USE_COMPLEX)
+#if defined(MRB_32BIT) && !defined(MRB_USE_FLOAT32)
+ size += sizeof(mrb_float)*2;
+#endif
+ size += mrb_objspace_page_slot_size();
+#endif
+ break;
case MRB_TT_DATA:
- case MRB_TT_ISTRUCT:
+ case MRB_TT_ISTRUCT:
size += mrb_objspace_page_slot_size();
break;
/* zero heap size types.
diff --git a/mrbgems/mruby-rational/mrbgem.rake b/mrbgems/mruby-rational/mrbgem.rake
index 358fb838a..ab5dc5fd1 100644
--- a/mrbgems/mruby-rational/mrbgem.rake
+++ b/mrbgems/mruby-rational/mrbgem.rake
@@ -2,5 +2,5 @@ MRuby::Gem::Specification.new('mruby-rational') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'Rational class'
- spec.build.cc.defines << "MRB_USE_RATIONAL"
+ spec.build.defines << "MRB_USE_RATIONAL"
end
diff --git a/mrbgems/mruby-rational/src/rational.c b/mrbgems/mruby-rational/src/rational.c
index d046864c7..9d819d0f8 100644
--- a/mrbgems/mruby-rational/src/rational.c
+++ b/mrbgems/mruby-rational/src/rational.c
@@ -379,9 +379,10 @@ mrb_rational_eq(mrb_state *mrb, mrb_value x, mrb_value y)
}
return a == b;
}
+
#ifdef MRB_USE_COMPLEX
case MRB_TT_COMPLEX:
- {
+ {
mrb_bool mrb_complex_eq(mrb_state *mrb, mrb_value, mrb_value);
return mrb_complex_eq(mrb, y, x);
}
diff --git a/tasks/mrbgems.rake b/tasks/mrbgems.rake
index 509f5164f..9328f0b99 100644
--- a/tasks/mrbgems.rake
+++ b/tasks/mrbgems.rake
@@ -37,7 +37,7 @@ MRuby.each_target do
f.puts %Q[]
f.write gem_func_decls
unless gem_final_calls.empty?
- f.puts %Q[]
+ f.puts %Q[]
f.puts %Q[static void]
f.puts %Q[mrb_final_mrbgems(mrb_state *mrb) {]
f.write gem_final_calls