* 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
This commit is contained in:
akr 2007-11-10 09:22:59 +00:00
Родитель 66c127bc6f
Коммит 040ffb5d79
7 изменённых файлов: 103 добавлений и 14 удалений

Просмотреть файл

@ -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> 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 * thread.c (call_trace_proc): don't call ID2SYM() for ID_ALLOCATOR

Просмотреть файл

@ -50,7 +50,7 @@ LDSHARED = @LIBRUBY_LDSHARED@
DLDFLAGS = @LIBRUBY_DLDFLAGS@ $(EXTLDFLAGS) @ARCH_FLAG@ DLDFLAGS = @LIBRUBY_DLDFLAGS@ $(EXTLDFLAGS) @ARCH_FLAG@
SOLIBS = @SOLIBS@ SOLIBS = @SOLIBS@
MAINLIBS = @MAINLIBS@ MAINLIBS = @MAINLIBS@
MINIOBJS = @MINIOBJS@ MINIOBJS = @MINIOBJS@ prelude.$(OBJEXT)
RUBY_INSTALL_NAME=@RUBY_INSTALL_NAME@ RUBY_INSTALL_NAME=@RUBY_INSTALL_NAME@
RUBY_SO_NAME=@RUBY_SO_NAME@ RUBY_SO_NAME=@RUBY_SO_NAME@

Просмотреть файл

@ -15,7 +15,7 @@ RDOCOUT = $(EXTOUT)/rdoc
DMYEXT = dmyext.$(OBJEXT) DMYEXT = dmyext.$(OBJEXT)
MAINOBJ = main.$(OBJEXT) MAINOBJ = main.$(OBJEXT)
EXTOBJS = EXTOBJS = ext_prelude.$(OBJEXT)
DLDOBJS = $(DMYEXT) DLDOBJS = $(DMYEXT)
ENCOBJS = ascii.$(OBJEXT) \ ENCOBJS = ascii.$(OBJEXT) \
@ -78,7 +78,6 @@ OBJS = array.$(OBJEXT) \
thread.$(OBJEXT) \ thread.$(OBJEXT) \
cont.$(OBJEXT) \ cont.$(OBJEXT) \
id.$(OBJEXT) \ id.$(OBJEXT) \
prelude.$(OBJEXT) \
$(ENCOBJS) \ $(ENCOBJS) \
$(MISSING) $(MISSING)
@ -586,6 +585,7 @@ blockinlining.$(OBJEXT): {$(VPATH)}blockinlining.c \
{$(VPATH)}thread_$(THREAD_MODEL).h {$(VPATH)}thread_$(THREAD_MODEL).h
id.$(OBJEXT): {$(VPATH)}id.c {$(VPATH)}ruby.h id.$(OBJEXT): {$(VPATH)}id.c {$(VPATH)}ruby.h
prelude.$(OBJEXT): {$(VPATH)}prelude.c {$(VPATH)}ruby.h {$(VPATH)}vm_core.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 \ ascii.$(OBJEXT): {$(VPATH)}ascii.c {$(VPATH)}regenc.h \
{$(VPATH)}oniguruma.h {$(VPATH)}config.h {$(VPATH)}defines.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 prelude.c: $(srcdir)/tool/compile_prelude.rb $(srcdir)/prelude.rb
$(BASERUBY) $(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 prereq: incs {$(VPATH)}prelude.c
docs: docs:

10
gem_prelude.rb Normal file
Просмотреть файл

@ -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"]

Просмотреть файл

@ -51,7 +51,6 @@ void Init_VM(void);
void Init_Thread(void); void Init_Thread(void);
void Init_Cont(void); void Init_Cont(void);
void Init_top_self(void); void Init_top_self(void);
void Init_prelude(void);
void Init_Encoding(void); void Init_Encoding(void);
void void
@ -97,5 +96,4 @@ rb_call_inits()
Init_Thread(); Init_Thread();
Init_Cont(); Init_Cont();
Init_version(); Init_version();
Init_prelude();
} }

16
ruby.c
Просмотреть файл

@ -75,6 +75,7 @@ struct cmdline_options {
int usage; int usage;
int version; int version;
int copyright; int copyright;
int disable_gems;
int verbose; int verbose;
int yydebug; int yydebug;
char *script; char *script;
@ -121,6 +122,7 @@ usage(const char *name)
"-w turn warnings on for your script", "-w turn warnings on for your script",
"-W[level] set warning level; 0=silence, 1=medium, 2=verbose (default)", "-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", "-x[directory] strip off text before #!ruby line and perhaps cd to directory",
"--disable_gems disable gem libraries",
"--copyright print the copyright", "--copyright print the copyright",
"--version print the version", "--version print the version",
NULL NULL
@ -813,6 +815,8 @@ proc_options(int argc, char **argv, struct cmdline_options *opt)
ruby_debug = Qtrue; ruby_debug = Qtrue;
ruby_verbose = Qtrue; ruby_verbose = Qtrue;
} }
else if (strcmp("disable-gems", s) == 0)
opt->disable_gems = 1;
else if (strcmp("encoding", s) == 0) { else if (strcmp("encoding", s) == 0) {
if (!--argc || !(s = *++argv)) { if (!--argc || !(s = *++argv)) {
noencoding: noencoding:
@ -873,6 +877,17 @@ proc_options(int argc, char **argv, struct cmdline_options *opt)
return argc0 - argc; 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 static VALUE
process_options(VALUE arg) process_options(VALUE arg)
{ {
@ -976,6 +991,7 @@ process_options(VALUE arg)
process_sflag(opt); process_sflag(opt);
ruby_init_loadpath(); ruby_init_loadpath();
ruby_init_gems(opt);
parser = rb_parser_new(); parser = rb_parser_new();
if (opt->e_script) { if (opt->e_script) {
if (opt->enc_index >= 0) if (opt->enc_index >= 0)

Просмотреть файл

@ -1,33 +1,79 @@
*preludes, outfile = *ARGV
prelude, outfile = *ARGV C_ESC = {
"\\" => "\\\\",
'"' => '\"',
"\n" => '\n',
}
lines = File.readlines(prelude).map{|line| 0x00.upto(0x1f) {|ch| C_ESC[[ch].pack("C")] ||= "\\x%02x" % ch }
line.dump 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_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| open(outfile, 'w'){|f|
f.puts <<EOS__, <<'EOS__' f.puts <<'EOS__'
#include "ruby/ruby.h" #include "ruby/ruby.h"
#include "vm_core.h" #include "vm_core.h"
static const char prelude_name[] = "#{File.basename(prelude)}"; EOS__
static const char prelude_code[] =
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")} #{lines.join("\n")}
; ;
EOS__ EOS__
}
f.puts <<'EOS__'
void void
Init_prelude(void) Init_prelude(void)
{ {
EOS__
preludes.length.times {|i|
f.puts <<EOS__
rb_iseq_eval(rb_iseq_compile( rb_iseq_eval(rb_iseq_compile(
rb_str_new(prelude_code, sizeof(prelude_code) - 1), rb_str_new(prelude_code#{i}, sizeof(prelude_code#{i}) - 1),
rb_str_new(prelude_name, sizeof(prelude_name) - 1), rb_str_new(prelude_name#{i}, sizeof(prelude_name#{i}) - 1),
INT2FIX(1))); INT2FIX(1)));
EOS__
}
f.puts <<EOS__
#if 0 #if 0
printf("%s\n", prelude_code); EOS__
preludes.length.times {|i|
f.puts <<EOS__
puts(prelude_code#{i});
EOS__
}
f.puts <<EOS__
#endif #endif
EOS__
f.puts <<'EOS__'
} }
EOS__ EOS__
} }