diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2012-05-14 06:15:42 -0700 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2012-05-14 06:15:42 -0700 |
| commit | bcb743fccba0628362e284515edade211dd55e19 (patch) | |
| tree | a29397364f5c6f05b2f1bdd24af5f13a6472a6f7 /tools/mrit/mrit.c | |
| parent | 6b67801d4e643583746da41a74218145236b8f9d (diff) | |
| parent | c82a518ee1df250a03abb82aa58a1bfd2c04cfc3 (diff) | |
| download | mruby-bcb743fccba0628362e284515edade211dd55e19.tar.gz mruby-bcb743fccba0628362e284515edade211dd55e19.zip | |
Merge pull request #131 from bovi/master
mrit - Embeddable Ruby ISO Test
Diffstat (limited to 'tools/mrit/mrit.c')
| -rw-r--r-- | tools/mrit/mrit.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tools/mrit/mrit.c b/tools/mrit/mrit.c new file mode 100644 index 000000000..594ab012d --- /dev/null +++ b/tools/mrit/mrit.c @@ -0,0 +1,59 @@ +/* +** mrit - Embeddable Ruby ISO Test +** +** This program verifies ISO/IEC 30170:2012 +** against the current mruby implementation. +*/ + +#include <string.h> + +#include <mruby.h> +#include <mruby/proc.h> +#include <mruby/data.h> +#include <compile.h> + +void +mrb_init_mritlib(mrb_state *); + +/* Print a short remark for the user */ +void print_hint(void) +{ + printf("mrit - Embeddable Ruby ISO Test\n"); + printf("\nThis is a very early version, please test and report errors.\n"); + printf("Thanks :)\n\n"); +} + +int +main(void) +{ + struct mrb_parser_state *parser; + mrb_state *mrb_interpreter; + mrb_value mrb_return_value; + int byte_code; + + print_hint(); + + /* new interpreter instance */ + mrb_interpreter = mrb_open(); + mrb_init_mritlib(mrb_interpreter); + parser = mrb_parse_nstring_ext(mrb_interpreter, "report()", strlen("report()")); + + /* generate bytecode */ + byte_code = mrb_generate_code(mrb_interpreter, parser->tree); + + /* evaluate the bytecode */ + mrb_return_value = mrb_run(mrb_interpreter, + /* pass a proc for evaulation */ + mrb_proc_new(mrb_interpreter, mrb_interpreter->irep[byte_code]), + mrb_top_self(mrb_interpreter)); + /* did an exception occur? */ + if (mrb_interpreter->exc) { + mrb_p(mrb_interpreter, mrb_obj_value(mrb_interpreter->exc)); + mrb_interpreter->exc = 0; + } + else { + /* no */ + } + + return 0; +} |
