From 10b1a52bb88ac3a7443c91fd866f8724169a2586 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 2 May 2020 09:06:28 +0900 Subject: Small updates on documents: - README.md - CONTRIBUTING.md - doc/limitations.md --- doc/limitations.md | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'doc') diff --git a/doc/limitations.md b/doc/limitations.md index 770daa7a4..79979fd5a 100644 --- a/doc/limitations.md +++ b/doc/limitations.md @@ -245,8 +245,7 @@ trace (most recent call last): ## Keyword arguments mruby keyword arguments behave slightly different from CRuby 2.5 -to make the behavior simpler and less confusing. Maybe in the -future, the simpler behavior will be adopted to CRuby as well. +to make the behavior simpler and less confusing. #### Ruby [ruby 2.5.1p57 (2018-03-29 revision 63029)] @@ -264,6 +263,20 @@ trace (most recent call last): -e:1: keyword argument hash with non symbol keys (ArgumentError) ``` +## `nil?` redefinition in conditional expressions + +Redefinition of `nil?` is ignored in conditional expressions. + +```ruby +a = "a" +def a.nil? + true +end +puts(a.nil? ? "truthy" : "falsy") +``` + +Ruby outputs `falsy`. mruby outputs `truthy`. + ## Argument Destructuring ```ruby @@ -283,17 +296,3 @@ f(1,[2,3]) ``` CRuby gives `[1,2,3,nil]`. mruby raises `NoMethodError` for `b`. - -## `nil?` redefinition in conditional expressions - -Redefinition of `nil?` is ignored in conditional expressions. - -```ruby -a = "a" -def a.nil? - true -end -puts(a.nil? ? "truthy" : "falsy") -``` - -Ruby outputs `falsy`. mruby outputs `truthy`. -- cgit v1.2.3 From 80c15ddd1544f7cfe342701368cade2b5cec0193 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 19 May 2020 18:59:14 +0900 Subject: Update the build instruction. --- doc/guides/compile.md | 99 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 68 insertions(+), 31 deletions(-) (limited to 'doc') diff --git a/doc/guides/compile.md b/doc/guides/compile.md index d7937bb2e..233c3e594 100644 --- a/doc/guides/compile.md +++ b/doc/guides/compile.md @@ -14,37 +14,53 @@ To compile mruby out of the source code you need the following tools: Note that `bison` bundled with MacOS is too old to compile `mruby`. Try `brew install bison` and follow the instuction shown to update -the `$PATH` to compile `mruby`. +the `$PATH` to compile `mruby`. We also encourage to upgrade `ruby` +on MacOS in similar manner. Optional: -* GIT (to update mruby source and integrate mrbgems easier) +* git (to update mruby source and integrate mrbgems easier) * C++ compiler (to use GEMs which include \*.cpp, \*.cxx, \*.cc) * Assembler (to use GEMs which include \*.asm) -## Usage +## Build + +To compile `mruby`, just call `rake` inside of the mruby source +root. To generate and execute the test tools call `rake test`. To +clean all build files call `rake clean`. To see full command line on +build, call `rake -v`. + +If you want to compile for the specific configuration, specify +`MRUBY_TARGET` or `TARGET` environment variable, e.g + +```sh +rake TAGRET=host +``` + +The default target is `host`. The compilation target desciption files +(with `.rb` suffix) are contained in the `target` directory. + +A build description file contains the build configuration of mruby and +looks like the following for example: -Inside of the root directory of the mruby source a file exists -called *build_config.rb*. This file contains the build configuration -of mruby and looks like this for example: ```ruby MRuby::Build.new do |conf| toolchain :gcc end ``` -All tools necessary to compile mruby can be set or modified here. In case -you want to maintain an additional *build_config.rb* you can define a -customized path using the *$MRUBY_CONFIG* environment variable. - -To compile just call `rake` inside of the mruby source root. To -generate and execute the test tools call `rake test`. To clean -all build files call `rake clean`. To see full command line on -build, call `rake -v`. +All tools necessary to compile mruby can be set or modified here. In +case you want to try different configuration, you can create a new +configuration file under `target` and specify the configuration using +the `MRUBY_TARGET` environment variable. ## Build Configuration -Inside of the *build_config.rb* the following options can be configured -based on your environment. +To create a new configuration, copy the existing configuration in the +`target` directory, and modify it. We wish you submit a pull-request, +once you created a new configuration for a new platform. + +Inside of the configuration file, the following options can be +configured based on your environment. ### Toolchains @@ -88,15 +104,12 @@ in `ANDROID_STANDALONE_TOOLCHAIN`. ### Binaries It is possible to select which tools should be compiled during the compilation -process. The following tools can be selected: -* mruby (mruby interpreter) -* mirb (mruby interactive shell) +process. For example, -To select them declare conf.gem as follows: -```ruby -conf.gem "#{root}/mrbgems/mruby-bin-mruby" -conf.gem "#{root}/mrbgems/mruby-bin-mirb" -``` +* `mruby` +* `mirb` + +The configuration are done via `mrbgems`. See `Mrbgems` section. ### File Separator @@ -209,17 +222,33 @@ end ### Mrbgems -Integrate GEMs in the build process. +`mruby` comes with the (sort of) packaging system named `mrbgems`. To +specify `gem`, you can use `conf.gem` in the configuration file. + ```ruby -# Integrate GEM with additional configuration -conf.gem 'path/to/gem' do |g| - g.cc.flags << ... -end +# Integrate a bundled Gem you see in `mrbgems` directory +conf.gem :core => 'mruby-something' + +# Integrate a Gem from GitHub +conf.gem :github => 'someone/mruby-another' -# Integrate GEM without additional configuration -conf.gem 'path/to/another/gem' +# Integrate a mruby binary Gem +conf.gem :core => 'mruby-bin-mruby' + +# Integrate a interactive mruby binary Gem +conf.gem :core => 'mruby-bin-mirb' + +# Integrate GemBox (set of Gems) +conf.gembox "default" ``` +A GemBox is a set of Gems defined in `mrbgems/default.gembox` for example. +It's just a set of `mrbgem` configurations. + +There is a `RubyGem` (gem for CRuby) named `mgem` that help you to +manage `mrbgems`. Try `gem install mgem`. `mgem` can show you the list +of registered `mrbgems`. + See doc/mrbgems/README.md for more option about mrbgems. ### Mrbtest @@ -327,6 +356,10 @@ root directory. The structure of this directory will look like this: +- build | + +- presym <- List of preallocated symbolx + | + +- presym.inc <- C source file for preallocated symbols + | +- host | +- bin <- Binaries (mirb, mrbc and mruby) @@ -378,6 +411,10 @@ In case of a cross-compilation to *i386* the *build* directory structure looks like this: +- build + | + +- presym <- List of preallocated symbolx + | + +- presym.inc <- C source file for preallocated symbols | +- host | | -- cgit v1.2.3 From fd10c7231906ca48cb35892d2a86460004b62249 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 5 Jun 2020 19:17:33 +0900 Subject: Remove `OP_EXT[123]` from operands. --- doc/opcode.md | 11 -- include/mruby/opcode.h | 27 ---- include/mruby/ops.h | 3 - mrbgems/mruby-compiler/core/codegen.c | 88 +------------ src/codedump.c | 239 +++++++++++++++------------------- src/vm.c | 37 +----- 6 files changed, 112 insertions(+), 293 deletions(-) (limited to 'doc') diff --git a/doc/opcode.md b/doc/opcode.md index a79453e8a..d5b71d9f0 100644 --- a/doc/opcode.md +++ b/doc/opcode.md @@ -20,14 +20,6 @@ sign) of operands. * sS: signed 16bit * W: 24bit -First two byte operands may be extended to 16bit. When those byte -operands are bigger than 256, the instruction will be prefixed by -`OP_EXT1` (means 1st operand is 16bit) or `OP_EXT2` (means 2nd operand -is 16bit) or `OP_EXT3` (means 1st and 2nd operands are 16bit). - -For instructions marked by `'`, `OP_EXT1` can be prefixed. For those -with `"`, either `OP_EXT1` or `OP_EXT2` or `OP_EXT2` can be prefixed. - ## table.1 Instruction Table | Instruction Name | Operand type | Semantics | @@ -133,8 +125,5 @@ with `"`, either `OP_EXT1` or `OP_EXT2` or `OP_EXT2` can be prefixed. | OP_TCLASS' | B | R(a) = target_class | | OP_DEBUG" | BBB | print a,b,c | | OP_ERR' | B | raise(LocalJumpError, Lit(a)) | -| OP_EXT1 | - | make 1st operand 16bit | -| OP_EXT2 | - | make 2nd operand 16bit | -| OP_EXT3 | - | make 1st and 2nd operands 16bit | | OP_STOP | - | stop VM | |------------------|--------------|--------------------------------------------------------| diff --git a/include/mruby/opcode.h b/include/mruby/opcode.h index 95e6736a4..a6c636cf8 100644 --- a/include/mruby/opcode.h +++ b/include/mruby/opcode.h @@ -39,31 +39,4 @@ enum mrb_insn { #define FETCH_S() do {a=READ_S();} while (0) #define FETCH_W() do {a=READ_W();} while (0) -/* with OP_EXT1 (1st 16bit) */ -#define FETCH_Z_1() FETCH_Z() -#define FETCH_B_1() FETCH_S() -#define FETCH_BB_1() do {a=READ_S(); b=READ_B();} while (0) -#define FETCH_BBB_1() do {a=READ_S(); b=READ_B(); c=READ_B();} while (0) -#define FETCH_BS_1() do {a=READ_S(); b=READ_S();} while (0) -#define FETCH_S_1() FETCH_S() -#define FETCH_W_1() FETCH_W() - -/* with OP_EXT2 (2nd 16bit) */ -#define FETCH_Z_2() FETCH_Z() -#define FETCH_B_2() FETCH_B() -#define FETCH_BB_2() do {a=READ_B(); b=READ_S();} while (0) -#define FETCH_BBB_2() do {a=READ_B(); b=READ_S(); c=READ_B();} while (0) -#define FETCH_BS_2() FETCH_BS() -#define FETCH_S_2() FETCH_S() -#define FETCH_W_2() FETCH_W() - -/* with OP_EXT3 (1st & 2nd 16bit) */ -#define FETCH_Z_3() FETCH_Z() -#define FETCH_B_3() FETCH_B() -#define FETCH_BB_3() do {a=READ_S(); b=READ_S();} while (0) -#define FETCH_BBB_3() do {a=READ_S(); b=READ_S(); c=READ_B();} while (0) -#define FETCH_BS_3() do {a=READ_S(); b=READ_S();} while (0) -#define FETCH_S_3() FETCH_S() -#define FETCH_W_3() FETCH_W() - #endif /* MRUBY_OPCODE_H */ diff --git a/include/mruby/ops.h b/include/mruby/ops.h index e85ee3133..de6106796 100644 --- a/include/mruby/ops.h +++ b/include/mruby/ops.h @@ -111,8 +111,5 @@ OPCODE(SCLASS, B) /* R(a) = R(a).singleton_class */ OPCODE(TCLASS, B) /* R(a) = target_class */ OPCODE(DEBUG, BBB) /* print a,b,c */ OPCODE(ERR, B) /* raise(LocalJumpError, Lit(a)) */ -OPCODE(EXT1, Z) /* make 1st operand 16bit */ -OPCODE(EXT2, Z) /* make 2nd operand 16bit */ -OPCODE(EXT3, Z) /* make 1st and 2nd operands 16bit */ OPCODE(STOP, Z) /* stop VM */ OPCODE(LOADI16, BS) /* R(a) = mrb_int(b) */ diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 189bb95b8..9da80536b 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -217,9 +217,7 @@ genop_1(codegen_scope *s, mrb_code i, uint16_t a) { s->lastpc = s->pc; if (a > 0xff) { - gen_B(s, OP_EXT1); - gen_B(s, i); - gen_S(s, a); + codegen_error(s, "too big operand"); } else { gen_B(s, i); @@ -231,23 +229,8 @@ static void genop_2(codegen_scope *s, mrb_code i, uint16_t a, uint16_t b) { s->lastpc = s->pc; - if (a > 0xff && b > 0xff) { - gen_B(s, OP_EXT3); - gen_B(s, i); - gen_S(s, a); - gen_S(s, b); - } - else if (b > 0xff) { - gen_B(s, OP_EXT2); - gen_B(s, i); - gen_B(s, (uint8_t)a); - gen_S(s, b); - } - else if (a > 0xff) { - gen_B(s, OP_EXT1); - gen_B(s, i); - gen_S(s, a); - gen_B(s, (uint8_t)b); + if (a > 0xff || b > 0xff) { + codegen_error(s, "too big operand"); } else { gen_B(s, i); @@ -309,32 +292,6 @@ mrb_decode_insn(const mrb_code *pc) #define OPCODE(i,x) case OP_ ## i: FETCH_ ## x (); break; #include "mruby/ops.h" #undef OPCODE - } - switch (insn) { - case OP_EXT1: - insn = READ_B(); - switch (insn) { -#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _1 (); break; -#include "mruby/ops.h" -#undef OPCODE - } - break; - case OP_EXT2: - insn = READ_B(); - switch (insn) { -#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _2 (); break; -#include "mruby/ops.h" -#undef OPCODE - } - break; - case OP_EXT3: - insn = READ_B(); - switch (insn) { -#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _3 (); break; -#include "mruby/ops.h" -#undef OPCODE - } - break; default: break; } @@ -391,11 +348,8 @@ genjmp2(codegen_scope *s, mrb_code i, uint16_t a, int pc, int val) s->lastpc = s->pc; if (a > 0xff) { - gen_B(s, OP_EXT1); - gen_B(s, i); - gen_S(s, a); - pos = s->pc; - gen_S(s, pc); + codegen_error(s, "too big operand"); + pos = 0; } else { gen_B(s, i); @@ -3314,35 +3268,3 @@ uint8_t mrb_insn_size[] = { #undef SB #undef BBB }; -/* EXT1 instruction sizes */ -uint8_t mrb_insn_size1[] = { -#define B 3 -#define BB 4 -#define BBB 5 -#define BS 5 -#define SB 5 -#define OPCODE(_,x) x, -#include "mruby/ops.h" -#undef OPCODE -#undef B -}; -/* EXT2 instruction sizes */ -uint8_t mrb_insn_size2[] = { -#define B 2 -#define OPCODE(_,x) x, -#include "mruby/ops.h" -#undef OPCODE -#undef BB -#undef BBB -#undef BS -#undef SB -}; -/* EXT3 instruction sizes */ -#define BB 5 -#define BBB 6 -#define BS 4 -#define SB 5 -uint8_t mrb_insn_size3[] = { -#define OPCODE(_,x) x, -#include "mruby/ops.h" -}; diff --git a/src/codedump.c b/src/codedump.c index 0e90f22db..67bd8754d 100644 --- a/src/codedump.c +++ b/src/codedump.c @@ -63,7 +63,7 @@ print_header(mrb_state *mrb, const mrb_irep *irep, ptrdiff_t i) printf("%03d ", (int)i); } -#define CASE(insn,ops) case insn: FETCH_ ## ops (); L_ ## insn +#define CASE(insn,ops) case insn: FETCH_ ## ops (); static void codedump(mrb_state *mrb, const mrb_irep *irep) @@ -107,14 +107,14 @@ codedump(mrb_state *mrb, const mrb_irep *irep) print_header(mrb, irep, i); ins = READ_B(); switch (ins) { - CASE(OP_NOP, Z): + CASE(OP_NOP, Z); printf("OP_NOP\n"); break; - CASE(OP_MOVE, BB): + CASE(OP_MOVE, BB); printf("OP_MOVE\tR%d\tR%d\t", a, b); print_lv_ab(mrb, irep, a, b); break; - CASE(OP_LOADL, BB): + CASE(OP_LOADL, BB); switch (irep->pool[b].tt) { case IREP_TT_FLOAT: printf("OP_LOADL\tR%d\tL(%d)\t; %f", a, b, (double)irep->pool[b].u.f); @@ -133,144 +133,144 @@ codedump(mrb_state *mrb, const mrb_irep *irep) } print_lv_a(mrb, irep, a); break; - CASE(OP_LOADI, BB): + CASE(OP_LOADI, BB); printf("OP_LOADI\tR%d\t%d\t", a, b); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADINEG, BB): + CASE(OP_LOADINEG, BB); printf("OP_LOADI\tR%d\t-%d\t", a, b); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADI16, BS): + CASE(OP_LOADI16, BS); printf("OP_LOADI16\tR%d\t%d\t", a, (int)(int16_t)b); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADI__1, B): + CASE(OP_LOADI__1, B); printf("OP_LOADI__1\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADI_0, B): goto L_LOADI; - CASE(OP_LOADI_1, B): goto L_LOADI; - CASE(OP_LOADI_2, B): goto L_LOADI; - CASE(OP_LOADI_3, B): goto L_LOADI; - CASE(OP_LOADI_4, B): goto L_LOADI; - CASE(OP_LOADI_5, B): goto L_LOADI; - CASE(OP_LOADI_6, B): goto L_LOADI; - CASE(OP_LOADI_7, B): + CASE(OP_LOADI_0, B); goto L_LOADI; + CASE(OP_LOADI_1, B); goto L_LOADI; + CASE(OP_LOADI_2, B); goto L_LOADI; + CASE(OP_LOADI_3, B); goto L_LOADI; + CASE(OP_LOADI_4, B); goto L_LOADI; + CASE(OP_LOADI_5, B); goto L_LOADI; + CASE(OP_LOADI_6, B); goto L_LOADI; + CASE(OP_LOADI_7, B); L_LOADI: printf("OP_LOADI_%d\tR%d\t\t", ins-(int)OP_LOADI_0, a); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADSYM, BB): + CASE(OP_LOADSYM, BB); printf("OP_LOADSYM\tR%d\t:%s\t", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADNIL, B): + CASE(OP_LOADNIL, B); printf("OP_LOADNIL\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADSELF, B): + CASE(OP_LOADSELF, B); printf("OP_LOADSELF\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADT, B): + CASE(OP_LOADT, B); printf("OP_LOADT\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_LOADF, B): + CASE(OP_LOADF, B); printf("OP_LOADF\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_GETGV, BB): + CASE(OP_GETGV, BB); printf("OP_GETGV\tR%d\t:%s", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_SETGV, BB): - printf("OP_SETGV\t:%s\tR%d", mrb_sym_dump(mrb, irep->syms[b]), a); + CASE(OP_SETGV, BB); + printf("OP_SETGV\t;%s\tR%d", mrb_sym_dump(mrb, irep->syms[b]), a); print_lv_a(mrb, irep, a); break; - CASE(OP_GETSV, BB): + CASE(OP_GETSV, BB); printf("OP_GETSV\tR%d\t:%s", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_SETSV, BB): + CASE(OP_SETSV, BB); printf("OP_SETSV\t:%s\tR%d", mrb_sym_dump(mrb, irep->syms[b]), a); print_lv_a(mrb, irep, a); break; - CASE(OP_GETCONST, BB): + CASE(OP_GETCONST, BB); printf("OP_GETCONST\tR%d\t:%s", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_SETCONST, BB): + CASE(OP_SETCONST, BB); printf("OP_SETCONST\t:%s\tR%d", mrb_sym_dump(mrb, irep->syms[b]), a); print_lv_a(mrb, irep, a); break; - CASE(OP_GETMCNST, BB): + CASE(OP_GETMCNST, BB); printf("OP_GETMCNST\tR%d\tR%d::%s", a, a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_SETMCNST, BB): + CASE(OP_SETMCNST, BB); printf("OP_SETMCNST\tR%d::%s\tR%d", a+1, mrb_sym_dump(mrb, irep->syms[b]), a); print_lv_a(mrb, irep, a); break; - CASE(OP_GETIV, BB): + CASE(OP_GETIV, BB); printf("OP_GETIV\tR%d\t%s", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_SETIV, BB): + CASE(OP_SETIV, BB); printf("OP_SETIV\t%s\tR%d", mrb_sym_dump(mrb, irep->syms[b]), a); print_lv_a(mrb, irep, a); break; - CASE(OP_GETUPVAR, BBB): + CASE(OP_GETUPVAR, BBB); printf("OP_GETUPVAR\tR%d\t%d\t%d", a, b, c); print_lv_a(mrb, irep, a); break; - CASE(OP_SETUPVAR, BBB): + CASE(OP_SETUPVAR, BBB); printf("OP_SETUPVAR\tR%d\t%d\t%d", a, b, c); print_lv_a(mrb, irep, a); break; - CASE(OP_GETCV, BB): + CASE(OP_GETCV, BB); printf("OP_GETCV\tR%d\t%s", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_SETCV, BB): + CASE(OP_SETCV, BB); printf("OP_SETCV\t%s\tR%d", mrb_sym_dump(mrb, irep->syms[b]), a); print_lv_a(mrb, irep, a); break; - CASE(OP_JMP, S): + CASE(OP_JMP, S); printf("OP_JMP\t\t%03d\n", a); break; - CASE(OP_JMPIF, BS): + CASE(OP_JMPIF, BS); printf("OP_JMPIF\tR%d\t%03d\t", a, b); print_lv_a(mrb, irep, a); break; - CASE(OP_JMPNOT, BS): + CASE(OP_JMPNOT, BS); printf("OP_JMPNOT\tR%d\t%03d\t", a, b); print_lv_a(mrb, irep, a); break; - CASE(OP_JMPNIL, BS): + CASE(OP_JMPNIL, BS); printf("OP_JMPNIL\tR%d\t%03d\t", a, b); print_lv_a(mrb, irep, a); break; - CASE(OP_SENDV, BB): + CASE(OP_SENDV, BB); printf("OP_SENDV\tR%d\t:%s\n", a, mrb_sym_dump(mrb, irep->syms[b])); break; - CASE(OP_SENDVB, BB): + CASE(OP_SENDVB, BB); printf("OP_SENDVB\tR%d\t:%s\n", a, mrb_sym_dump(mrb, irep->syms[b])); break; - CASE(OP_SEND, BBB): + CASE(OP_SEND, BBB); printf("OP_SEND\tR%d\t:%s\t%d\n", a, mrb_sym_dump(mrb, irep->syms[b]), c); break; - CASE(OP_SENDB, BBB): + CASE(OP_SENDB, BBB); printf("OP_SENDB\tR%d\t:%s\t%d\n", a, mrb_sym_dump(mrb, irep->syms[b]), c); break; - CASE(OP_CALL, Z): + CASE(OP_CALL, Z); printf("OP_CALL\n"); break; - CASE(OP_SUPER, BB): + CASE(OP_SUPER, BB); printf("OP_SUPER\tR%d\t%d\n", a, b); break; - CASE(OP_ARGARY, BS): + CASE(OP_ARGARY, BS); printf("OP_ARGARY\tR%d\t%d:%d:%d:%d (%d)", a, (b>>11)&0x3f, (b>>10)&0x1, @@ -279,7 +279,7 @@ codedump(mrb_state *mrb, const mrb_irep *irep) (b>>0)&0xf); print_lv_a(mrb, irep, a); break; - CASE(OP_ENTER, W): + CASE(OP_ENTER, W); printf("OP_ENTER\t%d:%d:%d:%d:%d:%d:%d\n", MRB_ASPEC_REQ(a), MRB_ASPEC_OPT(a), @@ -289,30 +289,30 @@ codedump(mrb_state *mrb, const mrb_irep *irep) MRB_ASPEC_KDICT(a), MRB_ASPEC_BLOCK(a)); break; - CASE(OP_KEY_P, BB): + CASE(OP_KEY_P, BB); printf("OP_KEY_P\tR%d\t:%s\t", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_KEYEND, Z): + CASE(OP_KEYEND, Z); printf("OP_KEYEND\n"); break; - CASE(OP_KARG, BB): + CASE(OP_KARG, BB); printf("OP_KARG\tR%d\t:%s\t", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_RETURN, B): + CASE(OP_RETURN, B); printf("OP_RETURN\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_RETURN_BLK, B): + CASE(OP_RETURN_BLK, B); printf("OP_RETURN_BLK\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_BREAK, B): + CASE(OP_BREAK, B); printf("OP_BREAK\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_BLKPUSH, BS): + CASE(OP_BLKPUSH, BS); printf("OP_BLKPUSH\tR%d\t%d:%d:%d:%d (%d)", a, (b>>11)&0x3f, (b>>10)&0x1, @@ -321,100 +321,100 @@ codedump(mrb_state *mrb, const mrb_irep *irep) (b>>0)&0xf); print_lv_a(mrb, irep, a); break; - CASE(OP_LAMBDA, BB): + CASE(OP_LAMBDA, BB); printf("OP_LAMBDA\tR%d\tI(%d:%p)\n", a, b, irep->reps[b]); break; - CASE(OP_BLOCK, BB): + CASE(OP_BLOCK, BB); printf("OP_BLOCK\tR%d\tI(%d:%p)\n", a, b, irep->reps[b]); break; - CASE(OP_METHOD, BB): + CASE(OP_METHOD, BB); printf("OP_METHOD\tR%d\tI(%d:%p)\n", a, b, irep->reps[b]); break; - CASE(OP_RANGE_INC, B): + CASE(OP_RANGE_INC, B); printf("OP_RANGE_INC\tR%d\n", a); break; - CASE(OP_RANGE_EXC, B): + CASE(OP_RANGE_EXC, B); printf("OP_RANGE_EXC\tR%d\n", a); break; - CASE(OP_DEF, BB): + CASE(OP_DEF, BB); printf("OP_DEF\tR%d\t:%s\n", a, mrb_sym_dump(mrb, irep->syms[b])); break; - CASE(OP_UNDEF, B): + CASE(OP_UNDEF, B); printf("OP_UNDEF\t:%s\n", mrb_sym_dump(mrb, irep->syms[a])); break; - CASE(OP_ALIAS, BB): + CASE(OP_ALIAS, BB); printf("OP_ALIAS\t:%s\t%s\n", mrb_sym_dump(mrb, irep->syms[a]), mrb_sym_dump(mrb, irep->syms[b])); break; - CASE(OP_ADD, B): + CASE(OP_ADD, B); printf("OP_ADD\tR%d\t\n", a); break; - CASE(OP_ADDI, BB): + CASE(OP_ADDI, BB); printf("OP_ADDI\tR%d\t%d\n", a, b); break; - CASE(OP_SUB, B): + CASE(OP_SUB, B); printf("OP_SUB\tR%d\t\n", a); break; - CASE(OP_SUBI, BB): + CASE(OP_SUBI, BB); printf("OP_SUBI\tR%d\t%d\n", a, b); break; - CASE(OP_MUL, B): + CASE(OP_MUL, B); printf("OP_MUL\tR%d\t\n", a); break; - CASE(OP_DIV, B): + CASE(OP_DIV, B); printf("OP_DIV\tR%d\t\n", a); break; - CASE(OP_LT, B): + CASE(OP_LT, B); printf("OP_LT\t\tR%d\t\n", a); break; - CASE(OP_LE, B): + CASE(OP_LE, B); printf("OP_LE\t\tR%d\t\n", a); break; - CASE(OP_GT, B): + CASE(OP_GT, B); printf("OP_GT\t\tR%d\t\n", a); break; - CASE(OP_GE, B): + CASE(OP_GE, B); printf("OP_GE\t\tR%d\t\n", a); break; - CASE(OP_EQ, B): + CASE(OP_EQ, B); printf("OP_EQ\t\tR%d\t\n", a); break; - CASE(OP_ARRAY, BB): + CASE(OP_ARRAY, BB); printf("OP_ARRAY\tR%d\t%d\t", a, b); print_lv_a(mrb, irep, a); break; - CASE(OP_ARRAY2, BBB): + CASE(OP_ARRAY2, BBB); printf("OP_ARRAY\tR%d\tR%d\t%d\t", a, b, c); print_lv_ab(mrb, irep, a, b); break; - CASE(OP_ARYCAT, B): + CASE(OP_ARYCAT, B); printf("OP_ARYCAT\tR%d\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_ARYPUSH, B): + CASE(OP_ARYPUSH, B); printf("OP_ARYPUSH\tR%d\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_ARYDUP, B): + CASE(OP_ARYDUP, B); printf("OP_ARYDUP\tR%d\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_AREF, BBB): + CASE(OP_AREF, BBB); printf("OP_AREF\tR%d\tR%d\t%d", a, b, c); print_lv_ab(mrb, irep, a, b); break; - CASE(OP_ASET, BBB): + CASE(OP_ASET, BBB); printf("OP_ASET\tR%d\tR%d\t%d", a, b, c); print_lv_ab(mrb, irep, a, b); break; - CASE(OP_APOST, BBB): + CASE(OP_APOST, BBB); printf("OP_APOST\tR%d\t%d\t%d", a, b, c); print_lv_a(mrb, irep, a); break; - CASE(OP_INTERN, B): + CASE(OP_INTERN, B); printf("OP_INTERN\tR%d", a); print_lv_a(mrb, irep, a); break; - CASE(OP_STRING, BB): + CASE(OP_STRING, BB); if ((irep->pool[b].tt & IREP_TT_NFLAG) == 0) { printf("OP_STRING\tR%d\tL(%d)\t; %s", a, b, irep->pool[b].u.str); } @@ -423,48 +423,48 @@ codedump(mrb_state *mrb, const mrb_irep *irep) } print_lv_a(mrb, irep, a); break; - CASE(OP_STRCAT, B): + CASE(OP_STRCAT, B); printf("OP_STRCAT\tR%d\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_HASH, BB): + CASE(OP_HASH, BB); printf("OP_HASH\tR%d\t%d\t", a, b); print_lv_a(mrb, irep, a); break; - CASE(OP_HASHADD, BB): + CASE(OP_HASHADD, BB); printf("OP_HASHADD\tR%d\t%d\t", a, b); print_lv_a(mrb, irep, a); break; - CASE(OP_HASHCAT, B): + CASE(OP_HASHCAT, B); printf("OP_HASHCAT\tR%d\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_OCLASS, B): + CASE(OP_OCLASS, B); printf("OP_OCLASS\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_CLASS, BB): + CASE(OP_CLASS, BB); printf("OP_CLASS\tR%d\t:%s", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_MODULE, BB): + CASE(OP_MODULE, BB); printf("OP_MODULE\tR%d\t:%s", a, mrb_sym_dump(mrb, irep->syms[b])); print_lv_a(mrb, irep, a); break; - CASE(OP_EXEC, BB): + CASE(OP_EXEC, BB); printf("OP_EXEC\tR%d\tI(%d:%p)", a, b, irep->reps[b]); print_lv_a(mrb, irep, a); break; - CASE(OP_SCLASS, B): + CASE(OP_SCLASS, B); printf("OP_SCLASS\tR%d\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_TCLASS, B): + CASE(OP_TCLASS, B); printf("OP_TCLASS\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_ERR, B): + CASE(OP_ERR, B); if ((irep->pool[a].tt & IREP_TT_NFLAG) == 0) { printf("OP_ERR\t%s\n", irep->pool[a].u.str); } @@ -472,70 +472,39 @@ codedump(mrb_state *mrb, const mrb_irep *irep) printf("OP_ERR\tL(%d)\n", a); } break; - CASE(OP_EPUSH, B): + CASE(OP_EPUSH, B); printf("OP_EPUSH\t\t:I(%d:%p)\n", a, irep->reps[a]); break; - CASE(OP_ONERR, S): + CASE(OP_ONERR, S); printf("OP_ONERR\t%03d\n", a); break; - CASE(OP_EXCEPT, B): + CASE(OP_EXCEPT, B); printf("OP_EXCEPT\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_RESCUE, BB): + CASE(OP_RESCUE, BB); printf("OP_RESCUE\tR%d\tR%d", a, b); print_lv_ab(mrb, irep, a, b); break; - CASE(OP_RAISE, B): + CASE(OP_RAISE, B); printf("OP_RAISE\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_POPERR, B): + CASE(OP_POPERR, B); printf("OP_POPERR\t%d\t\t\n", a); break; - CASE(OP_EPOP, B): + CASE(OP_EPOP, B); printf("OP_EPOP\t%d\n", a); break; - CASE(OP_DEBUG, BBB): + CASE(OP_DEBUG, BBB); printf("OP_DEBUG\t%d\t%d\t%d\n", a, b, c); break; - CASE(OP_STOP, Z): + CASE(OP_STOP, Z); printf("OP_STOP\n"); break; - CASE(OP_EXT1, Z): - ins = READ_B(); - printf("OP_EXT1\n"); - print_header(mrb, irep, pc-irep->iseq-2); - switch (ins) { -#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _1 (); goto L_OP_ ## i; -#include "mruby/ops.h" -#undef OPCODE - } - break; - CASE(OP_EXT2, Z): - ins = READ_B(); - printf("OP_EXT2\n"); - print_header(mrb, irep, pc-irep->iseq-2); - switch (ins) { -#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _2 (); goto L_OP_ ## i; -#include "mruby/ops.h" -#undef OPCODE - } - break; - CASE(OP_EXT3, Z): - ins = READ_B(); - printf("OP_EXT3\n"); - print_header(mrb, irep, pc-irep->iseq-2); - switch (ins) { -#define OPCODE(i,x) case OP_ ## i: FETCH_ ## x ## _3 (); goto L_OP_ ## i; -#include "mruby/ops.h" -#undef OPCODE - } - break; - default: printf("OP_unknown (0x%x)\n", ins); break; diff --git a/src/vm.c b/src/vm.c index 98f17e287..c97c9678c 100644 --- a/src/vm.c +++ b/src/vm.c @@ -901,7 +901,7 @@ argnum_error(mrb_state *mrb, mrb_int num) #ifndef DIRECT_THREADED #define INIT_DISPATCH for (;;) { insn = BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); switch (insn) { -#define CASE(insn,ops) case insn: pc0=pc++; FETCH_ ## ops ();; L_ ## insn ## _BODY: +#define CASE(insn,ops) case insn: pc0=pc++; FETCH_ ## ops (); #define NEXT break #define JUMP NEXT #define END_DISPATCH }} @@ -909,7 +909,7 @@ argnum_error(mrb_state *mrb, mrb_int num) #else #define INIT_DISPATCH JUMP; return mrb_nil_value(); -#define CASE(insn,ops) L_ ## insn: pc0=pc++; FETCH_ ## ops (); L_ ## insn ## _BODY: +#define CASE(insn,ops) L_ ## insn: pc0=pc++; FETCH_ ## ops (); #define NEXT insn=BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); goto *optable[insn] #define JUMP NEXT @@ -1512,7 +1512,7 @@ RETRY_TRY_BLOCK: mrb->c->stack[0] = mrb_nil_value(); a = 0; c = OP_R_NORMAL; - goto L_OP_RETURN_BODY; + goto L_RETURN; } pool = irep->pool; syms = irep->syms; @@ -2733,37 +2733,6 @@ RETRY_TRY_BLOCK: goto L_RAISE; } - CASE(OP_EXT1, Z) { - insn = READ_B(); - switch (insn) { -#define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _1(); goto L_OP_ ## insn ## _BODY; -#include "mruby/ops.h" -#undef OPCODE - } - pc--; - NEXT; - } - CASE(OP_EXT2, Z) { - insn = READ_B(); - switch (insn) { -#define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _2(); goto L_OP_ ## insn ## _BODY; -#include "mruby/ops.h" -#undef OPCODE - } - pc--; - NEXT; - } - CASE(OP_EXT3, Z) { - uint8_t insn = READ_B(); - switch (insn) { -#define OPCODE(insn,ops) case OP_ ## insn: FETCH_ ## ops ## _3(); goto L_OP_ ## insn ## _BODY; -#include "mruby/ops.h" -#undef OPCODE - } - pc--; - NEXT; - } - CASE(OP_STOP, Z) { /* stop VM */ L_STOP: -- cgit v1.2.3 From 8f0ac27196ff103560222b236584d7e5ccfab99d Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 6 Jun 2020 17:43:17 +0900 Subject: Update opcode reference and comment. - no OP_EXT_ anymore - OP_LOADI16 in right position --- doc/opcode.md | 190 ++++++++++++++++++++++++++-------------------------- include/mruby/ops.h | 2 +- 2 files changed, 96 insertions(+), 96 deletions(-) (limited to 'doc') diff --git a/doc/opcode.md b/doc/opcode.md index d5b71d9f0..98d29cdc0 100644 --- a/doc/opcode.md +++ b/doc/opcode.md @@ -25,105 +25,105 @@ sign) of operands. | Instruction Name | Operand type | Semantics | |------------------|--------------|--------------------------------------------------------| | OP_NOP | - | no operation | -| OP_MOVE" | BB | R(a) = R(b) | -| OP_LOADL" | BB | R(a) = Pool(b) | -| OP_LOADI" | BB | R(a) = mrb_int(b) | -| OP_LOADINEG" | BB | R(a) = mrb_int(-b) | -| OP_LOADI__1' | B | R(a) = mrb_int(-1) | -| OP_LOADI_0' | B | R(a) = mrb_int(0) | -| OP_LOADI_1' | B | R(a) = mrb_int(1) | -| OP_LOADI_2' | B | R(a) = mrb_int(2) | -| OP_LOADI_3' | B | R(a) = mrb_int(3) | -| OP_LOADI_4' | B | R(a) = mrb_int(4) | -| OP_LOADI_5' | B | R(a) = mrb_int(5) | -| OP_LOADI_6' | B | R(a) = mrb_int(6) | -| OP_LOADI_7' | B | R(a) = mrb_int(7) | -| OP_LOADI16' | BsS | R(a) = mrb_int(b) | -| OP_LOADSYM" | BB | R(a) = Syms(b) | -| OP_LOADNIL' | B | R(a) = nil | -| OP_LOADSELF' | B | R(a) = self | -| OP_LOADT' | B | R(a) = true | -| OP_LOADF' | B | R(a) = false | -| OP_GETGV" | BB | R(a) = getglobal(Syms(b)) | -| OP_SETGV" | BB | setglobal(Syms(b), R(a)) | -| OP_GETSV" | BB | R(a) = Special[Syms(b)] | -| OP_SETSV" | BB | Special[Syms(b)] = R(a) | -| OP_GETIV" | BB | R(a) = ivget(Syms(b)) | -| OP_SETIV" | BB | ivset(Syms(b),R(a)) | -| OP_GETCV" | BB | R(a) = cvget(Syms(b)) | -| OP_SETCV" | BB | cvset(Syms(b),R(a)) | -| OP_GETCONST" | BB | R(a) = constget(Syms(b)) | -| OP_SETCONST" | BB | constset(Syms(b),R(a)) | -| OP_GETMCNST" | BB | R(a) = R(a)::Syms(b) | -| OP_SETMCNST" | BB | R(a+1)::Syms(b) = R(a) | -| OP_GETUPVAR" | BBB | R(a) = uvget(b,c) | -| OP_SETUPVAR" | BBB | uvset(b,c,R(a)) | +| OP_MOVE | BB | R(a) = R(b) | +| OP_LOADL | BB | R(a) = Pool(b) | +| OP_LOADI | BB | R(a) = mrb_int(b) | +| OP_LOADINEG | BB | R(a) = mrb_int(-b) | +| OP_LOADI__1 | B | R(a) = mrb_int(-1) | +| OP_LOADI_0 | B | R(a) = mrb_int(0) | +| OP_LOADI_1 | B | R(a) = mrb_int(1) | +| OP_LOADI_2 | B | R(a) = mrb_int(2) | +| OP_LOADI_3 | B | R(a) = mrb_int(3) | +| OP_LOADI_4 | B | R(a) = mrb_int(4) | +| OP_LOADI_5 | B | R(a) = mrb_int(5) | +| OP_LOADI_6 | B | R(a) = mrb_int(6) | +| OP_LOADI_7 | B | R(a) = mrb_int(7) | +| OP_LOADI16 | BsS | R(a) = mrb_int(b) | +| OP_LOADSYM | BB | R(a) = Syms(b) | +| OP_LOADNIL | B | R(a) = nil | +| OP_LOADSELF | B | R(a) = self | +| OP_LOADT | B | R(a) = true | +| OP_LOADF | B | R(a) = false | +| OP_GETGV | BB | R(a) = getglobal(Syms(b)) | +| OP_SETGV | BB | setglobal(Syms(b), R(a)) | +| OP_GETSV | BB | R(a) = Special[Syms(b)] | +| OP_SETSV | BB | Special[Syms(b)] = R(a) | +| OP_GETIV | BB | R(a) = ivget(Syms(b)) | +| OP_SETIV | BB | ivset(Syms(b),R(a)) | +| OP_GETCV | BB | R(a) = cvget(Syms(b)) | +| OP_SETCV | BB | cvset(Syms(b),R(a)) | +| OP_GETCONST | BB | R(a) = constget(Syms(b)) | +| OP_SETCONST | BB | constset(Syms(b),R(a)) | +| OP_GETMCNST | BB | R(a) = R(a)::Syms(b) | +| OP_SETMCNST | BB | R(a+1)::Syms(b) = R(a) | +| OP_GETUPVAR | BBB | R(a) = uvget(b,c) | +| OP_SETUPVAR | BBB | uvset(b,c,R(a)) | | OP_JMP | S | pc=a | -| OP_JMPIF' | BS | if R(a) pc=b | -| OP_JMPNOT' | BS | if !R(a) pc=b | -| OP_JMPNIL' | BS | if R(a)==nil pc=b | +| OP_JMPIF | BS | if R(a) pc=b | +| OP_JMPNOT | BS | if !R(a) pc=b | +| OP_JMPNIL | BS | if R(a)==nil pc=b | | OP_ONERR | S | rescue_push(a) | -| OP_EXCEPT' | B | R(a) = exc | -| OP_RESCUE" | BB | R(b) = R(a).isa?(R(b)) | -| OP_POPERR' | B | a.times{rescue_pop()} | -| OP_RAISE' | B | raise(R(a)) | -| OP_EPUSH' | B | ensure_push(SEQ[a]) | -| OP_EPOP' | B | A.times{ensure_pop().call} | -| OP_SENDV" | BB | R(a) = call(R(a),Syms(b),*R(a+1)) | -| OP_SENDVB" | BB | R(a) = call(R(a),Syms(b),*R(a+1),&R(a+2)) | -| OP_SEND" | BBB | R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c)) | -| OP_SENDB" | BBB | R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c),&R(a+c+1)) | +| OP_EXCEPT | B | R(a) = exc | +| OP_RESCUE | BB | R(b) = R(a).isa?(R(b)) | +| OP_POPERR | B | a.times{rescue_pop()} | +| OP_RAISE | B | raise(R(a)) | +| OP_EPUSH | B | ensure_push(SEQ[a]) | +| OP_EPOP | B | A.times{ensure_pop().call} | +| OP_SENDV | BB | R(a) = call(R(a),Syms(b),*R(a+1)) | +| OP_SENDVB | BB | R(a) = call(R(a),Syms(b),*R(a+1),&R(a+2)) | +| OP_SEND | BBB | R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c)) | +| OP_SENDB | BBB | R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c),&R(a+c+1)) | | OP_CALL | - | R(0) = self.call(frame.argc, frame.argv) | -| OP_SUPER" | BB | R(a) = super(R(a+1),... ,R(a+b+1)) | -| OP_ARGARY' | BS | R(a) = argument array (16=5:1:5:1:4) | +| OP_SUPER | BB | R(a) = super(R(a+1),... ,R(a+b+1)) | +| OP_ARGARY | BS | R(a) = argument array (16=5:1:5:1:4) | | OP_ENTER | W | arg setup according to flags (23=5:5:1:5:5:1:1) | -| OP_KEY_P" | BB | R(a) = kdict.key?(Syms(b)) | +| OP_KEY_P | BB | R(a) = kdict.key?(Syms(b)) | | OP_KEYEND | - | raise unless kdict.empty? | -| OP_KARG" | BB | R(a) = kdict[Syms(b)]; kdict.delete(Syms(b)) | -| OP_RETURN' | B | return R(a) (normal) | -| 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' | B | R(a) = R(a)+R(a+1) | -| OP_ADDI" | BB | R(a) = R(a)+mrb_int(b) | -| OP_SUB' | B | R(a) = R(a)-R(a+1) | -| OP_SUBI" | BB | R(a) = R(a)-mrb_int(b) | -| OP_MUL' | B | R(a) = R(a)*R(a+1) | -| OP_DIV' | B | R(a) = R(a)/R(a+1) | -| OP_EQ' | B | R(a) = R(a)==R(a+1) | -| OP_LT' | B | R(a) = R(a)R(a+1) | -| OP_GE' | B | R(a) = R(a)>=R(a+1) | -| OP_ARRAY" | BB | R(a) = ary_new(R(a),R(a+1)..R(a+b)) | -| OP_ARRAY2" | BBB | R(a) = ary_new(R(b),R(b+1)..R(b+c)) | -| OP_ARYCAT' | B | ary_cat(R(a),R(a+1)) | -| OP_ARYPUSH' | B | ary_push(R(a),R(a+1)) | -| OP_ARYDUP' | B | R(a) = ary_dup(R(a)) | -| OP_AREF" | BBB | R(a) = R(b)[c] | -| OP_ASET" | BBB | R(a)[c] = R(b) | -| OP_APOST" | BBB | *R(a),R(a+1)..R(a+c) = R(a)[b..] | -| OP_INTERN' | B | R(a) = intern(R(a)) | -| OP_STRING" | BB | R(a) = str_dup(Lit(b)) | -| OP_STRCAT' | B | str_cat(R(a),R(a+1)) | -| OP_HASH" | BB | R(a) = hash_new(R(a),R(a+1)..R(a+b)) | -| OP_HASHADD" | BB | R(a) = hash_push(R(a),R(a+1)..R(a+b)) | -| OP_HASHCAT' | B | R(a) = hash_cat(R(a),R(a+1)) | -| OP_LAMBDA" | BB | R(a) = lambda(SEQ[b],OP_L_LAMBDA) | -| OP_BLOCK" | BB | R(a) = lambda(SEQ[b],OP_L_BLOCK) | -| OP_METHOD" | BB | R(a) = lambda(SEQ[b],OP_L_METHOD) | -| OP_RANGE_INC' | B | R(a) = range_new(R(a),R(a+1),FALSE) | -| OP_RANGE_EXC' | B | R(a) = range_new(R(a),R(a+1),TRUE) | -| OP_OCLASS' | B | R(a) = ::Object | -| OP_CLASS" | BB | R(a) = newclass(R(a),Syms(b),R(a+1)) | -| OP_MODULE" | BB | R(a) = newmodule(R(a),Syms(b)) | -| OP_EXEC" | BB | R(a) = blockexec(R(a),SEQ[b]) | -| OP_DEF" | BB | R(a).newmethod(Syms(b),R(a+1)) | -| OP_ALIAS" | BB | alias_method(target_class,Syms(a),Syms(b)) | -| OP_UNDEF' | B | undef_method(target_class,Syms(a)) | -| OP_SCLASS' | B | R(a) = R(a).singleton_class | -| OP_TCLASS' | B | R(a) = target_class | -| OP_DEBUG" | BBB | print a,b,c | -| OP_ERR' | B | raise(LocalJumpError, Lit(a)) | +| OP_KARG | BB | R(a) = kdict[Syms(b)]; kdict.delete(Syms(b)) | +| OP_RETURN | B | return R(a) (normal) | +| 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 | B | R(a) = R(a)+R(a+1) | +| OP_ADDI | BB | R(a) = R(a)+mrb_int(b) | +| OP_SUB | B | R(a) = R(a)-R(a+1) | +| OP_SUBI | BB | R(a) = R(a)-mrb_int(b) | +| OP_MUL | B | R(a) = R(a)*R(a+1) | +| OP_DIV | B | R(a) = R(a)/R(a+1) | +| OP_EQ | B | R(a) = R(a)==R(a+1) | +| OP_LT | B | R(a) = R(a)R(a+1) | +| OP_GE | B | R(a) = R(a)>=R(a+1) | +| OP_ARRAY | BB | R(a) = ary_new(R(a),R(a+1)..R(a+b)) | +| OP_ARRAY2 | BBB | R(a) = ary_new(R(b),R(b+1)..R(b+c)) | +| OP_ARYCAT | B | ary_cat(R(a),R(a+1)) | +| OP_ARYPUSH | B | ary_push(R(a),R(a+1)) | +| OP_ARYDUP | B | R(a) = ary_dup(R(a)) | +| OP_AREF | BBB | R(a) = R(b)[c] | +| OP_ASET | BBB | R(a)[c] = R(b) | +| OP_APOST | BBB | *R(a),R(a+1)..R(a+c) = R(a)[b..] | +| OP_INTERN | B | R(a) = intern(R(a)) | +| OP_STRING | BB | R(a) = str_dup(Lit(b)) | +| OP_STRCAT | B | str_cat(R(a),R(a+1)) | +| OP_HASH | BB | R(a) = hash_new(R(a),R(a+1)..R(a+b)) | +| OP_HASHADD | BB | R(a) = hash_push(R(a),R(a+1)..R(a+b)) | +| OP_HASHCAT | B | R(a) = hash_cat(R(a),R(a+1)) | +| OP_LAMBDA | BB | R(a) = lambda(SEQ[b],OP_L_LAMBDA) | +| OP_BLOCK | BB | R(a) = lambda(SEQ[b],OP_L_BLOCK) | +| OP_METHOD | BB | R(a) = lambda(SEQ[b],OP_L_METHOD) | +| OP_RANGE_INC | B | R(a) = range_new(R(a),R(a+1),FALSE) | +| OP_RANGE_EXC | B | R(a) = range_new(R(a),R(a+1),TRUE) | +| OP_OCLASS | B | R(a) = ::Object | +| OP_CLASS | BB | R(a) = newclass(R(a),Syms(b),R(a+1)) | +| OP_MODULE | BB | R(a) = newmodule(R(a),Syms(b)) | +| OP_EXEC | BB | R(a) = blockexec(R(a),SEQ[b]) | +| OP_DEF | BB | R(a).newmethod(Syms(b),R(a+1)) | +| OP_ALIAS | BB | alias_method(target_class,Syms(a),Syms(b)) | +| OP_UNDEF | B | undef_method(target_class,Syms(a)) | +| OP_SCLASS | B | R(a) = R(a).singleton_class | +| OP_TCLASS | B | R(a) = target_class | +| OP_DEBUG | BBB | print a,b,c | +| OP_ERR | B | raise(LocalJumpError, Lit(a)) | | OP_STOP | - | stop VM | |------------------|--------------|--------------------------------------------------------| diff --git a/include/mruby/ops.h b/include/mruby/ops.h index de6106796..7d20ac0ad 100644 --- a/include/mruby/ops.h +++ b/include/mruby/ops.h @@ -25,6 +25,7 @@ OPCODE(LOADI_4, B) /* R(a) = mrb_int(4) */ OPCODE(LOADI_5, B) /* R(a) = mrb_int(5) */ OPCODE(LOADI_6, B) /* R(a) = mrb_int(6) */ OPCODE(LOADI_7, B) /* R(a) = mrb_int(7) */ +OPCODE(LOADI16, BS) /* R(a) = mrb_int(b) */ OPCODE(LOADSYM, BB) /* R(a) = Syms(b) */ OPCODE(LOADNIL, B) /* R(a) = nil */ OPCODE(LOADSELF, B) /* R(a) = self */ @@ -112,4 +113,3 @@ OPCODE(TCLASS, B) /* R(a) = target_class */ OPCODE(DEBUG, BBB) /* print a,b,c */ OPCODE(ERR, B) /* raise(LocalJumpError, Lit(a)) */ OPCODE(STOP, Z) /* stop VM */ -OPCODE(LOADI16, BS) /* R(a) = mrb_int(b) */ -- cgit v1.2.3 From 639946a006c29f648551512af8aa0bb0cd969412 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 27 Jun 2020 17:38:24 +0900 Subject: Enable method cache by default. Introduced `MRB_NO_METHOD_CACHE` which is inverse of `MRB_METHOD_CACHE` that should be enabled intestinally. In addition, the default cache is made bigger (128 -> 256). --- doc/guides/mrbconf.md | 8 ++++---- include/mrbconf.h | 18 +++++++----------- include/mruby.h | 10 +++++----- include/mruby/class.h | 2 +- src/class.c | 8 ++++---- target/appveyor.rb | 2 +- target/host-gprof.rb | 1 - target/travis.rb | 2 +- 8 files changed, 23 insertions(+), 28 deletions(-) (limited to 'doc') diff --git a/doc/guides/mrbconf.md b/doc/guides/mrbconf.md index 1e1a5afcf..003c2b300 100644 --- a/doc/guides/mrbconf.md +++ b/doc/guides/mrbconf.md @@ -163,12 +163,12 @@ largest value of required alignment. * Default value is `128`. * Specifies initial capacity of `RString` created by `mrb_str_buf_new` function.. -`MRB_METHOD_CACHE` -* Improve performance for method dispatch. +`MRB_NO_METHOD_CACHE` +* Disable method cache to save memory. `MRB_METHOD_CACHE_SIZE` -* Default value is `128`. -* Ignored if `MRB_METHOD_CACHE` is not defined. +* Default value is `256`. +* Ignored if `MRB_NO_METHOD_CACHE` is defined. * Need to be the power of 2. `MRB_METHOD_T_STRUCT` diff --git a/include/mrbconf.h b/include/mrbconf.h index 2b1adb24e..81ab36977 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -31,10 +31,10 @@ /* exclude floating point numbers */ //#define MRB_WITHOUT_FLOAT -/* add -DMRB_METHOD_CACHE to use method cache to improve performance */ -//#define MRB_METHOD_CACHE +/* add -DMRB_NO_METHOD_CACHE to disable method cache to save memory */ +//#define MRB_NO_METHOD_CACHE /* size of the method cache (need to be the power of 2) */ -//#define MRB_METHOD_CACHE_SIZE (1<<7) +//#define MRB_METHOD_CACHE_SIZE (1<<8) /* add -DMRB_METHOD_T_STRUCT on machines that use higher bits of pointers */ /* no MRB_METHOD_T_STRUCT requires highest 2 bits of function pointers to be zero */ @@ -160,6 +160,10 @@ /* A profile for micro controllers */ #if defined(MRB_CONSTRAINED_BASELINE_PROFILE) +# ifndef MRB_NO_METHOD_CACHE +# define MRB_NO_METHOD_CACHE +# endif + # ifndef KHASH_DEFAULT_SIZE # define KHASH_DEFAULT_SIZE 16 # endif @@ -177,10 +181,6 @@ /* A profile for desktop computers or workstations; rich memory! */ #elif defined(MRB_MAIN_PROFILE) -# ifndef MRB_METHOD_CACHE -# define MRB_METHOD_CACHE -# endif - # ifndef MRB_METHOD_CACHE_SIZE # define MRB_METHOD_CACHE_SIZE (1<<10) # endif @@ -195,10 +195,6 @@ /* A profile for server; mruby vm is long life */ #elif defined(MRB_HIGH_PROFILE) -# ifndef MRB_METHOD_CACHE -# define MRB_METHOD_CACHE -# endif - # ifndef MRB_METHOD_CACHE_SIZE # define MRB_METHOD_CACHE_SIZE (1<<12) # endif diff --git a/include/mruby.h b/include/mruby.h index 27c428e85..c9425e8a7 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -188,11 +188,11 @@ struct mrb_context { }; #ifdef MRB_METHOD_CACHE_SIZE -# define MRB_METHOD_CACHE +# undef MRB_NO_METHOD_CACHE #else -/* default method cache size: 128 */ +/* default method cache size: 256 */ /* cache size needs to be power of 2 */ -# define MRB_METHOD_CACHE_SIZE (1<<7) +# define MRB_METHOD_CACHE_SIZE (1<<8) #endif /** @@ -218,7 +218,7 @@ typedef struct { } mrb_method_t; #endif -#ifdef MRB_METHOD_CACHE +#ifndef MRB_NO_METHOD_CACHE struct mrb_cache_entry { struct RClass *c, *c0; mrb_sym mid; @@ -264,7 +264,7 @@ typedef struct mrb_state { mrb_gc gc; -#ifdef MRB_METHOD_CACHE +#ifndef MRB_NO_METHOD_CACHE struct mrb_cache_entry cache[MRB_METHOD_CACHE_SIZE]; #endif diff --git a/include/mruby/class.h b/include/mruby/class.h index 94356d3b2..88e5915e5 100644 --- a/include/mruby/class.h +++ b/include/mruby/class.h @@ -92,7 +92,7 @@ void mrb_gc_mark_mt(mrb_state*, struct RClass*); size_t mrb_gc_mark_mt_size(mrb_state*, struct RClass*); void mrb_gc_free_mt(mrb_state*, struct RClass*); -#ifdef MRB_METHOD_CACHE +#ifndef MRB_NO_METHOD_CACHE void mrb_mc_clear_by_class(mrb_state *mrb, struct RClass* c); #else #define mrb_mc_clear_by_class(mrb,c) diff --git a/src/class.c b/src/class.c index c48229d8a..30f4a3e2f 100644 --- a/src/class.c +++ b/src/class.c @@ -292,7 +292,7 @@ mrb_define_class(mrb_state *mrb, const char *name, struct RClass *super) } static mrb_value mrb_bob_init(mrb_state *mrb, mrb_value); -#ifdef MRB_METHOD_CACHE +#ifndef MRB_NO_METHOD_CACHE static void mc_clear_all(mrb_state *mrb); static void mc_clear_by_id(mrb_state *mrb, struct RClass*, mrb_sym); #else @@ -1404,7 +1404,7 @@ mrb_define_module_function(mrb_state *mrb, struct RClass *c, const char *name, m mrb_define_module_function_id(mrb, c, mrb_intern_cstr(mrb, name), func, aspec); } -#ifdef MRB_METHOD_CACHE +#ifndef MRB_NO_METHOD_CACHE static void mc_clear_all(mrb_state *mrb) { @@ -1456,7 +1456,7 @@ mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid) khiter_t k; mrb_method_t m; struct RClass *c = *cp; -#ifdef MRB_METHOD_CACHE +#ifndef MRB_NO_METHOD_CACHE struct RClass *oc = c; int h = kh_int_hash_func(mrb, ((intptr_t)oc) ^ mid) & (MRB_METHOD_CACHE_SIZE-1); struct mrb_cache_entry *mc = &mrb->cache[h]; @@ -1476,7 +1476,7 @@ mrb_method_search_vm(mrb_state *mrb, struct RClass **cp, mrb_sym mid) m = kh_value(h, k); if (MRB_METHOD_UNDEF_P(m)) break; *cp = c; -#ifdef MRB_METHOD_CACHE +#ifndef MRB_NO_METHOD_CACHE mc->c = oc; mc->c0 = c; mc->mid = mid; diff --git a/target/appveyor.rb b/target/appveyor.rb index 2336935c9..6a8dbbf4a 100644 --- a/target/appveyor.rb +++ b/target/appveyor.rb @@ -10,7 +10,7 @@ MRuby::Build.new('full-debug') do |conf| # include all core GEMs conf.gembox 'full-core' - conf.cc.defines += %w(MRB_GC_STRESS MRB_METHOD_CACHE MRB_ENABLE_DEBUG_HOOK) + conf.cc.defines += %w(MRB_GC_STRESS MRB_ENABLE_DEBUG_HOOK) setup_option(conf) conf.enable_test diff --git a/target/host-gprof.rb b/target/host-gprof.rb index c8a2f3b13..31b952920 100644 --- a/target/host-gprof.rb +++ b/target/host-gprof.rb @@ -5,7 +5,6 @@ MRuby::Build.new do |conf| # include the GEM box conf.gembox 'full-core' - conf.cc.defines = %w(MRB_METHOD_CACHE) conf.cc.flags << '-pg' conf.linker.flags << '-pg' diff --git a/target/travis.rb b/target/travis.rb index f4bef0a52..b8b04da18 100644 --- a/target/travis.rb +++ b/target/travis.rb @@ -5,7 +5,7 @@ MRuby::Build.new('full-debug') do |conf| # include all core GEMs conf.gembox 'full-core' conf.cc.flags += %w(-Werror=declaration-after-statement) - conf.cc.defines += %w(MRB_GC_STRESS MRB_METHOD_CACHE MRB_ENABLE_DEBUG_HOOK) + conf.cc.defines += %w(MRB_GC_STRESS MRB_ENABLE_DEBUG_HOOK) conf.enable_test end -- cgit v1.2.3 From f467b02d4598ab64d98727348e8a9c4f04fc9b83 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 24 May 2020 11:44:31 +0900 Subject: Extended `OP_EXCEPT` and `OP_RAISE` (`OP_RAISEIF`) instructions - `OP_EXCEPT` checks if `mrb->exc` is `NULL`, `MRB_TT_EXCEPTION` or `MRB_TT_BREAK`. If `mrb->exc` is `NULL`, it will be replaced with `nil`. - If `OP_RAISE` is `nil`, it does nothing and the immediately following instruction is executed (like `OP_NOP`). Also, in case of `RBreak` object, it moves to the processing for `break`. With this change, the instruction name is changed from `OP_RAISE` to `OP_RAISEIF`. --- doc/opcode.md | 2 +- include/mruby/ops.h | 2 +- mrbgems/mruby-compiler/core/codegen.c | 2 +- src/codedump.c | 4 ++-- src/vm.c | 34 +++++++++++++++++++++++++++++----- 5 files changed, 34 insertions(+), 10 deletions(-) (limited to 'doc') diff --git a/doc/opcode.md b/doc/opcode.md index 98d29cdc0..d7e620350 100644 --- a/doc/opcode.md +++ b/doc/opcode.md @@ -66,7 +66,7 @@ sign) of operands. | OP_EXCEPT | B | R(a) = exc | | OP_RESCUE | BB | R(b) = R(a).isa?(R(b)) | | OP_POPERR | B | a.times{rescue_pop()} | -| OP_RAISE | B | raise(R(a)) | +| OP_RAISEIF | B | raise(R(a)) if R(a) | | OP_EPUSH | B | ensure_push(SEQ[a]) | | OP_EPOP | B | A.times{ensure_pop().call} | | OP_SENDV | BB | R(a) = call(R(a),Syms(b),*R(a+1)) | diff --git a/include/mruby/ops.h b/include/mruby/ops.h index 7d20ac0ad..45397e2ed 100644 --- a/include/mruby/ops.h +++ b/include/mruby/ops.h @@ -53,7 +53,7 @@ OPCODE(ONERR, S) /* rescue_push(a) */ OPCODE(EXCEPT, B) /* R(a) = exc */ OPCODE(RESCUE, BB) /* R(b) = R(a).isa?(R(b)) */ OPCODE(POPERR, B) /* a.times{rescue_pop()} */ -OPCODE(RAISE, B) /* raise(R(a)) */ +OPCODE(RAISEIF, B) /* raise(R(a)) if R(a) */ OPCODE(EPUSH, B) /* ensure_push(SEQ[a]) */ OPCODE(EPOP, B) /* A.times{ensure_pop().call} */ OPCODE(SENDV, BB) /* R(a) = call(R(a),Syms(b),*R(a+1)) */ diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index e55b6791d..7911ecb36 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -1533,7 +1533,7 @@ codegen(codegen_scope *s, node *tree, int val) } if (pos1) { dispatch(s, pos1); - genop_1(s, OP_RAISE, exc); + genop_1(s, OP_RAISEIF, exc); } } pop(); diff --git a/src/codedump.c b/src/codedump.c index a19d60708..2225da4ce 100644 --- a/src/codedump.c +++ b/src/codedump.c @@ -507,8 +507,8 @@ codedump(mrb_state *mrb, const mrb_irep *irep) printf("OP_RESCUE\tR%d\tR%d", a, b); print_lv_ab(mrb, irep, a, b); break; - CASE(OP_RAISE, B); - printf("OP_RAISE\tR%d\t\t", a); + CASE(OP_RAISEIF, B); + printf("OP_RAISEIF\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; CASE(OP_POPERR, B); diff --git a/src/vm.c b/src/vm.c index 3faecfaf2..2dbbe85f8 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1255,8 +1255,24 @@ RETRY_TRY_BLOCK: } CASE(OP_EXCEPT, B) { - mrb_value exc = mrb_obj_value(mrb->exc); - mrb->exc = 0; + mrb_value exc; + + if (mrb->exc == NULL) { + exc = mrb_nil_value(); + } + else { + switch (mrb->exc->tt) { + case MRB_TT_BREAK: + case MRB_TT_EXCEPTION: + exc = mrb_obj_value(mrb->exc); + break; + default: + mrb_assert(!"bad mrb_type"); + exc = mrb_nil_value(); + break; + } + mrb->exc = NULL; + } regs[a] = exc; NEXT; } @@ -1289,9 +1305,17 @@ RETRY_TRY_BLOCK: NEXT; } - CASE(OP_RAISE, B) { - mrb_exc_set(mrb, regs[a]); - goto L_RAISE; + CASE(OP_RAISEIF, B) { + mrb_value exc = regs[a]; + if (mrb_break_p(exc)) { + mrb->exc = mrb_obj_ptr(exc); + goto L_BREAK; + } + mrb_exc_set(mrb, exc); + if (mrb->exc) { + goto L_RAISE; + } + NEXT; } CASE(OP_EPUSH, B) { -- cgit v1.2.3 From 0d7b4deccf445e3edae9239bf40b91cc79e83634 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 24 May 2020 00:42:09 +0900 Subject: Removed push/pop instructions for rescue/ensure `OP_PUSHERR`, `OP_POPERR`, `OP_EPUSH` and `OP_EPOP` are removed. --- doc/opcode.md | 4 --- include/mruby/ops.h | 4 --- src/codedump.c | 12 -------- src/vm.c | 86 ----------------------------------------------------- 4 files changed, 106 deletions(-) (limited to 'doc') diff --git a/doc/opcode.md b/doc/opcode.md index d7e620350..385bf9468 100644 --- a/doc/opcode.md +++ b/doc/opcode.md @@ -62,13 +62,9 @@ sign) of operands. | OP_JMPIF | BS | if R(a) pc=b | | OP_JMPNOT | BS | if !R(a) pc=b | | OP_JMPNIL | BS | if R(a)==nil pc=b | -| OP_ONERR | S | rescue_push(a) | | OP_EXCEPT | B | R(a) = exc | | OP_RESCUE | BB | R(b) = R(a).isa?(R(b)) | -| OP_POPERR | B | a.times{rescue_pop()} | | OP_RAISEIF | B | raise(R(a)) if R(a) | -| OP_EPUSH | B | ensure_push(SEQ[a]) | -| OP_EPOP | B | A.times{ensure_pop().call} | | OP_SENDV | BB | R(a) = call(R(a),Syms(b),*R(a+1)) | | OP_SENDVB | BB | R(a) = call(R(a),Syms(b),*R(a+1),&R(a+2)) | | OP_SEND | BBB | R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c)) | diff --git a/include/mruby/ops.h b/include/mruby/ops.h index 45397e2ed..8ff44088e 100644 --- a/include/mruby/ops.h +++ b/include/mruby/ops.h @@ -49,13 +49,9 @@ OPCODE(JMP, S) /* pc=a */ OPCODE(JMPIF, BS) /* if R(a) pc=b */ OPCODE(JMPNOT, BS) /* if !R(a) pc=b */ OPCODE(JMPNIL, BS) /* if R(a)==nil pc=b */ -OPCODE(ONERR, S) /* rescue_push(a) */ OPCODE(EXCEPT, B) /* R(a) = exc */ OPCODE(RESCUE, BB) /* R(b) = R(a).isa?(R(b)) */ -OPCODE(POPERR, B) /* a.times{rescue_pop()} */ OPCODE(RAISEIF, B) /* raise(R(a)) if R(a) */ -OPCODE(EPUSH, B) /* ensure_push(SEQ[a]) */ -OPCODE(EPOP, B) /* A.times{ensure_pop().call} */ OPCODE(SENDV, BB) /* R(a) = call(R(a),Syms(b),*R(a+1)) */ OPCODE(SENDVB, BB) /* R(a) = call(R(a),Syms(b),*R(a+1),&R(a+2)) */ OPCODE(SEND, BBB) /* R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c)) */ diff --git a/src/codedump.c b/src/codedump.c index 2225da4ce..81212921d 100644 --- a/src/codedump.c +++ b/src/codedump.c @@ -493,12 +493,6 @@ codedump(mrb_state *mrb, const mrb_irep *irep) printf("OP_ERR\tL(%d)\n", a); } break; - CASE(OP_EPUSH, B); - printf("OP_EPUSH\t\t:I(%d:%p)\n", a, irep->reps[a]); - break; - CASE(OP_ONERR, S); - printf("OP_ONERR\t%03d\n", a); - break; CASE(OP_EXCEPT, B); printf("OP_EXCEPT\tR%d\t\t", a); print_lv_a(mrb, irep, a); @@ -511,12 +505,6 @@ codedump(mrb_state *mrb, const mrb_irep *irep) printf("OP_RAISEIF\tR%d\t\t", a); print_lv_a(mrb, irep, a); break; - CASE(OP_POPERR, B); - printf("OP_POPERR\t%d\t\t\n", a); - break; - CASE(OP_EPOP, B); - printf("OP_EPOP\t%d\n", a); - break; CASE(OP_DEBUG, BBB); printf("OP_DEBUG\t%d\t%d\t%d\n", a, b, c); diff --git a/src/vm.c b/src/vm.c index 2dbbe85f8..d11caa5c7 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1231,29 +1231,6 @@ RETRY_TRY_BLOCK: NEXT; } - CASE(OP_ONERR, S) { - /* check rescue stack */ - if (mrb->c->ci->ridx == UINT16_MAX-1) { - mrb_value exc = mrb_exc_new_str_lit(mrb, E_RUNTIME_ERROR, "too many nested rescues"); - mrb_exc_set(mrb, exc); - goto L_RAISE; - } - /* expand rescue stack */ - if (mrb->c->rsize <= mrb->c->ci->ridx) { - if (mrb->c->rsize == 0) mrb->c->rsize = RESCUE_STACK_INIT_SIZE; - else { - mrb->c->rsize *= 2; - if (mrb->c->rsize <= mrb->c->ci->ridx) { - mrb->c->rsize = UINT16_MAX; - } - } - mrb->c->rescue = (uint16_t*)mrb_realloc(mrb, mrb->c->rescue, sizeof(uint16_t)*mrb->c->rsize); - } - /* push rescue stack */ - mrb->c->rescue[mrb->c->ci->ridx++] = a; - NEXT; - } - CASE(OP_EXCEPT, B) { mrb_value exc; @@ -1300,11 +1277,6 @@ RETRY_TRY_BLOCK: NEXT; } - CASE(OP_POPERR, B) { - mrb->c->ci->ridx -= a; - NEXT; - } - CASE(OP_RAISEIF, B) { mrb_value exc = regs[a]; if (mrb_break_p(exc)) { @@ -1318,64 +1290,6 @@ RETRY_TRY_BLOCK: NEXT; } - CASE(OP_EPUSH, B) { - struct RProc *p; - - p = mrb_closure_new(mrb, irep->reps[a]); - /* check ensure stack */ - if (mrb->c->eidx == UINT16_MAX-1) { - mrb_value exc = mrb_exc_new_str_lit(mrb, E_RUNTIME_ERROR, "too many nested ensures"); - mrb_exc_set(mrb, exc); - goto L_RAISE; - } - /* expand ensure stack */ - if (mrb->c->esize <= mrb->c->eidx+1) { - if (mrb->c->esize == 0) mrb->c->esize = ENSURE_STACK_INIT_SIZE; - else { - mrb->c->esize *= 2; - if (mrb->c->esize <= mrb->c->eidx) { - mrb->c->esize = UINT16_MAX; - } - } - mrb->c->ensure = (struct RProc**)mrb_realloc(mrb, mrb->c->ensure, sizeof(struct RProc*)*mrb->c->esize); - } - /* push ensure stack */ - mrb->c->ensure[mrb->c->eidx++] = p; - mrb->c->ensure[mrb->c->eidx] = NULL; - mrb_gc_arena_restore(mrb, ai); - NEXT; - } - - CASE(OP_EPOP, B) { - mrb_callinfo *ci = mrb->c->ci; - unsigned int n, epos = ci->epos; - mrb_value self = regs[0]; - struct RClass *target_class = ci->target_class; - - if (mrb->c->eidx <= epos) { - NEXT; - } - - if (a > (int)mrb->c->eidx - epos) - a = mrb->c->eidx - epos; - for (n=0; nnregs; - - proc = mrb->c->ensure[epos+n]; - mrb->c->ensure[epos+n] = NULL; - if (proc == NULL) continue; - irep = proc->body.irep; - ci = cipush(mrb, pc, nregs, nregs, target_class, proc, ci->mid, 0); - mrb_stack_extend(mrb, irep->nregs); - regs[0] = self; - pc = irep->iseq; - } - pool = irep->pool; - syms = irep->syms; - mrb->c->eidx = epos; - JUMP; - } - CASE(OP_SENDV, BB) { c = CALL_MAXARGS; goto L_SEND; -- cgit v1.2.3 From c1f112c49a597da8478516261f0812bc073f6cd8 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sat, 18 Jul 2020 19:05:12 +0900 Subject: Replace global jump with catch handler implementation When a global jump occurs, look at the catch handler table to determine where to jump. In that case, `pc` already shows the following instruction, but since the table shows `begin_offset ... end_offset`, the comparison is done with `begin_offset < pc && pc <= end_offset`. If there is a corresponding handler, move `pc` to `handler.target_offset` and continue running the VM. When a global jump across `ensure` is made by `return`, `break`, `next`, `redo` and `retry`, the extended `RBreak` object saves and restores the C-level execution position. This extended `RBreak` can have tag information, which makes it a pseudo coroutine (the "tag" mimics CRuby). The implementation of pseudo coroutines by `RBreak` is summarized by `CHECKPOINT_RESTORE ... CHECKPOINT_MAIN ... CHECKPOINT_END` and `throw_tagged_break` / `unwind_ensure` macros. The restart of processing is branched by `RBREAK_TAG_FOREACH(DISPATCH_CHECKPOINTS)`. - Not only `rescue` blocks but also `ensure` blocks are now sandwiched between `OP_EXCEPT` and `OP_RAISEIF`. - Remove the function `ecall()`. It is no longer necessary to re-enter the VM to perform an "ensure block". This will resolves #1888. - Added instruction `OP_JUW` (Jump while UnWind). It jumps unconditionally like `OP_JMP`, but searches the catch handler table and executes the ensure block. Since it searches the catch handler table, it is much heavier than `OP_JMP`. --- doc/opcode.md | 1 + include/mruby.h | 8 - include/mruby/error.h | 33 ++++ include/mruby/ops.h | 1 + mrbgems/mruby-compiler/core/codegen.c | 91 ++++----- mrbgems/mruby-os-memsize/src/memsize.c | 2 - src/codedump.c | 3 + src/gc.c | 8 - src/state.c | 2 - src/vm.c | 339 +++++++++++++++++++++++---------- 10 files changed, 311 insertions(+), 177 deletions(-) (limited to 'doc') diff --git a/doc/opcode.md b/doc/opcode.md index 385bf9468..abdee704f 100644 --- a/doc/opcode.md +++ b/doc/opcode.md @@ -62,6 +62,7 @@ sign) of operands. | OP_JMPIF | BS | if R(a) pc=b | | OP_JMPNOT | BS | if !R(a) pc=b | | OP_JMPNIL | BS | if R(a)==nil pc=b | +| OP_JUW | S | unwind_and_jump_to(a) | | OP_EXCEPT | B | R(a) = exc | | OP_RESCUE | BB | R(b) = R(a).isa?(R(b)) | | OP_RAISEIF | B | raise(R(a)) if R(a) | diff --git a/include/mruby.h b/include/mruby.h index c9425e8a7..9f1d1aa30 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -149,8 +149,6 @@ typedef struct { mrb_sym mid; const struct RProc *proc; mrb_value *stackent; - uint16_t ridx; - uint16_t epos; struct REnv *env; const mrb_code *pc; /* return address */ const mrb_code *err; /* error position */ @@ -177,11 +175,6 @@ struct mrb_context { mrb_callinfo *ci; mrb_callinfo *cibase, *ciend; - uint16_t *rescue; /* exception handler stack */ - uint16_t rsize; - struct RProc **ensure; /* ensure handler stack */ - uint16_t esize, eidx; - enum mrb_fiber_state status : 4; mrb_bool vmexec : 1; struct RFiber *fib; @@ -301,7 +294,6 @@ typedef struct mrb_state { mrb_atexit_func *atexit_stack; #endif uint16_t atexit_stack_len; - uint16_t ecall_nest; /* prevent infinite recursive ecall() */ } mrb_state; /** diff --git a/include/mruby/error.h b/include/mruby/error.h index 72f6c5f3d..67a0a539e 100644 --- a/include/mruby/error.h +++ b/include/mruby/error.h @@ -66,6 +66,39 @@ mrb_break_value_set(struct RBreak *brk, mrb_value val) #define mrb_break_proc_get(brk) ((brk)->proc) #define mrb_break_proc_set(brk, p) ((brk)->proc = p) +#define RBREAK_TAG_FOREACH(f) \ + f(RBREAK_TAG_BREAK, 0) \ + f(RBREAK_TAG_BREAK_UPPER, 1) \ + f(RBREAK_TAG_BREAK_INTARGET, 2) \ + f(RBREAK_TAG_RETURN_BLOCK, 3) \ + f(RBREAK_TAG_RETURN, 4) \ + f(RBREAK_TAG_RETURN_TOPLEVEL, 5) \ + f(RBREAK_TAG_JUMP, 6) \ + f(RBREAK_TAG_STOP, 7) + +#define RBREAK_TAG_DEFINE(tag, i) tag = i, +enum { + RBREAK_TAG_FOREACH(RBREAK_TAG_DEFINE) +}; +#undef RBREAK_TAG_DEFINE + +#define RBREAK_TAG_BIT 3 +#define RBREAK_TAG_BIT_OFF 8 +#define RBREAK_TAG_MASK (~(~UINT32_C(0) << RBREAK_TAG_BIT)) + +static inline uint32_t +mrb_break_tag_get(struct RBreak *brk) +{ + return (brk->flags >> RBREAK_TAG_BIT_OFF) & RBREAK_TAG_MASK; +} + +static inline void +mrb_break_tag_set(struct RBreak *brk, uint32_t tag) +{ + brk->flags &= ~(RBREAK_TAG_MASK << RBREAK_TAG_BIT_OFF); + brk->flags |= (tag & RBREAK_TAG_MASK) << RBREAK_TAG_BIT_OFF; +} + /** * Protect * diff --git a/include/mruby/ops.h b/include/mruby/ops.h index 8ff44088e..770e54f3d 100644 --- a/include/mruby/ops.h +++ b/include/mruby/ops.h @@ -49,6 +49,7 @@ OPCODE(JMP, S) /* pc=a */ OPCODE(JMPIF, BS) /* if R(a) pc=b */ OPCODE(JMPNOT, BS) /* if !R(a) pc=b */ OPCODE(JMPNIL, BS) /* if R(a)==nil pc=b */ +OPCODE(JUW, S) /* unwind_and_jump_to(a) */ OPCODE(EXCEPT, B) /* R(a) = exc */ OPCODE(RESCUE, BB) /* R(b) = R(a).isa?(R(b)) */ OPCODE(RAISEIF, B) /* raise(R(a)) if R(a) */ diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 7911ecb36..b3ce388a9 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -40,7 +40,6 @@ enum looptype { struct loopinfo { enum looptype type; int pc0, pc1, pc2, pc3, acc; - int ensure_level; struct loopinfo *prev; }; @@ -61,7 +60,6 @@ typedef struct scope { mrb_bool mscope:1; struct loopinfo *loop; - int ensure_level; mrb_sym filename_sym; uint16_t lineno; @@ -1465,16 +1463,19 @@ codegen(codegen_scope *s, node *tree, int val) { int noexc, exend, pos1, pos2, tmp; struct loopinfo *lp; + int catch_entry, begin, end; if (tree->car == NULL) goto exit; lp = loop_push(s, LOOP_BEGIN); lp->pc0 = new_label(s); - lp->pc1 = genjmp(s, OP_ONERR, 0); + catch_entry = catch_hander_new(s); + begin = s->pc; codegen(s, tree->car, VAL); pop(); lp->type = LOOP_RESCUE; + end = s->pc; noexc = genjmp(s, OP_JMP, 0); - dispatch(s, lp->pc1); + catch_hander_set(s, catch_entry, MRB_CATCH_RESCUE, begin, end, s->pc); tree = tree->cdr; exend = 0; pos1 = 0; @@ -1539,7 +1540,6 @@ codegen(codegen_scope *s, node *tree, int val) pop(); tree = tree->cdr; dispatch(s, noexc); - genop_1(s, OP_POPERR, 1); if (tree->car) { codegen(s, tree->car, val); } @@ -1555,14 +1555,22 @@ codegen(codegen_scope *s, node *tree, int val) if (!tree->cdr || !tree->cdr->cdr || (nint(tree->cdr->cdr->car) == NODE_BEGIN && tree->cdr->cdr->cdr)) { + int catch_entry, begin, end, target; int idx; - s->ensure_level++; - idx = scope_body(s, tree->cdr, NOVAL); - genop_1(s, OP_EPUSH, idx); + catch_entry = catch_hander_new(s); + begin = s->pc; codegen(s, tree->car, val); - s->ensure_level--; - genop_1(s, OP_EPOP, 1); + end = target = s->pc; + push(); + idx = cursp(); + genop_1(s, OP_EXCEPT, idx); + push(); + codegen(s, tree->cdr->cdr, NOVAL); + pop(); + genop_1(s, OP_RAISEIF, idx); + pop(); + catch_hander_set(s, catch_entry, MRB_CATCH_ENSURE, begin, end, target); } else { /* empty ensure ignored */ codegen(s, tree->car, val); @@ -2024,18 +2032,20 @@ codegen(codegen_scope *s, node *tree, int val) if ((len == 2 && name[0] == '|' && name[1] == '|') && (nint(tree->car->car) == NODE_CONST || nint(tree->car->car) == NODE_CVAR)) { - int onerr, noexc, exc; + int catch_entry, begin, end; + int noexc, exc; struct loopinfo *lp; - onerr = genjmp(s, OP_ONERR, 0); lp = loop_push(s, LOOP_BEGIN); - lp->pc1 = onerr; + lp->pc0 = new_label(s); + catch_entry = catch_hander_new(s); + begin = s->pc; exc = cursp(); codegen(s, tree->car, VAL); - lp->type = LOOP_RESCUE; - genop_1(s, OP_POPERR, 1); + end = s->pc; noexc = genjmp(s, OP_JMP, 0); - dispatch(s, onerr); + lp->type = LOOP_RESCUE; + catch_hander_set(s, catch_entry, MRB_CATCH_RESCUE, begin, end, s->pc); genop_1(s, OP_EXCEPT, exc); genop_1(s, OP_LOADF, exc); dispatch(s, noexc); @@ -2288,11 +2298,8 @@ codegen(codegen_scope *s, node *tree, int val) raise_error(s, "unexpected next"); } else if (s->loop->type == LOOP_NORMAL) { - if (s->ensure_level > s->loop->ensure_level) { - genop_1(s, OP_EPOP, s->ensure_level - s->loop->ensure_level); - } codegen(s, tree, NOVAL); - genjmp(s, OP_JMP, s->loop->pc0); + genjmp(s, OP_JUW, s->loop->pc0); } else { if (tree) { @@ -2312,10 +2319,7 @@ codegen(codegen_scope *s, node *tree, int val) raise_error(s, "unexpected redo"); } else { - if (s->ensure_level > s->loop->ensure_level) { - genop_1(s, OP_EPOP, s->ensure_level - s->loop->ensure_level); - } - genjmp(s, OP_JMP, s->loop->pc2); + genjmp(s, OP_JUW, s->loop->pc2); } if (val) push(); break; @@ -2323,32 +2327,16 @@ codegen(codegen_scope *s, node *tree, int val) case NODE_RETRY: { const char *msg = "unexpected retry"; + const struct loopinfo *lp = s->loop; - if (!s->loop) { + while (lp && lp->type != LOOP_RESCUE) { + lp = lp->prev; + } + if (!lp) { raise_error(s, msg); } else { - struct loopinfo *lp = s->loop; - int n = 0; - - while (lp && lp->type != LOOP_RESCUE) { - if (lp->type == LOOP_BEGIN) { - n++; - } - lp = lp->prev; - } - if (!lp) { - raise_error(s, msg); - } - else { - if (n > 0) { - genop_1(s, OP_POPERR, n); - } - if (s->ensure_level > lp->ensure_level) { - genop_1(s, OP_EPOP, s->ensure_level - lp->ensure_level); - } - genjmp(s, OP_JMP, lp->pc0); - } + genjmp(s, OP_JUW, lp->pc0); } if (val) push(); } @@ -3132,7 +3120,6 @@ loop_push(codegen_scope *s, enum looptype t) p->type = t; p->pc0 = p->pc1 = p->pc2 = p->pc3 = 0; p->prev = s->loop; - p->ensure_level = s->ensure_level; p->acc = cursp(); s->loop = p; @@ -3148,7 +3135,6 @@ loop_break(codegen_scope *s, node *tree) } else { struct loopinfo *loop; - int n = 0; if (tree) { gen_retval(s, tree); @@ -3157,7 +3143,6 @@ loop_break(codegen_scope *s, node *tree) loop = s->loop; while (loop) { if (loop->type == LOOP_BEGIN) { - n++; loop = loop->prev; } else if (loop->type == LOOP_RESCUE) { @@ -3171,20 +3156,14 @@ loop_break(codegen_scope *s, node *tree) raise_error(s, "unexpected break"); return; } - if (n > 0) { - genop_1(s, OP_POPERR, n); - } if (loop->type == LOOP_NORMAL) { int tmp; - if (s->ensure_level > s->loop->ensure_level) { - genop_1(s, OP_EPOP, s->ensure_level - s->loop->ensure_level); - } if (tree) { gen_move(s, loop->acc, cursp(), 0); } - tmp = genjmp(s, OP_JMP, loop->pc3); + tmp = genjmp(s, OP_JUW, loop->pc3); loop->pc3 = tmp; } else { diff --git a/mrbgems/mruby-os-memsize/src/memsize.c b/mrbgems/mruby-os-memsize/src/memsize.c index 191ab062d..7030299f4 100644 --- a/mrbgems/mruby-os-memsize/src/memsize.c +++ b/mrbgems/mruby-os-memsize/src/memsize.c @@ -133,8 +133,6 @@ os_memsize_of_object(mrb_state* mrb, mrb_value obj) size += mrb_objspace_page_slot_size() + sizeof(struct RFiber) + sizeof(struct mrb_context) + - sizeof(struct RProc *) * f->cxt->esize + - sizeof(uint16_t *) * f->cxt->rsize + sizeof(mrb_value) * stack_size + sizeof(mrb_callinfo) * ci_size; break; diff --git a/src/codedump.c b/src/codedump.c index 81212921d..095028a39 100644 --- a/src/codedump.c +++ b/src/codedump.c @@ -261,6 +261,9 @@ codedump(mrb_state *mrb, const mrb_irep *irep) CASE(OP_JMP, S); printf("OP_JMP\t\t%03d\n", a); break; + CASE(OP_JUW, S); + printf("OP_JUW\t\t%03d\n", a); + break; CASE(OP_JMPIF, BS); printf("OP_JMPIF\tR%d\t%03d\t", a, b); print_lv_a(mrb, irep, a); diff --git a/src/gc.c b/src/gc.c index ab9779e1b..17f7e81e4 100644 --- a/src/gc.c +++ b/src/gc.c @@ -640,7 +640,6 @@ mark_context_stack(mrb_state *mrb, struct mrb_context *c) static void mark_context(mrb_state *mrb, struct mrb_context *c) { - int i; mrb_callinfo *ci; start: @@ -657,10 +656,6 @@ mark_context(mrb_state *mrb, struct mrb_context *c) mrb_gc_mark(mrb, (struct RBasic*)ci->target_class); } } - /* mark ensure stack */ - for (i=0; ieidx; i++) { - mrb_gc_mark(mrb, (struct RBasic*)c->ensure[i]); - } /* mark fibers */ mrb_gc_mark(mrb, (struct RBasic*)c->fib); if (c->prev) { @@ -1014,9 +1009,6 @@ gc_gray_counts(mrb_state *mrb, mrb_gc *gc, struct RBasic *obj) if (c->stbase + i > c->stend) i = c->stend - c->stbase; children += i; - /* mark ensure stack */ - children += c->eidx; - /* mark closure */ if (c->cibase) { for (i=0, ci = c->cibase; ci <= c->ci; i++, ci++) diff --git a/src/state.c b/src/state.c index 7a1283fa6..1f85448a1 100644 --- a/src/state.c +++ b/src/state.c @@ -171,8 +171,6 @@ mrb_free_context(mrb_state *mrb, struct mrb_context *c) if (!c) return; mrb_free(mrb, c->stbase); mrb_free(mrb, c->cibase); - mrb_free(mrb, c->rescue); - mrb_free(mrb, c->ensure); mrb_free(mrb, c); } diff --git a/src/vm.c b/src/vm.c index d11caa5c7..cc6f087f9 100644 --- a/src/vm.c +++ b/src/vm.c @@ -23,6 +23,7 @@ #include #include "value_array.h" #include +#include #ifdef MRB_DISABLE_STDIO #if defined(__cplusplus) @@ -280,8 +281,6 @@ cipush(mrb_state *mrb, const mrb_code *pc, int push_stacks, int acc, ci->mid = mid; ci->proc = proc; ci->stackent = c->stack; - ci->epos = c->eidx; - ci->ridx = ci[-1].ridx; ci->pc = pc; ci->argc = argc; ci->acc = acc; @@ -329,54 +328,6 @@ cipop(mrb_state *mrb) void mrb_exc_set(mrb_state *mrb, mrb_value exc); static mrb_value mrb_run(mrb_state *mrb, const struct RProc* proc, mrb_value self); -static void -ecall(mrb_state *mrb) -{ - struct RProc *p; - struct mrb_context *c = mrb->c; - mrb_callinfo *ci = c->ci; - struct RObject *exc; - struct REnv *env; - ptrdiff_t cioff; - int ai = mrb_gc_arena_save(mrb); - uint16_t i; - int nregs; - - if (c->eidx == 0) return; - i = --c->eidx; - - /* restrict total call depth of ecall() */ - if (++mrb->ecall_nest > MRB_ECALL_DEPTH_MAX) { - mrb_exc_raise(mrb, mrb_obj_value(mrb->stack_err)); - } - p = c->ensure[i]; - if (!p) return; - mrb_assert(!MRB_PROC_CFUNC_P(p)); - c->ensure[i] = NULL; - nregs = p->upper->body.irep->nregs; - if (ci->proc && !MRB_PROC_CFUNC_P(ci->proc) && - ci->proc->body.irep->nregs > nregs) { - nregs = ci->proc->body.irep->nregs; - } - cioff = ci - c->cibase; - ci = cipush(mrb, NULL, nregs, CI_ACC_SKIP, MRB_PROC_TARGET_CLASS(p), p, ci->mid, 0); - env = MRB_PROC_ENV(p); - mrb_assert(env); - exc = mrb->exc; mrb->exc = 0; - if (exc) { - mrb_gc_protect(mrb, mrb_obj_value(exc)); - } - if (mrb->c->fib) { - mrb_gc_protect(mrb, mrb_obj_value(mrb->c->fib)); - } - mrb_run(mrb, p, env->stack[0]); - mrb->c = c; - c->ci = c->cibase + cioff; - if (!mrb->exc) mrb->exc = exc; - mrb_gc_arena_restore(mrb, ai); - mrb->ecall_nest--; -} - #ifndef MRB_FUNCALL_ARGC_MAX #define MRB_FUNCALL_ARGC_MAX 16 #endif @@ -821,17 +772,56 @@ mrb_yield_cont(mrb_state *mrb, mrb_value b, mrb_value self, mrb_int argc, const } static struct RBreak* -break_new(mrb_state *mrb, const struct RProc *p, mrb_value val) +break_new(mrb_state *mrb, uint32_t tag, const struct RProc *p, mrb_value val) { struct RBreak *brk; brk = (struct RBreak*)mrb_obj_alloc(mrb, MRB_TT_BREAK, NULL); mrb_break_proc_set(brk, p); mrb_break_value_set(brk, val); + mrb_break_tag_set(brk, tag); return brk; } +#define MRB_CATCH_FILTER_RESCUE (UINT32_C(1) << MRB_CATCH_RESCUE) +#define MRB_CATCH_FILTER_ENSURE (UINT32_C(1) << MRB_CATCH_ENSURE) +#define MRB_CATCH_FILTER_ALL (MRB_CATCH_FILTER_RESCUE | MRB_CATCH_FILTER_ENSURE) + +static const struct mrb_irep_catch_hander * +catch_handler_find(mrb_state *mrb, mrb_callinfo *ci, const mrb_code *pc, uint32_t filter) +{ + mrb_irep *irep; + ptrdiff_t xpc; + size_t cnt; + const struct mrb_irep_catch_hander *e; + +/* The comparison operators use `>` and `<=` because pc already points to the next instruction */ +#define catch_cover_p(pc, beg, end) ((pc) > (beg) && (pc) <= (end)) + + if (ci->proc == NULL || MRB_PROC_CFUNC_P(ci->proc)) return NULL; + irep = ci->proc->body.irep; + if (irep->clen < 1) return NULL; + xpc = pc - irep->iseq; + /* If it retry at the top level, pc will be 0, so check with -1 as the start position */ + mrb_assert(catch_cover_p(xpc, -1, irep->ilen)); + if (!catch_cover_p(xpc, -1, irep->ilen)) return NULL; + + /* Currently uses a simple linear search to avoid processing complexity. */ + cnt = irep->clen; + e = mrb_irep_catch_handler_table(irep) + cnt - 1; + for (; cnt > 0; cnt --, e --) { + if (((UINT32_C(1) << e->type) & filter) && + catch_cover_p(xpc, bin_to_uint16(e->begin), bin_to_uint16(e->end))) { + return e; + } + } + +#undef catch_cover_p + + return NULL; +} + typedef enum { LOCALJUMP_ERROR_RETURN = 0, LOCALJUMP_ERROR_BREAK = 1, @@ -878,6 +868,81 @@ argnum_error(mrb_state *mrb, mrb_int num) mrb_exc_set(mrb, exc); } +static mrb_bool +break_tag_p(struct RBreak *brk, uint32_t tag) +{ + return (brk != NULL && brk->tt == MRB_TT_BREAK) ? TRUE : FALSE; +} + +static void +prepare_tagged_break(mrb_state *mrb, uint32_t tag, struct RProc *proc, mrb_value val) +{ + if (break_tag_p((struct RBreak*)mrb->exc, tag)) { + mrb_break_tag_set((struct RBreak*)mrb->exc, tag); + } + else { + mrb->exc = (struct RObject*)break_new(mrb, tag, proc, val); + } +} + +#define THROW_TAGGED_BREAK(mrb, tag, proc, val) \ + do { \ + prepare_tagged_break(mrb, tag, proc, val); \ + goto L_CATCH_TAGGED_BREAK; \ + } while (0) + +#define UNWIND_ENSURE(mrb, ci, pc, tag, proc, val) \ + do { \ + ch = catch_handler_find(mrb, ci, pc, MRB_CATCH_FILTER_ENSURE); \ + if (ch) { \ + THROW_TAGGED_BREAK(mrb, tag, proc, val); \ + } \ + } while (0) + +/* + * CHECKPOINT_RESTORE(tag) { + * This part is executed when jumping by the same "tag" of RBreak (it is not executed the first time). + * Write the code required (initialization of variables, etc.) for the subsequent processing. + * } + * CHECKPOINT_MAIN(tag) { + * This part is always executed. + * } + * CHECKPOINT_END(tag); + * + * ... + * + * // Jump to CHECKPOINT_RESTORE with the same "tag". + * goto CHECKPOINT_LABEL_MAKE(tag); + */ + +#define CHECKPOINT_LABEL_MAKE(tag) L_CHECKPOINT_ ## tag + +#define CHECKPOINT_RESTORE(tag) \ + do { \ + DEBUG_ONLY_EXPR(int current_checkpoint_tag); \ + DEBUG_ONLY_EXPR(current_checkpoint_tag = (tag)); \ + if (FALSE) { \ + CHECKPOINT_LABEL_MAKE(tag): \ + DEBUG_ONLY_EXPR(current_checkpoint_tag = (tag)); \ + do { + +#define CHECKPOINT_MAIN(tag) \ + } while (0); \ + } \ + mrb_assert((tag) == current_checkpoint_tag); \ + do { + +#define CHECKPOINT_END(tag) \ + } while (0); \ + mrb_assert((tag) == current_checkpoint_tag); \ + } while (0) + +#ifdef MRB_DEBUG +#define DEBUG_ONLY_EXPR(e) e +#else +#define DEBUG_ONLY_EXPR(e) ((void)0) +#endif + #define ERR_PC_SET(mrb) mrb->c->ci->err = pc0; #define ERR_PC_CLR(mrb) mrb->c->ci->err = 0; #ifdef MRB_ENABLE_DEBUG_HOOK @@ -976,6 +1041,7 @@ mrb_vm_exec(mrb_state *mrb, const struct RProc *proc, const mrb_code *pc) uint16_t b; uint8_t c; mrb_sym mid; + const struct mrb_irep_catch_hander *ch; #ifdef DIRECT_THREADED static void *optable[] = { @@ -1231,6 +1297,30 @@ RETRY_TRY_BLOCK: NEXT; } + CASE(OP_JUW, S) { + CHECKPOINT_RESTORE(RBREAK_TAG_JUMP) { + struct RBreak *brk = (struct RBreak*)mrb->exc; + mrb_value target = mrb_break_value_get(brk); + mrb_assert(mrb_fixnum_p(target)); + a = mrb_fixnum(target); + mrb_assert(a >= 0 && a < irep->ilen); + } + CHECKPOINT_MAIN(RBREAK_TAG_JUMP) { + ch = catch_handler_find(mrb, mrb->c->ci, pc, MRB_CATCH_FILTER_ENSURE); + if (ch) { + /* avoiding a jump from a catch handler into the same handler */ + if (a < bin_to_uint16(ch->begin) || a >= bin_to_uint16(ch->end)) { + THROW_TAGGED_BREAK(mrb, RBREAK_TAG_JUMP, proc, mrb_fixnum_value(a)); + } + } + } + CHECKPOINT_END(RBREAK_TAG_JUMP); + + mrb->exc = NULL; /* clear break object */ + pc = irep->iseq + a; + JUMP; + } + CASE(OP_EXCEPT, B) { mrb_value exc; @@ -1563,6 +1653,7 @@ RETRY_TRY_BLOCK: mrb_gc_arena_restore(mrb, ai); if (mrb->exc) goto L_RAISE; ci = mrb->c->ci; + mrb_assert(!mrb_break_p(v)); if (!ci->target_class) { /* return from context modifying method (resume/yield) */ if (ci->acc == CI_ACC_RESUMED) { mrb->jmp = prev_jmp; @@ -1839,13 +1930,7 @@ RETRY_TRY_BLOCK: c = OP_R_NORMAL; L_RETURN: { - mrb_callinfo *ci; - -#define ecall_adjust() do {\ - ptrdiff_t cioff = ci - mrb->c->cibase;\ - ecall(mrb);\ - ci = mrb->c->cibase + cioff;\ -} while (0) + mrb_callinfo *ci; ci = mrb->c->ci; if (ci->mid) { @@ -1873,17 +1958,20 @@ RETRY_TRY_BLOCK: L_RAISE: ci0 = ci = mrb->c->ci; if (ci == mrb->c->cibase) { - if (ci->ridx == 0) goto L_FTOP; - goto L_RESCUE; + ch = catch_handler_find(mrb, ci, pc, MRB_CATCH_FILTER_ALL); + if (ch == NULL) goto L_FTOP; + goto L_CATCH; } - while (ci[0].ridx == ci[-1].ridx) { + while ((ch = catch_handler_find(mrb, ci, pc, MRB_CATCH_FILTER_ALL)) == NULL) { ci = cipop(mrb); if (ci[1].acc == CI_ACC_SKIP && prev_jmp) { mrb->jmp = prev_jmp; MRB_THROW(prev_jmp); } + pc = ci[1].pc; if (ci == mrb->c->cibase) { - if (ci->ridx == 0) { + ch = catch_handler_find(mrb, ci, pc, MRB_CATCH_FILTER_ALL); + if (ch == NULL) { L_FTOP: /* fiber top */ if (mrb->c == mrb->root_c) { mrb->c->stack = mrb->c->stbase; @@ -1892,9 +1980,6 @@ RETRY_TRY_BLOCK: else { struct mrb_context *c = mrb->c; - while (c->eidx > ci->epos) { - ecall_adjust(); - } c->status = MRB_FIBER_TERMINATED; mrb->c = c->prev; c->prev = NULL; @@ -1903,15 +1988,13 @@ RETRY_TRY_BLOCK: } break; } - /* call ensure only when we skip this callinfo */ - if (ci[0].ridx == ci[-1].ridx) { - while (mrb->c->eidx > ci->epos) { - ecall_adjust(); - } - } } - L_RESCUE: - if (ci->ridx == 0) goto L_STOP; + L_CATCH: + if (ch == NULL) goto L_STOP; + if (FALSE) { + L_CATCH_TAGGED_BREAK: /* from THROW_TAGGED_BREAK() or UNWIND_ENSURE() */ + ci = ci0 = mrb->c->ci; + } proc = ci->proc; irep = proc->body.irep; pool = irep->pool; @@ -1920,7 +2003,7 @@ RETRY_TRY_BLOCK: mrb->c->stack = ci[1].stackent; } mrb_stack_extend(mrb, irep->nregs); - pc = irep->iseq+mrb->c->rescue[--ci->ridx]; + pc = irep->iseq + bin_to_uint16(ch->target); } else { int acc; @@ -1950,8 +2033,19 @@ RETRY_TRY_BLOCK: localjump_error(mrb, LOCALJUMP_ERROR_RETURN); goto L_RAISE; } - ci--; + CHECKPOINT_RESTORE(RBREAK_TAG_RETURN_BLOCK) { + cibase = mrb->c->cibase; + dst = top_proc(mrb, proc); + } + CHECKPOINT_MAIN(RBREAK_TAG_RETURN_BLOCK) { + UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_RETURN_BLOCK, proc, v); + } + CHECKPOINT_END(RBREAK_TAG_RETURN_BLOCK); + pc = ci->pc; + ci = cipop(mrb); } + mrb->exc = NULL; /* clear break object */ + proc = ci->proc; if (ci <= cibase) { localjump_error(mrb, LOCALJUMP_ERROR_RETURN); goto L_RAISE; @@ -1966,16 +2060,20 @@ RETRY_TRY_BLOCK: if (!c->prev) { /* toplevel return */ regs[irep->nlocals] = v; - goto L_STOP; + goto CHECKPOINT_LABEL_MAKE(RBREAK_TAG_STOP); } if (c->prev->ci == c->prev->cibase) { mrb_value exc = mrb_exc_new_str_lit(mrb, E_FIBER_ERROR, "double resume"); mrb_exc_set(mrb, exc); goto L_RAISE; } - while (c->eidx > 0) { - ecall(mrb); + CHECKPOINT_RESTORE(RBREAK_TAG_RETURN_TOPLEVEL) { + c = mrb->c; } + CHECKPOINT_MAIN(RBREAK_TAG_RETURN_TOPLEVEL) { + UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_RETURN_TOPLEVEL, proc, v); + } + CHECKPOINT_END(RBREAK_TAG_RETURN_TOPLEVEL); /* automatic yield at the end */ c->status = MRB_FIBER_TERMINATED; mrb->c = c->prev; @@ -1983,6 +2081,14 @@ RETRY_TRY_BLOCK: mrb->c->status = MRB_FIBER_RUNNING; ci = mrb->c->ci; } + CHECKPOINT_RESTORE(RBREAK_TAG_RETURN) { + /* do nothing */ + } + CHECKPOINT_MAIN(RBREAK_TAG_RETURN) { + UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_RETURN, proc, v); + } + CHECKPOINT_END(RBREAK_TAG_RETURN); + mrb->exc = NULL; /* clear break object */ break; case OP_R_BREAK: if (MRB_PROC_STRICT_P(proc)) goto NORMAL_RETURN; @@ -2005,9 +2111,13 @@ RETRY_TRY_BLOCK: goto L_BREAK_ERROR; } } - while (mrb->c->eidx > mrb->c->ci->epos) { - ecall_adjust(); + CHECKPOINT_RESTORE(RBREAK_TAG_BREAK) { + /* do nothing */ } + CHECKPOINT_MAIN(RBREAK_TAG_BREAK) { + UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_BREAK, proc, v); + } + CHECKPOINT_END(RBREAK_TAG_BREAK); /* break from fiber block */ if (ci == mrb->c->cibase && ci->pc) { struct mrb_context *c = mrb->c; @@ -2017,45 +2127,64 @@ RETRY_TRY_BLOCK: ci = mrb->c->ci; } if (ci->acc < 0) { + ci = cipop(mrb); mrb_gc_arena_restore(mrb, ai); mrb->c->vmexec = FALSE; - mrb->exc = (struct RObject*)break_new(mrb, proc, v); + mrb->exc = (struct RObject*)break_new(mrb, RBREAK_TAG_BREAK, proc, v); mrb->jmp = prev_jmp; MRB_THROW(prev_jmp); } if (FALSE) { + struct RBreak *brk; + L_BREAK: - v = mrb_break_value_get((struct RBreak*)mrb->exc); - proc = mrb_break_proc_get((struct RBreak*)mrb->exc); - mrb->exc = NULL; + brk = (struct RBreak*)mrb->exc; + proc = mrb_break_proc_get(brk); + v = mrb_break_value_get(brk); ci = mrb->c->ci; + + switch (mrb_break_tag_get(brk)) { +#define DISPATCH_CHECKPOINTS(n, i) case n: goto CHECKPOINT_LABEL_MAKE(n); + RBREAK_TAG_FOREACH(DISPATCH_CHECKPOINTS) +#undef DISPATCH_CHECKPOINTS + default: + mrb_assert(!"wrong break tag"); + } } mrb->c->stack = ci->stackent; - proc = proc->upper; - while (mrb->c->cibase < ci && ci[-1].proc != proc) { + while (mrb->c->cibase < ci && ci[-1].proc != proc->upper) { if (ci[-1].acc == CI_ACC_SKIP) { - while (ci < mrb->c->ci) { - cipop(mrb); - } goto L_BREAK_ERROR; } - ci--; + CHECKPOINT_RESTORE(RBREAK_TAG_BREAK_UPPER) { + /* do nothing */ + } + CHECKPOINT_MAIN(RBREAK_TAG_BREAK_UPPER) { + UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_BREAK_UPPER, proc, v); + } + CHECKPOINT_END(RBREAK_TAG_BREAK_UPPER); + pc = ci->pc; + ci = cipop(mrb); } + CHECKPOINT_RESTORE(RBREAK_TAG_BREAK_INTARGET) { + /* do nothing */ + } + CHECKPOINT_MAIN(RBREAK_TAG_BREAK_INTARGET) { + UNWIND_ENSURE(mrb, ci, pc, RBREAK_TAG_BREAK_INTARGET, proc, v); + } + CHECKPOINT_END(RBREAK_TAG_BREAK_INTARGET); if (ci == mrb->c->cibase) { goto L_BREAK_ERROR; } + mrb->exc = NULL; /* clear break object */ break; default: /* cannot happen */ break; } - while (ci < mrb->c->ci) { - cipop(mrb); - } - ci[0].ridx = ci[-1].ridx; - while (mrb->c->eidx > ci->epos) { - ecall_adjust(); - } + mrb_assert(ci == mrb->c->ci); + mrb_assert(mrb->exc == NULL); + if (mrb->c->vmexec && !ci->target_class) { mrb_gc_arena_restore(mrb, ai); mrb->c->vmexec = FALSE; @@ -2679,14 +2808,18 @@ RETRY_TRY_BLOCK: CASE(OP_STOP, Z) { /* stop VM */ - L_STOP: - while (mrb->c->eidx > 0) { - ecall(mrb); + CHECKPOINT_RESTORE(RBREAK_TAG_STOP) { + /* do nothing */ + } + CHECKPOINT_MAIN(RBREAK_TAG_STOP) { + UNWIND_ENSURE(mrb, mrb->c->ci, pc, RBREAK_TAG_STOP, proc, mrb_nil_value()); } - mrb->c->cibase->ridx = 0; + CHECKPOINT_END(RBREAK_TAG_STOP); + L_STOP: ERR_PC_CLR(mrb); mrb->jmp = prev_jmp; if (mrb->exc) { + mrb_assert(mrb->exc->tt == MRB_TT_EXCEPTION); return mrb_obj_value(mrb->exc); } return regs[irep->nlocals]; @@ -2696,6 +2829,10 @@ RETRY_TRY_BLOCK: #undef regs } MRB_CATCH(&c_jmp) { + mrb_callinfo *ci = mrb->c->ci; + while (ci > mrb->c->cibase && ci->acc == CI_ACC_DIRECT) { + ci = cipop(mrb); + } exc_catched = TRUE; goto RETRY_TRY_BLOCK; } -- cgit v1.2.3 From 107c777341c4768f0208e590a9ec6c8b9a241060 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 8 Aug 2020 15:57:42 +0900 Subject: Rename `OP_JUW` instruction to `OP_JMPUW`. --- doc/opcode.md | 2 +- include/mruby/ops.h | 2 +- mrbgems/mruby-compiler/core/codegen.c | 8 ++++---- src/codedump.c | 4 ++-- src/vm.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'doc') diff --git a/doc/opcode.md b/doc/opcode.md index abdee704f..513b28302 100644 --- a/doc/opcode.md +++ b/doc/opcode.md @@ -62,7 +62,7 @@ sign) of operands. | OP_JMPIF | BS | if R(a) pc=b | | OP_JMPNOT | BS | if !R(a) pc=b | | OP_JMPNIL | BS | if R(a)==nil pc=b | -| OP_JUW | S | unwind_and_jump_to(a) | +| OP_JMPUW | S | unwind_and_jump_to(a) | | OP_EXCEPT | B | R(a) = exc | | OP_RESCUE | BB | R(b) = R(a).isa?(R(b)) | | OP_RAISEIF | B | raise(R(a)) if R(a) | diff --git a/include/mruby/ops.h b/include/mruby/ops.h index 770e54f3d..75936a791 100644 --- a/include/mruby/ops.h +++ b/include/mruby/ops.h @@ -49,7 +49,7 @@ OPCODE(JMP, S) /* pc=a */ OPCODE(JMPIF, BS) /* if R(a) pc=b */ OPCODE(JMPNOT, BS) /* if !R(a) pc=b */ OPCODE(JMPNIL, BS) /* if R(a)==nil pc=b */ -OPCODE(JUW, S) /* unwind_and_jump_to(a) */ +OPCODE(JMPUW, S) /* unwind_and_jump_to(a) */ OPCODE(EXCEPT, B) /* R(a) = exc */ OPCODE(RESCUE, BB) /* R(b) = R(a).isa?(R(b)) */ OPCODE(RAISEIF, B) /* raise(R(a)) if R(a) */ diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 2ede5b81e..f60f1f077 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -2299,7 +2299,7 @@ codegen(codegen_scope *s, node *tree, int val) } else if (s->loop->type == LOOP_NORMAL) { codegen(s, tree, NOVAL); - genjmp(s, OP_JUW, s->loop->pc0); + genjmp(s, OP_JMPUW, s->loop->pc0); } else { if (tree) { @@ -2319,7 +2319,7 @@ codegen(codegen_scope *s, node *tree, int val) raise_error(s, "unexpected redo"); } else { - genjmp(s, OP_JUW, s->loop->pc2); + genjmp(s, OP_JMPUW, s->loop->pc2); } if (val) push(); break; @@ -2336,7 +2336,7 @@ codegen(codegen_scope *s, node *tree, int val) raise_error(s, msg); } else { - genjmp(s, OP_JUW, lp->pc0); + genjmp(s, OP_JMPUW, lp->pc0); } if (val) push(); } @@ -3163,7 +3163,7 @@ loop_break(codegen_scope *s, node *tree) if (tree) { gen_move(s, loop->acc, cursp(), 0); } - tmp = genjmp(s, OP_JUW, loop->pc3); + tmp = genjmp(s, OP_JMPUW, loop->pc3); loop->pc3 = tmp; } else { diff --git a/src/codedump.c b/src/codedump.c index 389ed3c8f..3f0801929 100644 --- a/src/codedump.c +++ b/src/codedump.c @@ -261,8 +261,8 @@ codedump(mrb_state *mrb, const mrb_irep *irep) CASE(OP_JMP, S); printf("OP_JMP\t\t%03d\n", a); break; - CASE(OP_JUW, S); - printf("OP_JUW\t\t%03d\n", a); + CASE(OP_JMPUW, S); + printf("OP_JMPUW\t\t%03d\n", a); break; CASE(OP_JMPIF, BS); printf("OP_JMPIF\tR%d\t%03d\t", a, b); diff --git a/src/vm.c b/src/vm.c index 727c37d53..82301aaf4 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1298,7 +1298,7 @@ RETRY_TRY_BLOCK: NEXT; } - CASE(OP_JUW, S) { + CASE(OP_JMPUW, S) { CHECKPOINT_RESTORE(RBREAK_TAG_JUMP) { struct RBreak *brk = (struct RBreak*)mrb->exc; mrb_value target = mrb_break_value_get(brk); -- cgit v1.2.3 From 72d071540ce5bc249ebd986596eb7c3db77e0bfb Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 14 Aug 2020 07:52:20 +0900 Subject: Rename `MRB_METHOD_T_STRUCT` to `MRB_USE_METHOD_T_STRUCT`. It's the first change of renaming configuration options to `MRB_XXX` to `MRB_USE_XXX` or `MRB_NO_XXX`. --- doc/guides/mrbconf.md | 4 ++-- include/mrbconf.h | 8 ++++---- include/mruby.h | 2 +- include/mruby/proc.h | 5 +++-- 4 files changed, 10 insertions(+), 9 deletions(-) (limited to 'doc') diff --git a/doc/guides/mrbconf.md b/doc/guides/mrbconf.md index 003c2b300..d662e05bf 100644 --- a/doc/guides/mrbconf.md +++ b/doc/guides/mrbconf.md @@ -171,9 +171,9 @@ largest value of required alignment. * Ignored if `MRB_NO_METHOD_CACHE` is defined. * Need to be the power of 2. -`MRB_METHOD_T_STRUCT` +`MRB_USE_METHOD_T_STRUCT` * Use C struct to represent `mrb_method_t` -* No `MRB_METHOD_T_STRUCT` requires highest 2 bits of function pointers to be zero +* No `MRB_USE_METHOD_T_STRUCT` requires highest 2 bits of function pointers to be zero * Define this macro on machines that use higher bits of pointers `MRB_ENABLE_ALL_SYMBOLS` diff --git a/include/mrbconf.h b/include/mrbconf.h index 3241346b2..734ec98e7 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -47,13 +47,13 @@ /* size of the method cache (need to be the power of 2) */ //#define MRB_METHOD_CACHE_SIZE (1<<8) -/* add -DMRB_METHOD_T_STRUCT on machines that use higher bits of pointers */ -/* no MRB_METHOD_T_STRUCT requires highest 2 bits of function pointers to be zero */ -#ifndef MRB_METHOD_T_STRUCT +/* add -DMRB_USE_METHOD_T_STRUCT on machines that use higher bits of function pointers */ +/* no MRB_USE_METHOD_T_STRUCT requires highest 2 bits of function pointers to be zero */ +#ifndef MRB_USE_METHOD_T_STRUCT // can't use highest 2 bits of function pointers at least on 32bit // Windows and 32bit Linux. # ifdef MRB_32BIT -# define MRB_METHOD_T_STRUCT +# define MRB_USE_METHOD_T_STRUCT # endif #endif diff --git a/include/mruby.h b/include/mruby.h index 9f1d1aa30..dea0a9c88 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -199,7 +199,7 @@ struct mrb_context { */ typedef mrb_value (*mrb_func_t)(struct mrb_state *mrb, mrb_value self); -#ifndef MRB_METHOD_T_STRUCT +#ifndef MRB_USE_METHOD_T_STRUCT typedef uintptr_t mrb_method_t; #else typedef struct { diff --git a/include/mruby/proc.h b/include/mruby/proc.h index fe0cf2eb0..c14c1ff9c 100644 --- a/include/mruby/proc.h +++ b/include/mruby/proc.h @@ -101,7 +101,8 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx); #define MRB_METHOD_FUNC_FL 1 #define MRB_METHOD_NOARG_FL 2 -#ifndef MRB_METHOD_T_STRUCT + +#ifndef MRB_USE_METHOD_T_STRUCT #define MRB_METHOD_FUNC_P(m) (((uintptr_t)(m))&MRB_METHOD_FUNC_FL) #define MRB_METHOD_NOARG_P(m) (((uintptr_t)(m))&MRB_METHOD_NOARG_FL) @@ -125,7 +126,7 @@ MRB_API mrb_value mrb_proc_cfunc_env_get(mrb_state *mrb, mrb_int idx); #define MRB_METHOD_PROC(m) ((m).proc) #define MRB_METHOD_UNDEF_P(m) ((m).proc==NULL) -#endif /* MRB_METHOD_T_STRUCT */ +#endif /* MRB_USE_METHOD_T_STRUCT */ #define MRB_METHOD_CFUNC_P(m) (MRB_METHOD_FUNC_P(m)?TRUE:(MRB_METHOD_PROC(m)?(MRB_PROC_CFUNC_P(MRB_METHOD_PROC(m))):FALSE)) #define MRB_METHOD_CFUNC(m) (MRB_METHOD_FUNC_P(m)?MRB_METHOD_FUNC(m):((MRB_METHOD_PROC(m)&&MRB_PROC_CFUNC_P(MRB_METHOD_PROC(m)))?MRB_PROC_CFUNC(MRB_METHOD_PROC(m)):NULL)) -- cgit v1.2.3 From 7dc595f98f86aa4f10f4d926086b859eab8e590e Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 14 Aug 2020 10:10:12 +0900 Subject: Add a new document named `mruby3.md`. That describes the changes in `mruby3`. --- doc/mruby3.md | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 doc/mruby3.md (limited to 'doc') diff --git a/doc/mruby3.md b/doc/mruby3.md new file mode 100644 index 000000000..75bd5870e --- /dev/null +++ b/doc/mruby3.md @@ -0,0 +1,61 @@ +User visible changes in `mruby3` +=== + += New Syntax + +We have ported some new syntax from CRuby. + +* R-assignment (`12 => x`) +* Numbered block parameter (`x.map{_1 * 2}`) +* End-less `def` (`def double(x) = x*2`) + += Build System + +You can specify `TARGET` option to `rake` via a command line +option, or via an environment variable, e.g. + +`rake TARGET=host all` + +or + +`TARGET=host rake all` + +It's much easier to switch multiple targets than the +previous `build_config.rb` system. + +== `presym` target + +The first compilation of `mruby` may require generation of a +static symbol table named `build/presym`. You can generate +the table by `rake gensym`. + +== `target` directory + +Build target specification files are loaded from `target` +directory. The default `TARGET` is `host` which is described +in `target/host.rb`. There are many other targets for example: + +* `host-gprof`: compiles with `gprof` for performance tuning +* `host-m32`: compiles in gcc 32bit mode on 64bit platforms +* `boxing`: compiles all three boxing options +* `clang-asan`: compiles with `clang`'s Address Sanitizer + +`target/host.rb` comes with comments to help writing a new +target description. + += Build Target Contribution + +When you write a new target description, please +contribute. We welcome your contribution as a GitHub +pull-request. + += Configuration Options + +Some configuration macro names are changed for consistency + +== `MRB_USE_METHOD_T_STRUCT` + +Changed from `MRB_METHOD_T_STRUCT`. + +To use `struct` version of `mrb_method_t`. More portable but consumes more memory. +Turned on by default on 32bit platforms. -- cgit v1.2.3 From ef9df5dc7d32b79e6b4e0d6924eeae2cc614dfce Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 14 Aug 2020 14:15:29 +0900 Subject: Allow `MRUBY_CONFIG` to specify target file out of source tree. --- Rakefile | 9 +++++++-- doc/mruby3.md | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/Rakefile b/Rakefile index 2198b27fd..52b4c75c1 100644 --- a/Rakefile +++ b/Rakefile @@ -14,8 +14,13 @@ require "mruby-core-ext" require "mruby/build" # load configuration file -MRUBY_TARGET = ENV['MRUBY_TARGET'] || ENV['TARGET'] || "host" -MRUBY_CONFIG = "#{MRUBY_ROOT}/target/#{MRUBY_TARGET}.rb" +if ENV['MRUBY_CONFIG'] + MRUBY_CONFIG = ENV['MRUBY_CONFIG'] + MRUBY_TARGET = File.basename(MRUBY_CONFIG, ".rb") +else + MRUBY_TARGET = ENV['MRUBY_TARGET'] || ENV['TARGET'] || "host" + MRUBY_CONFIG = "#{MRUBY_ROOT}/target/#{MRUBY_TARGET}.rb" +end load MRUBY_CONFIG # load basic rules diff --git a/doc/mruby3.md b/doc/mruby3.md index 75bd5870e..29da25cbc 100644 --- a/doc/mruby3.md +++ b/doc/mruby3.md @@ -43,6 +43,10 @@ in `target/host.rb`. There are many other targets for example: `target/host.rb` comes with comments to help writing a new target description. +If you want to have your target description out of the +source tree, you can specify the path to the description +file in `MRUBY_CONFIG`. + = Build Target Contribution When you write a new target description, please -- cgit v1.2.3 From 8a87549315d0c7fd984a8ad239ebe3dbab4d2855 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 14 Aug 2020 14:34:53 +0900 Subject: Rename float configuration option names. - `MRB_WITHOUT_FLOAT` => `MRB_NO_FLOAT` - `MRB_USE_FLOAT` => `MRB_USE_FLOAT32` The former is to use `USE_XXX` naming convention. The latter is to make sure `float` is 32bit float and not floating point number in general. --- doc/guides/mrbconf.md | 8 +-- doc/mruby3.md | 11 ++++ include/mrbconf.h | 22 ++++++-- include/mruby.h | 10 ++-- include/mruby/boxing_nan.h | 8 +-- include/mruby/boxing_no.h | 6 +- include/mruby/boxing_word.h | 12 ++-- include/mruby/class.h | 2 +- include/mruby/error.h | 4 +- include/mruby/numeric.h | 16 +++--- include/mruby/value.h | 10 ++-- mrbgems/mruby-compiler/core/codegen.c | 16 +++--- mrbgems/mruby-compiler/core/parse.y | 4 +- mrbgems/mruby-compiler/core/y.tab.c | 4 +- mrbgems/mruby-complex/src/complex.c | 8 +-- mrbgems/mruby-complex/test/complex.rb | 4 +- mrbgems/mruby-inline-struct/test/inline.c | 2 +- mrbgems/mruby-io/src/file.c | 4 +- mrbgems/mruby-io/src/io.c | 6 +- mrbgems/mruby-kernel-ext/src/kernel.c | 4 +- mrbgems/mruby-math/src/math.c | 4 +- mrbgems/mruby-numeric-ext/src/numeric_ext.c | 4 +- mrbgems/mruby-object-ext/src/object.c | 4 +- mrbgems/mruby-os-memsize/src/memsize.c | 2 +- mrbgems/mruby-pack/src/pack.c | 8 +-- mrbgems/mruby-random/src/random.c | 4 +- mrbgems/mruby-range-ext/src/range.c | 4 +- mrbgems/mruby-rational/src/rational.c | 6 +- mrbgems/mruby-sleep/src/mrb_sleep.c | 2 +- mrbgems/mruby-sprintf/src/sprintf.c | 10 ++-- mrbgems/mruby-string-ext/src/string.c | 2 +- mrbgems/mruby-test/driver.c | 4 +- mrbgems/mruby-test/vformat.c | 4 +- mrbgems/mruby-time/src/time.c | 20 +++---- src/array.c | 2 +- src/class.c | 4 +- src/dump.c | 10 ++-- src/error.c | 2 +- src/etc.c | 10 ++-- src/fmt_fp.c | 2 +- src/gc.c | 6 +- src/hash.c | 8 +-- src/load.c | 6 +- src/numeric.c | 88 ++++++++++++++--------------- src/object.c | 12 ++-- src/range.c | 2 +- src/string.c | 10 ++-- src/vm.c | 16 +++--- target/RX630.rb | 2 +- tasks/gitlab.rake | 4 +- test/t/float.rb | 2 +- 51 files changed, 223 insertions(+), 202 deletions(-) (limited to 'doc') diff --git a/doc/guides/mrbconf.md b/doc/guides/mrbconf.md index d662e05bf..c95634604 100644 --- a/doc/guides/mrbconf.md +++ b/doc/guides/mrbconf.md @@ -46,11 +46,11 @@ You can use mrbconfs with following ways: ## Primitive type configuration. -`MRB_USE_FLOAT` +`MRB_USE_FLOAT32` * When defined single precision floating point type(C type `float`) is used as `mrb_float`. -* Else double precision floating point type(C type `double`) is used as `mrb_float`. +* Otherwise double precision floating point type(C type `double`) is used as `mrb_float`. -`MRB_WITHOUT_FLOAT` +`MRB_NO_FLOAT` * When defined removes floating point numbers from mruby. * It makes mruby easier to handle in "Microcontroller without FPU" and "Kernel Space". @@ -117,7 +117,7 @@ largest value of required alignment. `MRB_NAN_BOXING` * If defined represent `mrb_value` in boxed `double`. -* Conflicts with `MRB_USE_FLOAT` and `MRB_WITHOUT_FLOAT`. +* Conflicts with `MRB_USE_FLOAT32` and `MRB_NO_FLOAT`. `MRB_WORD_BOXING` * If defined represent `mrb_value` as a word. diff --git a/doc/mruby3.md b/doc/mruby3.md index 29da25cbc..02884f51b 100644 --- a/doc/mruby3.md +++ b/doc/mruby3.md @@ -57,6 +57,17 @@ pull-request. Some configuration macro names are changed for consistency +== `MRB_NO_FLOAT` + +Changed from `MRB_WITHOUT_FLOAT` to conform `USE_XXX` naming +convention. + +== `MRB_USE_FLOAT32` + +Changed from `MRB_USE_FLOAT` to make sure `float` here means +using single precision float, and not the opposite of +`MRB_NO_FLOAT`. + == `MRB_USE_METHOD_T_STRUCT` Changed from `MRB_METHOD_T_STRUCT`. diff --git a/include/mrbconf.h b/include/mrbconf.h index 734ec98e7..159aee48f 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -25,14 +25,24 @@ #endif /* configuration options: */ -/* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */ -//#define MRB_USE_FLOAT +/* add -DMRB_USE_FLOAT32 to use float instead of double for floating point numbers */ +//#define MRB_USE_FLOAT32 /* exclude floating point numbers */ -//#define MRB_WITHOUT_FLOAT +//#define MRB_NO_FLOAT -#if defined(MRB_USE_FLOAT) && defined(MRB_WITHOUT_FLOAT) -#error Cannot define MRB_USE_FLOAT and MRB_WITHOUT_FLOAT at the same time +/* obsolete configuration */ +#if defined(MRB_USE_FLOAT) +# define MRB_USE_FLOAT32 +#endif + +/* obsolete configuration */ +#if defined(MRB_WITHOUT_FLOAT) +# define MRB_NO_FLOAT +#endif + +#if defined(MRB_USE_FLOAT32) && defined(MRB_NO_FLOAT) +#error Cannot define MRB_USE_FLOAT32 and MRB_NO_FLOAT at the same time #endif /* stop inlining floating point numbers in mrb_value (effective only with MRB_WORD_BOXING)*/ @@ -65,7 +75,7 @@ # endif #endif -/* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT and MRB_WITHOUT_FLOAT */ +/* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT32 and MRB_NO_FLOAT */ //#define MRB_NAN_BOXING /* represent mrb_value as a word (natural unit of data for the processor) */ diff --git a/include/mruby.h b/include/mruby.h index dea0a9c88..485a94d70 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -92,7 +92,7 @@ #include #include -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #include #ifndef FLT_EPSILON #define FLT_EPSILON (1.19209290e-07f) @@ -104,7 +104,7 @@ #define LDBL_EPSILON (1.08420217248550443401e-19L) #endif -#ifdef MRB_USE_FLOAT +#ifdef MRB_USE_FLOAT32 #define MRB_FLOAT_EPSILON FLT_EPSILON #else #define MRB_FLOAT_EPSILON DBL_EPSILON @@ -245,7 +245,7 @@ typedef struct mrb_state { struct RClass *hash_class; struct RClass *range_class; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT struct RClass *float_class; #endif struct RClass *fixnum_class; @@ -1211,7 +1211,7 @@ MRB_API mrb_bool mrb_obj_equal(mrb_state *mrb, mrb_value a, mrb_value b); MRB_API mrb_bool mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2); MRB_API mrb_value mrb_convert_to_integer(mrb_state *mrb, mrb_value val, mrb_int base); MRB_API mrb_value mrb_Integer(mrb_state *mrb, mrb_value val); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT MRB_API mrb_value mrb_Float(mrb_state *mrb, mrb_value val); #endif MRB_API mrb_value mrb_inspect(mrb_state *mrb, mrb_value obj); @@ -1304,7 +1304,7 @@ MRB_API mrb_value mrb_vformat(mrb_state *mrb, const char *format, va_list ap); #define E_FROZEN_ERROR (mrb_exc_get_id(mrb, MRB_SYM(FrozenError))) #define E_NOTIMP_ERROR (mrb_exc_get_id(mrb, MRB_SYM(NotImplementedError))) -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #define E_FLOATDOMAIN_ERROR (mrb_exc_get_id(mrb, MRB_SYM(FloatDomainError))) #endif diff --git a/include/mruby/boxing_nan.h b/include/mruby/boxing_nan.h index a8655ca19..eb89ac1f9 100644 --- a/include/mruby/boxing_nan.h +++ b/include/mruby/boxing_nan.h @@ -7,12 +7,12 @@ #ifndef MRUBY_BOXING_NAN_H #define MRUBY_BOXING_NAN_H -#ifdef MRB_USE_FLOAT -# error ---->> MRB_NAN_BOXING and MRB_USE_FLOAT conflict <<---- +#ifdef MRB_USE_FLOAT32 +# error ---->> MRB_NAN_BOXING and MRB_USE_FLOAT32 conflict <<---- #endif -#ifdef MRB_WITHOUT_FLOAT -# error ---->> MRB_NAN_BOXING and MRB_WITHOUT_FLOAT conflict <<---- +#ifdef MRB_NO_FLOAT +# error ---->> MRB_NAN_BOXING and MRB_NO_FLOAT conflict <<---- #endif #ifdef MRB_INT64 diff --git a/include/mruby/boxing_no.h b/include/mruby/boxing_no.h index 23b48c6f8..345f6b35b 100644 --- a/include/mruby/boxing_no.h +++ b/include/mruby/boxing_no.h @@ -11,7 +11,7 @@ #define MRB_SYMBOL_SHIFT 0 union mrb_value_union { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT mrb_float f; #endif void *p; @@ -26,7 +26,7 @@ typedef struct mrb_value { #define mrb_ptr(o) (o).value.p #define mrb_cptr(o) mrb_ptr(o) -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #define mrb_float(o) (o).value.f #endif #define mrb_fixnum(o) (o).value.i @@ -43,7 +43,7 @@ typedef struct mrb_value { #define SET_TRUE_VALUE(r) BOXNIX_SET_VALUE(r, MRB_TT_TRUE, value.i, 1) #define SET_BOOL_VALUE(r,b) BOXNIX_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, value.i, 1) #define SET_INT_VALUE(r,n) BOXNIX_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n)) -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #define SET_FLOAT_VALUE(mrb,r,v) BOXNIX_SET_VALUE(r, MRB_TT_FLOAT, value.f, (v)) #endif #define SET_SYM_VALUE(r,v) BOXNIX_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v)) diff --git a/include/mruby/boxing_word.h b/include/mruby/boxing_word.h index a91d10421..b9b6a3fe9 100644 --- a/include/mruby/boxing_word.h +++ b/include/mruby/boxing_word.h @@ -11,7 +11,7 @@ #error MRB_INT64 cannot be used with MRB_WORD_BOXING in 32-bit mode. #endif -#if !defined(MRB_WITHOUT_FLOAT) || defined(MRB_NO_FLOAT_INLINE) +#if !defined(MRB_NO_FLOAT) || defined(MRB_NO_FLOAT_INLINE) struct RFloat { MRB_OBJECT_HEADER; mrb_float f; @@ -80,7 +80,7 @@ union mrb_value_ { }; #endif struct RBasic *bp; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT struct RFloat *fp; #endif struct RCptr *vp; @@ -96,13 +96,13 @@ mrb_val_union(mrb_value v) } MRB_API mrb_value mrb_word_boxing_cptr_value(struct mrb_state*, void*); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT MRB_API mrb_value mrb_word_boxing_float_value(struct mrb_state*, mrb_float); #endif #define mrb_ptr(o) mrb_val_union(o).p #define mrb_cptr(o) mrb_val_union(o).vp->p -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #define mrb_float(o) mrb_val_union(o).fp->f #endif #define mrb_fixnum(o) BOXWORD_SHIFT_VALUE(o, FIXNUM, mrb_int) @@ -124,7 +124,7 @@ MRB_API mrb_value mrb_word_boxing_float_value(struct mrb_state*, mrb_float); #define mrb_nil_p(o) ((o) == MRB_Qnil) #define mrb_false_p(o) ((o) == MRB_Qfalse) #define mrb_true_p(o) ((o) == MRB_Qtrue) -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #define mrb_float_p(o) BOXWORD_OBJ_TYPE_P(o, FLOAT) #endif #define mrb_array_p(o) BOXWORD_OBJ_TYPE_P(o, ARRAY) @@ -146,7 +146,7 @@ MRB_API mrb_value mrb_word_boxing_float_value(struct mrb_state*, mrb_float); #define mrb_istruct_p(o) BOXWORD_OBJ_TYPE_P(o, ISTRUCT) #define mrb_break_p(o) BOXWORD_OBJ_TYPE_P(o, BREAK) -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #define SET_FLOAT_VALUE(mrb,r,v) ((r) = mrb_word_boxing_float_value(mrb, v)) #endif #define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_word_boxing_cptr_value(mrb, v)) diff --git a/include/mruby/class.h b/include/mruby/class.h index 88e5915e5..a02c4ef17 100644 --- a/include/mruby/class.h +++ b/include/mruby/class.h @@ -37,7 +37,7 @@ mrb_class(mrb_state *mrb, mrb_value v) return mrb->symbol_class; case MRB_TT_FIXNUM: return mrb->fixnum_class; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: return mrb->float_class; #endif diff --git a/include/mruby/error.h b/include/mruby/error.h index 67a0a539e..b607dd957 100644 --- a/include/mruby/error.h +++ b/include/mruby/error.h @@ -32,7 +32,7 @@ MRB_API mrb_noreturn void mrb_no_method_error(mrb_state *mrb, mrb_sym id, mrb_va /* declaration for `fail` method */ MRB_API mrb_value mrb_f_raise(mrb_state*, mrb_value); -#if defined(MRB_64BIT) || defined(MRB_USE_FLOAT) || defined(MRB_NAN_BOXING) || defined(MRB_WORD_BOXING) +#if defined(MRB_64BIT) || defined(MRB_USE_FLOAT32) || defined(MRB_NAN_BOXING) || defined(MRB_WORD_BOXING) struct RBreak { MRB_OBJECT_HEADER; const struct RProc *proc; @@ -62,7 +62,7 @@ mrb_break_value_set(struct RBreak *brk, mrb_value val) brk->flags &= ~RBREAK_VALUE_TT_MASK; brk->flags |= val.tt; } -#endif /* MRB_64BIT || MRB_USE_FLOAT || MRB_NAN_BOXING || MRB_WORD_BOXING */ +#endif /* MRB_64BIT || MRB_USE_FLOAT32 || MRB_NAN_BOXING || MRB_WORD_BOXING */ #define mrb_break_proc_get(brk) ((brk)->proc) #define mrb_break_proc_set(brk, p) ((brk)->proc = p) diff --git a/include/mruby/numeric.h b/include/mruby/numeric.h index 06a33cc6f..10b242688 100644 --- a/include/mruby/numeric.h +++ b/include/mruby/numeric.h @@ -22,7 +22,7 @@ MRB_BEGIN_DECL #define POSFIXABLE(f) TYPED_POSFIXABLE(f,mrb_int) #define NEGFIXABLE(f) TYPED_NEGFIXABLE(f,mrb_int) #define FIXABLE(f) TYPED_FIXABLE(f,mrb_int) -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #ifdef MRB_INT64 #define FIXABLE_FLOAT(f) ((f)>=-9223372036854775808.0 && (f)<9223372036854775808.0) #else @@ -30,12 +30,12 @@ MRB_BEGIN_DECL #endif #endif -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT MRB_API mrb_value mrb_flo_to_fixnum(mrb_state *mrb, mrb_value val); #endif MRB_API mrb_value mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, mrb_int base); /* ArgumentError if format string doesn't match /%(\.[0-9]+)?[aAeEfFgG]/ */ -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT MRB_API mrb_value mrb_float_to_str(mrb_state *mrb, mrb_value x, const char *fmt); MRB_API int mrb_float_to_cstr(mrb_state *mrb, char *buf, size_t len, const char *fmt, mrb_float f); MRB_API mrb_float mrb_to_flo(mrb_state *mrb, mrb_value x); @@ -161,13 +161,13 @@ mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product) #endif -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT # include # include # define MRB_FLT_RADIX FLT_RADIX -# ifdef MRB_USE_FLOAT +# ifdef MRB_USE_FLOAT32 # define MRB_FLT_MANT_DIG FLT_MANT_DIG # define MRB_FLT_EPSILON FLT_EPSILON # define MRB_FLT_DIG FLT_DIG @@ -178,7 +178,7 @@ mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product) # define MRB_FLT_MAX FLT_MAX # define MRB_FLT_MAX_10_EXP FLT_MAX_10_EXP -# else /* not MRB_USE_FLOAT */ +# else /* not MRB_USE_FLOAT32 */ # define MRB_FLT_MANT_DIG DBL_MANT_DIG # define MRB_FLT_EPSILON DBL_EPSILON # define MRB_FLT_DIG DBL_DIG @@ -188,8 +188,8 @@ mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product) # define MRB_FLT_MAX_EXP DBL_MAX_EXP # define MRB_FLT_MAX DBL_MAX # define MRB_FLT_MAX_10_EXP DBL_MAX_10_EXP -# endif /* MRB_USE_FLOAT */ -#endif /* MRB_WITHOUT_FLOAT */ +# endif /* MRB_USE_FLOAT32 */ +#endif /* MRB_NO_FLOAT */ MRB_END_DECL diff --git a/include/mruby/value.h b/include/mruby/value.h index 473774b00..88c8d4dba 100644 --- a/include/mruby/value.h +++ b/include/mruby/value.h @@ -75,9 +75,9 @@ struct mrb_state; # define MRB_ENDIAN_LOHI(a,b) b a #endif -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT MRB_API double mrb_float_read(const char*, char**); -#ifdef MRB_USE_FLOAT +#ifdef MRB_USE_FLOAT32 typedef float mrb_float; #else typedef double mrb_float; @@ -90,7 +90,7 @@ MRB_API int mrb_msvc_vsnprintf(char *s, size_t n, const char *format, va_list ar MRB_API int mrb_msvc_snprintf(char *s, size_t n, const char *format, ...); # define vsnprintf(s, n, format, arg) mrb_msvc_vsnprintf(s, n, format, arg) # define snprintf(s, n, format, ...) mrb_msvc_snprintf(s, n, format, __VA_ARGS__) -# if _MSC_VER < 1800 && !defined MRB_WITHOUT_FLOAT +# if _MSC_VER < 1800 && !defined MRB_NO_FLOAT # include # define isfinite(n) _finite(n) # define isnan _isnan @@ -195,7 +195,7 @@ struct RCptr { #ifndef mrb_true_p #define mrb_true_p(o) (mrb_type(o) == MRB_TT_TRUE) #endif -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #ifndef mrb_float_p #define mrb_float_p(o) (mrb_type(o) == MRB_TT_FLOAT) #endif @@ -264,7 +264,7 @@ struct RCptr { * * Takes a float and boxes it into an mrb_value */ -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT MRB_INLINE mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f) { mrb_value v; diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index f60f1f077..372a2c5f7 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -530,7 +530,7 @@ new_lit(codegen_scope *s, mrb_value val) return i; } break; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: for (i=0; iirep->plen; i++) { mrb_float f1, f2; @@ -588,7 +588,7 @@ new_lit(codegen_scope *s, mrb_value val) } break; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: pv->tt = IREP_TT_FLOAT; pv->u.f = mrb_float(val); @@ -1330,7 +1330,7 @@ raise_error(codegen_scope *s, const char *msg) genop_1(s, OP_ERR, idx); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT static double readint_float(codegen_scope *s, const char *p, int base) { @@ -2442,7 +2442,7 @@ codegen(codegen_scope *s, node *tree, int val) mrb_bool overflow; i = readint_mrb_int(s, p, base, FALSE, &overflow); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT if (overflow) { double f = readint_float(s, p, base); int off = new_lit(s, mrb_float_value(s->mrb, f)); @@ -2473,7 +2473,7 @@ codegen(codegen_scope *s, node *tree, int val) } break; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case NODE_FLOAT: if (val) { char *p = (char*)tree; @@ -2490,7 +2490,7 @@ codegen(codegen_scope *s, node *tree, int val) { nt = nint(tree->car); switch (nt) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case NODE_FLOAT: if (val) { char *p = (char*)tree->cdr; @@ -2511,7 +2511,7 @@ codegen(codegen_scope *s, node *tree, int val) mrb_bool overflow; i = readint_mrb_int(s, p, base, TRUE, &overflow); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT if (overflow) { double f = readint_float(s, p, base); int off = new_lit(s, mrb_float_value(s->mrb, -f)); @@ -2531,7 +2531,7 @@ codegen(codegen_scope *s, node *tree, int val) int off = new_lit(s, mrb_fixnum_value(i)); genop_2(s, OP_LOADL, cursp(), off); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT } #endif push(); diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index c67c694fe..8e3087a2a 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -981,7 +981,7 @@ new_int(parser_state *p, const char *s, int base, int suffix) return result; } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT /* (:float . i) */ static node* new_float(parser_state *p, const char *s, int suffix) @@ -5661,7 +5661,7 @@ parser_yylex(parser_state *p) } tokfix(p); if (is_float) { -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT yywarning_s(p, "floating point numbers are not supported", tok(p)); pylval.nd = new_int(p, "0", 10, 0); return tINTEGER; diff --git a/mrbgems/mruby-compiler/core/y.tab.c b/mrbgems/mruby-compiler/core/y.tab.c index 096543349..48173933f 100644 --- a/mrbgems/mruby-compiler/core/y.tab.c +++ b/mrbgems/mruby-compiler/core/y.tab.c @@ -1044,7 +1044,7 @@ new_int(parser_state *p, const char *s, int base, int suffix) return result; } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT /* (:float . i) */ static node* new_float(parser_state *p, const char *s, int suffix) @@ -11553,7 +11553,7 @@ parser_yylex(parser_state *p) } tokfix(p); if (is_float) { -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT yywarning_s(p, "floating point numbers are not supported", tok(p)); pylval.nd = new_int(p, "0", 10, 0); return tINTEGER; diff --git a/mrbgems/mruby-complex/src/complex.c b/mrbgems/mruby-complex/src/complex.c index 24dad4235..85735b704 100644 --- a/mrbgems/mruby-complex/src/complex.c +++ b/mrbgems/mruby-complex/src/complex.c @@ -3,8 +3,8 @@ #include #include -#ifdef MRB_WITHOUT_FLOAT -# error Complex conflicts 'MRB_WITHOUT_FLOAT' configuration in your 'build_config.rb' +#ifdef MRB_NO_FLOAT +# error Complex conflicts with 'MRB_NO_FLOAT' configuration #endif struct mrb_complex { @@ -12,13 +12,13 @@ struct mrb_complex { mrb_float imaginary; }; -#ifdef MRB_USE_FLOAT +#ifdef MRB_USE_FLOAT32 #define F(x) x##f #else #define F(x) x #endif -#if defined(MRB_64BIT) || defined(MRB_USE_FLOAT) +#if defined(MRB_64BIT) || defined(MRB_USE_FLOAT32) #define COMPLEX_USE_ISTRUCT /* use TT_ISTRUCT */ diff --git a/mrbgems/mruby-complex/test/complex.rb b/mrbgems/mruby-complex/test/complex.rb index d996e8277..14711ad73 100644 --- a/mrbgems/mruby-complex/test/complex.rb +++ b/mrbgems/mruby-complex/test/complex.rb @@ -60,7 +60,7 @@ assert 'Complex#/' do assert_complex Complex(9, 8) / 4 , ((9 / 4) + 2i) assert_complex Complex(20, 9) / 9.8 , (2.0408163265306123 + 0.9183673469387754i) if 1e39.infinite? then - # MRB_USE_FLOAT in effect + # MRB_USE_FLOAT32 in effect ten = 1e21 one = 1e20 else @@ -80,7 +80,7 @@ assert 'Complex#abs' do assert_float Complex(-1).abs, 1 assert_float Complex(3.0, -4.0).abs, 5.0 if 1e39.infinite? then - # MRB_USE_FLOAT in effect + # MRB_USE_FLOAT32 in effect exp = 125 else exp = 1021 diff --git a/mrbgems/mruby-inline-struct/test/inline.c b/mrbgems/mruby-inline-struct/test/inline.c index 5d307dcab..b4d9b1f1e 100644 --- a/mrbgems/mruby-inline-struct/test/inline.c +++ b/mrbgems/mruby-inline-struct/test/inline.c @@ -13,7 +13,7 @@ istruct_test_initialize(mrb_state *mrb, mrb_value self) if (mrb_fixnum_p(object)) { strncpy(string, "fixnum", size-1); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT else if (mrb_float_p(object)) { strncpy(string, "float", size-1); } diff --git a/mrbgems/mruby-io/src/file.c b/mrbgems/mruby-io/src/file.c index 04dece910..a28360d81 100644 --- a/mrbgems/mruby-io/src/file.c +++ b/mrbgems/mruby-io/src/file.c @@ -448,8 +448,8 @@ mrb_file_size(mrb_state *mrb, mrb_value self) } if (st.st_size > MRB_INT_MAX) { -#ifdef MRB_WITHOUT_FLOAT - mrb_raise(mrb, E_RUNTIME_ERROR, "File#size too large for MRB_WITHOUT_FLOAT"); +#ifdef MRB_NO_FLOAT + mrb_raise(mrb, E_RUNTIME_ERROR, "File#size too large for MRB_NO_FLOAT"); #else return mrb_float_value(mrb, (mrb_float)st.st_size); #endif diff --git a/mrbgems/mruby-io/src/io.c b/mrbgems/mruby-io/src/io.c index 988d19b02..587e195d9 100644 --- a/mrbgems/mruby-io/src/io.c +++ b/mrbgems/mruby-io/src/io.c @@ -973,10 +973,10 @@ mrb_io_sysseek(mrb_state *mrb, mrb_value io) mrb_sys_fail(mrb, "sysseek"); } if (pos > MRB_INT_MAX) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT return mrb_float_value(mrb, (mrb_float)pos); #else - mrb_raise(mrb, E_IO_ERROR, "sysseek reached too far for MRB_WITHOUT_FLOAT"); + mrb_raise(mrb, E_IO_ERROR, "sysseek reached too far for MRB_NO_FLOAT"); #endif } else { return mrb_fixnum_value(pos); @@ -1081,7 +1081,7 @@ time2timeval(mrb_state *mrb, mrb_value time) t.tv_usec = 0; break; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: t.tv_sec = (ftime_t)mrb_float(time); t.tv_usec = (fsuseconds_t)((mrb_float(time) - t.tv_sec) * 1000000.0); diff --git a/mrbgems/mruby-kernel-ext/src/kernel.c b/mrbgems/mruby-kernel-ext/src/kernel.c index 70991c704..eaf8c6eb0 100644 --- a/mrbgems/mruby-kernel-ext/src/kernel.c +++ b/mrbgems/mruby-kernel-ext/src/kernel.c @@ -112,7 +112,7 @@ mrb_f_integer(mrb_state *mrb, mrb_value self) return mrb_convert_to_integer(mrb, arg, base); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT /* * call-seq: * Float(arg) -> float @@ -212,7 +212,7 @@ mrb_mruby_kernel_ext_gem_init(mrb_state *mrb) mrb_define_module_function(mrb, krn, "caller", mrb_f_caller, MRB_ARGS_OPT(2)); mrb_define_method(mrb, krn, "__method__", mrb_f_method, MRB_ARGS_NONE()); mrb_define_module_function(mrb, krn, "Integer", mrb_f_integer, MRB_ARGS_ARG(1,1)); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT mrb_define_module_function(mrb, krn, "Float", mrb_f_float, MRB_ARGS_REQ(1)); #endif mrb_define_module_function(mrb, krn, "String", mrb_f_string, MRB_ARGS_REQ(1)); diff --git a/mrbgems/mruby-math/src/math.c b/mrbgems/mruby-math/src/math.c index ff1e84684..fcde7e700 100644 --- a/mrbgems/mruby-math/src/math.c +++ b/mrbgems/mruby-math/src/math.c @@ -4,8 +4,8 @@ ** See Copyright Notice in mruby.h */ -#ifdef MRB_WITHOUT_FLOAT -# error Math conflicts 'MRB_WITHOUT_FLOAT' configuration in your 'build_config.rb' +#ifdef MRB_NO_FLOAT +# error Math conflicts with 'MRB_NO_FLOAT' configuration #endif #include diff --git a/mrbgems/mruby-numeric-ext/src/numeric_ext.c b/mrbgems/mruby-numeric-ext/src/numeric_ext.c index fd7072ccd..d00be4b5d 100644 --- a/mrbgems/mruby-numeric-ext/src/numeric_ext.c +++ b/mrbgems/mruby-numeric-ext/src/numeric_ext.c @@ -59,7 +59,7 @@ mrb_mruby_numeric_ext_gem_init(mrb_state* mrb) mrb_define_method(mrb, i, "anybits?", mrb_int_anybits, MRB_ARGS_REQ(1)); mrb_define_method(mrb, i, "nobits?", mrb_int_nobits, MRB_ARGS_REQ(1)); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(RADIX), mrb_fixnum_value(MRB_FLT_RADIX)); mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MANT_DIG), mrb_fixnum_value(MRB_FLT_MANT_DIG)); mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(EPSILON), mrb_float_value(mrb, MRB_FLT_EPSILON)); @@ -70,7 +70,7 @@ mrb_mruby_numeric_ext_gem_init(mrb_state* mrb) mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MAX_EXP), mrb_fixnum_value(MRB_FLT_MAX_EXP)); mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MAX), mrb_float_value(mrb, MRB_FLT_MAX)); mrb_define_const_id(mrb, mrb->float_class, MRB_SYM(MAX_10_EXP), mrb_fixnum_value(MRB_FLT_MAX_10_EXP)); -#endif /* MRB_WITHOUT_FLOAT */ +#endif /* MRB_NO_FLOAT */ } void diff --git a/mrbgems/mruby-object-ext/src/object.c b/mrbgems/mruby-object-ext/src/object.c index 57361e8e2..2d99ce8c2 100644 --- a/mrbgems/mruby-object-ext/src/object.c +++ b/mrbgems/mruby-object-ext/src/object.c @@ -17,7 +17,7 @@ nil_to_a(mrb_state *mrb, mrb_value obj) return mrb_ary_new(mrb); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT /* * call-seq: * nil.to_f -> 0.0 @@ -115,7 +115,7 @@ mrb_mruby_object_ext_gem_init(mrb_state* mrb) struct RClass * n = mrb->nil_class; mrb_define_method(mrb, n, "to_a", nil_to_a, MRB_ARGS_NONE()); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT mrb_define_method(mrb, n, "to_f", nil_to_f, MRB_ARGS_NONE()); #endif mrb_define_method(mrb, n, "to_h", nil_to_h, MRB_ARGS_NONE()); diff --git a/mrbgems/mruby-os-memsize/src/memsize.c b/mrbgems/mruby-os-memsize/src/memsize.c index 7030299f4..78ef1e4df 100644 --- a/mrbgems/mruby-os-memsize/src/memsize.c +++ b/mrbgems/mruby-os-memsize/src/memsize.c @@ -111,7 +111,7 @@ os_memsize_of_object(mrb_state* mrb, mrb_value obj) case MRB_TT_DATA: size += mrb_objspace_page_slot_size(); break; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: #ifdef MRB_WORD_BOXING size += mrb_objspace_page_slot_size() + diff --git a/mrbgems/mruby-pack/src/pack.c b/mrbgems/mruby-pack/src/pack.c index e222cd946..45427afa0 100644 --- a/mrbgems/mruby-pack/src/pack.c +++ b/mrbgems/mruby-pack/src/pack.c @@ -425,7 +425,7 @@ unpack_q(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, un return 8; } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT static int pack_double(mrb_state *mrb, mrb_value o, mrb_value str, mrb_int sidx, unsigned int flags) { @@ -1248,7 +1248,7 @@ mrb_pack_pack(mrb_state *mrb, mrb_value ary) if (type == PACK_TYPE_INTEGER) { o = mrb_to_int(mrb, o); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT else if (type == PACK_TYPE_FLOAT) { if (!mrb_float_p(o)) { mrb_float f = mrb_to_flo(mrb, o); @@ -1284,7 +1284,7 @@ mrb_pack_pack(mrb_state *mrb, mrb_value ary) case PACK_DIR_STR: ridx += pack_a(mrb, o, result, ridx, count, flags); break; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case PACK_DIR_DOUBLE: ridx += pack_double(mrb, o, result, ridx, flags); break; @@ -1381,7 +1381,7 @@ pack_unpack(mrb_state *mrb, mrb_value str, int single) case PACK_DIR_QUAD: srcidx += unpack_q(mrb, sptr, srclen - srcidx, result, flags); break; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case PACK_DIR_FLOAT: srcidx += unpack_float(mrb, sptr, srclen - srcidx, result, flags); break; diff --git a/mrbgems/mruby-random/src/random.c b/mrbgems/mruby-random/src/random.c index fdb28e012..3010b3db7 100644 --- a/mrbgems/mruby-random/src/random.c +++ b/mrbgems/mruby-random/src/random.c @@ -85,7 +85,7 @@ rand_uint32(rand_state *state) } #endif /* XORSHIFT96 */ -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT static double rand_real(rand_state *t) { @@ -100,7 +100,7 @@ random_rand(mrb_state *mrb, rand_state *t, mrb_value max) mrb_value value; if (mrb_fixnum(max) == 0) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT value = mrb_float_value(mrb, rand_real(t)); #else mrb_raise(mrb, E_ARGUMENT_ERROR, "Float not supported"); diff --git a/mrbgems/mruby-range-ext/src/range.c b/mrbgems/mruby-range-ext/src/range.c index 633894070..421e7d33a 100644 --- a/mrbgems/mruby-range-ext/src/range.c +++ b/mrbgems/mruby-range-ext/src/range.c @@ -96,7 +96,7 @@ range_last(mrb_state *mrb, mrb_value range) * ('a'..'z').size #=> nil */ -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT static mrb_value range_size(mrb_state *mrb, mrb_value range) { @@ -170,7 +170,7 @@ range_size(mrb_state *mrb, mrb_value range) } return mrb_nil_value(); } -#endif /* MRB_WITHOUT_FLOAT */ +#endif /* MRB_NO_FLOAT */ void mrb_mruby_range_ext_gem_init(mrb_state* mrb) diff --git a/mrbgems/mruby-rational/src/rational.c b/mrbgems/mruby-rational/src/rational.c index 4a72a42f2..f9470de86 100644 --- a/mrbgems/mruby-rational/src/rational.c +++ b/mrbgems/mruby-rational/src/rational.c @@ -87,7 +87,7 @@ rational_s_new(mrb_state *mrb, mrb_value self) { mrb_int numerator, denominator; -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT mrb_get_args(mrb, "ii", &numerator, &denominator); #else @@ -136,7 +136,7 @@ rational_s_new(mrb_state *mrb, mrb_value self) return rational_new(mrb, numerator, denominator); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT static mrb_value rational_to_f(mrb_state *mrb, mrb_value self) { @@ -194,7 +194,7 @@ void mrb_mruby_rational_gem_init(mrb_state *mrb) mrb_define_class_method(mrb, rat, "_new", rational_s_new, MRB_ARGS_REQ(2)); mrb_define_method(mrb, rat, "numerator", rational_numerator, MRB_ARGS_NONE()); mrb_define_method(mrb, rat, "denominator", rational_denominator, MRB_ARGS_NONE()); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT mrb_define_method(mrb, rat, "to_f", rational_to_f, MRB_ARGS_NONE()); #endif mrb_define_method(mrb, rat, "to_i", rational_to_i, MRB_ARGS_NONE()); diff --git a/mrbgems/mruby-sleep/src/mrb_sleep.c b/mrbgems/mruby-sleep/src/mrb_sleep.c index a653242d1..7771db56b 100644 --- a/mrbgems/mruby-sleep/src/mrb_sleep.c +++ b/mrbgems/mruby-sleep/src/mrb_sleep.c @@ -44,7 +44,7 @@ mrb_f_sleep(mrb_state *mrb, mrb_value self) { time_t beg = time(0); time_t end; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT mrb_float sec; mrb_get_args(mrb, "f", &sec); diff --git a/mrbgems/mruby-sprintf/src/sprintf.c b/mrbgems/mruby-sprintf/src/sprintf.c index 0cf462ef7..7f36616ec 100644 --- a/mrbgems/mruby-sprintf/src/sprintf.c +++ b/mrbgems/mruby-sprintf/src/sprintf.c @@ -10,7 +10,7 @@ #include #include #include -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #include #endif #include @@ -20,7 +20,7 @@ #define EXTENDSIGN(n, l) (((~0U << (n)) >> (((n)*(l)) % BITSPERDIG)) & ~(~0U << (n))) mrb_value mrb_str_format(mrb_state *, mrb_int, const mrb_value *, mrb_value); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT static void fmt_setup(char*,size_t,int,int,mrb_int,mrb_int); #endif @@ -863,7 +863,7 @@ retry: bin_retry: switch (mrb_type(val)) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: val = mrb_flo_to_fixnum(mrb, val); if (mrb_fixnum_p(val)) goto bin_retry; @@ -1030,7 +1030,7 @@ retry: } break; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case 'f': case 'g': case 'G': @@ -1131,7 +1131,7 @@ retry: return result; } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT static void fmt_setup(char *buf, size_t size, int c, int flags, mrb_int width, mrb_int prec) { diff --git a/mrbgems/mruby-string-ext/src/string.c b/mrbgems/mruby-string-ext/src/string.c index ded34a89e..71fb5bb65 100644 --- a/mrbgems/mruby-string-ext/src/string.c +++ b/mrbgems/mruby-string-ext/src/string.c @@ -12,7 +12,7 @@ #define ENC_COMP_P(enc, enc_lit) \ str_casecmp_p(RSTRING_PTR(enc), RSTRING_LEN(enc), enc_lit, sizeof(enc_lit"")-1) -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT # define mrb_float_p(o) FALSE #endif diff --git a/mrbgems/mruby-test/driver.c b/mrbgems/mruby-test/driver.c index fe1a475d5..4b82a9abc 100644 --- a/mrbgems/mruby-test/driver.c +++ b/mrbgems/mruby-test/driver.c @@ -224,8 +224,8 @@ mrb_init_test_driver(mrb_state *mrb, mrb_bool verbose) mrb_define_const(mrb, mrbtest, "FIXNUM_MIN", mrb_fixnum_value(MRB_INT_MIN)); mrb_define_const(mrb, mrbtest, "FIXNUM_BIT", mrb_fixnum_value(MRB_INT_BIT)); -#ifndef MRB_WITHOUT_FLOAT -#ifdef MRB_USE_FLOAT +#ifndef MRB_NO_FLOAT +#ifdef MRB_USE_FLOAT32 mrb_define_const(mrb, mrbtest, "FLOAT_TOLERANCE", mrb_float_value(mrb, 1e-6)); #else mrb_define_const(mrb, mrbtest, "FLOAT_TOLERANCE", mrb_float_value(mrb, 1e-12)); diff --git a/mrbgems/mruby-test/vformat.c b/mrbgems/mruby-test/vformat.c index e7ada02da..d73e52311 100644 --- a/mrbgems/mruby-test/vformat.c +++ b/mrbgems/mruby-test/vformat.c @@ -48,7 +48,7 @@ vf_s_format_d(mrb_state *mrb, mrb_value klass) return mrb_format(mrb, fmt, d); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT /* f float */ static mrb_value vf_s_format_f(mrb_state *mrb, mrb_value klass) @@ -167,7 +167,7 @@ mrb_init_test_vformat(mrb_state *mrb) VF_DEFINE_FORMAT_METHOD(c); VF_DEFINE_FORMAT_METHOD(d); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT VF_DEFINE_FORMAT_METHOD(f); #endif VF_DEFINE_FORMAT_METHOD(i); diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 3655695cf..3d5cdca2e 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -4,7 +4,7 @@ ** See Copyright Notice in mruby.h */ -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #include #endif @@ -30,7 +30,7 @@ double round(double x) { } #endif -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT # if !defined(__MINGW64__) && defined(_WIN32) # define llround(x) round(x) # endif @@ -199,7 +199,7 @@ struct mrb_time { static const struct mrb_data_type mrb_time_type = { "Time", mrb_free }; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT void mrb_check_num_exact(mrb_state *mrb, mrb_float num); typedef mrb_float mrb_sec; #define mrb_sec_value(mrb, sec) mrb_float_value(mrb, sec) @@ -231,7 +231,7 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec) time_t t; switch (mrb_type(obj)) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: { mrb_float f = mrb_float(obj); @@ -250,7 +250,7 @@ mrb_to_time_t(mrb_state *mrb, mrb_value obj, time_t *usec) } } break; -#endif /* MRB_WITHOUT_FLOAT */ +#endif /* MRB_NO_FLOAT */ default: case MRB_TT_FIXNUM: { @@ -572,7 +572,7 @@ mrb_time_minus(mrb_state *mrb, mrb_value self) tm = time_get_ptr(mrb, self); tm2 = DATA_CHECK_GET_PTR(mrb, other, &mrb_time_type, struct mrb_time); if (tm2) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT mrb_float f; f = (mrb_sec)(tm->sec - tm2->sec) + (mrb_sec)(tm->usec - tm2->usec) / 1.0e6; @@ -843,7 +843,7 @@ mrb_time_sec(mrb_state *mrb, mrb_value self) return mrb_fixnum_value(tm->datetime.tm_sec); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT /* 15.2.19.7.24 */ /* Returns a Float with the time since the epoch in seconds. */ static mrb_value @@ -864,7 +864,7 @@ mrb_time_to_i(mrb_state *mrb, mrb_value self) struct mrb_time *tm; tm = time_get_ptr(mrb, self); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT if (!fixable_time_t_p(tm->sec)) { return mrb_float_value(mrb, (mrb_float)tm->sec); } @@ -880,7 +880,7 @@ mrb_time_usec(mrb_state *mrb, mrb_value self) struct mrb_time *tm; tm = time_get_ptr(mrb, self); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT if (!fixable_time_t_p(tm->usec)) { return mrb_float_value(mrb, (mrb_float)tm->usec); } @@ -995,7 +995,7 @@ mrb_mruby_time_gem_init(mrb_state* mrb) mrb_define_method(mrb, tc, "sec" , mrb_time_sec, MRB_ARGS_NONE()); /* 15.2.19.7.23 */ mrb_define_method(mrb, tc, "to_i", mrb_time_to_i, MRB_ARGS_NONE()); /* 15.2.19.7.25 */ -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT mrb_define_method(mrb, tc, "to_f", mrb_time_to_f, MRB_ARGS_NONE()); /* 15.2.19.7.24 */ #endif mrb_define_method(mrb, tc, "usec", mrb_time_usec, MRB_ARGS_NONE()); /* 15.2.19.7.26 */ diff --git a/src/array.c b/src/array.c index 285600969..432599bf7 100644 --- a/src/array.c +++ b/src/array.c @@ -825,7 +825,7 @@ aget_index(mrb_state *mrb, mrb_value index) if (mrb_fixnum_p(index)) { return mrb_fixnum(index); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT else if (mrb_float_p(index)) { return (mrb_int)mrb_float(index); } diff --git a/src/class.c b/src/class.c index 455a1b4e1..845246e97 100644 --- a/src/class.c +++ b/src/class.c @@ -899,7 +899,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) } } break; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case 'f': { mrb_float *p; @@ -1343,7 +1343,7 @@ mrb_singleton_class_ptr(mrb_state *mrb, mrb_value v) return mrb->object_class; case MRB_TT_SYMBOL: case MRB_TT_FIXNUM: -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: #endif return NULL; diff --git a/src/dump.c b/src/dump.c index 3bc95f629..489e70f8a 100644 --- a/src/dump.c +++ b/src/dump.c @@ -13,8 +13,8 @@ #include #include -#ifndef MRB_WITHOUT_FLOAT -#ifdef MRB_USE_FLOAT +#ifndef MRB_NO_FLOAT +#ifdef MRB_USE_FLOAT32 #define MRB_FLOAT_FMT "%.9g" #else #define MRB_FLOAT_FMT "%.17g" @@ -88,7 +88,7 @@ write_iseq_block(mrb_state *mrb, const mrb_irep *irep, uint8_t *buf, uint8_t fla return cur - buf; } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT static mrb_value float_to_str(mrb_state *mrb, mrb_float f) { @@ -131,7 +131,7 @@ get_pool_block_size(mrb_state *mrb, const mrb_irep *irep) break; case IREP_TT_FLOAT: -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT { mrb_value str = float_to_str(mrb, irep->pool[pool_no].u.f); mrb_int len = RSTRING_LEN(str); @@ -192,7 +192,7 @@ write_pool_block(mrb_state *mrb, const mrb_irep *irep, uint8_t *buf) case IREP_TT_FLOAT: cur += uint8_to_bin(IREP_TT_FLOAT, cur); /* data type */ -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT { mrb_value str = float_to_str(mrb, irep->pool[pool_no].u.f); ptr = RSTRING_PTR(str); diff --git a/src/error.c b/src/error.c index 742049ace..b6a82f867 100644 --- a/src/error.c +++ b/src/error.c @@ -288,7 +288,7 @@ mrb_vformat(mrb_state *mrb, const char *format, va_list ap) #endif obj = mrb_fixnum_value(i); goto L_cat_obj; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case 'f': obj = mrb_float_value(mrb, (mrb_float)va_arg(ap, double)); goto L_cat_obj; diff --git a/src/etc.c b/src/etc.c index a1e384717..b0019e6de 100644 --- a/src/etc.c +++ b/src/etc.c @@ -70,7 +70,7 @@ mrb_obj_to_sym(mrb_state *mrb, mrb_value name) } MRB_API mrb_int -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT mrb_fixnum_id(mrb_int f) #else mrb_float_id(mrb_float f) @@ -80,7 +80,7 @@ mrb_float_id(mrb_float f) int len = sizeof(f); uint32_t id = 0; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT /* normalize -0.0 to 0.0 */ if (f == 0) f = 0.0; #endif @@ -115,7 +115,7 @@ mrb_obj_id(mrb_value obj) case MRB_TT_SYMBOL: return MakeID(mrb_symbol(obj)); case MRB_TT_FIXNUM: -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT return MakeID(mrb_fixnum_id(mrb_fixnum(obj))); #else return MakeID2(mrb_float_id((mrb_float)mrb_fixnum(obj)), MRB_TT_FLOAT); @@ -147,7 +147,7 @@ mrb_obj_id(mrb_value obj) #ifdef MRB_WORD_BOXING #define mrb_xxx_boxing_cptr_value mrb_word_boxing_cptr_value -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT MRB_API mrb_value mrb_word_boxing_float_value(mrb_state *mrb, mrb_float f) { @@ -158,7 +158,7 @@ mrb_word_boxing_float_value(mrb_state *mrb, mrb_float f) MRB_SET_FROZEN_FLAG(v.bp); return v.w; } -#endif /* MRB_WITHOUT_FLOAT */ +#endif /* MRB_NO_FLOAT */ #endif /* MRB_WORD_BOXING */ #if defined(MRB_WORD_BOXING) || (defined(MRB_NAN_BOXING) && defined(MRB_64BIT)) diff --git a/src/fmt_fp.c b/src/fmt_fp.c index 81ace6ec8..2c1e13c36 100644 --- a/src/fmt_fp.c +++ b/src/fmt_fp.c @@ -1,4 +1,4 @@ -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #if defined(MRB_DISABLE_STDIO) || defined(_WIN32) || defined(_WIN64) /* diff --git a/src/gc.c b/src/gc.c index 17f7e81e4..50269f95c 100644 --- a/src/gc.c +++ b/src/gc.c @@ -122,7 +122,7 @@ typedef struct { struct RException exc; struct RBreak brk; #ifdef MRB_WORD_BOXING -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT struct RFloat floatv; #endif struct RCptr cptr; @@ -784,7 +784,7 @@ obj_free(mrb_state *mrb, struct RBasic *obj, int end) /* cannot happen */ return; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: #ifdef MRB_WORD_BOXING break; @@ -929,7 +929,7 @@ root_scan_phase(mrb_state *mrb, mrb_gc *gc) mrb_gc_mark(mrb, (struct RBasic*)mrb->hash_class); mrb_gc_mark(mrb, (struct RBasic*)mrb->range_class); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT mrb_gc_mark(mrb, (struct RBasic*)mrb->float_class); #endif mrb_gc_mark(mrb, (struct RBasic*)mrb->fixnum_class); diff --git a/src/hash.c b/src/hash.c index 72ed3c731..2eef4afaf 100644 --- a/src/hash.c +++ b/src/hash.c @@ -11,7 +11,7 @@ #include #include -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT /* a function to get hash value of a float number */ mrb_int mrb_float_id(mrb_float f); #endif @@ -65,7 +65,7 @@ ht_hash_func(mrb_state *mrb, htable *t, mrb_value key) case MRB_TT_FALSE: case MRB_TT_SYMBOL: case MRB_TT_FIXNUM: -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: #endif h = (size_t)mrb_obj_id(key); @@ -99,7 +99,7 @@ ht_hash_equal(mrb_state *mrb, htable *t, mrb_value a, mrb_value b) switch (mrb_type(b)) { case MRB_TT_FIXNUM: return mrb_fixnum(a) == mrb_fixnum(b); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: return (mrb_float)mrb_fixnum(a) == mrb_float(b); #endif @@ -107,7 +107,7 @@ ht_hash_equal(mrb_state *mrb, htable *t, mrb_value a, mrb_value b) return FALSE; } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: switch (mrb_type(b)) { case MRB_TT_FIXNUM: diff --git a/src/load.c b/src/load.c index 67217b128..b06b9ff37 100644 --- a/src/load.c +++ b/src/load.c @@ -39,7 +39,7 @@ offset_crc_body(void) return ((uint8_t *)header.binary_crc - (uint8_t *)&header) + sizeof(header.binary_crc); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT double mrb_str_len_to_dbl(mrb_state *mrb, const char *s, size_t len, mrb_bool badcheck); static double @@ -165,7 +165,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flag #endif case IREP_TT_FLOAT: -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT pool[i].tt = tt; pool_data_len = bin_to_uint16(src); /* pool data length */ src += sizeof(uint16_t); @@ -173,7 +173,7 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flag src += pool_data_len; break; #else - return NULL; /* MRB_WITHOUT_FLOAT */ + return NULL; /* MRB_NO_FLOAT */ #endif case IREP_TT_STR: diff --git a/src/numeric.c b/src/numeric.c index 195bd40cf..f4ad116a4 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -4,7 +4,7 @@ ** See Copyright Notice in mruby.h */ -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #include #include #endif @@ -18,8 +18,8 @@ #include #include -#ifndef MRB_WITHOUT_FLOAT -#ifdef MRB_USE_FLOAT +#ifndef MRB_NO_FLOAT +#ifdef MRB_USE_FLOAT32 #define trunc(f) truncf(f) #define floor(f) floorf(f) #define ceil(f) ceilf(f) @@ -30,7 +30,7 @@ #endif #endif -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT MRB_API mrb_float mrb_to_flo(mrb_state *mrb, mrb_value val) { @@ -68,7 +68,7 @@ static mrb_value integral_pow(mrb_state *mrb, mrb_value x) { mrb_value y = mrb_get_arg1(mrb); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT mrb_float d; #endif @@ -79,7 +79,7 @@ integral_pow(mrb_state *mrb, mrb_value x) mrb_int result = 1; if (exp < 0) -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT return mrb_fixnum_value(0); #else goto float_pow; @@ -87,7 +87,7 @@ integral_pow(mrb_state *mrb, mrb_value x) for (;;) { if (exp & 1) { if (mrb_int_mul_overflow(result, base, &result)) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT goto float_pow; #endif } @@ -95,14 +95,14 @@ integral_pow(mrb_state *mrb, mrb_value x) exp >>= 1; if (exp == 0) break; if (mrb_int_mul_overflow(base, base, &base)) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT goto float_pow; #endif } } return mrb_fixnum_value(result); } -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value"); #else float_pow: @@ -114,7 +114,7 @@ integral_pow(mrb_state *mrb, mrb_value x) static mrb_value integral_idiv(mrb_state *mrb, mrb_value x) { -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT mrb_value y = mrb_get_arg1(mrb); if (!mrb_fixnum_p(y)) { @@ -151,7 +151,7 @@ integral_idiv(mrb_state *mrb, mrb_value x) static mrb_value integral_div(mrb_state *mrb, mrb_value xv) { -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT mrb_int y; mrb_get_args(mrb, "i", &y); @@ -184,7 +184,7 @@ integral_coerce_step_counter(mrb_state *mrb, mrb_value self) mrb_get_args(mrb, "oo", &num, &step); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT if (mrb_float_p(self) || mrb_float_p(num) || mrb_float_p(step)) { return mrb_Float(mrb, self); } @@ -193,7 +193,7 @@ integral_coerce_step_counter(mrb_state *mrb, mrb_value self) return self; } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT /******************************************************************** * * Document-class: Float @@ -386,7 +386,7 @@ fix_eql(mrb_state *mrb, mrb_value x) return mrb_bool_value(mrb_fixnum(x) == mrb_fixnum(y)); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT static mrb_value flo_eql(mrb_state *mrb, mrb_value x) { @@ -803,13 +803,13 @@ fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y) if (a == 0) return x; b = mrb_fixnum(y); if (mrb_int_mul_overflow(a, b, &c)) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT return mrb_float_value(mrb, (mrb_float)a * (mrb_float)b); #endif } return mrb_fixnum_value(c); } -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value"); #else return mrb_float_value(mrb, (mrb_float)a * mrb_to_flo(mrb, y)); @@ -822,7 +822,7 @@ mrb_num_mul(mrb_state *mrb, mrb_value x, mrb_value y) if (mrb_fixnum_p(x)) { return fixnum_mul(mrb, x, y); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT if (mrb_float_p(x)) { return mrb_float_value(mrb, mrb_float(x) * mrb_to_flo(mrb, y)); } @@ -898,7 +898,7 @@ fix_mod(mrb_state *mrb, mrb_value x) mrb_int mod; if (b == 0) { -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT /* ZeroDivisionError */ return mrb_fixnum_value(0); #else @@ -910,7 +910,7 @@ fix_mod(mrb_state *mrb, mrb_value x) fixdivmod(mrb, a, b, NULL, &mod); return mrb_fixnum_value(mod); } -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value"); #else else { @@ -937,7 +937,7 @@ fix_divmod(mrb_state *mrb, mrb_value x) mrb_int div, mod; if (mrb_fixnum(y) == 0) { -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT return mrb_assoc_new(mrb, mrb_fixnum_value(0), mrb_fixnum_value(0)); #else return mrb_assoc_new(mrb, ((mrb_fixnum(x) == 0) ? @@ -949,7 +949,7 @@ fix_divmod(mrb_state *mrb, mrb_value x) fixdivmod(mrb, mrb_fixnum(x), mrb_fixnum(y), &div, &mod); return mrb_assoc_new(mrb, mrb_fixnum_value(div), mrb_fixnum_value(mod)); } -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value"); #else else { @@ -964,7 +964,7 @@ fix_divmod(mrb_state *mrb, mrb_value x) #endif } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT static mrb_value flo_divmod(mrb_state *mrb, mrb_value x) { @@ -999,7 +999,7 @@ fix_equal(mrb_state *mrb, mrb_value x) switch (mrb_type(y)) { case MRB_TT_FIXNUM: return mrb_bool_value(mrb_fixnum(x) == mrb_fixnum(y)); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: return mrb_bool_value((mrb_float)mrb_fixnum(x) == mrb_float(y)); #endif @@ -1027,7 +1027,7 @@ fix_rev(mrb_state *mrb, mrb_value num) return mrb_fixnum_value(~val); } -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT #define bit_op(x,y,op1,op2) do {\ return mrb_fixnum_value(mrb_fixnum(x) op2 mrb_fixnum(y));\ } while(0) @@ -1095,7 +1095,7 @@ static mrb_value lshift(mrb_state *mrb, mrb_int val, mrb_int width) { if (width < 0) { /* mrb_int overflow */ -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT return mrb_fixnum_value(0); #else return mrb_float_value(mrb, INFINITY); @@ -1104,7 +1104,7 @@ lshift(mrb_state *mrb, mrb_int val, mrb_int width) if (val > 0) { if ((width > NUMERIC_SHIFT_WIDTH_MAX) || (val > (MRB_INT_MAX >> width))) { -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT return mrb_fixnum_value(-1); #else goto bit_overflow; @@ -1115,7 +1115,7 @@ lshift(mrb_state *mrb, mrb_int val, mrb_int width) else { if ((width > NUMERIC_SHIFT_WIDTH_MAX) || (val <= (MRB_INT_MIN >> width))) { -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT return mrb_fixnum_value(0); #else goto bit_overflow; @@ -1124,7 +1124,7 @@ lshift(mrb_state *mrb, mrb_int val, mrb_int width) return mrb_fixnum_value(val * ((mrb_int)1 << width)); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT bit_overflow: { mrb_float f = (mrb_float)val; @@ -1210,7 +1210,7 @@ fix_rshift(mrb_state *mrb, mrb_value x) * */ -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT static mrb_value fix_to_f(mrb_state *mrb, mrb_value num) { @@ -1267,13 +1267,13 @@ fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y) if (a == 0) return y; b = mrb_fixnum(y); if (mrb_int_add_overflow(a, b, &c)) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT return mrb_float_value(mrb, (mrb_float)a + (mrb_float)b); #endif } return mrb_fixnum_value(c); } -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value"); #else return mrb_float_value(mrb, (mrb_float)a + mrb_to_flo(mrb, y)); @@ -1286,7 +1286,7 @@ mrb_num_plus(mrb_state *mrb, mrb_value x, mrb_value y) if (mrb_fixnum_p(x)) { return fixnum_plus(mrb, x, y); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT if (mrb_float_p(x)) { return mrb_float_value(mrb, mrb_float(x) + mrb_to_flo(mrb, y)); } @@ -1323,13 +1323,13 @@ fixnum_minus(mrb_state *mrb, mrb_value x, mrb_value y) b = mrb_fixnum(y); if (mrb_int_sub_overflow(a, b, &c)) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT return mrb_float_value(mrb, (mrb_float)a - (mrb_float)b); #endif } return mrb_fixnum_value(c); } -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT mrb_raise(mrb, E_TYPE_ERROR, "non fixnum value"); #else return mrb_float_value(mrb, (mrb_float)a - mrb_to_flo(mrb, y)); @@ -1342,7 +1342,7 @@ mrb_num_minus(mrb_state *mrb, mrb_value x, mrb_value y) if (mrb_fixnum_p(x)) { return fixnum_minus(mrb, x, y); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT if (mrb_float_p(x)) { return mrb_float_value(mrb, mrb_float(x) - mrb_to_flo(mrb, y)); } @@ -1431,26 +1431,26 @@ fix_to_s(mrb_state *mrb, mrb_value self) static mrb_int cmpnum(mrb_state *mrb, mrb_value v1, mrb_value v2) { -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT mrb_int x, y; #else mrb_float x, y; #endif -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT x = mrb_fixnum(v1); #else x = mrb_to_flo(mrb, v1); #endif switch (mrb_type(v2)) { case MRB_TT_FIXNUM: -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT y = mrb_fixnum(v2); #else y = (mrb_float)mrb_fixnum(v2); #endif break; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: y = mrb_float(v2); break; @@ -1585,7 +1585,7 @@ num_infinite_p(mrb_state *mrb, mrb_value self) * Returns a new float which is the sum of float * and other. */ -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT static mrb_value flo_plus(mrb_state *mrb, mrb_value x) { @@ -1600,7 +1600,7 @@ void mrb_init_numeric(mrb_state *mrb) { struct RClass *numeric, *integer, *fixnum, *integral; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT struct RClass *fl; #endif @@ -1627,7 +1627,7 @@ mrb_init_numeric(mrb_state *mrb) mrb_undef_class_method(mrb, integer, "new"); mrb_define_method(mrb, integer, "to_i", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.24 */ mrb_define_method(mrb, integer, "to_int", int_to_i, MRB_ARGS_NONE()); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT mrb_define_method(mrb, integer, "ceil", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.8 (x) */ mrb_define_method(mrb, integer, "floor", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.10 (x) */ mrb_define_method(mrb, integer, "round", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.12 (x) */ @@ -1648,14 +1648,14 @@ mrb_init_numeric(mrb_state *mrb) mrb_define_method(mrb, fixnum, "<<", fix_lshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.12 */ mrb_define_method(mrb, fixnum, ">>", fix_rshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.13 */ mrb_define_method(mrb, fixnum, "eql?", fix_eql, MRB_ARGS_REQ(1)); /* 15.2.8.3.16 */ -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT mrb_define_method(mrb, fixnum, "to_f", fix_to_f, MRB_ARGS_NONE()); /* 15.2.8.3.23 */ #endif mrb_define_method(mrb, fixnum, "to_s", fix_to_s, MRB_ARGS_OPT(1)); /* 15.2.8.3.25 */ mrb_define_method(mrb, fixnum, "inspect", fix_to_s, MRB_ARGS_OPT(1)); mrb_define_method(mrb, fixnum, "divmod", fix_divmod, MRB_ARGS_REQ(1)); /* 15.2.8.3.30 (x) */ -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT /* Float Class */ mrb->float_class = fl = mrb_define_class(mrb, "Float", numeric); /* 15.2.9 */ MRB_SET_INSTANCE_TT(fl, MRB_TT_FLOAT); diff --git a/src/object.c b/src/object.c index fd1f9e215..634f70830 100644 --- a/src/object.c +++ b/src/object.c @@ -24,7 +24,7 @@ mrb_obj_eq(mrb_state *mrb, mrb_value v1, mrb_value v2) case MRB_TT_SYMBOL: return (mrb_symbol(v1) == mrb_symbol(v2)); -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: return (mrb_float(v1) == mrb_float(v2)); #endif @@ -47,7 +47,7 @@ mrb_equal(mrb_state *mrb, mrb_value obj1, mrb_value obj2) mrb_value result; if (mrb_obj_eq(mrb, obj1, obj2)) return TRUE; -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT /* value mixing with integer and float */ if (mrb_fixnum_p(obj1)) { if (mrb_float_p(obj2) && (mrb_float)mrb_fixnum(obj1) == mrb_float(obj2)) @@ -330,7 +330,7 @@ static const struct types { {MRB_TT_ICLASS, "iClass"}, /* internal use: mixed-in module holder */ {MRB_TT_SCLASS, "SClass"}, {MRB_TT_PROC, "Proc"}, -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT {MRB_TT_FLOAT, "Float"}, #endif {MRB_TT_ARRAY, "Array"}, @@ -510,7 +510,7 @@ mrb_to_int(mrb_state *mrb, mrb_value val) { if (!mrb_fixnum_p(val)) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT if (mrb_float_p(val)) { return mrb_flo_to_fixnum(mrb, val); } @@ -530,7 +530,7 @@ mrb_convert_to_integer(mrb_state *mrb, mrb_value val, mrb_int base) mrb_raise(mrb, E_TYPE_ERROR, "can't convert nil into Integer"); } switch (mrb_type(val)) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: if (base != 0) goto arg_error; return mrb_flo_to_fixnum(mrb, val); @@ -566,7 +566,7 @@ mrb_Integer(mrb_state *mrb, mrb_value val) return mrb_convert_to_integer(mrb, val, 0); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT MRB_API mrb_value mrb_Float(mrb_state *mrb, mrb_value val) { diff --git a/src/range.c b/src/range.c index 868d3d397..8f09eda24 100644 --- a/src/range.c +++ b/src/range.c @@ -23,7 +23,7 @@ r_check(mrb_state *mrb, mrb_value a, mrb_value b) ta = mrb_type(a); tb = mrb_type(b); -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT if (ta == MRB_TT_FIXNUM && tb == MRB_TT_FIXNUM ) { #else if ((ta == MRB_TT_FIXNUM || ta == MRB_TT_FLOAT) && diff --git a/src/string.c b/src/string.c index 73e514f41..f15770403 100644 --- a/src/string.c +++ b/src/string.c @@ -8,7 +8,7 @@ # define _CRT_NONSTDC_NO_DEPRECATE #endif -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #include #include #endif @@ -2365,7 +2365,7 @@ mrb_str_len_to_inum(mrb_state *mrb, const char *str, size_t len, mrb_int base, i n *= base; n += c; if (n > (uint64_t)MRB_INT_MAX + (sign ? 0 : 1)) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT if (base == 10) { return mrb_float_value(mrb, mrb_str_to_dbl(mrb, mrb_str_new(mrb, str, len), badcheck)); } @@ -2476,7 +2476,7 @@ mrb_str_to_i(mrb_state *mrb, mrb_value self) return mrb_str_to_inum(mrb, self, base, FALSE); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT double mrb_str_len_to_dbl(mrb_state *mrb, const char *s, size_t len, mrb_bool badcheck) { @@ -2937,7 +2937,7 @@ mrb_init_string(mrb_state *mrb) mrb_define_method(mrb, s, "slice", mrb_str_aref_m, MRB_ARGS_ANY()); /* 15.2.10.5.34 */ mrb_define_method(mrb, s, "split", mrb_str_split_m, MRB_ARGS_ANY()); /* 15.2.10.5.35 */ -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT mrb_define_method(mrb, s, "to_f", mrb_str_to_f, MRB_ARGS_NONE()); /* 15.2.10.5.38 */ #endif mrb_define_method(mrb, s, "to_i", mrb_str_to_i, MRB_ARGS_ANY()); /* 15.2.10.5.39 */ @@ -2954,7 +2954,7 @@ mrb_init_string(mrb_state *mrb) mrb_define_method(mrb, s, "byteslice", mrb_str_byteslice, MRB_ARGS_ARG(1,1)); } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT /* * Source code for the "strtod" library procedure. * diff --git a/src/vm.c b/src/vm.c index 87606c1b4..48dea94fb 100644 --- a/src/vm.c +++ b/src/vm.c @@ -6,7 +6,7 @@ #include #include -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT #include #endif #include @@ -1101,7 +1101,7 @@ RETRY_TRY_BLOCK: } goto L_RAISE; #endif -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT case IREP_TT_FLOAT: regs[a] = mrb_float_value(mrb, pool[b].u.f); break; @@ -2265,7 +2265,7 @@ RETRY_TRY_BLOCK: SET_INT_VALUE(regs[a], z); \ } \ break -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT #define OP_MATH_CASE_FLOAT(op_name, t1, t2) (void)0 #define OP_MATH_OVERFLOW_INT(op_name, x, y, z) SET_INT_VALUE(regs[a], z) #else @@ -2305,14 +2305,14 @@ RETRY_TRY_BLOCK: } CASE(OP_DIV, B) { -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT double x, y, f; #endif /* need to check if op is overridden */ switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) { case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM): -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT { mrb_int x = mrb_fixnum(regs[a]); mrb_int y = mrb_fixnum(regs[a+1]); @@ -2342,7 +2342,7 @@ RETRY_TRY_BLOCK: goto L_SEND_SYM; } -#ifndef MRB_WITHOUT_FLOAT +#ifndef MRB_NO_FLOAT if (y == 0) { if (x > 0) f = INFINITY; else if (x < 0) f = -INFINITY; @@ -2378,7 +2378,7 @@ RETRY_TRY_BLOCK: SET_INT_VALUE(regs[a], z); \ } \ break -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT #define OP_MATHI_CASE_FLOAT(op_name) (void)0 #else #define OP_MATHI_CASE_FLOAT(op_name) \ @@ -2400,7 +2400,7 @@ RETRY_TRY_BLOCK: #define OP_CMP_BODY(op,v1,v2) (v1(regs[a]) op v2(regs[a+1])) -#ifdef MRB_WITHOUT_FLOAT +#ifdef MRB_NO_FLOAT #define OP_CMP(op,sym) do {\ int result;\ /* need to check if - is overridden */\ diff --git a/target/RX630.rb b/target/RX630.rb index 8b1bbb42f..1b1f425c1 100644 --- a/target/RX630.rb +++ b/target/RX630.rb @@ -30,7 +30,7 @@ MRuby::CrossBuild.new("RX630") do |conf| cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"] #configuration for low memory environment - cc.defines << %w(MRB_USE_FLOAT) + cc.defines << %w(MRB_USE_FLOAT32) cc.defines << %w(MRB_HEAP_PAGE_SIZE=64) cc.defines << %w(KHASH_DEFAULT_SIZE=8) cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20) diff --git a/tasks/gitlab.rake b/tasks/gitlab.rake index 377b1cc9d..5c7b3d8c5 100644 --- a/tasks/gitlab.rake +++ b/tasks/gitlab.rake @@ -62,10 +62,10 @@ task :gitlab_config do configs = [] [true, false].each do |mode_32| - ['', 'MRB_USE_FLOAT'].each do |float_conf| + ['', 'MRB_USE_FLOAT32'].each do |float_conf| ['', 'MRB_NAN_BOXING', 'MRB_WORD_BOXING'].each do |boxing_conf| ['', 'MRB_UTF8_STRING'].each do |utf8_conf| - next if (float_conf == 'MRB_USE_FLOAT') && (boxing_conf == 'MRB_NAN_BOXING') + next if (float_conf == 'MRB_USE_FLOAT32') && (boxing_conf == 'MRB_NAN_BOXING') next if (int_conf == 'MRB_INT64') && (boxing_conf == 'MRB_NAN_BOXING') next if (int_conf == 'MRB_INT64') && (boxing_conf == 'MRB_WORD_BOXING') && mode_32 env = [float_conf, int_conf, boxing_conf, utf8_conf].map do |conf| diff --git a/test/t/float.rb b/test/t/float.rb index dc989636f..1cbc90532 100644 --- a/test/t/float.rb +++ b/test/t/float.rb @@ -207,7 +207,7 @@ assert('Float#>>') do end assert('Float#to_s') do - uses_float = 4e38.infinite? # enable MRB_USE_FLOAT? + uses_float = 4e38.infinite? # enable MRB_USE_FLOAT32? assert_equal("Infinity", Float::INFINITY.to_s) assert_equal("-Infinity", (-Float::INFINITY).to_s) -- cgit v1.2.3 From 02e69d1c2cce62850ecbd0ca0e8af564286cc55c Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 17 Aug 2020 15:51:26 +0900 Subject: Update `mruby3.md`. --- doc/mruby3.md | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) (limited to 'doc') diff --git a/doc/mruby3.md b/doc/mruby3.md index 02884f51b..c8ec76937 100644 --- a/doc/mruby3.md +++ b/doc/mruby3.md @@ -1,14 +1,6 @@ User visible changes in `mruby3` === -= New Syntax - -We have ported some new syntax from CRuby. - -* R-assignment (`12 => x`) -* Numbered block parameter (`x.map{_1 * 2}`) -* End-less `def` (`def double(x) = x*2`) - = Build System You can specify `TARGET` option to `rake` via a command line @@ -53,7 +45,17 @@ When you write a new target description, please contribute. We welcome your contribution as a GitHub pull-request. -= Configuration Options += Languge Changes + +== New Syntax + +We have ported some new syntax from CRuby. + +* R-assignment (`12 => x`) +* Numbered block parameter (`x.map{_1 * 2}`) +* End-less `def` (`def double(x) = x*2`) + += Configuration Options Changed Some configuration macro names are changed for consistency @@ -74,3 +76,28 @@ Changed from `MRB_METHOD_T_STRUCT`. To use `struct` version of `mrb_method_t`. More portable but consumes more memory. Turned on by default on 32bit platforms. + +== `MRB_NO_BOXING` + +Uses `struct` to represent `mrb_value`. Consumes more memory +but easier to inveticate the internal and to debug. It used +to be default `mrb_value` representation. Now the default is +`MRB_WORD_BOXING`. + +== `MRB_WORD_BOXING` + +Pack `mrb_value` in an `intptr_t` integer. Consumes less +memory compared to `MRB_NO_BOXING` especially on 32 bit +platforms. `Fixnum` size is 31 bits so some integer values +does not fit in `Fixnum` integers. + +== `MRB_NAN_BOXING` + +Pack `mrb_value` in a floating pointer number. Nothing +changed from previous versions. + += Internal Changes + +== `Random` now use `xoshiro128++`. + +For better and faster random number generation. -- cgit v1.2.3 From 80fe9838d2fdab1bb819bbeea892ebe748837b99 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 19 Jan 2020 09:48:14 +0900 Subject: Integrate `Fixnum` class into `Integer` class * The `Fixnum` constant is now an alias for the `Integer` class. * Remove `struct mrb_state::fixnum_class` member. If necessary, use `struct mrb_state::integer_class` instead. --- doc/limitations.md | 2 +- include/mruby.h | 6 +-- include/mruby/class.h | 2 +- include/mruby/numeric.h | 4 +- mrbgems/mruby-complex/mrblib/complex.rb | 2 +- mrbgems/mruby-io/mrblib/file.rb | 2 +- mrbgems/mruby-io/mrblib/io.rb | 4 +- mrbgems/mruby-io/test/io.rb | 4 +- mrbgems/mruby-kernel-ext/src/kernel.c | 2 +- mrbgems/mruby-math/src/math.c | 2 +- mrbgems/mruby-metaprog/test/metaprog.rb | 8 ++-- mrbgems/mruby-method/test/method.rb | 8 ++-- mrbgems/mruby-pack/src/pack.c | 8 ++-- mrbgems/mruby-random/test/random.rb | 4 +- mrbgems/mruby-range-ext/mrblib/range.rb | 2 +- mrbgems/mruby-rational/mrblib/rational.rb | 2 +- mrbgems/mruby-rational/src/rational.c | 2 +- mrbgems/mruby-rational/test/rational.rb | 12 ++--- mrbgems/mruby-socket/src/socket.c | 2 +- mrbgems/mruby-struct/src/struct.c | 4 +- mrblib/range.rb | 2 +- src/class.c | 6 +-- src/gc.c | 2 +- src/kernel.c | 8 ++-- src/numeric.c | 78 +++++++++++++++---------------- src/string.c | 6 +-- test/t/bs_literal.rb | 2 +- test/t/integer.rb | 2 +- test/t/kernel.rb | 2 +- test/t/module.rb | 2 +- test/t/vformat.rb | 6 +-- 31 files changed, 99 insertions(+), 99 deletions(-) (limited to 'doc') diff --git a/doc/limitations.md b/doc/limitations.md index 79979fd5a..7e58ca420 100644 --- a/doc/limitations.md +++ b/doc/limitations.md @@ -17,7 +17,7 @@ Please help to improve it by submitting your findings. ## `1/2` gives `0.5` Since mruby does not have `Bignum`, bigger integers are represented -by `Float` numbers. To enhance interoperability between `Fixnum` +by `Float` numbers. To enhance interoperability between `Integer` and `Float`, mruby provides `Float#upto` and other iterating methods for the `Float` class. As a side effect, `1/2` gives `0.5` not `0`. diff --git a/include/mruby.h b/include/mruby.h index 485a94d70..f07adbb13 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -248,7 +248,7 @@ typedef struct mrb_state { #ifndef MRB_NO_FLOAT struct RClass *float_class; #endif - struct RClass *fixnum_class; + struct RClass *integer_class; struct RClass *true_class; struct RClass *false_class; struct RClass *nil_class; @@ -890,8 +890,8 @@ MRB_API struct RClass* mrb_define_module_under_id(mrb_state *mrb, struct RClass * | `s` | {String} | const char *, {mrb_int} | Receive two arguments; `s!` gives (`NULL`,`0`) for `nil` | * | `z` | {String} | const char * | `NULL` terminated string; `z!` gives `NULL` for `nil` | * | `a` | {Array} | {mrb_value} *, {mrb_int} | Receive two arguments; `a!` gives (`NULL`,`0`) for `nil` | - * | `f` | {Fixnum}/{Float} | {mrb_float} | | - * | `i` | {Fixnum}/{Float} | {mrb_int} | | + * | `f` | {Integer}/{Float} | {mrb_float} | | + * | `i` | {Integer}/{Float} | {mrb_int} | | * | `b` | boolean | {mrb_bool} | | * | `n` | {String}/{Symbol} | {mrb_sym} | | * | `d` | data | void *, {mrb_data_type} const | 2nd argument will be used to check data type so it won't be modified; when `!` follows, the value may be `nil` | diff --git a/include/mruby/class.h b/include/mruby/class.h index a02c4ef17..b4b5454d5 100644 --- a/include/mruby/class.h +++ b/include/mruby/class.h @@ -36,7 +36,7 @@ mrb_class(mrb_state *mrb, mrb_value v) case MRB_TT_SYMBOL: return mrb->symbol_class; case MRB_TT_FIXNUM: - return mrb->fixnum_class; + return mrb->integer_class; #ifndef MRB_NO_FLOAT case MRB_TT_FLOAT: return mrb->float_class; diff --git a/include/mruby/numeric.h b/include/mruby/numeric.h index 10b242688..b8cc5b50f 100644 --- a/include/mruby/numeric.h +++ b/include/mruby/numeric.h @@ -1,5 +1,5 @@ /** -** @file mruby/numeric.h - Numeric, Integer, Float, Fixnum class +** @file mruby/numeric.h - Numeric, Integer, Float class ** ** See Copyright Notice in mruby.h */ @@ -12,7 +12,7 @@ /** * Numeric class and it's sub-classes. * - * Integer, Float and Fixnum + * Integer and Float */ MRB_BEGIN_DECL diff --git a/mrbgems/mruby-complex/mrblib/complex.rb b/mrbgems/mruby-complex/mrblib/complex.rb index 74c128a07..67f940865 100644 --- a/mrbgems/mruby-complex/mrblib/complex.rb +++ b/mrbgems/mruby-complex/mrblib/complex.rb @@ -104,7 +104,7 @@ class Complex < Numeric alias_method :imag, :imaginary - [Fixnum, Float].each do |cls| + [Integer, Float].each do |cls| [:+, :-, :*, :/, :==].each do |op| cls.instance_eval do original_operator_name = :"__original_operator_#{op}_complex" diff --git a/mrbgems/mruby-io/mrblib/file.rb b/mrbgems/mruby-io/mrblib/file.rb index aa73252e1..9398acef6 100644 --- a/mrbgems/mruby-io/mrblib/file.rb +++ b/mrbgems/mruby-io/mrblib/file.rb @@ -2,7 +2,7 @@ class File < IO attr_accessor :path def initialize(fd_or_path, mode = "r", perm = 0666) - if fd_or_path.kind_of? Fixnum + if fd_or_path.kind_of? Integer super(fd_or_path, mode) else @path = fd_or_path diff --git a/mrbgems/mruby-io/mrblib/io.rb b/mrbgems/mruby-io/mrblib/io.rb index e597db886..034f88529 100644 --- a/mrbgems/mruby-io/mrblib/io.rb +++ b/mrbgems/mruby-io/mrblib/io.rb @@ -186,7 +186,7 @@ class IO def read(length = nil, outbuf = "") unless length.nil? - unless length.is_a? Fixnum + unless length.is_a? Integer raise TypeError.new "can't convert #{length.class} into Integer" end if length < 0 @@ -229,7 +229,7 @@ class IO case arg when String rs = arg - when Fixnum + when Integer rs = "\n" limit = arg else diff --git a/mrbgems/mruby-io/test/io.rb b/mrbgems/mruby-io/test/io.rb index 2088a61e3..47c70cc60 100644 --- a/mrbgems/mruby-io/test/io.rb +++ b/mrbgems/mruby-io/test/io.rb @@ -7,7 +7,7 @@ $cr, $crlf, $cmd = MRubyIOTestUtil.win? ? [1, "\r\n", "cmd /c "] : [0, "\n", ""] def assert_io_open(meth) assert "assert_io_open" do fd = IO.sysopen($mrbtest_io_rfname) - assert_equal Fixnum, fd.class + assert_equal Integer, fd.class io1 = IO.__send__(meth, fd) begin assert_equal IO, io1.class @@ -433,7 +433,7 @@ assert('IO.popen') do $? = nil io = IO.popen("#{$cmd}echo mruby-io") assert_true io.close_on_exec? - assert_equal Fixnum, io.pid.class + assert_equal Integer, io.pid.class out = io.read assert_equal out.class, String diff --git a/mrbgems/mruby-kernel-ext/src/kernel.c b/mrbgems/mruby-kernel-ext/src/kernel.c index eaf8c6eb0..e738287db 100644 --- a/mrbgems/mruby-kernel-ext/src/kernel.c +++ b/mrbgems/mruby-kernel-ext/src/kernel.c @@ -84,7 +84,7 @@ mrb_f_method(mrb_state *mrb, mrb_value self) * call-seq: * Integer(arg,base=0) -> integer * - * Converts arg to a Fixnum. + * Converts arg to a Integer. * Numeric types are converted directly (with floating point numbers * being truncated). base (0, or between 2 and 36) is a base for * integer string representation. If arg is a String, diff --git a/mrbgems/mruby-math/src/math.c b/mrbgems/mruby-math/src/math.c index fcde7e700..f2622109d 100644 --- a/mrbgems/mruby-math/src/math.c +++ b/mrbgems/mruby-math/src/math.c @@ -629,7 +629,7 @@ math_cbrt(mrb_state *mrb, mrb_value obj) * Math.frexp(numeric) -> [ fraction, exponent ] * * Returns a two-element array containing the normalized fraction (a - * Float) and exponent (a Fixnum) of + * Float) and exponent (a Integer) of * numeric. * * fraction, exponent = Math.frexp(1234) #=> [0.6025390625, 11] diff --git a/mrbgems/mruby-metaprog/test/metaprog.rb b/mrbgems/mruby-metaprog/test/metaprog.rb index 82ba0a3a5..84f4e00a0 100644 --- a/mrbgems/mruby-metaprog/test/metaprog.rb +++ b/mrbgems/mruby-metaprog/test/metaprog.rb @@ -395,15 +395,15 @@ end assert('alias_method and remove_method') do begin - Fixnum.alias_method :to_s_, :to_s - Fixnum.remove_method :to_s + Integer.alias_method :to_s_, :to_s + Integer.remove_method :to_s assert_nothing_raised do # segfaults if mrb_cptr is used 1.to_s end ensure - Fixnum.alias_method :to_s, :to_s_ - Fixnum.remove_method :to_s_ + Integer.alias_method :to_s, :to_s_ + Integer.remove_method :to_s_ end end diff --git a/mrbgems/mruby-method/test/method.rb b/mrbgems/mruby-method/test/method.rb index 641979d71..123ae34be 100644 --- a/mrbgems/mruby-method/test/method.rb +++ b/mrbgems/mruby-method/test/method.rb @@ -77,7 +77,7 @@ end assert 'instance' do assert_kind_of Method, 1.method(:+) - assert_kind_of UnboundMethod, Fixnum.instance_method(:+) + assert_kind_of UnboundMethod, Integer.instance_method(:+) end assert 'Method#call' do @@ -404,9 +404,9 @@ assert 'UnboundMethod#arity' do end assert 'UnboundMethod#==' do - assert_false(Fixnum.instance_method(:+) == Fixnum.instance_method(:-)) - assert_true(Fixnum.instance_method(:+) == Fixnum.instance_method(:+)) - assert_false(Fixnum.instance_method(:+) == Float.instance_method(:+)) + assert_false(Integer.instance_method(:+) == Integer.instance_method(:-)) + assert_true(Integer.instance_method(:+) == Integer.instance_method(:+)) + assert_false(Integer.instance_method(:+) == Float.instance_method(:+)) assert_true(UnboundMethod.instance_method(:==) == UnboundMethod.instance_method(:eql?)) end diff --git a/mrbgems/mruby-pack/src/pack.c b/mrbgems/mruby-pack/src/pack.c index 45427afa0..f797b599b 100644 --- a/mrbgems/mruby-pack/src/pack.c +++ b/mrbgems/mruby-pack/src/pack.c @@ -290,7 +290,7 @@ unpack_l(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, un #ifndef MRB_INT64 if (!FIXABLE(sl)) { i32tostr(msg, sizeof(msg), sl); - mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Fixnum: %s", msg); + mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Integer: %s", msg); } #endif n = sl; @@ -298,7 +298,7 @@ unpack_l(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, un #ifndef MRB_INT64 if (!POSFIXABLE(ul)) { u32tostr(msg, sizeof(msg), ul); - mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Fixnum: %s", msg); + mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Integer: %s", msg); } #endif n = ul; @@ -411,13 +411,13 @@ unpack_q(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, un int64_t sll = ull; if (!FIXABLE(sll)) { i64tostr(msg, sizeof(msg), sll); - mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Fixnum: %s", msg); + mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Integer: %s", msg); } n = (mrb_int)sll; } else { if (!POSFIXABLE(ull)) { u64tostr(msg, sizeof(msg), ull); - mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Fixnum: %s", msg); + mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Integer: %s", msg); } n = (mrb_int)ull; } diff --git a/mrbgems/mruby-random/test/random.rb b/mrbgems/mruby-random/test/random.rb index cf4a55141..f3067748b 100644 --- a/mrbgems/mruby-random/test/random.rb +++ b/mrbgems/mruby-random/test/random.rb @@ -32,8 +32,8 @@ assert("Random.srand") do end assert("return class of Kernel.rand") do - assert_kind_of(Fixnum, rand(3)) - assert_kind_of(Fixnum, rand(1.5)) + assert_kind_of(Integer, rand(3)) + assert_kind_of(Integer, rand(1.5)) assert_kind_of(Float, rand) assert_kind_of(Float, rand(0.5)) end diff --git a/mrbgems/mruby-range-ext/mrblib/range.rb b/mrbgems/mruby-range-ext/mrblib/range.rb index a213beb57..fadddc343 100644 --- a/mrbgems/mruby-range-ext/mrblib/range.rb +++ b/mrbgems/mruby-range-ext/mrblib/range.rb @@ -33,7 +33,7 @@ class Range # fast path for numerics if val.kind_of?(Numeric) && last.kind_of?(Numeric) - raise TypeError if exclude_end? && !last.kind_of?(Fixnum) + raise TypeError if exclude_end? && !last.kind_of?(Integer) return nil if val > last return nil if val == last && exclude_end? diff --git a/mrbgems/mruby-rational/mrblib/rational.rb b/mrbgems/mruby-rational/mrblib/rational.rb index b65f77e2f..489d89ebd 100644 --- a/mrbgems/mruby-rational/mrblib/rational.rb +++ b/mrbgems/mruby-rational/mrblib/rational.rb @@ -92,7 +92,7 @@ module Kernel [:+, :-, :*, :/, :<=>, :==, :<, :<=, :>, :>=].each do |op| original_operator_name = :"__original_operator_#{op}_rational" - Fixnum.instance_eval do + Integer.instance_eval do alias_method original_operator_name, op define_method op do |rhs| if rhs.is_a? Rational diff --git a/mrbgems/mruby-rational/src/rational.c b/mrbgems/mruby-rational/src/rational.c index f9470de86..fcaba3df5 100644 --- a/mrbgems/mruby-rational/src/rational.c +++ b/mrbgems/mruby-rational/src/rational.c @@ -200,7 +200,7 @@ void mrb_mruby_rational_gem_init(mrb_state *mrb) mrb_define_method(mrb, rat, "to_i", rational_to_i, MRB_ARGS_NONE()); mrb_define_method(mrb, rat, "to_r", rational_to_r, MRB_ARGS_NONE()); mrb_define_method(mrb, rat, "negative?", rational_negative_p, MRB_ARGS_NONE()); - mrb_define_method(mrb, mrb->fixnum_class, "to_r", fix_to_r, MRB_ARGS_NONE()); + mrb_define_method(mrb, mrb->integer_class, "to_r", fix_to_r, MRB_ARGS_NONE()); } void diff --git a/mrbgems/mruby-rational/test/rational.rb b/mrbgems/mruby-rational/test/rational.rb index a8ebb8ea2..3fb4e4e82 100644 --- a/mrbgems/mruby-rational/test/rational.rb +++ b/mrbgems/mruby-rational/test/rational.rb @@ -143,7 +143,7 @@ assert 'Rational#==, Rational#!=' do assert_equal_rational(false, 1r, ComplexLikeNumeric.new(2)) end -assert 'Fixnum#==(Rational), Fixnum#!=(Rational)' do +assert 'Integer#==(Rational), Integer#!=(Rational)' do assert_equal_rational(true, 2, Rational(4,2)) assert_equal_rational(true, -2, Rational(-4,2)) assert_equal_rational(true, -2, Rational(4,-2)) @@ -186,7 +186,7 @@ assert 'Rational#<=>' do assert_raise(NoMethodError) { 1r <=> ComplexLikeNumeric.new(2) } end -assert 'Fixnum#<=>(Rational)' do +assert 'Integer#<=>(Rational)' do assert_cmp(-1, -2, Rational(-9,5)) assert_cmp(0, 5, 5r) assert_cmp(1, 3, Rational(8,3)) @@ -210,7 +210,7 @@ assert 'Rational#<' do assert_raise(ArgumentError) { 1r < "2" } end -assert 'Fixnum#<(Rational)' do +assert 'Integer#<(Rational)' do assert_not_operator(1, :<, Rational(2,3)) assert_not_operator(2, :<, 2r) assert_operator(-3, :<, Rational(2,3)) @@ -234,7 +234,7 @@ assert 'Rational#<=' do assert_raise(ArgumentError) { 1r <= "2" } end -assert 'Fixnum#<=(Rational)' do +assert 'Integer#<=(Rational)' do assert_not_operator(1, :<=, Rational(2,3)) assert_operator(2, :<=, 2r) assert_operator(-3, :<=, Rational(2,3)) @@ -258,7 +258,7 @@ assert 'Rational#>' do assert_raise(ArgumentError) { 1r > "2" } end -assert 'Fixnum#>(Rational)' do +assert 'Integer#>(Rational)' do assert_operator(1, :>, Rational(2,3)) assert_not_operator(2, :>, 2r) assert_not_operator(-3, :>, Rational(2,3)) @@ -282,7 +282,7 @@ assert 'Rational#>=' do assert_raise(ArgumentError) { 1r >= "2" } end -assert 'Fixnum#>=(Rational)' do +assert 'Integer#>=(Rational)' do assert_operator(1, :>=, Rational(2,3)) assert_operator(2, :>=, 2r) assert_not_operator(-3, :>=, Rational(2,3)) diff --git a/mrbgems/mruby-socket/src/socket.c b/mrbgems/mruby-socket/src/socket.c index 001021b81..6542c1603 100644 --- a/mrbgems/mruby-socket/src/socket.c +++ b/mrbgems/mruby-socket/src/socket.c @@ -145,7 +145,7 @@ mrb_addrinfo_getaddrinfo(mrb_state *mrb, mrb_value klass) } else if (mrb_nil_p(service)) { servname = NULL; } else { - mrb_raise(mrb, E_TYPE_ERROR, "service must be String, Fixnum, or nil"); + mrb_raise(mrb, E_TYPE_ERROR, "service must be String, Integer, or nil"); } memset(&hints, 0, sizeof(hints)); diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index 4f50fe5dd..423cf99a5 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -604,8 +604,8 @@ mrb_struct_eql(mrb_state *mrb, mrb_value s) /* * call-seq: - * struct.length -> Fixnum - * struct.size -> Fixnum + * struct.length -> Integer + * struct.size -> Integer * * Returns number of struct members. */ diff --git a/mrblib/range.rb b/mrblib/range.rb index 392cc2274..9f94f35d1 100644 --- a/mrblib/range.rb +++ b/mrblib/range.rb @@ -15,7 +15,7 @@ class Range val = self.first last = self.last - if val.kind_of?(Fixnum) && last.kind_of?(Fixnum) # fixnums are special + if val.kind_of?(Integer) && last.kind_of?(Integer) # fixnums are special lim = last lim += 1 unless exclude_end? i = val diff --git a/src/class.c b/src/class.c index 845246e97..df33feffb 100644 --- a/src/class.c +++ b/src/class.c @@ -638,8 +638,8 @@ void mrb_hash_check_kdict(mrb_state *mrb, mrb_value self); z: String [const char*] NUL terminated string; z! gives NULL for nil a: Array [mrb_value*,mrb_int] Receive two arguments; a! gives (NULL,0) for nil c: Class/Module [strcut RClass*] - f: Fixnum/Float [mrb_float] - i: Fixnum/Float [mrb_int] + f: Integer/Float [mrb_float] + i: Integer/Float [mrb_int] b: boolean [mrb_bool] n: String/Symbol [mrb_sym] d: data [void*,mrb_data_type const] 2nd argument will be used to check data type so it won't be modified; when ! follows, the value may be nil @@ -1874,7 +1874,7 @@ mrb_module_new(mrb_state *mrb) * called with an explicit receiver, as class is also a * reserved word in Ruby. * - * 1.class #=> Fixnum + * 1.class #=> Integer * self.class #=> Object */ diff --git a/src/gc.c b/src/gc.c index 50269f95c..fd472217e 100644 --- a/src/gc.c +++ b/src/gc.c @@ -932,7 +932,7 @@ root_scan_phase(mrb_state *mrb, mrb_gc *gc) #ifndef MRB_NO_FLOAT mrb_gc_mark(mrb, (struct RBasic*)mrb->float_class); #endif - mrb_gc_mark(mrb, (struct RBasic*)mrb->fixnum_class); + mrb_gc_mark(mrb, (struct RBasic*)mrb->integer_class); mrb_gc_mark(mrb, (struct RBasic*)mrb->true_class); mrb_gc_mark(mrb, (struct RBasic*)mrb->false_class); mrb_gc_mark(mrb, (struct RBasic*)mrb->nil_class); diff --git a/src/kernel.c b/src/kernel.c index 020bce226..699c681d7 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -209,7 +209,7 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self) * called with an explicit receiver, as class is also a * reserved word in Ruby. * - * 1.class #=> Fixnum + * 1.class #=> Integer * self.class #=> Object */ static mrb_value @@ -341,7 +341,7 @@ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj) * behavior will be documented under the #+initialize_copy+ method of * the class. * - * Some Class(True False Nil Symbol Fixnum Float) Object cannot clone. + * Some Class(True False Nil Symbol Integer Float) Object cannot clone. */ MRB_API mrb_value mrb_obj_clone(mrb_state *mrb, mrb_value self) @@ -480,11 +480,11 @@ mrb_obj_frozen(mrb_state *mrb, mrb_value self) * call-seq: * obj.hash -> fixnum * - * Generates a Fixnum hash value for this object. This + * Generates a Integer hash value for this object. This * function must have the property that a.eql?(b) implies * a.hash == b.hash. The hash value is used by class * Hash. Any hash value that exceeds the capacity of a - * Fixnum will be truncated before being used. + * Integer will be truncated before being used. */ static mrb_value mrb_obj_hash(mrb_state *mrb, mrb_value self) diff --git a/src/numeric.c b/src/numeric.c index f4ad116a4..40114c07d 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -1,5 +1,5 @@ /* -** numeric.c - Numeric, Integer, Float, Fixnum class +** numeric.c - Numeric, Integer, Float class ** ** See Copyright Notice in mruby.h */ @@ -378,7 +378,7 @@ flo_mod(mrb_state *mrb, mrb_value x) * (1.0).eql?(1.0) #=> true */ static mrb_value -fix_eql(mrb_state *mrb, mrb_value x) +int_eql(mrb_state *mrb, mrb_value x) { mrb_value y = mrb_get_arg1(mrb); @@ -771,8 +771,7 @@ flo_nan_p(mrb_state *mrb, mrb_value num) /* * Document-class: Integer * - * Integer is the basis for the two concrete classes that - * hold whole numbers, Bignum and Fixnum. + * Integer is hold whole numbers. * */ @@ -842,7 +841,7 @@ mrb_num_mul(mrb_state *mrb, mrb_value x, mrb_value y) */ static mrb_value -fix_mul(mrb_state *mrb, mrb_value x) +int_mul(mrb_state *mrb, mrb_value x) { mrb_value y = mrb_get_arg1(mrb); @@ -888,7 +887,7 @@ fixdivmod(mrb_state *mrb, mrb_int x, mrb_int y, mrb_int *divp, mrb_int *modp) */ static mrb_value -fix_mod(mrb_state *mrb, mrb_value x) +int_mod(mrb_state *mrb, mrb_value x) { mrb_value y = mrb_get_arg1(mrb); mrb_int a, b; @@ -929,7 +928,7 @@ fix_mod(mrb_state *mrb, mrb_value x) * See Numeric#divmod. */ static mrb_value -fix_divmod(mrb_state *mrb, mrb_value x) +int_divmod(mrb_state *mrb, mrb_value x) { mrb_value y = mrb_get_arg1(mrb); @@ -992,7 +991,7 @@ flo_divmod(mrb_state *mrb, mrb_value x) */ static mrb_value -fix_equal(mrb_state *mrb, mrb_value x) +int_equal(mrb_state *mrb, mrb_value x) { mrb_value y = mrb_get_arg1(mrb); @@ -1020,7 +1019,7 @@ fix_equal(mrb_state *mrb, mrb_value x) */ static mrb_value -fix_rev(mrb_state *mrb, mrb_value num) +int_rev(mrb_state *mrb, mrb_value num) { mrb_int val = mrb_fixnum(num); @@ -1050,7 +1049,7 @@ static mrb_value flo_xor(mrb_state *mrb, mrb_value x); */ static mrb_value -fix_and(mrb_state *mrb, mrb_value x) +int_and(mrb_state *mrb, mrb_value x) { mrb_value y = mrb_get_arg1(mrb); @@ -1066,7 +1065,7 @@ fix_and(mrb_state *mrb, mrb_value x) */ static mrb_value -fix_or(mrb_state *mrb, mrb_value x) +int_or(mrb_state *mrb, mrb_value x) { mrb_value y = mrb_get_arg1(mrb); @@ -1082,7 +1081,7 @@ fix_or(mrb_state *mrb, mrb_value x) */ static mrb_value -fix_xor(mrb_state *mrb, mrb_value x) +int_xor(mrb_state *mrb, mrb_value x) { mrb_value y = mrb_get_arg1(mrb); @@ -1160,7 +1159,7 @@ rshift(mrb_int val, mrb_int width) */ static mrb_value -fix_lshift(mrb_state *mrb, mrb_value x) +int_lshift(mrb_state *mrb, mrb_value x) { mrb_int width, val; @@ -1185,7 +1184,7 @@ fix_lshift(mrb_state *mrb, mrb_value x) */ static mrb_value -fix_rshift(mrb_state *mrb, mrb_value x) +int_rshift(mrb_state *mrb, mrb_value x) { mrb_int width, val; @@ -1212,7 +1211,7 @@ fix_rshift(mrb_state *mrb, mrb_value x) #ifndef MRB_NO_FLOAT static mrb_value -fix_to_f(mrb_state *mrb, mrb_value num) +int_to_f(mrb_state *mrb, mrb_value num) { return mrb_float_value(mrb, (mrb_float)mrb_fixnum(num)); } @@ -1305,7 +1304,7 @@ mrb_num_plus(mrb_state *mrb, mrb_value x, mrb_value y) * result. */ static mrb_value -fix_plus(mrb_state *mrb, mrb_value self) +int_plus(mrb_state *mrb, mrb_value self) { mrb_value other = mrb_get_arg1(mrb); @@ -1362,7 +1361,7 @@ mrb_num_minus(mrb_state *mrb, mrb_value x, mrb_value y) * result. */ static mrb_value -fix_minus(mrb_state *mrb, mrb_value self) +int_minus(mrb_state *mrb, mrb_value self) { mrb_value other = mrb_get_arg1(mrb); @@ -1419,7 +1418,7 @@ mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, mrb_int base) * */ static mrb_value -fix_to_s(mrb_state *mrb, mrb_value self) +int_to_s(mrb_state *mrb, mrb_value self) { mrb_int base = 10; @@ -1599,7 +1598,7 @@ flo_plus(mrb_state *mrb, mrb_value x) void mrb_init_numeric(mrb_state *mrb) { - struct RClass *numeric, *integer, *fixnum, *integral; + struct RClass *numeric, *integer, *integral; #ifndef MRB_NO_FLOAT struct RClass *fl; #endif @@ -1622,7 +1621,7 @@ mrb_init_numeric(mrb_state *mrb) mrb_define_method(mrb, numeric, "infinite?",num_infinite_p, MRB_ARGS_NONE()); /* Integer Class */ - integer = mrb_define_class(mrb, "Integer", numeric); /* 15.2.8 */ + mrb->integer_class = integer = mrb_define_class(mrb, "Integer", numeric); /* 15.2.8 */ MRB_SET_INSTANCE_TT(integer, MRB_TT_FIXNUM); mrb_undef_class_method(mrb, integer, "new"); mrb_define_method(mrb, integer, "to_i", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.24 */ @@ -1634,26 +1633,27 @@ mrb_init_numeric(mrb_state *mrb) mrb_define_method(mrb, integer, "truncate", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.15 (x) */ #endif - /* Fixnum Class */ - mrb->fixnum_class = fixnum = mrb_define_class(mrb, "Fixnum", integer); - mrb_define_method(mrb, fixnum, "+", fix_plus, MRB_ARGS_REQ(1)); /* 15.2.8.3.1 */ - mrb_define_method(mrb, fixnum, "-", fix_minus, MRB_ARGS_REQ(1)); /* 15.2.8.3.2 */ - mrb_define_method(mrb, fixnum, "*", fix_mul, MRB_ARGS_REQ(1)); /* 15.2.8.3.3 */ - mrb_define_method(mrb, fixnum, "%", fix_mod, MRB_ARGS_REQ(1)); /* 15.2.8.3.5 */ - mrb_define_method(mrb, fixnum, "==", fix_equal, MRB_ARGS_REQ(1)); /* 15.2.8.3.7 */ - mrb_define_method(mrb, fixnum, "~", fix_rev, MRB_ARGS_NONE()); /* 15.2.8.3.8 */ - mrb_define_method(mrb, fixnum, "&", fix_and, MRB_ARGS_REQ(1)); /* 15.2.8.3.9 */ - mrb_define_method(mrb, fixnum, "|", fix_or, MRB_ARGS_REQ(1)); /* 15.2.8.3.10 */ - mrb_define_method(mrb, fixnum, "^", fix_xor, MRB_ARGS_REQ(1)); /* 15.2.8.3.11 */ - mrb_define_method(mrb, fixnum, "<<", fix_lshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.12 */ - mrb_define_method(mrb, fixnum, ">>", fix_rshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.13 */ - mrb_define_method(mrb, fixnum, "eql?", fix_eql, MRB_ARGS_REQ(1)); /* 15.2.8.3.16 */ -#ifndef MRB_NO_FLOAT - mrb_define_method(mrb, fixnum, "to_f", fix_to_f, MRB_ARGS_NONE()); /* 15.2.8.3.23 */ + mrb_define_method(mrb, integer, "+", int_plus, MRB_ARGS_REQ(1)); /* 15.2.8.3.1 */ + mrb_define_method(mrb, integer, "-", int_minus, MRB_ARGS_REQ(1)); /* 15.2.8.3.2 */ + mrb_define_method(mrb, integer, "*", int_mul, MRB_ARGS_REQ(1)); /* 15.2.8.3.3 */ + mrb_define_method(mrb, integer, "%", int_mod, MRB_ARGS_REQ(1)); /* 15.2.8.3.5 */ + mrb_define_method(mrb, integer, "==", int_equal, MRB_ARGS_REQ(1)); /* 15.2.8.3.7 */ + mrb_define_method(mrb, integer, "~", int_rev, MRB_ARGS_NONE()); /* 15.2.8.3.8 */ + mrb_define_method(mrb, integer, "&", int_and, MRB_ARGS_REQ(1)); /* 15.2.8.3.9 */ + mrb_define_method(mrb, integer, "|", int_or, MRB_ARGS_REQ(1)); /* 15.2.8.3.10 */ + mrb_define_method(mrb, integer, "^", int_xor, MRB_ARGS_REQ(1)); /* 15.2.8.3.11 */ + mrb_define_method(mrb, integer, "<<", int_lshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.12 */ + mrb_define_method(mrb, integer, ">>", int_rshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.13 */ + mrb_define_method(mrb, integer, "eql?", int_eql, MRB_ARGS_REQ(1)); /* 15.2.8.3.16 */ +#ifndef MRB_WITHOUT_FLOAT + mrb_define_method(mrb, integer, "to_f", int_to_f, MRB_ARGS_NONE()); /* 15.2.8.3.23 */ #endif - mrb_define_method(mrb, fixnum, "to_s", fix_to_s, MRB_ARGS_OPT(1)); /* 15.2.8.3.25 */ - mrb_define_method(mrb, fixnum, "inspect", fix_to_s, MRB_ARGS_OPT(1)); - mrb_define_method(mrb, fixnum, "divmod", fix_divmod, MRB_ARGS_REQ(1)); /* 15.2.8.3.30 (x) */ + mrb_define_method(mrb, integer, "to_s", int_to_s, MRB_ARGS_OPT(1)); /* 15.2.8.3.25 */ + mrb_define_method(mrb, integer, "inspect", int_to_s, MRB_ARGS_OPT(1)); + mrb_define_method(mrb, integer, "divmod", int_divmod, MRB_ARGS_REQ(1)); /* 15.2.8.3.30 (x) */ + + /* Fixnum Class for compatibility */ + mrb_define_const(mrb, mrb->object_class, "Fixnum", mrb_obj_value(integer)); #ifndef MRB_NO_FLOAT /* Float Class */ diff --git a/src/string.c b/src/string.c index f15770403..a8dfb5503 100644 --- a/src/string.c +++ b/src/string.c @@ -1186,7 +1186,7 @@ range_arg: break; } - mrb_raise(mrb, E_TYPE_ERROR, "can't convert to Fixnum"); + mrb_raise(mrb, E_TYPE_ERROR, "can't convert to Integer"); } } return STR_OUT_OF_RANGE; @@ -1230,8 +1230,8 @@ mrb_str_aref(mrb_state *mrb, mrb_value str, mrb_value indx, mrb_value alen) * str.slice(range) => new_str or nil * str.slice(other_str) => new_str or nil * - * Element Reference---If passed a single Fixnum, returns the code - * of the character at that position. If passed two Fixnum + * Element Reference---If passed a single Integer, returns the code + * of the character at that position. If passed two Integer * objects, returns a substring starting at the offset given by the first, and * a length given by the second. If given a range, a substring containing * characters at offsets given by the range is returned. In all three cases, if diff --git a/test/t/bs_literal.rb b/test/t/bs_literal.rb index c6c38140b..d60957f0b 100644 --- a/test/t/bs_literal.rb +++ b/test/t/bs_literal.rb @@ -34,5 +34,5 @@ assert('BS Literal 8') do end assert('BS Literal 9') do - assert_equal Fixnum, 1234.class + assert_equal Integer, 1234.class end diff --git a/test/t/integer.rb b/test/t/integer.rb index f9c44a64f..620ec94d3 100644 --- a/test/t/integer.rb +++ b/test/t/integer.rb @@ -156,7 +156,7 @@ assert('Integer#<<', '15.2.8.3.12') do skip unless Object.const_defined?(:Float) - # Overflow to Fixnum + # Overflow to Integer assert_float 9223372036854775808.0, 1 << 63 assert_float(-13835058055282163712.0, -3 << 62) end diff --git a/test/t/kernel.rb b/test/t/kernel.rb index 606150147..cab1ddd3d 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -76,7 +76,7 @@ assert('Kernel.raise', '15.3.1.2.12') do end assert('Kernel#__id__', '15.3.1.3.3') do - assert_equal Fixnum, __id__.class + assert_equal Integer, __id__.class end assert('Kernel#__send__', '15.3.1.3.4') do diff --git a/test/t/module.rb b/test/t/module.rb index 12b7f1344..2957dec52 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -593,7 +593,7 @@ end # to_f / other # end # end - # Fixnum.send(:prepend, M) + # Integer.send(:prepend, M) # assert_equal(0.5, 1 / 2, "#{bug7983}") # } # assert_equal(0, 1 / 2) diff --git a/test/t/vformat.rb b/test/t/vformat.rb index df6950ee6..f645351ee 100644 --- a/test/t/vformat.rb +++ b/test/t/vformat.rb @@ -17,7 +17,7 @@ assert('mrb_vformat') do assert_equal '`t`: NilClass', vf.v('`t`: %t', nil) assert_equal '`t`: FalseClass', vf.v('`t`: %t', false) assert_equal '`t`: TrueClass', vf.v('`t`: %t', true) - assert_equal '`t`: Fixnum', vf.v('`t`: %t', 0) + assert_equal '`t`: Integer', vf.v('`t`: %t', 0) assert_equal '`t`: Hash', vf.v('`t`: %t', {k: "value"}) assert_match '#>>', vf.v('%t', sclass({})) assert_equal 'string and length', vf.l('string %l length', 'andante', 3) @@ -29,13 +29,13 @@ assert('mrb_vformat') do assert_equal '`T`: NilClass', vf.v('`T`: %T', nil) assert_equal '`T`: FalseClass', vf.v('`T`: %T', false) assert_equal '`T`: TrueClass', vf.v('`T`: %T', true) - assert_equal '`T`: Fixnum', vf.v('`T`: %T', 0) + assert_equal '`T`: Integer', vf.v('`T`: %T', 0) assert_equal '`T`: Hash', vf.v('`T`: %T', {k: "value"}) assert_match 'Class', vf.v('%T', sclass({})) assert_equal '`Y`: nil', vf.v('`Y`: %Y', nil) assert_equal '`Y`: false', vf.v('`Y`: %Y', false) assert_equal '`Y`: true', vf.v('`Y`: %Y', true) - assert_equal '`Y`: Fixnum', vf.v('`Y`: %Y', 0) + assert_equal '`Y`: Integer', vf.v('`Y`: %Y', 0) assert_equal '`Y`: Hash', vf.v('`Y`: %Y', {k: "value"}) assert_equal 'Class', vf.v('%Y', sclass({})) assert_match '#>', vf.v('%v', sclass("")) -- cgit v1.2.3 From 2a92fb2516251fb0ddfa2d1026930a2c7465e528 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 18 Aug 2020 22:12:28 +0900 Subject: Make division by zero cause `ZeroDivisionError`. As described in ISO 15.2.30. --- doc/limitations.md | 9 ++++++++- include/mruby.h | 1 + mrblib/10error.rb | 4 ++++ src/numeric.c | 20 +++----------------- src/vm.c | 13 +++++++------ test/t/superclass.rb | 2 +- 6 files changed, 24 insertions(+), 25 deletions(-) (limited to 'doc') diff --git a/doc/limitations.md b/doc/limitations.md index 7e58ca420..8ac959b98 100644 --- a/doc/limitations.md +++ b/doc/limitations.md @@ -63,8 +63,15 @@ end #### mruby [2.1.2 (2020-08-06)] -No exception is raised. +No exception is raised. Instead you have to do: +```ruby +begin + 1 / 0 +rescue => e + raise e +end +``` ## Fiber execution can't cross C function boundary mruby's `Fiber` is implemented in a similar way to Lua's co-routine. This diff --git a/include/mruby.h b/include/mruby.h index f07adbb13..959d1ac6d 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -1292,6 +1292,7 @@ MRB_API mrb_value mrb_vformat(mrb_state *mrb, const char *format, va_list ap); */ #define E_RUNTIME_ERROR (mrb_exc_get_id(mrb, MRB_SYM(RuntimeError))) #define E_TYPE_ERROR (mrb_exc_get_id(mrb, MRB_SYM(TypeError))) +#define E_ZERODIV_ERROR (mrb_exc_get_id(mrb, MRB_SYM(ZeroDivisionError))) #define E_ARGUMENT_ERROR (mrb_exc_get_id(mrb, MRB_SYM(ArgumentError))) #define E_INDEX_ERROR (mrb_exc_get_id(mrb, MRB_SYM(IndexError))) #define E_RANGE_ERROR (mrb_exc_get_id(mrb, MRB_SYM(RangeError))) diff --git a/mrblib/10error.rb b/mrblib/10error.rb index 0d9f38d58..054603514 100644 --- a/mrblib/10error.rb +++ b/mrblib/10error.rb @@ -21,6 +21,10 @@ end class TypeError < StandardError end +# ISO 15.2.30 +class ZeroDivisionError < StandardError +end + # ISO 15.2.31 class NameError < StandardError attr_accessor :name diff --git a/src/numeric.c b/src/numeric.c index 99d32f919..0cc7958e6 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -156,7 +156,7 @@ integral_div(mrb_state *mrb, mrb_value xv) mrb_get_args(mrb, "i", &y); if (y == 0) { - mrb_raise(mrb, E_RUNTIME_ERROR, "devided by zero"); + mrb_raise(mrb, E_ZERODIV_ERROR, "devided by zero"); } return mrb_fixnum_value(mrb_fixnum(xv) / y); #else @@ -932,14 +932,7 @@ int_mod(mrb_state *mrb, mrb_value x) mrb_int mod; if (b == 0) { -#ifdef MRB_NO_FLOAT - /* ZeroDivisionError */ - return mrb_fixnum_value(0); -#else - if (a > 0) return mrb_float_value(mrb, INFINITY); - if (a < 0) return mrb_float_value(mrb, INFINITY); - return mrb_float_value(mrb, NAN); -#endif + mrb_raise(mrb, E_ZERODIV_ERROR, "divided by 0"); } fixdivmod(mrb, a, b, NULL, &mod); return mrb_fixnum_value(mod); @@ -971,14 +964,7 @@ int_divmod(mrb_state *mrb, mrb_value x) mrb_int div, mod; if (mrb_fixnum(y) == 0) { -#ifdef MRB_NO_FLOAT - return mrb_assoc_new(mrb, mrb_fixnum_value(0), mrb_fixnum_value(0)); -#else - return mrb_assoc_new(mrb, ((mrb_fixnum(x) == 0) ? - mrb_float_value(mrb, NAN): - mrb_float_value(mrb, INFINITY)), - mrb_float_value(mrb, NAN)); -#endif + mrb_raise(mrb, E_ZERODIV_ERROR, "divided by 0"); } fixdivmod(mrb, mrb_fixnum(x), mrb_fixnum(y), &div, &mod); return mrb_assoc_new(mrb, mrb_fixnum_value(div), mrb_fixnum_value(mod)); diff --git a/src/vm.c b/src/vm.c index 979c67424..15a38c0e4 100644 --- a/src/vm.c +++ b/src/vm.c @@ -2315,12 +2315,13 @@ RETRY_TRY_BLOCK: { mrb_int x = mrb_fixnum(regs[a]); mrb_int y = mrb_fixnum(regs[a+1]); - if (y == 0 || (x == MRB_INT_MIN && y == -1)) { -#ifdef MRB_NO_FLOAT - SET_INT_VALUE(regs[a], y ? x / y : 0); -#else - SET_FLOAT_VALUE(mrb, regs[a], (mrb_float)x / (mrb_float)y); -#endif + + + if (y == 0) { + mrb_raise(mrb, E_ZERODIV_ERROR, "divided by 0"); + } + else if(x == MRB_INT_MIN && y == -1) { + mrb_raise(mrb, E_RANGE_ERROR, "integer overflow in division"); } else { mrb_int div, mod; diff --git a/test/t/superclass.rb b/test/t/superclass.rb index 10b6438d3..70d5c24d9 100644 --- a/test/t/superclass.rb +++ b/test/t/superclass.rb @@ -29,7 +29,7 @@ [:RegexpError, :StandardError, '12.2.27.2'], [:RuntimeError, :StandardError, '12.2.28.2'], [:TypeError, :StandardError, '12.2.29.2'], -# [:ZeroDivisionError, :StandardError, '12.2.30.2'], # No ZeroDivisionError in mruby + [:ZeroDivisionError, :StandardError, '12.2.30.2'], [:NameError, :StandardError, '15.2.31.2'], [:NoMethodError, :NameError, '15.2.32.2'], [:IndexError, :StandardError, '15.2.33.2'], -- cgit v1.2.3 From 7f66e50ba2f71514da711a7927554956faea2f29 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 2 Sep 2020 08:41:55 +0900 Subject: Explain `MRB_USE_MALLOC_TRIM`; ref #5069 --- doc/mruby3.md | 5 +++++ include/mrbconf.h | 3 +++ 2 files changed, 8 insertions(+) (limited to 'doc') diff --git a/doc/mruby3.md b/doc/mruby3.md index c8ec76937..ae6e674e5 100644 --- a/doc/mruby3.md +++ b/doc/mruby3.md @@ -96,6 +96,11 @@ does not fit in `Fixnum` integers. Pack `mrb_value` in a floating pointer number. Nothing changed from previous versions. +== `MRB_USE_MALLOC_TRIM` + +Call `malloc_trim(0)` from mrb_full_gc() if this macro is defined. +If you are using glibc malloc, this macro could reduce memory consumption. + = Internal Changes == `Random` now use `xoshiro128++`. diff --git a/include/mrbconf.h b/include/mrbconf.h index 249bb72e4..89b3e9022 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -101,6 +101,9 @@ # endif #endif +/* call malloc_trim(0) from mrb_full_gc() */ +//#define MRB_USE_MALLOC_TRIM + /* string class to handle UTF-8 encoding */ //#define MRB_UTF8_STRING -- cgit v1.2.3 From 5d1d94d911abd2fe6abe9d1f23d98f8995ec8c4e Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 19 Sep 2020 23:56:27 +0900 Subject: Use Markdown section marker `#`; ref #5084 [ci skip] The fix was proposed by @dearblue --- doc/mruby3.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'doc') diff --git a/doc/mruby3.md b/doc/mruby3.md index ae6e674e5..4e4f94d07 100644 --- a/doc/mruby3.md +++ b/doc/mruby3.md @@ -1,7 +1,7 @@ User visible changes in `mruby3` === -= Build System +# Build System You can specify `TARGET` option to `rake` via a command line option, or via an environment variable, e.g. @@ -15,13 +15,13 @@ or It's much easier to switch multiple targets than the previous `build_config.rb` system. -== `presym` target +## `presym` target The first compilation of `mruby` may require generation of a static symbol table named `build/presym`. You can generate the table by `rake gensym`. -== `target` directory +## `target` directory Build target specification files are loaded from `target` directory. The default `TARGET` is `host` which is described @@ -39,15 +39,15 @@ If you want to have your target description out of the source tree, you can specify the path to the description file in `MRUBY_CONFIG`. -= Build Target Contribution +# Build Target Contribution When you write a new target description, please contribute. We welcome your contribution as a GitHub pull-request. -= Languge Changes +# Languge Changes -== New Syntax +## New Syntax We have ported some new syntax from CRuby. @@ -55,54 +55,54 @@ We have ported some new syntax from CRuby. * Numbered block parameter (`x.map{_1 * 2}`) * End-less `def` (`def double(x) = x*2`) -= Configuration Options Changed +# Configuration Options Changed Some configuration macro names are changed for consistency -== `MRB_NO_FLOAT` +## `MRB_NO_FLOAT` Changed from `MRB_WITHOUT_FLOAT` to conform `USE_XXX` naming convention. -== `MRB_USE_FLOAT32` +## `MRB_USE_FLOAT32` Changed from `MRB_USE_FLOAT` to make sure `float` here means using single precision float, and not the opposite of `MRB_NO_FLOAT`. -== `MRB_USE_METHOD_T_STRUCT` +## `MRB_USE_METHOD_T_STRUCT` Changed from `MRB_METHOD_T_STRUCT`. To use `struct` version of `mrb_method_t`. More portable but consumes more memory. Turned on by default on 32bit platforms. -== `MRB_NO_BOXING` +## `MRB_NO_BOXING` Uses `struct` to represent `mrb_value`. Consumes more memory but easier to inveticate the internal and to debug. It used to be default `mrb_value` representation. Now the default is `MRB_WORD_BOXING`. -== `MRB_WORD_BOXING` +## `MRB_WORD_BOXING` Pack `mrb_value` in an `intptr_t` integer. Consumes less memory compared to `MRB_NO_BOXING` especially on 32 bit platforms. `Fixnum` size is 31 bits so some integer values does not fit in `Fixnum` integers. -== `MRB_NAN_BOXING` +## `MRB_NAN_BOXING` Pack `mrb_value` in a floating pointer number. Nothing changed from previous versions. -== `MRB_USE_MALLOC_TRIM` +## `MRB_USE_MALLOC_TRIM` Call `malloc_trim(0)` from mrb_full_gc() if this macro is defined. If you are using glibc malloc, this macro could reduce memory consumption. -= Internal Changes +# Internal Changes -== `Random` now use `xoshiro128++`. +## `Random` now use `xoshiro128++`. For better and faster random number generation. -- cgit v1.2.3