Ignore:
Timestamp:
Jul 9, 2020, 8:51:43 AM (4 years ago)
Author:
coas-nagasima
Message:

mrubyを2.1.1に更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/prototool/src/apiprint.c

    r321 r439  
    44*/
    55
    6 #include <stdlib.h>
    7 
     6#include <string.h>
    87#include "mrdb.h"
    9 #include "mruby/value.h"
    10 #include "mruby/class.h"
    11 #include "mruby/compile.h"
    12 #include "mruby/error.h"
    13 #include "mruby/numeric.h"
    14 #include "mruby/string.h"
     8#include <mruby/value.h>
     9#include <mruby/class.h>
     10#include <mruby/compile.h>
     11#include <mruby/error.h>
     12#include <mruby/numeric.h>
     13#include <mruby/string.h>
    1514#include "apiprint.h"
    1615
     
    1817mrdb_check_syntax(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t len)
    1918{
    20         mrbc_context *c;
     19  mrbc_context *c;
    2120
    22         c = mrbc_context_new(mrb);
    23         c->no_exec = TRUE;
    24         c->capture_errors = TRUE;
    25         c->filename = (char*)dbg->prvfile;
    26         c->lineno = dbg->prvline;
     21  c = mrbc_context_new(mrb);
     22  c->no_exec = TRUE;
     23  c->capture_errors = TRUE;
     24  mrbc_filename(mrb, c, (const char*)dbg->prvfile);
     25  c->lineno = dbg->prvline;
    2726
    28         /* Load program */
    29         mrb_load_nstring_cxt(mrb, expr, len, c);
     27  /* Load program */
     28  mrb_load_nstring_cxt(mrb, expr, len, c);
    3029
    31         mrbc_context_free(mrb, c);
     30  mrbc_context_free(mrb, c);
    3231}
    3332
    3433mrb_value
    35 mrb_debug_eval(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t len, mrb_bool *exc)
     34mrb_debug_eval(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t len, mrb_bool *exc, int direct_eval)
    3635{
    37         void(*tmp)(struct mrb_state *, struct mrb_irep *, mrb_code *, mrb_value *);
    38         mrb_value ruby_code;
    39         mrb_value s;
    40         mrb_value v;
    41         mrb_value recv;
     36  void (*tmp)(struct mrb_state *, struct mrb_irep *, const mrb_code *, mrb_value *);
     37  mrb_value ruby_code;
     38  mrb_value s;
     39  mrb_value v;
     40  mrb_value recv;
    4241
    43         /* disable code_fetch_hook */
    44         tmp = mrb->code_fetch_hook;
    45         mrb->code_fetch_hook = NULL;
     42  /* disable code_fetch_hook */
     43  tmp = mrb->code_fetch_hook;
     44  mrb->code_fetch_hook = NULL;
    4645
    47         mrdb_check_syntax(mrb, dbg, expr, len);
    48         if (mrb->exc) {
    49                 v = mrb_obj_value(mrb->exc);
    50                 mrb->exc = 0;
    51         }
    52         else {
    53                 /*
    54                  * begin
    55                  *   expr
    56                  * rescue => e
    57                  *   e
    58                  * end
    59                  */
    60                 ruby_code = mrb_str_new_lit(mrb, "begin\n");
    61                 ruby_code = mrb_str_cat(mrb, ruby_code, expr, len);
    62                 ruby_code = mrb_str_cat_lit(mrb, ruby_code, "\nrescue => e\ne\nend");
     46  mrdb_check_syntax(mrb, dbg, expr, len);
     47  if (mrb->exc) {
     48    v = mrb_obj_value(mrb->exc);
     49    mrb->exc = 0;
     50  }
     51  else if (direct_eval) {
     52    recv = dbg->regs[0];
    6353
    64                 recv = dbg->regs[0];
     54    v = mrb_funcall(mrb, recv, expr, 0);
     55  }
     56  else {
     57    /*
     58     * begin
     59     *   expr
     60     * rescue => e
     61     *   e
     62     * end
     63     */
     64    ruby_code = mrb_str_new_lit(mrb, "begin\n");
     65    ruby_code = mrb_str_cat(mrb, ruby_code, expr, len);
     66    ruby_code = mrb_str_cat_lit(mrb, ruby_code, "\nrescue => e\ne\nend");
    6567
    66                 v = mrb_funcall(mrb, recv, "instance_eval", 1, ruby_code);
    67         }
     68    recv = dbg->regs[0];
    6869
    69         if (exc) {
    70                 *exc = mrb_obj_is_kind_of(mrb, v, mrb->eException_class);
    71         }
     70    v =  mrb_funcall(mrb, recv, "instance_eval", 1, ruby_code);
     71  }
    7272
    73         s = mrb_funcall(mrb, v, "inspect", 0);
     73  if (exc) {
     74    *exc = mrb_obj_is_kind_of(mrb, v, mrb->eException_class);
     75  }
    7476
    75         /* enable code_fetch_hook */
    76         mrb->code_fetch_hook = tmp;
     77  s = mrb_inspect(mrb, v);
    7778
    78         return s;
     79  /* enable code_fetch_hook */
     80  mrb->code_fetch_hook = tmp;
     81
     82  return s;
    7983}
Note: See TracChangeset for help on using the changeset viewer.