From a54a3df32c379a6953664f1d9241c731066915ec Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 24 May 2020 00:19:04 +0900 Subject: Extended mruby binary format The catch handler table is combined with iseq block. This is to prevent the structure from growing by adding a field for the catch handler table to the `mrb_irep` structure. "iseq block" and "catch handler table": [number of catch handler table (2 bytes)] [number of byte code (4 bytes)] [iseq (any bytes)] [catch handlers (multiple of 7 bytes)] catch handler: [catch type (1 byte)] [begin offset (2 bytes)] [end offset (2 bytes)] [target offset (2 bytes)] catch type: enum mrb_catch_type (0 = rescue, 1 = ensure) begin offset: Includes the specified instruction address end offset: Does not include the specified instruction address target offset: replaces pc with the specified instruction address This table is not expanded by `read_irep_record_1()`. The necessary elements are expanded one by one when used. --- src/codedump.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/codedump.c') diff --git a/src/codedump.c b/src/codedump.c index 106312f67..a19d60708 100644 --- a/src/codedump.c +++ b/src/codedump.c @@ -4,6 +4,7 @@ #include #include #include +#include #ifndef MRB_DISABLE_STDIO static void @@ -80,6 +81,34 @@ codedump(mrb_state *mrb, const mrb_irep *irep) } } + if (irep->clen > 0) { + int i = irep->clen; + const struct mrb_irep_catch_hander *e = mrb_irep_catch_handler_table(irep); + + for (; i > 0; i --, e ++) { + int begin = bin_to_uint16(e->begin); + int end = bin_to_uint16(e->end); + int target = bin_to_uint16(e->target); + char buf[20]; + const char *type; + + switch (e->type) { + case MRB_CATCH_RESCUE: + type = "rescue"; + break; + case MRB_CATCH_ENSURE: + type = "ensure"; + break; + default: + buf[0] = '\0'; + snprintf(buf, sizeof(buf), "0x%02x ", (int)e->type); + type = buf; + break; + } + printf("catch type: %-8s begin: %04d end: %04d target: %04d\n", type, begin, end, target); + } + } + pc = irep->iseq; pcend = pc + irep->ilen; while (pc < pcend) { -- cgit v1.2.3