summaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-05-14 22:15:55 +0900
committerYukihiro Matsumoto <[email protected]>2012-05-14 22:15:55 +0900
commit0c6ff97b8e88e6f848ba73a2bf799de98d27a526 (patch)
tree3002c26da73be768056a5ff3dce13f959b6095a8 /tools
parentd55bd6fe52836395d739cc830cd9d7256991f84e (diff)
parentbcb743fccba0628362e284515edade211dd55e19 (diff)
downloadmruby-0c6ff97b8e88e6f848ba73a2bf799de98d27a526.tar.gz
mruby-0c6ff97b8e88e6f848ba73a2bf799de98d27a526.zip
Merge branch 'master' of github.com:mruby/mruby
Diffstat (limited to 'tools')
-rw-r--r--tools/mrit/Makefile82
-rw-r--r--tools/mrit/mrit.c59
2 files changed, 141 insertions, 0 deletions
diff --git a/tools/mrit/Makefile b/tools/mrit/Makefile
new file mode 100644
index 000000000..af973d9de
--- /dev/null
+++ b/tools/mrit/Makefile
@@ -0,0 +1,82 @@
+# makefile discription.
+# basic build file for mrit executable
+
+# project-specific macros
+# extension of the executable-file is modifiable(.exe .out ...)
+BASEDIR = ../../src
+TARGET := ../../bin/mrit
+LIBR := ../../lib/libmruby.a
+LIBRIT := ../../lib/libmrit.a
+ifeq ($(OS),Windows_NT)
+EXE := $(TARGET).exe
+else
+EXE := $(TARGET)
+endif
+OBJ0 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/../tools/mrit/*.c))
+#OBJ1 := $(patsubst %.c,%.o,$(filter-out $(EXCEPT1),$(wildcard $(BASEDIR)/*.c)))
+#OBJ2 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/ext/regex/*.c))
+#OBJ3 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/ext/enc/*.c))
+OBJS := $(OBJ0)
+
+# ext libraries
+#EXT1 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/../ext/socket/*.c))
+EXTS := $(EXT1)
+
+# libraries, includes
+LIBS = -lm
+INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include
+
+# compiler, linker (gcc)
+CC = gcc
+LL = gcc
+YACC = bison
+DEBUG_MODE = 1
+ifeq ($(DEBUG_MODE),1)
+CFLAGS = -g -O3
+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 : all
+all : $(LIBRIT) $(LIBR) $(EXE)
+ @echo "make: built targets of `pwd`"
+
+# executable constructed using linker from object files
+$(EXE) : $(LIBRIT) $(LIBR) $(OBJS) $(EXTS)
+ $(LL) -o $@ $(CFLAGS) $(OBJS) $(LIBRIT) $(LIBR) $(EXTS) $(LIBS)
+
+-include $(OBJS:.o=.d)
+
+# objects compiled from source
+$(OBJS) : %.o : %.c
+ $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@
+
+# C library compile
+$(LIBR) :
+ @$(MAKE) -C $(BASEDIR) $(MAKE_FLAGS)
+$(LIBRIT) :
+ @$(MAKE) -C $(BASEDIR) $(MAKE_FLAGS)
+
+# mrit library compile
+# extend libraries complile
+$(EXTS) : %.o : %.c
+ $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@
+
+# clean up
+.PHONY : clean #cleandep
+clean :
+ $(MAKE) clean -C ../../test $(MAKE_FLAGS)
+ $(MAKE) clean -C ../../mrblib $(MAKE_FLAGS)
+ $(MAKE) clean -C ../mrbc $(MAKE_FLAGS)
+ @echo "make: removing targets, objects and depend files of `pwd`"
+ -rm -f $(EXE) $(OBJS)
+ -rm -f $(OBJS:.o=.d)
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;
+}