mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
prelude.c.tmpl: split prelude code
* template/prelude.c.tmpl: split prelude code into blocks so that each elements do not exceed the string literal size limit in C89. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60953 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5761093ee1
commit
b7a908f61b
1 changed files with 38 additions and 10 deletions
|
@ -6,6 +6,8 @@
|
||||||
# Ruby 1.9 feature should not be used.
|
# Ruby 1.9 feature should not be used.
|
||||||
|
|
||||||
class Prelude
|
class Prelude
|
||||||
|
LINE_LIMIT = 509 # by C89
|
||||||
|
|
||||||
C_ESC = {
|
C_ESC = {
|
||||||
"\\" => "\\\\",
|
"\\" => "\\\\",
|
||||||
'"' => '\"',
|
'"' => '\"',
|
||||||
|
@ -42,7 +44,10 @@ class Prelude
|
||||||
result = [@preludes.size, @vpath.strip(filename), lines, sub]
|
result = [@preludes.size, @vpath.strip(filename), lines, sub]
|
||||||
@vpath.foreach(filename) do |line|
|
@vpath.foreach(filename) do |line|
|
||||||
@preludes[filename] ||= result
|
@preludes[filename] ||= result
|
||||||
line.sub!(/(?:^|\s+)\#(?:$|[#\s].*)/, '')
|
comment = ($1 || '' if line.sub!(/(?:^|\s+)\#(?:$|[#\s](.*))/, ''))
|
||||||
|
if line.size > LINE_LIMIT
|
||||||
|
raise "#{filename}:#{lines.size+1}: too long line"
|
||||||
|
end
|
||||||
line.sub!(/require(_relative)?\s*\(?\s*(["'])(.*?)(?:\.rb)?\2\)?/) do
|
line.sub!(/require(_relative)?\s*\(?\s*(["'])(.*?)(?:\.rb)?\2\)?/) do
|
||||||
orig, rel, path = $&, $2, $3
|
orig, rel, path = $&, $2, $3
|
||||||
if rel
|
if rel
|
||||||
|
@ -57,7 +62,7 @@ class Prelude
|
||||||
orig
|
orig
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
lines << c_esc(line)
|
lines << [line, comment]
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
@ -67,7 +72,7 @@ Prelude.new(output && output[/\w+(?=_prelude.c\b)/] || 'prelude', ARGV, vpath).i
|
||||||
/* -*-c-*-
|
/* -*-c-*-
|
||||||
THIS FILE WAS AUTOGENERATED BY template/prelude.c.tmpl. DO NOT EDIT.
|
THIS FILE WAS AUTOGENERATED BY template/prelude.c.tmpl. DO NOT EDIT.
|
||||||
|
|
||||||
sources: <%= @preludes.map {|n,*| prelude_base(n)}.join(', ') %>
|
sources: <%= @preludes.map {|n,*| prelude_base(n)}.join(', ') %><%=%>
|
||||||
*/
|
*/
|
||||||
%unless @preludes.empty?
|
%unless @preludes.empty?
|
||||||
#include "ruby/ruby.h"
|
#include "ruby/ruby.h"
|
||||||
|
@ -79,11 +84,34 @@ Prelude.new(output && output[/\w+(?=_prelude.c\b)/] || 'prelude', ARGV, vpath).i
|
||||||
% preludes.each {|i, prelude, lines, sub|
|
% preludes.each {|i, prelude, lines, sub|
|
||||||
|
|
||||||
static const char prelude_name<%=i%><%=%>[] = <%=c_esc(prelude_name(*prelude))%><%=%>;
|
static const char prelude_name<%=i%><%=%>[] = <%=c_esc(prelude_name(*prelude))%><%=%>;
|
||||||
static const char prelude_code<%=i%><%=%>[] =
|
static const struct {
|
||||||
% lines.each {|line|
|
% size = beg = 0
|
||||||
<%=line%><%=%>
|
% lines.each_with_index {|(line, comment), n|
|
||||||
|
% if size + line.size < Prelude::LINE_LIMIT
|
||||||
|
% size += line.size
|
||||||
|
% next
|
||||||
|
% end
|
||||||
|
char L<%=beg%><%=%>[<%=size%><%=%>]; /* <%=beg+1%>..<%=n%> */
|
||||||
|
% size = line.size
|
||||||
|
% beg = n
|
||||||
% }
|
% }
|
||||||
;
|
% if size > 0
|
||||||
|
char L<%=beg%><%=%>[<%=size%><%=%>]; /* <%=beg+1%>..<%=lines.size+1%> */
|
||||||
|
% end
|
||||||
|
} prelude_code<%=i%><%=%> = {
|
||||||
|
% size = 0
|
||||||
|
#line 1 <%=c_esc(prelude)%>
|
||||||
|
% lines.each_with_index {|(line, comment), n|
|
||||||
|
% if size + line.size >= Prelude::LINE_LIMIT
|
||||||
|
% size = 0
|
||||||
|
,
|
||||||
|
#line <%=n+1%> <%=c_esc(prelude)%>
|
||||||
|
% end
|
||||||
|
% size += line.size
|
||||||
|
<%=c_esc(line)%><%=%><%if comment%>/* <%=comment%> */<%end%>
|
||||||
|
% }
|
||||||
|
#line <%=_erbout.count("\n")+2%> "<%=@init_name%>.c"
|
||||||
|
};
|
||||||
% }
|
% }
|
||||||
|
|
||||||
% if @have_sublib
|
% if @have_sublib
|
||||||
|
@ -147,7 +175,7 @@ prelude_require(VALUE self, VALUE nth)
|
||||||
% @preludes.each_value do |i, prelude, lines, sub|
|
% @preludes.each_value do |i, prelude, lines, sub|
|
||||||
% if sub
|
% if sub
|
||||||
case <%=i%><%=%>:
|
case <%=i%><%=%>:
|
||||||
code = rb_usascii_str_new(prelude_code<%=i%><%=%>, sizeof(prelude_code<%=i%><%=%>) - 1);
|
code = rb_usascii_str_new(prelude_code<%=i%><%=%>.L0, sizeof(prelude_code<%=i%><%=%>));
|
||||||
name = rb_usascii_str_new(prelude_name<%=i%><%=%>, sizeof(prelude_name<%=i%><%=%>) - 1);
|
name = rb_usascii_str_new(prelude_name<%=i%><%=%>, sizeof(prelude_name<%=i%><%=%>) - 1);
|
||||||
break;
|
break;
|
||||||
% end
|
% end
|
||||||
|
@ -181,7 +209,7 @@ Init_<%=@init_name%><%=%>(void)
|
||||||
% preludes.each do |i, prelude, lines, sub|
|
% preludes.each do |i, prelude, lines, sub|
|
||||||
% next if sub
|
% next if sub
|
||||||
prelude_eval(
|
prelude_eval(
|
||||||
rb_usascii_str_new(prelude_code<%=i%><%=%>, sizeof(prelude_code<%=i%><%=%>) - 1),
|
rb_usascii_str_new(prelude_code<%=i%><%=%>.L0, sizeof(prelude_code<%=i%><%=%>)),
|
||||||
rb_usascii_str_new(prelude_name<%=i%><%=%>, sizeof(prelude_name<%=i%><%=%>) - 1),
|
rb_usascii_str_new(prelude_name<%=i%><%=%>, sizeof(prelude_name<%=i%><%=%>) - 1),
|
||||||
INT2FIX(1));
|
INT2FIX(1));
|
||||||
% end
|
% end
|
||||||
|
@ -191,7 +219,7 @@ Init_<%=@init_name%><%=%>(void)
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
% preludes.length.times {|i|
|
% preludes.length.times {|i|
|
||||||
puts(prelude_code<%=i%><%=%>);
|
printf("%.*s", (int)sizeof(prelude_code<%=i%><%=%>), prelude_code<%=i%><%=%>.L0);
|
||||||
% }
|
% }
|
||||||
#endif
|
#endif
|
||||||
%end
|
%end
|
||||||
|
|
Loading…
Reference in a new issue