[前][次][番号順一覧][スレッド一覧]

ruby-changes:2437

From: ko1@a...
Date: 15 Nov 2007 12:26:42 +0900
Subject: [ruby-changes:2437] akr - Ruby:r13928 (trunk): * tool/compile_prelude.rb: use simple template system for source

akr	2007-11-15 12:26:20 +0900 (Thu, 15 Nov 2007)

  New Revision: 13928

  Modified files:
    trunk/ChangeLog
    trunk/tool/compile_prelude.rb

  Log:
    * tool/compile_prelude.rb: use simple template system for source
      code generation.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/tool/compile_prelude.rb?r1=13928&r2=13927
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13928&r2=13927

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 13927)
+++ ChangeLog	(revision 13928)
@@ -1,3 +1,8 @@
+Thu Nov 15 12:24:39 2007  Tanaka Akira  <akr@f...>
+
+	* tool/compile_prelude.rb: use simple template system for source
+	  code generation.
+
 Thu Nov 15 12:19:14 2007  Yukihiro Matsumoto  <matz@r...>
 
 	* lib/cgi/session.rb (CGI::Session::FileStore::restore): use
Index: tool/compile_prelude.rb
===================================================================
--- tool/compile_prelude.rb	(revision 13927)
+++ tool/compile_prelude.rb	(revision 13928)
@@ -51,51 +51,57 @@
   [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__
+}
+EOS
 
-  f.puts <<'EOS__'
+open(outfile, 'w'){|f|
+  f << tmp
 }
-EOS__
-}
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]