Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closure At initialization time upper is not necessarily initialized #397

Merged
merged 4 commits into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mruby/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ MRuby.each_target do |target|
exec = exefile("#{build_dir}/bin/#{bin}")
objs = Dir.glob("#{current_dir}/tools/#{bin}/*.{c,cpp,cxx,cc}").map { |f| objfile(f.pathmap("#{current_build_dir}/tools/#{bin}/%n")) }

file exec => objs + [libfile("#{build_dir}/lib/libmruby")] do |t|
file exec => objs + target.libraries do |t|
gem_flags = gems.map { |g| g.linker.flags }
gem_flags_before_libraries = gems.map { |g| g.linker.flags_before_libraries }
gem_flags_after_libraries = gems.map { |g| g.linker.flags_after_libraries }
Expand Down Expand Up @@ -100,7 +100,7 @@ MRuby.each_target do |target|
end

depfiles += MRuby.targets.map { |n, t|
[t.libfile("#{t.build_dir}/lib/libmruby")]
t.libraries
}.flatten

depfiles += MRuby.targets.reject { |n, t| n == 'host' }.map { |n, t|
Expand Down
22 changes: 11 additions & 11 deletions mruby/doc/opcode.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ with `"`, either `OP_EXT1` or `OP_EXT2` or `OP_EXT2` can be prefixed.
|OP_RETURN_BLK' |B |return R(a) (in-block return)
|OP_BREAK' |B |break R(a)
|OP_BLKPUSH' |BS |R(a) = block (16=5:1:5:1:4)
|OP_ADD" |BB |R(a) = R(a)+R(a+1) (Syms[b]=:+)
|OP_ADDI" |BBB |R(a) = R(a)+mrb_int(c) (Syms[b]=:+)
|OP_SUB" |BB |R(a) = R(a)-R(a+1) (Syms[b]=:-)
|OP_SUBI" |BB |R(a) = R(a)-C (Syms[b]=:-)
|OP_MUL" |BB |R(a) = R(a)*R(a+1) (Syms[b]=:*)
|OP_DIV" |BB |R(a) = R(a)/R(a+1) (Syms[b]=:/)
|OP_EQ" |BB |R(a) = R(a)==R(a+1) (Syms[b]=:==)
|OP_LT" |BB |R(a) = R(a)<R(a+1) (Syms[b]=:<)
|OP_LE" |BB |R(a) = R(a)<=R(a+1) (Syms[b]=:<=)
|OP_GT" |BB |R(a) = R(a)>R(a+1) (Syms[b]=:>)
|OP_GE" |BB |R(a) = R(a)>=R(a+1) (Syms[b]=:>=)
|OP_ADD" |BB |R(a) = R(a)+R(a+1)
|OP_ADDI" |BBB |R(a) = R(a)+mrb_int(c)
|OP_SUB" |BB |R(a) = R(a)-R(a+1)
|OP_SUBI" |BB |R(a) = R(a)-C
|OP_MUL" |BB |R(a) = R(a)*R(a+1)
|OP_DIV" |BB |R(a) = R(a)/R(a+1)
|OP_EQ" |BB |R(a) = R(a)==R(a+1)
|OP_LT" |BB |R(a) = R(a)<R(a+1)
|OP_LE" |BB |R(a) = R(a)<=R(a+1)
|OP_GT" |BB |R(a) = R(a)>R(a+1)
|OP_GE" |BB |R(a) = R(a)>=R(a+1)
|OP_ARRAY' |BB |R(a) = ary_new(R(a),R(a+1)..R(a+b))
|OP_ARRAY2" |BB |R(a) = ary_new(R(b),R(b+1)..R(b+c))
|OP_ARYCAT' |B |ary_cat(R(a),R(a+1))
Expand Down
22 changes: 11 additions & 11 deletions mruby/include/mruby/ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ OPCODE(RETURN, B) /* return R(a) (normal) */
OPCODE(RETURN_BLK, B) /* return R(a) (in-block return) */
OPCODE(BREAK, B) /* break R(a) */
OPCODE(BLKPUSH, BS) /* R(a) = block (16=m5:r1:m5:d1:lv4) */
OPCODE(ADD, BB) /* R(a) = R(a)+R(a+1) (Syms[b]=:+) */
OPCODE(ADDI, BBB) /* R(a) = R(a)+mrb_int(c) (Syms[b]=:+) */
OPCODE(SUB, BB) /* R(a) = R(a)-R(a+1) (Syms[b]=:-) */
OPCODE(SUBI, BBB) /* R(a) = R(a)-C (Syms[b]=:-) */
OPCODE(MUL, BB) /* R(a) = R(a)*R(a+1) (Syms[b]=:*) */
OPCODE(DIV, BB) /* R(a) = R(a)/R(a+1) (Syms[b]=:/) */
OPCODE(EQ, BB) /* R(a) = R(a)==R(a+1) (Syms[b]=:==) */
OPCODE(LT, BB) /* R(a) = R(a)<R(a+1) (Syms[b]=:<) */
OPCODE(LE, BB) /* R(a) = R(a)<=R(a+1) (Syms[b]=:<=) */
OPCODE(GT, BB) /* R(a) = R(a)>R(a+1) (Syms[b]=:>) */
OPCODE(GE, BB) /* R(a) = R(a)>=R(a+1) (Syms[b]=:>=) */
OPCODE(ADD, B) /* R(a) = R(a)+R(a+1) */
OPCODE(ADDI, BB) /* R(a) = R(a)+mrb_int(c) */
OPCODE(SUB, B) /* R(a) = R(a)-R(a+1) */
OPCODE(SUBI, BB) /* R(a) = R(a)-C */
OPCODE(MUL, B) /* R(a) = R(a)*R(a+1) */
OPCODE(DIV, B) /* R(a) = R(a)/R(a+1) */
OPCODE(EQ, B) /* R(a) = R(a)==R(a+1) */
OPCODE(LT, B) /* R(a) = R(a)<R(a+1) */
OPCODE(LE, B) /* R(a) = R(a)<=R(a+1) */
OPCODE(GT, B) /* R(a) = R(a)>R(a+1) */
OPCODE(GE, B) /* R(a) = R(a)>=R(a+1) */
OPCODE(ARRAY, BB) /* R(a) = ary_new(R(a),R(a+1)..R(a+b)) */
OPCODE(ARRAY2, BBB) /* R(a) = ary_new(R(b),R(b+1)..R(b+c)) */
OPCODE(ARYCAT, B) /* ary_cat(R(a),R(a+1)) */
Expand Down
24 changes: 22 additions & 2 deletions mruby/lib/mruby/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ class << self
include Rake::DSL
include LoadGems
attr_accessor :name, :bins, :exts, :file_separator, :build_dir, :gem_clone_dir
attr_reader :libmruby, :gems, :toolchains
attr_reader :libmruby_objs, :gems, :toolchains
attr_writer :enable_bintest, :enable_test

alias libmruby libmruby_objs

COMPILERS = %w(cc cxx objc asm)
COMMANDS = COMPILERS + %w(linker archiver yacc gperf git exts mrbc)
attr_block MRuby::Build::COMMANDS
Expand Down Expand Up @@ -81,7 +83,7 @@ def initialize(name='host', build_dir=nil, &block)
@mrbc = Command::Mrbc.new(self)

@bins = []
@gems, @libmruby = MRuby::Gem::List.new, []
@gems, @libmruby_objs = MRuby::Gem::List.new, []
@build_mrbtest_lib_only = false
@cxx_exception_enabled = false
@cxx_exception_disabled = false
Expand All @@ -100,6 +102,10 @@ def initialize(name='host', build_dir=nil, &block)
build_mrbtest if test_enabled?
end

def debug_enabled?
@enable_debug
end

def enable_debug
compilers.each do |c|
c.defines += %w(MRB_DEBUG)
Expand All @@ -108,6 +114,8 @@ def enable_debug
end
end
@mrbc.compile_options += ' -g'

@enable_debug = true
end

def disable_cxx_exception
Expand Down Expand Up @@ -327,6 +335,18 @@ def print_build_summary
puts "================================================"
puts
end

def libmruby_static
libfile("#{build_dir}/lib/libmruby")
end

def libmruby_core_static
libfile("#{build_dir}/lib/libmruby_core")
end

def libraries
[libmruby_static]
end
end # Build

class CrossBuild < Build
Expand Down
4 changes: 2 additions & 2 deletions mruby/lib/mruby/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def setup
objfile(f.relative_path_from(@dir).to_s.pathmap("#{build_dir}/%X"))
end

@test_rbfiles = Dir.glob("#{dir}/test/**/*.rb")
@test_rbfiles = Dir.glob("#{dir}/test/**/*.rb").sort
@test_objs = Dir.glob("#{dir}/test/*.{c,cpp,cxx,cc,m,asm,s,S}").map do |f|
objfile(f.relative_path_from(dir).to_s.pathmap("#{build_dir}/%X"))
end
Expand All @@ -87,7 +87,7 @@ def setup
fail "#{name || dir} required to set name, license(s) and author(s)"
end

build.libmruby << @objs
build.libmruby_objs << @objs

instance_eval(&@build_config_initializer) if @build_config_initializer
end
Expand Down
2 changes: 1 addition & 1 deletion mruby/mrbgems/mruby-bin-mrbc/mrbgem.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MRuby::Gem::Specification.new 'mruby-bin-mrbc' do |spec|
exec = exefile("#{build.build_dir}/bin/mrbc")
mrbc_objs = Dir.glob("#{spec.dir}/tools/mrbc/*.c").map { |f| objfile(f.pathmap("#{spec.build_dir}/tools/mrbc/%n")) }.flatten

file exec => mrbc_objs + [libfile("#{build.build_dir}/lib/libmruby_core")] do |t|
file exec => mrbc_objs + [build.libmruby_core_static] do |t|
build.linker.run t.name, t.prerequisites
end

Expand Down
2 changes: 1 addition & 1 deletion mruby/mrbgems/mruby-bin-mruby-config/mrbgem.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ MRuby.each_target do
@bins << mruby_config

make_cfg = "#{build_dir}/lib/libmruby.flags.mak"
file mruby_config_path => [libfile("#{build_dir}/lib/libmruby"), make_cfg] do |t|
file mruby_config_path => [libmruby_static, make_cfg] do |t|
FileUtils.copy "#{File.dirname(__FILE__)}/#{mruby_config}", t.name
config = Hash[open(make_cfg).read.split("\n").map {|x| a = x.split(/\s*=\s*/, 2); [a[0], a[1].gsub('\\"', '"') ]}]
IO.write(t.name, File.open(t.name) {|f|
Expand Down
49 changes: 25 additions & 24 deletions mruby/mrbgems/mruby-compiler/core/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,11 @@ gen_return(codegen_scope *s, uint8_t op, uint16_t src)
}

static void
gen_addsub(codegen_scope *s, uint8_t op, uint16_t dst, uint16_t idx)
gen_addsub(codegen_scope *s, uint8_t op, uint16_t dst)
{
if (no_peephole(s)) {
normal:
genop_2(s, op, dst, idx);
genop_1(s, op, dst);
return;
}
else {
Expand All @@ -493,10 +493,10 @@ gen_addsub(codegen_scope *s, uint8_t op, uint16_t dst, uint16_t idx)
if (data.b >= 128) goto normal;
s->pc = s->lastpc;
if (op == OP_ADD) {
genop_3(s, OP_ADDI, dst, idx, (uint8_t)data.b);
genop_2(s, OP_ADDI, dst, (uint8_t)data.b);
}
else {
genop_3(s, OP_SUBI, dst, idx, (uint8_t)data.b);
genop_2(s, OP_SUBI, dst, (uint8_t)data.b);
}
break;
default:
Expand Down Expand Up @@ -973,7 +973,7 @@ static void
gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
{
mrb_sym sym = name ? name : nsym(tree->cdr->car);
int idx, skip = 0;
int skip = 0;
int n = 0, noop = 0, sendv = 0, blk = 0;

codegen(s, tree->car, VAL); /* receiver */
Expand All @@ -982,7 +982,6 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
gen_move(s, cursp(), recv, 1);
skip = genjmp2(s, OP_JMPNIL, cursp(), 0, val);
}
idx = new_sym(s, sym);
tree = tree->cdr->cdr->car;
if (tree) {
n = gen_values(s, tree->car, VAL, sp?1:0);
Expand Down Expand Up @@ -1017,33 +1016,35 @@ gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val, int safe)
const char *symname = mrb_sym2name_len(s->mrb, sym, &symlen);

if (!noop && symlen == 1 && symname[0] == '+' && n == 1) {
gen_addsub(s, OP_ADD, cursp(), idx);
gen_addsub(s, OP_ADD, cursp());
}
else if (!noop && symlen == 1 && symname[0] == '-' && n == 1) {
gen_addsub(s, OP_SUB, cursp(), idx);
gen_addsub(s, OP_SUB, cursp());
}
else if (!noop && symlen == 1 && symname[0] == '*' && n == 1) {
genop_2(s, OP_MUL, cursp(), idx);
genop_1(s, OP_MUL, cursp());
}
else if (!noop && symlen == 1 && symname[0] == '/' && n == 1) {
genop_2(s, OP_DIV, cursp(), idx);
genop_1(s, OP_DIV, cursp());
}
else if (!noop && symlen == 1 && symname[0] == '<' && n == 1) {
genop_2(s, OP_LT, cursp(), idx);
genop_1(s, OP_LT, cursp());
}
else if (!noop && symlen == 2 && symname[0] == '<' && symname[1] == '=' && n == 1) {
genop_2(s, OP_LE, cursp(), idx);
genop_1(s, OP_LE, cursp());
}
else if (!noop && symlen == 1 && symname[0] == '>' && n == 1) {
genop_2(s, OP_GT, cursp(), idx);
genop_1(s, OP_GT, cursp());
}
else if (!noop && symlen == 2 && symname[0] == '>' && symname[1] == '=' && n == 1) {
genop_2(s, OP_GE, cursp(), idx);
genop_1(s, OP_GE, cursp());
}
else if (!noop && symlen == 2 && symname[0] == '=' && symname[1] == '=' && n == 1) {
genop_2(s, OP_EQ, cursp(), idx);
genop_1(s, OP_EQ, cursp());
}
else {
int idx = new_sym(s, sym);

if (sendv) {
genop_2(s, blk ? OP_SENDVB : OP_SENDV, cursp(), idx);
}
Expand Down Expand Up @@ -2023,32 +2024,32 @@ codegen(codegen_scope *s, node *tree, int val)
push(); pop();
pop(); pop();

idx = new_sym(s, sym);
if (len == 1 && name[0] == '+') {
gen_addsub(s, OP_ADD, cursp(), idx);
gen_addsub(s, OP_ADD, cursp());
}
else if (len == 1 && name[0] == '-') {
gen_addsub(s, OP_SUB, cursp(), idx);
gen_addsub(s, OP_SUB, cursp());
}
else if (len == 1 && name[0] == '*') {
genop_2(s, OP_MUL, cursp(), idx);
genop_1(s, OP_MUL, cursp());
}
else if (len == 1 && name[0] == '/') {
genop_2(s, OP_DIV, cursp(), idx);
genop_1(s, OP_DIV, cursp());
}
else if (len == 1 && name[0] == '<') {
genop_2(s, OP_LT, cursp(), idx);
genop_1(s, OP_LT, cursp());
}
else if (len == 2 && name[0] == '<' && name[1] == '=') {
genop_2(s, OP_LE, cursp(), idx);
genop_1(s, OP_LE, cursp());
}
else if (len == 1 && name[0] == '>') {
genop_2(s, OP_GT, cursp(), idx);
genop_1(s, OP_GT, cursp());
}
else if (len == 2 && name[0] == '>' && name[1] == '=') {
genop_2(s, OP_GE, cursp(), idx);
genop_1(s, OP_GE, cursp());
}
else {
idx = new_sym(s, sym);
genop_3(s, OP_SEND, cursp(), idx, 1);
}
if (callargs < 0) {
Expand Down
2 changes: 1 addition & 1 deletion mruby/mrbgems/mruby-compiler/mrbgem.rake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ MRuby::Gem::Specification.new 'mruby-compiler' do |spec|
gperf.run t.name, t.prerequisites.first
end

file libfile("#{build.build_dir}/lib/libmruby_core") => core_objs
file build.libmruby_core_static => core_objs
build.libmruby << core_objs
end
4 changes: 1 addition & 3 deletions mruby/mrbgems/mruby-enum-ext/mrblib/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ def sort_by(&block)
ary.push([block.call(e), i])
}
if ary.size > 1
ary.__sort_sub__(0, ary.size - 1) do |a,b|
a <=> b
end
ary.sort!
end
ary.collect{|e,i| orig[i]}
end
Expand Down
12 changes: 6 additions & 6 deletions mruby/mrbgems/mruby-eval/src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,16 @@ patch_irep(mrb_state *mrb, mrb_irep *irep, int bnest, mrb_irep *top)
break;

case OP_EXT1:
insn = PEEK_B(irep->iseq+1);
i += mrb_insn_size1[insn];
insn = PEEK_B(irep->iseq+i+1);
i += mrb_insn_size1[insn]+1;
continue;
case OP_EXT2:
insn = PEEK_B(irep->iseq+1);
i += mrb_insn_size2[insn];
insn = PEEK_B(irep->iseq+i+1);
i += mrb_insn_size2[insn]+1;
continue;
case OP_EXT3:
insn = PEEK_B(irep->iseq+1);
i += mrb_insn_size3[insn];
insn = PEEK_B(irep->iseq+i+1);
i += mrb_insn_size3[insn]+1;
continue;
}
i+=mrb_insn_size[insn];
Expand Down
2 changes: 1 addition & 1 deletion mruby/mrbgems/mruby-pack/src/pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static int littleendian = 0;

const static unsigned char base64chars[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static signed char base64_dec_tab[128];
static unsigned char base64_dec_tab[128];


static int
Expand Down
2 changes: 1 addition & 1 deletion mruby/mrbgems/mruby-sleep/src/mrb_sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#ifdef _WIN32
#include <windows.h>
#define sleep(x) Sleep(x * 1000)
#define usleep(x) Sleep(((x)<1000) ? 1 : ((x)/1000))
#define usleep(x) Sleep((DWORD)((x)<1000) ? 1 : ((x)/1000))
#else
#include <unistd.h>
#include <sys/time.h>
Expand Down
4 changes: 2 additions & 2 deletions mruby/mrbgems/mruby-sleep/test/sleep_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def run_with_catching_error &b
end

assert("sleep would not accept negative value") do
e = run_with_catching_error{ sleep -1 }
e = run_with_catching_error{ sleep(-1) }

assert_not_equal e, nil
assert_equal e.class, ArgumentError
Expand All @@ -29,7 +29,7 @@ def run_with_catching_error &b
end

assert("usleep would not accept negative value") do
e = run_with_catching_error{ usleep -100 }
e = run_with_catching_error{ usleep(-100) }

assert_not_equal e, nil
assert_equal e.class, ArgumentError
Expand Down
Loading