1/* -*-c-*-
2 THIS FILE WAS AUTOGENERATED BY tool/compile_prelude.rb. DO NOT EDIT.
3
4 sources: golf_prelude
5*/
6#include "ruby/ruby.h"
7#include "internal.h"
8#include "vm_core.h"
9
10
11static const char prelude_name0[] = "<internal:golf_prelude>";
12static const char prelude_code0[] =
13"class Object\n"
14"  @@golf_hash = {}\n"
15"  def method_missing m, *a, &b\n"
16"    t = @@golf_hash[ [m,self.class] ] ||= matching_methods(m)[0]\n"
17"    if t && b\n"
18"      __send__(t, *a) {|*args|\n"
19"        b.binding.eval(\"proc{|golf_matchdata| $~ = golf_matchdata }\").call($~) if $~\n"
20"        b.call(*args)\n"
21"      }\n"
22"    else\n"
23"      t ? __send__(t, *a, &b) : super\n"
24"    end\n"
25"  end\n"
26"\n"
27"  def matching_methods(s='', m=callable_methods)\n"
28"    r=/^#{s.to_s.gsub(/./){\"(.*?)\"+Regexp.escape($&)}}/\n"
29"    m.grep(r).sort_by do |i|\n"
30"      i.to_s.match(r).captures.map(&:size) << i\n"
31"    end\n"
32"  end\n"
33"\n"
34"  def self.const_missing c\n"
35"    t = @@golf_hash[ [c,self.class] ] ||= matching_methods(c,constants)[0]\n"
36"    t and return const_get(t)\n"
37"    raise NameError, \"uninitialized constant #{c}\", caller(1)\n"
38"  end\n"
39"\n"
40"  def shortest_abbreviation(s='', m=callable_methods)\n"
41"    s=s.to_s\n"
42"    our_case = (?A..?Z)===s[0]\n"
43"    if m.index(s.to_sym)\n"
44"      1.upto(s.size){|z|s.scan(/./).combination(z).map{|trial|\n"
45"        next unless ((?A..?Z)===trial[0]) == our_case\n"
46"        trial*=''\n"
47"        return trial if matching_methods(trial,m)[0].to_s==s\n"
48"      }}\n"
49"    else\n"
50"      nil\n"
51"    end\n"
52"  end\n"
53"\n"
54"  def callable_methods\n"
55"    self.class == Object ? methods + private_methods : methods\n"
56"  end\n"
57"\n"
58"  private\n"
59"\n"
60"  def h(a='H', b='w', c='!')\n"
61"    puts \"#{a}ello, #{b}orld#{c}\"\n"
62"  end\n"
63"\n"
64"  alias say puts\n"
65"\n"
66"  def do_while\n"
67"    0 while yield\n"
68"  end\n"
69"\n"
70"  def do_until\n"
71"    0 until yield\n"
72"  end\n"
73"end\n"
74"\n"
75"class Array\n"
76"  alias old_to_s to_s\n"
77"  alias to_s join\n"
78"end\n"
79"\n"
80"class FalseClass\n"
81"  alias old_to_s to_s\n"
82"  def to_s\n"
83"    \"\"\n"
84"  end\n"
85"end\n"
86"\n"
87"class Integer\n"
88"  alias each times\n"
89"  include Enumerable\n"
90"end\n"
91"\n"
92"class String\n"
93"  alias / split\n"
94"\n"
95"  def to_a\n"
96"    split('')\n"
97"  end\n"
98"\n"
99"  (Array.instance_methods-instance_methods-[:to_ary,:transpose,:flatten,:flatten!,:compact,:compact!,:assoc,:rassoc]).each{|meth|\n"
100"    eval\"\n"
101"    def #{meth}(*args, &block)\n"
102"      a=to_a\n"
103"      result = a.#{meth}(*args, &block)\n"
104"      replace(a.join)\n"
105"      if result.class == Array\n"
106"        Integer===result[0] ? result.pack('c*') : result.join\n"
107"      elsif result.class == Enumerator\n"
108"        result.map(&:join).to_enum\n"
109"      else\n"
110"        result\n"
111"      end\n"
112"    end\"\n"
113"  }\n"
114"end\n"
115"\n"
116"class Enumerator\n"
117"  alias old_to_s to_s\n"
118"  (Array.instance_methods-instance_methods-[:replace]+[:to_s]).each{|meth|\n"
119"    eval\"\n"
120"    def #{meth}(*args, &block)\n"
121"      to_a.#{meth}(*args, &block)\n"
122"    end\"\n"
123"  }\n"
124"  alias old_inspect inspect\n"
125"  alias inspect old_to_s\n"
126"end\n"
127"\n"
128"class Symbol\n"
129"  def call(*args, &block)\n"
130"    proc do |recv|\n"
131"      recv.__send__(self, *args, &block)\n"
132"    end\n"
133"  end\n"
134"end\n"
135;
136
137#define PRELUDE_COUNT 0
138
139
140static void
141prelude_eval(VALUE code, VALUE name, VALUE line)
142{
143    rb_iseq_eval(rb_iseq_compile_with_option(code, name, Qnil, line, 0, Qtrue));
144}
145
146void
147Init_golf(void)
148{
149    prelude_eval(
150      rb_usascii_str_new(prelude_code0, sizeof(prelude_code0) - 1),
151      rb_usascii_str_new(prelude_name0, sizeof(prelude_name0) - 1),
152      INT2FIX(1));
153
154#if 0
155    puts(prelude_code0);
156#endif
157}
158