Permalink
Browse files

Merge branch 'master' into iij

Conflicts:
	tools/mrbc/mrbc.c
  • Loading branch information...
2 parents 99f22a0 + e43216c commit 41daab800c500db72cc346c523ee71f57f0973a1 @akiray03 akiray03 committed Jan 30, 2013
View
15 Rakefile
@@ -8,8 +8,17 @@ load 'tasks/mrbgem_spec.rake'
##############################
# compile flags
-MRUBY_CONFIG = File.expand_path(ENV['MRUBY_CONFIG'] || './build_config.rb')
-load MRUBY_CONFIG
+load 'build_config.rb'
+
+MRUBY_CONFIGS = ['build_config.rb']
+if ENV['MRUBY_CONFIG']
+ MRUBY_CONFIGS << ENV['MRUBY_CONFIG']
+ load ENV['MRUBY_CONFIG']
+end
+
+MRuby.each_target do |build|
+ build.define_rules
+end
load 'src/mruby_core.rake'
load 'src/ext/mruby_ext.rake'
@@ -36,7 +45,7 @@ depfiles = MRuby.targets['host'].bins.map do |bin|
FileUtils.rm t.name, :force => true
FileUtils.cp t.prerequisites.first, t.name
end
-
+
install_path
end
View
2 build_config.rb
@@ -83,5 +83,5 @@
# conf.cc.flags << "-m32"
# conf.linker.flags << "-m32"
#
-# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
+# conf.gem 'doc/mrbgems/c_and_ruby_extension_example'
# end
View
34 include/mruby/cdump.h
@@ -1,34 +0,0 @@
-/*
-** mruby/cdump.h - mruby binary dumper (C source format)
-**
-** See Copyright Notice in mruby.h
-*/
-
-#ifndef MRUBY_CDUMP_H
-#define MRUBY_CDUMP_H
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#include "mruby.h"
-#ifdef DISABLE_STDIO
-# error "Configuration conflict. Can't use with DISABLE_STDIO option."
-#else
-# include <stdio.h>
-#endif
-
-int mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname);
-
-/* error code */
-#define MRB_CDUMP_OK 0
-#define MRB_CDUMP_GENERAL_FAILURE -1
-#define MRB_CDUMP_WRITE_FAULT -2
-#define MRB_CDUMP_INVALID_IREP -6
-#define MRB_CDUMP_INVALID_ARGUMENT -7
-
-#if defined(__cplusplus)
-} /* extern "C" { */
-#endif
-
-#endif /* MRUBY_CDUMP_H */
View
2 src/array.c
@@ -647,7 +647,7 @@ mrb_ary_splice(mrb_state *mrb, mrb_value ary, mrb_int head, mrb_int len, mrb_val
}
int
-mrb_ary_alen(mrb_state *mrb, mrb_value ary)
+mrb_ary_len(mrb_state *mrb, mrb_value ary)
{
return RARRAY_LEN(ary);
}
View
214 src/cdump.c
@@ -1,214 +0,0 @@
-/*
-** cdump.c - mruby binary dumper (C source format)
-**
-** See Copyright Notice in mruby.h
-*/
-
-#include "mruby/cdump.h"
-
-#include <string.h>
-
-#include "mruby/irep.h"
-#include "mruby/string.h"
-
-#define MRB_CDUMP_LINE_LEN 128
-
-#define SOURCE_CODE(fmt, ...) fprintf(f, fmt"\n", __VA_ARGS__)
-#define SOURCE_CODE0(str) do {fputs(str, f); putc('\n', f);} while (0)
-
-static int
-make_cdump_isec(mrb_state *mrb, int irep_no, FILE *f)
-{
- int i;
- mrb_irep *irep = mrb->irep[irep_no];
-
- if (irep == NULL)
- return MRB_CDUMP_INVALID_IREP;
-
- /* dump isec struct*/
- if (irep->ilen > 0) {
- SOURCE_CODE ("static mrb_code iseq_%d[] = {", irep_no);
- for (i=0; i<irep->ilen; i++)
- SOURCE_CODE(" 0x%08x," , irep->iseq[i]);
- SOURCE_CODE0 ("};");
- SOURCE_CODE0 ("");
- }
-
- return MRB_CDUMP_OK;
-}
-
-static size_t
-str_format_len(mrb_value str)
-{
- size_t dump_len = 0;
-
- char *src;
-
- for (src = RSTRING_PTR(str); src < RSTRING_END(str); src++) {
- switch (*src) {
- case 0x07:/* BEL */ /* fall through */
- case 0x08:/* BS */ /* fall through */
- case 0x09:/* HT */ /* fall through */
- case 0x0A:/* LF */ /* fall through */
- case 0x0B:/* VT */ /* fall through */
- case 0x0C:/* FF */ /* fall through */
- case 0x0D:/* CR */ /* fall through */
- case 0x22:/* " */ /* fall through */
- case 0x27:/* ' */ /* fall through */
- case 0x3F:/* ? */ /* fall through */
- case 0x5C:/* \ */ /* fall through */
- dump_len += 2;
- break;
-
- default:
- dump_len++;
- break;
- }
- }
-
- return dump_len;
-}
-
-static char*
-str_to_format(mrb_value str, char *buf)
-{
- char *src;
- char *dst;
-
- for (src = RSTRING_PTR(str), dst = buf; src < RSTRING_END(str); src++) {
- switch (*src) {
- case 0x07:/* BEL */ *dst++ = '\\'; *dst++ = 'a'; break;
- case 0x08:/* BS */ *dst++ = '\\'; *dst++ = 'b'; break;
- case 0x09:/* HT */ *dst++ = '\\'; *dst++ = 't'; break;
- case 0x0A:/* LF */ *dst++ = '\\'; *dst++ = 'n'; break;
- case 0x0B:/* VT */ *dst++ = '\\'; *dst++ = 'v'; break;
- case 0x0C:/* FF */ *dst++ = '\\'; *dst++ = 'f'; break;
- case 0x0D:/* CR */ *dst++ = '\\'; *dst++ = 'r'; break;
- case 0x22:/* " */ *dst++ = '\\'; *dst++ = '\"'; break;
- case 0x27:/* ' */ *dst++ = '\\'; *dst++ = '\''; break;
- case 0x3F:/* ? */ *dst++ = '\\'; *dst++ = '\?'; break;
- case 0x5C:/* \ */ *dst++ = '\\'; *dst++ = '\\'; break;
- default: *dst++ = *src; break;
- }
- }
-
- return buf;
-}
-
-int
-make_cdump_irep(mrb_state *mrb, int irep_no, FILE *f)
-{
- mrb_irep *irep = mrb->irep[irep_no];
- int n;
- char *buf = 0;
- size_t buf_len, str_len;
-
- if (irep == NULL)
- return MRB_CDUMP_INVALID_IREP;
-
- buf_len = MRB_CDUMP_LINE_LEN;
- if ((buf = (char *)mrb_malloc(mrb, buf_len)) == NULL) {
- return MRB_CDUMP_GENERAL_FAILURE;
- }
-
- SOURCE_CODE0 (" ai = mrb->arena_idx;");
- SOURCE_CODE0 (" irep = mrb_add_irep(mrb);");
- SOURCE_CODE0 (" irep->flags = MRB_ISEQ_NO_FREE;");
- SOURCE_CODE (" irep->nlocals = %d;", irep->nlocals);
- SOURCE_CODE (" irep->nregs = %d;", irep->nregs);
- SOURCE_CODE (" irep->ilen = %d;", irep->ilen);
- SOURCE_CODE (" irep->iseq = iseq_%d;", irep_no);
-
- SOURCE_CODE (" irep->slen = %d;", irep->slen);
- if(irep->slen > 0) {
- SOURCE_CODE (" irep->syms = mrb_malloc(mrb, sizeof(mrb_sym)*%d);", irep->slen);
- for (n=0; n<irep->slen; n++)
- if (irep->syms[n]) {
- const char *name;
- int len;
-
- name = mrb_sym2name_len(mrb, irep->syms[n], &len);
- SOURCE_CODE (" irep->syms[%d] = mrb_intern2(mrb, \"%s\", %d);", n, name, len);
- }
- }
- else
- SOURCE_CODE0 (" irep->syms = NULL;");
-
- SOURCE_CODE0 (" irep->pool = NULL;");
- SOURCE_CODE0 (" irep->lines = NULL;");
- SOURCE_CODE0 (" mrb->irep_len = idx;");
- SOURCE_CODE0 (" irep->plen = 0;");
- if(irep->plen > 0) {
- SOURCE_CODE (" irep->pool = mrb_malloc(mrb, sizeof(mrb_value)*%d);", irep->plen);
- for (n=0; n<irep->plen; n++) {
- switch (mrb_type(irep->pool[n])) {
- case MRB_TT_FLOAT:
- SOURCE_CODE(" irep->pool[%d] = mrb_float_value(%.16e);", n, mrb_float(irep->pool[n])); break;
- case MRB_TT_FIXNUM:
- SOURCE_CODE(" irep->pool[%d] = mrb_fixnum_value(%" MRB_INT_FORMAT ");", n, mrb_fixnum(irep->pool[n])); break;
- case MRB_TT_STRING:
- str_len = str_format_len(irep->pool[n]) + 1;
- if ( str_len > buf_len ) {
- buf_len = str_len;
- if ((buf = (char *)mrb_realloc(mrb, buf, buf_len)) == NULL) {
- return MRB_CDUMP_GENERAL_FAILURE;
- }
- }
- memset(buf, 0, buf_len);
- SOURCE_CODE(" irep->pool[%d] = mrb_str_new(mrb, \"%s\", %d);", n, str_to_format(irep->pool[n], buf), RSTRING_LEN(irep->pool[n]));
- SOURCE_CODE0 (" mrb->arena_idx = ai;");
- break;
- /* TODO MRB_TT_REGEX */
- default: break;
- }
- SOURCE_CODE0(" irep->plen++;");
- }
- }
- else
- SOURCE_CODE0("");
-
- mrb_free(mrb, buf);
-
- return MRB_CDUMP_OK;
-}
-
-int
-mrb_cdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname)
-{
- int irep_no;
- int error;
-
- if (mrb == NULL || n < 0 || n >= mrb->irep_len || f == NULL || initname == NULL)
- return MRB_CDUMP_INVALID_ARGUMENT;
-
- SOURCE_CODE0("#include \"mruby.h\"");
- SOURCE_CODE0("#include \"mruby/irep.h\"");
- SOURCE_CODE0("#include \"mruby/string.h\"");
- SOURCE_CODE0("#include \"mruby/proc.h\"");
- SOURCE_CODE0("");
-
- for (irep_no=n; irep_no<mrb->irep_len; irep_no++) {
- error = make_cdump_isec(mrb, irep_no, f);
- if (error != MRB_CDUMP_OK)
- return error;
- }
-
- SOURCE_CODE0("void");
- SOURCE_CODE ("%s(mrb_state *mrb)", initname);
- SOURCE_CODE0("{");
- SOURCE_CODE0(" int n = mrb->irep_len;");
- SOURCE_CODE0(" int idx = n;");
- SOURCE_CODE0(" int ai;");
- SOURCE_CODE0(" mrb_irep *irep;");
- SOURCE_CODE0("");
- for (irep_no=n; irep_no<mrb->irep_len; irep_no++) {
- error = make_cdump_irep(mrb, irep_no, f);
- if (error != MRB_CDUMP_OK)
- return error;
- }
-
- SOURCE_CODE0(" mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));");
- SOURCE_CODE0("}");
-
- return MRB_CDUMP_OK;
-}
View
1 tasks/mrbgem_spec.rake
@@ -35,7 +35,6 @@ module MRuby
def setup
MRuby::Gem.current = self
-
@build.compilers.each do |compiler|
compiler.include_paths << "#{dir}/include"
end
View
2 tasks/mrbgems.rake
@@ -8,7 +8,7 @@ MRuby.each_target do
# loader all gems
self.libmruby << objfile("#{build_dir}/mrbgems/gem_init")
file objfile("#{build_dir}/mrbgems/gem_init") => "#{build_dir}/mrbgems/gem_init.c"
- file "#{build_dir}/mrbgems/gem_init.c" => [MRUBY_CONFIG] do |t|
+ file "#{build_dir}/mrbgems/gem_init.c" => [MRUBY_CONFIGS].flatten do |t|
FileUtils.mkdir_p "#{build_dir}/mrbgems"
open(t.name, 'w') do |f|
f.puts %Q[/*]
View
69 tasks/mruby_build.rake
@@ -53,43 +53,37 @@ module MRuby
Exts = Struct.new(:object, :executable, :library)
def initialize(name='host', &block)
- MRuby::Build.current = self
- @name = name
- @root = File.expand_path("#{File.dirname(__FILE__)}/..")
+ @name = name.to_s
- if ENV['OS'] == 'Windows_NT'
- @exts = Exts.new('.o', '.exe', '.a')
- else
- @exts = Exts.new('.o', '', '.a')
- end
-
- @file_separator = '/'
- @cc = Command::Compiler.new(self, %w(.c))
- @cxx = Command::Compiler.new(self, %w(.cc .cxx .cpp))
- @objc = Command::Compiler.new(self, %w(.m))
- @asm = Command::Compiler.new(self, %w(.S .asm))
- @linker = Command::Linker.new(self)
- @archiver = Command::Archiver.new(self)
- @yacc = Command::Yacc.new(self)
- @gperf = Command::Gperf.new(self)
- @git = Command::Git.new(self)
- @mrbc = Command::Mrbc.new(self)
-
- @bins = %w(mruby mrbc mirb)
- @gems, @libmruby = [], []
-
- MRuby.targets[name.to_s] = self
-
- instance_eval(&block)
+ unless MRuby.targets[@name]
+ @root = File.expand_path("#{File.dirname(__FILE__)}/..")
- compilers.each do |compiler|
- if respond_to?(:enable_gems?) && enable_gems?
- compiler.defines -= %w(DISABLE_GEMS)
+ if ENV['OS'] == 'Windows_NT'
+ @exts = Exts.new('.o', '.exe', '.a')
else
- compiler.defines += %w(DISABLE_GEMS)
+ @exts = Exts.new('.o', '', '.a')
end
- compiler.define_rules build_dir
+
+ @file_separator = '/'
+ @cc = Command::Compiler.new(self, %w(.c))
+ @cxx = Command::Compiler.new(self, %w(.cc .cxx .cpp))
+ @objc = Command::Compiler.new(self, %w(.m))
+ @asm = Command::Compiler.new(self, %w(.S .asm))
+ @linker = Command::Linker.new(self)
+ @archiver = Command::Archiver.new(self)
+ @yacc = Command::Yacc.new(self)
+ @gperf = Command::Gperf.new(self)
+ @git = Command::Git.new(self)
+ @mrbc = Command::Mrbc.new(self)
+
+ @bins = %w(mruby mrbc mirb)
+ @gems, @libmruby = [], []
+
+ MRuby.targets[@name] = self
end
+
+ MRuby::Build.current = MRuby.targets[@name]
+ MRuby.targets[@name].instance_eval(&block)
end
def toolchain(name)
@@ -112,6 +106,17 @@ module MRuby
end
end
+ def define_rules
+ compilers.each do |compiler|
+ if respond_to?(:enable_gems?) && enable_gems?
+ compiler.defines -= %w(DISABLE_GEMS)
+ else
+ compiler.defines += %w(DISABLE_GEMS)
+ end
+ compiler.define_rules build_dir
+ end
+ end
+
def filename(name)
if name.is_a?(Array)
name.flatten.map { |n| filename(n) }
View
6 tasks/mruby_build_commands.rake
@@ -36,14 +36,14 @@ module MRuby
def initialize(build, source_exts=[])
super(build)
- @command = ENV['CC'] || 'gcc'
+ @command = ENV['CC'] || 'cc'
@flags = [ENV['CFLAGS'] || []]
@source_exts = source_exts
@include_paths = ["#{build.root}/include"]
@defines = %w()
@option_include_path = '-I%s'
@option_define = '-D%s'
- @compile_options = "%{flags} -MMD -o %{outfile} -c %{infile}"
+ @compile_options = '%{flags} -o %{outfile} -c %{infile}'
end
def all_flags(_defineds=[], _include_paths=[], _flags=[])
@@ -111,7 +111,7 @@ module MRuby
def initialize(build)
super
- @command = ENV['LD'] || 'gcc'
+ @command = ENV['LD'] || 'ld'
@flags = (ENV['LDFLAGS'] || [])
@flags_before_libraries, @flags_after_libraries = [], []
@libraries = []
View
2 tasks/toolchains/clang.rake
@@ -1,7 +1,7 @@
MRuby::Toolchain.new(:clang) do |conf|
toolchain :gcc
- [conf.cc, conf.cxx, conf.objc].each do |cc|
+ [conf.cc, conf.cxx, conf.objc, conf.asm].each do |cc|
cc.command = ENV['CC'] || 'clang'
end
conf.linker.command = ENV['LD'] || 'clang'
View
2 tasks/toolchains/gcc.rake
@@ -1,5 +1,5 @@
MRuby::Toolchain.new(:gcc) do |conf|
- [conf.cc, conf.cxx, conf.objc].each do |cc|
+ [conf.cc, conf.cxx, conf.objc, conf.asm].each do |cc|
cc.command = ENV['CC'] || 'gcc'
cc.flags = [ENV['CFLAGS'] || %w(-g -O3 -Wall -Werror-implicit-function-declaration)]
cc.include_paths = ["#{root}/include", "#{root}/src"]
View
36 tools/mrbc/mrbc.c
@@ -1,7 +1,6 @@
#include "mruby.h"
#include "mruby/proc.h"
#include "mruby/dump.h"
-#include "mruby/cdump.h"
#include "mruby/compile.h"
#include <stdio.h>
#include <string.h>
@@ -21,7 +20,6 @@ struct _args {
char *initname;
char *ext;
int check_syntax : 1;
- int dump_type : 2;
int verbose : 1;
int debug : 1;
};
@@ -35,7 +33,6 @@ usage(const char *name)
"-o<outfile> place the output into <outfile>",
"-v print version number, then trun on verbose mode",
"-B<symbol> binary <symbol> output in C language format",
- "-C<func> function <func> output in C language format",
"-g produce debugging information with mrb file",
"--verbose run at verbose mode",
"--version print the version",
@@ -81,25 +78,23 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
for (argc--,argv++; argc > 0; argc--,argv++) {
if (**argv == '-') {
if (strlen(*argv) == 1) {
- args->filename = infile = "-";
- args->rfp = stdin;
- break;
+ args->filename = infile = "-";
+ args->rfp = stdin;
+ break;
}
switch ((*argv)[1]) {
case 'o':
outfile = get_outfilename((*argv) + 2, "");
break;
case 'B':
- case 'C':
args->ext = C_EXT;
args->initname = (*argv) + 2;
if (*args->initname == '\0') {
printf("%s: Function name is not specified.\n", *origargv);
- result = -2;
- goto exit;
+ result = -2;
+ goto exit;
}
- args->dump_type = ((*argv)[1] == 'B') ? DUMP_TYPE_BIN : DUMP_TYPE_CODE;
break;
case 'c':
args->check_syntax = 1;
@@ -114,27 +109,27 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
case '-':
if (strcmp((*argv) + 2, "version") == 0) {
mrb_show_version(mrb);
- exit(0);
+ exit(0);
}
else if (strcmp((*argv) + 2, "verbose") == 0) {
args->verbose = 1;
break;
}
else if (strcmp((*argv) + 2, "copyright") == 0) {
mrb_show_copyright(mrb);
- exit(0);
+ exit(0);
}
- result = -3;
- goto exit;
+ result = -3;
+ goto exit;
default:
- break;
+ break;
}
}
else if (args->rfp == NULL) {
args->filename = infile = *argv;
if ((args->rfp = fopen(infile, "r")) == NULL) {
printf("%s: Cannot open program file. (%s)\n", *origargv, infile);
- goto exit;
+ goto exit;
}
}
}
@@ -146,10 +141,10 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
if (!args->check_syntax) {
if (outfile == NULL) {
if (strcmp("-", infile) == 0) {
- outfile = infile;
+ outfile = infile;
}
else {
- outfile = get_outfilename(infile, args->ext);
+ outfile = get_outfilename(infile, args->ext);
}
}
if (strcmp("-", outfile) == 0) {
@@ -213,10 +208,7 @@ main(int argc, char **argv)
return EXIT_SUCCESS;
}
if (args.initname) {
- if (args.dump_type == DUMP_TYPE_BIN)
- n = mrb_bdump_irep(mrb, n, args.wfp, args.initname);
- else
- n = mrb_cdump_irep(mrb, n, args.wfp, args.initname);
+ n = mrb_bdump_irep(mrb, n, args.wfp, args.initname);
}
else {
n = mrb_dump_irep(mrb, n, args.wfp, args.debug);

0 comments on commit 41daab8

Please sign in to comment.