diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/Makefile | 16 | ||||
| -rw-r--r-- | test/driver.c | 27 | ||||
| -rw-r--r-- | test/init_mrbtest.c | 4 |
3 files changed, 20 insertions, 27 deletions
diff --git a/test/Makefile b/test/Makefile index 8ee12dbf1..cb6ac3a5e 100644 --- a/test/Makefile +++ b/test/Makefile @@ -57,21 +57,16 @@ else CFLAGS = -O3 endif ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) -ifeq ($(OS),Windows_NT) - MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" -else - MAKE_FLAGS = CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' -endif ############################## # generic build targets, rules .PHONY : test -all : $(LIBR) $(EXE) +all : $(EXE) ./$(EXE) # executable constructed using linker from object files -$(EXE) : $(LIBR) $(OBJS) +$(EXE) : $(OBJS) $(LL) -o $@ $(CFLAGS) $(OBJS) $(LIBR) $(LIBS) -include $(OBJS:.o=.d) @@ -80,17 +75,10 @@ $(EXE) : $(LIBR) $(OBJS) $(OBJS) : %.o : %.c $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ -# C library compile -$(LIBR) : - @$(MAKE) -C $(BASEDIR) $(MAKE_FLAGS) - # Compile C source from merged mruby source $(CLIB) : $(RLIB) $(MRBC) $(INIT) $(MRBC) -Bmrbtest_irep -o$(DLIB) $(RLIB); cat $(INIT) $(DLIB) > $@ -$(MRBC) : ../src/opcode.h ../src/codegen.c ../src/parse.y - $(MAKE) -C ../tools/mrbc $(MAKE_FLAGS) - # merge mruby sources $(RLIB) : $(ASSLIB) $(MRBS) cat $? > $@ diff --git a/test/driver.c b/test/driver.c index 90fa6a6d0..afc93b10b 100644 --- a/test/driver.c +++ b/test/driver.c @@ -10,7 +10,7 @@ #include <mruby.h> #include <mruby/proc.h> #include <mruby/data.h> -#include <compile.h> +#include <mruby/compile.h> void mrb_init_mrbtest(mrb_state *); @@ -27,29 +27,30 @@ int main(void) { struct mrb_parser_state *parser; - mrb_state *mrb_interpreter; - mrb_value mrb_return_value; + mrb_state *mrb; + mrb_value return_value; int byte_code; + const char *prog = "report()"; print_hint(); /* new interpreter instance */ - mrb_interpreter = mrb_open(); - mrb_init_mrbtest(mrb_interpreter); - parser = mrb_parse_nstring_ext(mrb_interpreter, "report()", strlen("report()")); + mrb = mrb_open(); + mrb_init_mrbtest(mrb); + parser = mrb_parse_nstring(mrb, prog, strlen(prog)); /* generate bytecode */ - byte_code = mrb_generate_code(mrb_interpreter, parser->tree); + byte_code = mrb_generate_code(mrb, parser->tree); /* evaluate the bytecode */ - mrb_return_value = mrb_run(mrb_interpreter, + return_value = 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[byte_code]), + mrb_top_self(mrb)); /* did an exception occur? */ - if (mrb_interpreter->exc) { - mrb_p(mrb_interpreter, mrb_return_value); - mrb_interpreter->exc = 0; + if (mrb->exc) { + mrb_p(mrb, return_value); + mrb->exc = 0; } else { /* no */ diff --git a/test/init_mrbtest.c b/test/init_mrbtest.c index 5d977da34..b9f09dd2f 100644 --- a/test/init_mrbtest.c +++ b/test/init_mrbtest.c @@ -12,5 +12,9 @@ mrb_init_mrbtest(mrb_state *mrb) int n = mrb_read_irep(mrb, mrbtest_irep); mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); + if (mrb->exc) { + mrb_p(mrb, mrb_obj_value(mrb->exc)); + exit(0); + } } |
