diff options
| -rw-r--r-- | CMakeLists.txt | 9 | ||||
| -rw-r--r-- | src/codegen.c | 8 | ||||
| -rw-r--r-- | src/struct.c | 2 | ||||
| -rw-r--r-- | test/t/kernel.rb | 12 | ||||
| -rw-r--r-- | test/t/module.rb | 47 |
5 files changed, 66 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ee97ad8b4..c8b252d2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,12 +33,13 @@ project(mruby C) # TODO stop polluting source tree with CMakeFiles/ and CMakeCache.txt # on build location check failure # Make sure we are not trying to generate in in-tree build unless building -# with a MSVC IDE where it's OK. -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE) +# with an MSVC or Xcode IDE where it's OK. +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT (MSVC_IDE OR XCODE)) message(FATAL_ERROR "\nIn-source builds are not allowed as CMake would overwrite the " - "Makefiles distributed with mruby. Please change to the 'build' " - "subdirectory and run CMake from there.") + "Makefiles distributed with mruby. Delete any created 'CMakeFiles' " + "subdirectory and 'CMakeCache.txt' file from the current directory, " + "change to the 'build' subdirectory, and re-run CMake from there.") endif() if(COMMAND cmake_policy) diff --git a/src/codegen.c b/src/codegen.c index 505f0ad5b..20799f9ae 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -208,23 +208,19 @@ genop_peep(codegen_scope *s, mrb_code i, int val) case OP_SETCV: case OP_SETCONST: case OP_SETMCNST: - switch (c0) { - case OP_MOVE: + if (c0 == OP_MOVE) { if (GETARG_A(i) == GETARG_A(i0)) { s->iseq[s->pc-1] = MKOP_ABx(c1, GETARG_B(i0), GETARG_Bx(i)); return; } - break; } break; case OP_SETUPVAR: - switch (c0) { - case OP_MOVE: + if (c0 == OP_MOVE) { if (GETARG_A(i) == GETARG_A(i0)) { s->iseq[s->pc-1] = MKOP_ABC(c1, GETARG_B(i0), GETARG_B(i), GETARG_C(i)); return; } - break; } break; case OP_EPOP: diff --git a/src/struct.c b/src/struct.c index d06124b50..fbe018930 100644 --- a/src/struct.c +++ b/src/struct.c @@ -416,7 +416,7 @@ mrb_struct_initialize_withArg(mrb_state *mrb, int argc, mrb_value *argv, mrb_val mrb_raise(mrb, E_ARGUMENT_ERROR, "struct size differs"); } st = RSTRUCT(self); - st->ptr = malloc(sizeof(mrb_value)*argc); + st->ptr = mrb_malloc(mrb, sizeof(mrb_value)*argc); st->len = n; memcpy(st->ptr, argv, sizeof(mrb_value)*argc); //if (n > argc) { diff --git a/test/t/kernel.rb b/test/t/kernel.rb index cd1f2d99e..847f1baeb 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -112,7 +112,17 @@ assert('Kernel#respond_to?', '15.3.1.2.43') do respond_to? :nil? end -# TODO at the moment doesn't comply to ISO assert('Kernel#send', '15.3.1.2.44') do +assert('Kernel#send', '15.3.1.2.44') do + # test with block + l = send(:lambda) do + true + end + l.call and l.class == Proc and + # test with argument + send(:respond_to?, :nil?) and + # test without argument and without block + send(:public_methods).class == Array +end assert('Kernel#singleton_methods', '15.3.1.2.45') do singleton_methods.class == Array diff --git a/test/t/module.rb b/test/t/module.rb index 854be75a5..a5331e96d 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -5,6 +5,53 @@ assert('Module', '15.2.2') do Module.class == Class end +assert('Module#const_defined?', '15.2.2.4.20') do + module Test4ConstDefined + Const4Test4ConstDefined = true + end + + Test4ConstDefined.const_defined?(:Const4Test4ConstDefined) and + not Test4ConstDefined.const_defined?(:NotExisting) +end + +assert('Module#const_get', '15.2.2.4.21') do + module Test4ConstGet + Const4Test4ConstGet = 42 + end + + Test4ConstGet.const_get(:Const4Test4ConstGet) == 42 +end + +assert('Module.const_missing', '15.2.2.4.22') do + e1 = nil + + module Test4ConstMissing + def const_missing(sym) + # ATM this redirect doesn't work + puts "PLEASE GO TO TEST CASE Module.const_missing!" + puts "IT IS WORKING NOW!! PLEASE FINALIZE." + puts "Thanks :)" + end + end + + begin + Test4ConstMissing.const_get(:ConstDoesntExist) + rescue => e2 + e1 = e2 + end + + e1.class == NameError +end + +assert('Module#const_get', '15.2.2.4.23') do + module Test4ConstSet + Const4Test4ConstSet = 42 + end + + Test4ConstSet.const_set(:Const4Test4ConstSet, 23) + Test4ConstSet.const_get(:Const4Test4ConstSet) == 23 +end + # TODO not implemented ATM assert('Module.constants', '15.2.2') do # TODO not implemented ATM assert('Module.nesting', '15.2.2') do |
