source: EcnlProtoTool/trunk/mruby-1.2.0/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c@ 270

Last change on this file since 270 was 270, checked in by coas-nagasima, 7 years ago

mruby版ECNLプロトタイピング・ツールを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 1.6 KB
Line 
1/*
2** apiprint.c
3**
4*/
5
6#include <string.h>
7#include "mrdb.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"
14#include "apiprint.h"
15
16static void
17mrdb_check_syntax(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t len)
18{
19 mrbc_context *c;
20
21 c = mrbc_context_new(mrb);
22 c->no_exec = TRUE;
23 c->capture_errors = TRUE;
24 c->filename = (char*)dbg->prvfile;
25 c->lineno = dbg->prvline;
26
27 /* Load program */
28 mrb_load_nstring_cxt(mrb, expr, len, c);
29
30 mrbc_context_free(mrb, c);
31}
32
33mrb_value
34mrb_debug_eval(mrb_state *mrb, mrb_debug_context *dbg, const char *expr, size_t len, mrb_bool *exc)
35{
36 void (*tmp)(struct mrb_state *, struct mrb_irep *, mrb_code *, mrb_value *);
37 mrb_value ruby_code;
38 mrb_value s;
39 mrb_value v;
40 mrb_value recv;
41
42 /* disable code_fetch_hook */
43 tmp = mrb->code_fetch_hook;
44 mrb->code_fetch_hook = NULL;
45
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 {
52 /*
53 * begin
54 * expr
55 * rescue => e
56 * e
57 * end
58 */
59 ruby_code = mrb_str_new_lit(mrb, "begin\n");
60 ruby_code = mrb_str_cat(mrb, ruby_code, expr, len);
61 ruby_code = mrb_str_cat_lit(mrb, ruby_code, "\nrescue => e\ne\nend");
62
63 recv = dbg->regs[0];
64
65 v = mrb_funcall(mrb, recv, "instance_eval", 1, ruby_code);
66 }
67
68 if (exc) {
69 *exc = mrb_obj_is_kind_of(mrb, v, mrb->eException_class);
70 }
71
72 s = mrb_funcall(mrb, v, "inspect", 0);
73
74 /* enable code_fetch_hook */
75 mrb->code_fetch_hook = tmp;
76
77 return s;
78}
Note: See TracBrowser for help on using the repository browser.