mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* tool/compile_prelude.rb: use simple template system for source
code generation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
af2ab37334
commit
3b37c74564
2 changed files with 43 additions and 32 deletions
|
@ -1,3 +1,8 @@
|
|||
Thu Nov 15 12:24:39 2007 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* tool/compile_prelude.rb: use simple template system for source
|
||||
code generation.
|
||||
|
||||
Thu Nov 15 12:19:14 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* lib/cgi/session.rb (CGI::Session::FileStore::restore): use
|
||||
|
|
|
@ -51,51 +51,57 @@ lines_list = preludes.map {|filename|
|
|||
[setup_lines, lines]
|
||||
}
|
||||
|
||||
open(outfile, 'w'){|f|
|
||||
f.puts <<'EOS__'
|
||||
def serb(str, var)
|
||||
result = ''
|
||||
str.each_line {|line|
|
||||
if /\A!/ =~ line
|
||||
result << $'
|
||||
else
|
||||
line.split(/(<%.*?%>)/).each {|x|
|
||||
if /\A<%(.*)%>\z/ =~ x
|
||||
result << "#{var} << (#{$1}).to_s\n"
|
||||
else
|
||||
result << "#{var} << #{x.dump}\n"
|
||||
end
|
||||
}
|
||||
end
|
||||
}
|
||||
result
|
||||
end
|
||||
|
||||
tmp = ''
|
||||
eval(serb(<<'EOS', 'tmp'))
|
||||
#include "ruby/ruby.h"
|
||||
#include "vm_core.h"
|
||||
|
||||
EOS__
|
||||
|
||||
preludes.zip(lines_list).each_with_index {|(prelude, (setup_lines, lines)), i|
|
||||
f.puts <<EOS__
|
||||
static const char prelude_name#{i}[] = "#{File.basename(prelude)}";
|
||||
static const char prelude_code#{i}[] =
|
||||
#{(setup_lines+lines).join("\n")}
|
||||
! preludes.zip(lines_list).each_with_index {|(prelude, (setup_lines, lines)), i|
|
||||
static const char prelude_name<%i%>[] = <%c_esc(File.basename(prelude))%>;
|
||||
static const char prelude_code<%i%>[] =
|
||||
! (setup_lines+lines).each {|line|
|
||||
<%line%>
|
||||
! }
|
||||
;
|
||||
EOS__
|
||||
}
|
||||
f.puts <<'EOS__'
|
||||
! }
|
||||
|
||||
void
|
||||
Init_prelude(void)
|
||||
{
|
||||
EOS__
|
||||
lines_list.each_with_index {|(setup_lines, lines), i|
|
||||
f.puts <<EOS__
|
||||
! lines_list.each_with_index {|(setup_lines, lines), i|
|
||||
rb_iseq_eval(rb_iseq_compile(
|
||||
rb_str_new(prelude_code#{i}, sizeof(prelude_code#{i}) - 1),
|
||||
rb_str_new(prelude_name#{i}, sizeof(prelude_name#{i}) - 1),
|
||||
INT2FIX(#{1-setup_lines.length})));
|
||||
rb_str_new(prelude_code<%i%>, sizeof(prelude_code<%i%>) - 1),
|
||||
rb_str_new(prelude_name<%i%>, sizeof(prelude_name<%i%>) - 1),
|
||||
INT2FIX(<%1-setup_lines.length%>)));
|
||||
|
||||
EOS__
|
||||
}
|
||||
f.puts <<EOS__
|
||||
! }
|
||||
#if 0
|
||||
EOS__
|
||||
preludes.length.times {|i|
|
||||
f.puts <<EOS__
|
||||
puts(prelude_code#{i});
|
||||
EOS__
|
||||
}
|
||||
f.puts <<EOS__
|
||||
! preludes.length.times {|i|
|
||||
puts(prelude_code<%i%>);
|
||||
! }
|
||||
#endif
|
||||
EOS__
|
||||
|
||||
f.puts <<'EOS__'
|
||||
}
|
||||
EOS__
|
||||
EOS
|
||||
|
||||
open(outfile, 'w'){|f|
|
||||
f << tmp
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue