diff options
| author | Paolo Bosetti <[email protected]> | 2012-08-06 15:02:03 +0200 |
|---|---|---|
| committer | Paolo Bosetti <[email protected]> | 2012-08-06 15:02:56 +0200 |
| commit | aa0d2f91447c49363059f2e95cb9023f65a6fbef (patch) | |
| tree | 2cfa325956e62648f2161564adfdf6dddc45b737 /tools/mirb | |
| parent | fd097b8aff7b91bd105fc1daec5a4050a947b763 (diff) | |
| parent | 193c98ae540d43d082795fd77ea81a4f6f7fd0f6 (diff) | |
| download | mruby-aa0d2f91447c49363059f2e95cb9023f65a6fbef.tar.gz mruby-aa0d2f91447c49363059f2e95cb9023f65a6fbef.zip | |
Updated Xcode project build settings in conformity with 10.8/Xcode 4.4
Diffstat (limited to 'tools/mirb')
| -rw-r--r-- | tools/mirb/Makefile | 13 | ||||
| -rw-r--r-- | tools/mirb/mirb.c | 60 |
2 files changed, 50 insertions, 23 deletions
diff --git a/tools/mirb/Makefile b/tools/mirb/Makefile index ba307227c..52941f242 100644 --- a/tools/mirb/Makefile +++ b/tools/mirb/Makefile @@ -21,12 +21,19 @@ EXTS := $(EXT1) LIBS = -lm INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) +ifeq ($(strip $(COMPILE_MODE)),) + # default compile option + COMPILE_MODE = debug +endif + +ifeq ($(COMPILE_MODE),debug) CFLAGS = -g -O3 -else +else ifeq ($(COMPILE_MODE),release) CFLAGS = -O3 +else ifeq ($(COMPILE_MODE),small) + CFLAGS = -Os endif + ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) ifeq ($(OS),Windows_NT) MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" diff --git a/tools/mirb/mirb.c b/tools/mirb/mirb.c index 59e5046cb..54588d57e 100644 --- a/tools/mirb/mirb.c +++ b/tools/mirb/mirb.c @@ -13,6 +13,19 @@ #include <mruby/data.h> #include <mruby/compile.h> +#ifndef ENABLE_STDIO +#include <mruby/string.h> +static void +p(mrb_state *mrb, mrb_value obj) +{ + obj = mrb_funcall(mrb, obj, "inspect", 0); + fwrite(RSTRING_PTR(obj), RSTRING_LEN(obj), 1, stdout); + putc('\n', stdout); +} +#else +#define p(mrb,obj) mrb_p(mrb,obj) +#endif + /* Guess if the user might want to enter more * or if he wants an evaluation of his code now */ int @@ -37,10 +50,10 @@ is_code_block_open(struct mrb_parser_state *parser) code_block_open = TRUE; } else if (strcmp(message, "syntax error, unexpected keyword_end") == 0) { - code_block_open = TRUE; + code_block_open = FALSE; } else if (strcmp(message, "syntax error, unexpected tREGEXP_BEG") == 0) { - code_block_open = TRUE; + code_block_open = FALSE; } return code_block_open; } @@ -132,18 +145,24 @@ main(void) { char last_char, ruby_code[1024], last_code_line[1024]; int char_index; + mrbc_context *cxt; struct mrb_parser_state *parser; - mrb_state *mrb_interpreter; - mrb_value mrb_return_value; - int byte_code; + mrb_state *mrb; + mrb_value result; + int n; int code_block_open = FALSE; print_hint(); /* new interpreter instance */ - mrb_interpreter = mrb_open(); - /* new parser instance */ - parser = mrb_parser_new(mrb_interpreter); + mrb = mrb_open(); + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb interpreter, exiting mirb"); + return EXIT_FAILURE; + } + + cxt = mrbc_context_new(mrb); + cxt->capture_errors = 1; memset(ruby_code, 0, sizeof(*ruby_code)); memset(last_code_line, 0, sizeof(*last_code_line)); @@ -187,11 +206,11 @@ main(void) } /* parse code */ + parser = mrb_parser_new(mrb); parser->s = ruby_code; parser->send = ruby_code + strlen(ruby_code); - parser->capture_errors = 1; parser->lineno = 1; - mrb_parser_parse(parser); + mrb_parser_parse(parser, cxt); code_block_open = is_code_block_open(parser); if (code_block_open) { @@ -204,31 +223,32 @@ main(void) } else { /* generate bytecode */ - byte_code = mrb_generate_code(mrb_interpreter, parser->tree); + n = mrb_generate_code(mrb, parser->tree); /* evaluate the bytecode */ - mrb_return_value = mrb_run(mrb_interpreter, + result = mrb_run(mrb, /* pass a proc for evaulation */ - mrb_proc_new(mrb_interpreter, mrb_interpreter->irep[byte_code]), - mrb_top_self(mrb_interpreter)); + mrb_proc_new(mrb, mrb->irep[n]), + mrb_top_self(mrb)); /* did an exception occur? */ - if (mrb_interpreter->exc) { - mrb_p(mrb_interpreter, mrb_obj_value(mrb_interpreter->exc)); - mrb_interpreter->exc = 0; + if (mrb->exc) { + p(mrb, mrb_obj_value(mrb->exc)); + mrb->exc = 0; } else { /* no */ printf(" => "); - mrb_p(mrb_interpreter, mrb_return_value); + p(mrb, result); } } - memset(ruby_code, 0, sizeof(*ruby_code)); memset(ruby_code, 0, sizeof(*last_code_line)); } + mrb_parser_free(parser); } } - mrb_close(mrb_interpreter); + mrbc_context_free(mrb, cxt); + mrb_close(mrb); return 0; } |
