summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-10 09:22:59 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-10 09:22:59 +0000
commit040ffb5d792d932215b7b6fbce9ee9752d76e285 (patch)
tree2d8bfa467abc38cbeccfb504836dfe712784c190
parent66c127bc6f95761f967efc5109cd229973fbc50f (diff)
* gem_prelude.rb: new file for gem libraries. currently empty.
* common.mk: generate ext_prelude.c by prelude.rb and gem_prelude.rb. ruby (not miniruby) is linked with ext_prelude.o instead of prelude.o. * inits.c (rb_call_inits): don't call Init_prelude. * ruby.c: support --disable-gems option. (ruby_init_gems): new function to define Gem::Enable and invoke Init_prelude. (process_options): call ruby_init_gems just after ruby_init_loadpath. * tool/compile_prelude.rb: support multiple files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog16
-rw-r--r--Makefile.in2
-rw-r--r--common.mk7
-rw-r--r--gem_prelude.rb10
-rw-r--r--inits.c2
-rw-r--r--ruby.c16
-rw-r--r--tool/compile_prelude.rb64
7 files changed, 103 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index f9a67710f9..38d2b77ba3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+Sat Nov 10 18:10:07 2007 Tanaka Akira <akr@fsij.org>
+
+ * gem_prelude.rb: new file for gem libraries. currently empty.
+
+ * common.mk: generate ext_prelude.c by prelude.rb and gem_prelude.rb.
+ ruby (not miniruby) is linked with ext_prelude.o instead of prelude.o.
+ * inits.c (rb_call_inits): don't call Init_prelude.
+
+ * ruby.c: support --disable-gems option.
+ (ruby_init_gems): new function to define Gem::Enable and
+ invoke Init_prelude.
+ (process_options): call ruby_init_gems just after
+ ruby_init_loadpath.
+
+ * tool/compile_prelude.rb: support multiple files.
+
Sat Nov 10 17:27:55 2007 Shugo Maeda <shugo@ruby-lang.org>
* thread.c (call_trace_proc): don't call ID2SYM() for ID_ALLOCATOR
diff --git a/Makefile.in b/Makefile.in
index 2c5b4b23a9..99f4a3929d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -50,7 +50,7 @@ LDSHARED = @LIBRUBY_LDSHARED@
DLDFLAGS = @LIBRUBY_DLDFLAGS@ $(EXTLDFLAGS) @ARCH_FLAG@
SOLIBS = @SOLIBS@
MAINLIBS = @MAINLIBS@
-MINIOBJS = @MINIOBJS@
+MINIOBJS = @MINIOBJS@ prelude.$(OBJEXT)
RUBY_INSTALL_NAME=@RUBY_INSTALL_NAME@
RUBY_SO_NAME=@RUBY_SO_NAME@
diff --git a/common.mk b/common.mk
index 39669487bc..177a058253 100644
--- a/common.mk
+++ b/common.mk
@@ -15,7 +15,7 @@ RDOCOUT = $(EXTOUT)/rdoc
DMYEXT = dmyext.$(OBJEXT)
MAINOBJ = main.$(OBJEXT)
-EXTOBJS =
+EXTOBJS = ext_prelude.$(OBJEXT)
DLDOBJS = $(DMYEXT)
ENCOBJS = ascii.$(OBJEXT) \
@@ -78,7 +78,6 @@ OBJS = array.$(OBJEXT) \
thread.$(OBJEXT) \
cont.$(OBJEXT) \
id.$(OBJEXT) \
- prelude.$(OBJEXT) \
$(ENCOBJS) \
$(MISSING)
@@ -586,6 +585,7 @@ blockinlining.$(OBJEXT): {$(VPATH)}blockinlining.c \
{$(VPATH)}thread_$(THREAD_MODEL).h
id.$(OBJEXT): {$(VPATH)}id.c {$(VPATH)}ruby.h
prelude.$(OBJEXT): {$(VPATH)}prelude.c {$(VPATH)}ruby.h {$(VPATH)}vm_core.h
+ext_prelude.$(OBJEXT): {$(VPATH)}ext_prelude.c {$(VPATH)}ruby.h {$(VPATH)}vm_core.h
ascii.$(OBJEXT): {$(VPATH)}ascii.c {$(VPATH)}regenc.h \
{$(VPATH)}oniguruma.h {$(VPATH)}config.h {$(VPATH)}defines.h
@@ -631,6 +631,9 @@ node_name.inc: {$(VPATH)}node.h
prelude.c: $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb
$(BASERUBY) $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb $@
+ext_prelude.c: $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb $(srcdir)/gem_prelude.rb $(RBCONFIG)
+ $(MINIRUBY) -I$(srcdir) -rrbconfig $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb $(srcdir)/gem_prelude.rb $@
+
prereq: incs {$(VPATH)}prelude.c
docs:
diff --git a/gem_prelude.rb b/gem_prelude.rb
new file mode 100644
index 0000000000..7340efcaaf
--- /dev/null
+++ b/gem_prelude.rb
@@ -0,0 +1,10 @@
+# empty gem_prelude.rb
+#
+# p Gem::Enable
+# p RbConfig::CONFIG["arch"]
+# p RbConfig::CONFIG["bindir"]
+# p RbConfig::CONFIG["datadir"]
+# p RbConfig::CONFIG["sitedir"]
+# p RbConfig::CONFIG["sitelibdir"]
+# p RbConfig::CONFIG["EXEEXT"]
+# p RbConfig::CONFIG["RUBY_SO_NAME"]
diff --git a/inits.c b/inits.c
index f6e4502dfb..3006bf6098 100644
--- a/inits.c
+++ b/inits.c
@@ -51,7 +51,6 @@ void Init_VM(void);
void Init_Thread(void);
void Init_Cont(void);
void Init_top_self(void);
-void Init_prelude(void);
void Init_Encoding(void);
void
@@ -97,5 +96,4 @@ rb_call_inits()
Init_Thread();
Init_Cont();
Init_version();
- Init_prelude();
}
diff --git a/ruby.c b/ruby.c
index 6dc411eaa0..4285247005 100644
--- a/ruby.c
+++ b/ruby.c
@@ -75,6 +75,7 @@ struct cmdline_options {
int usage;
int version;
int copyright;
+ int disable_gems;
int verbose;
int yydebug;
char *script;
@@ -121,6 +122,7 @@ usage(const char *name)
"-w turn warnings on for your script",
"-W[level] set warning level; 0=silence, 1=medium, 2=verbose (default)",
"-x[directory] strip off text before #!ruby line and perhaps cd to directory",
+ "--disable_gems disable gem libraries",
"--copyright print the copyright",
"--version print the version",
NULL
@@ -813,6 +815,8 @@ proc_options(int argc, char **argv, struct cmdline_options *opt)
ruby_debug = Qtrue;
ruby_verbose = Qtrue;
}
+ else if (strcmp("disable-gems", s) == 0)
+ opt->disable_gems = 1;
else if (strcmp("encoding", s) == 0) {
if (!--argc || !(s = *++argv)) {
noencoding:
@@ -873,6 +877,17 @@ proc_options(int argc, char **argv, struct cmdline_options *opt)
return argc0 - argc;
}
+void Init_prelude(void);
+
+static void
+ruby_init_gems(struct cmdline_options *opt)
+{
+ VALUE gem;
+ gem = rb_define_module("Gem");
+ rb_const_set(gem, rb_intern("Enable"), opt->disable_gems ? Qfalse : Qtrue);
+ Init_prelude();
+}
+
static VALUE
process_options(VALUE arg)
{
@@ -976,6 +991,7 @@ process_options(VALUE arg)
process_sflag(opt);
ruby_init_loadpath();
+ ruby_init_gems(opt);
parser = rb_parser_new();
if (opt->e_script) {
if (opt->enc_index >= 0)
diff --git a/tool/compile_prelude.rb b/tool/compile_prelude.rb
index 1012d1fbc2..1f67d4c396 100644
--- a/tool/compile_prelude.rb
+++ b/tool/compile_prelude.rb
@@ -1,33 +1,79 @@
+*preludes, outfile = *ARGV
-prelude, outfile = *ARGV
+C_ESC = {
+ "\\" => "\\\\",
+ '"' => '\"',
+ "\n" => '\n',
+}
+
+0x00.upto(0x1f) {|ch| C_ESC[[ch].pack("C")] ||= "\\x%02x" % ch }
+0x7f.upto(0xff) {|ch| C_ESC[[ch].pack("C")] = "\\x%02x" % ch }
+C_ESC_PAT = Regexp.union(*C_ESC.keys)
+
+def c_esc(str)
+ '"' + str.gsub(C_ESC_PAT) { C_ESC[$&] } + '"'
+end
-lines = File.readlines(prelude).map{|line|
- line.dump
+lines_list = preludes.map {|prelude|
+ lines = []
+ File.readlines(prelude).each {|line|
+ line.gsub!(/RbConfig::CONFIG\["(\w+)"\]/) {
+ require 'rbconfig'
+ if RbConfig::CONFIG.has_key? $1
+ c_esc(RbConfig::CONFIG[$1])
+ else
+ $&
+ end
+ }
+ lines << c_esc(line)
+ }
+ lines
}
open(outfile, 'w'){|f|
- f.puts <<EOS__, <<'EOS__'
+ f.puts <<'EOS__'
#include "ruby/ruby.h"
#include "vm_core.h"
-static const char prelude_name[] = "#{File.basename(prelude)}";
-static const char prelude_code[] =
+EOS__
+
+ preludes.zip(lines_list).each_with_index {|(prelude, lines), i|
+ f.puts <<EOS__
+static const char prelude_name#{i}[] = "#{File.basename(prelude)}";
+static const char prelude_code#{i}[] =
#{lines.join("\n")}
;
EOS__
+ }
+ f.puts <<'EOS__'
void
Init_prelude(void)
{
+EOS__
+ preludes.length.times {|i|
+ f.puts <<EOS__
rb_iseq_eval(rb_iseq_compile(
- rb_str_new(prelude_code, sizeof(prelude_code) - 1),
- rb_str_new(prelude_name, sizeof(prelude_name) - 1),
+ rb_str_new(prelude_code#{i}, sizeof(prelude_code#{i}) - 1),
+ rb_str_new(prelude_name#{i}, sizeof(prelude_name#{i}) - 1),
INT2FIX(1)));
+EOS__
+ }
+ f.puts <<EOS__
#if 0
- printf("%s\n", prelude_code);
+EOS__
+ preludes.length.times {|i|
+ f.puts <<EOS__
+ puts(prelude_code#{i});
+EOS__
+ }
+ f.puts <<EOS__
#endif
+EOS__
+
+ f.puts <<'EOS__'
}
EOS__
}