crystalizer 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. data/Changelog +27 -0
  2. data/README +79 -0
  3. data/Rakefile +24 -0
  4. data/TODO +14 -0
  5. data/VERSION +1 -0
  6. data/benchmarks/bench.rb +129 -0
  7. data/benchmarks/concretize_test.rb +26 -0
  8. data/benchmarks/extconf.rb +10 -0
  9. data/benchmarks/tak_rb.rb +7 -0
  10. data/benchmarks/tak_so.rb +7 -0
  11. data/benchmarks/tak_source.rb +16 -0
  12. data/bin/rb2cx +162 -0
  13. data/doc/eval2c.txt +246 -0
  14. data/doc/gen_html.rb +26 -0
  15. data/doc/html_template +10 -0
  16. data/doc/index.txt +169 -0
  17. data/doc/limitations.txt +529 -0
  18. data/doc/optimizations.txt +185 -0
  19. data/doc/rb2cx.txt +130 -0
  20. data/doc/style.css +27 -0
  21. data/lib/concretizer.rb +3 -0
  22. data/lib/ruby2cext/c_function.rb +617 -0
  23. data/lib/ruby2cext/common_node_comp.rb +1412 -0
  24. data/lib/ruby2cext/compiler.rb +311 -0
  25. data/lib/ruby2cext/concretize.rb +269 -0
  26. data/lib/ruby2cext/error.rb +15 -0
  27. data/lib/ruby2cext/eval2c.rb +126 -0
  28. data/lib/ruby2cext/parser.rb +36 -0
  29. data/lib/ruby2cext/plugin.rb +24 -0
  30. data/lib/ruby2cext/plugins/builtin_methods.rb +817 -0
  31. data/lib/ruby2cext/plugins/cache_call.rb +293 -0
  32. data/lib/ruby2cext/plugins/case_optimize.rb +102 -0
  33. data/lib/ruby2cext/plugins/const_cache.rb +36 -0
  34. data/lib/ruby2cext/plugins/direct_self_call.rb +70 -0
  35. data/lib/ruby2cext/plugins/inline_builtin.rb +797 -0
  36. data/lib/ruby2cext/plugins/inline_methods.rb +68 -0
  37. data/lib/ruby2cext/plugins/ivar_cache.rb +147 -0
  38. data/lib/ruby2cext/plugins/require_include.rb +69 -0
  39. data/lib/ruby2cext/plugins/util.rb +154 -0
  40. data/lib/ruby2cext/plugins/warnings.rb +121 -0
  41. data/lib/ruby2cext/scopes.rb +225 -0
  42. data/lib/ruby2cext/str_to_c_strlit.rb +12 -0
  43. data/lib/ruby2cext/tools.rb +80 -0
  44. data/lib/ruby2cext/version.rb +22 -0
  45. data/results +68 -0
  46. data/setup.rb +1585 -0
  47. data/stuff/builtin_methods.rb +69 -0
  48. data/stuff/builtin_methods_test.rb +37 -0
  49. data/test/bootstrap.rb +10 -0
  50. data/test/causes_crash_all_opts.rb +1165 -0
  51. data/test/eval2c/test_eval2c.rb +37 -0
  52. data/test/temp_17.rb +16 -0
  53. data/test/temp_18.rb +8 -0
  54. data/test/temp_19.rb +8 -0
  55. data/test/temp_2.rb +7 -0
  56. data/test/temp_20.rb +5 -0
  57. data/test/temp_21.rb +161 -0
  58. data/test/temp_22.rb +7 -0
  59. data/test/temp_23.rb +7 -0
  60. data/test/temp_24.rb +219 -0
  61. data/test/temp_25.rb +7 -0
  62. data/test/temp_26.rb +11 -0
  63. data/test/temp_27.rb +11 -0
  64. data/test/temp_28.rb +9 -0
  65. data/test/temp_29.rb +9 -0
  66. data/test/temp_3.rb +0 -0
  67. data/test/temp_30.rb +0 -0
  68. data/test/temp_31.rb +10 -0
  69. data/test/temp_32.rb +10 -0
  70. data/test/temp_33.rb +15 -0
  71. data/test/temp_34.rb +15 -0
  72. data/test/temp_35.rb +7 -0
  73. data/test/temp_36.rb +7 -0
  74. data/test/temp_37.rb +10 -0
  75. data/test/temp_38.rb +10 -0
  76. data/test/temp_39.rb +0 -0
  77. data/test/temp_4.rb +7 -0
  78. data/test/temp_40.rb +50 -0
  79. data/test/temp_41.rb +50 -0
  80. data/test/temp_42.rb +8 -0
  81. data/test/temp_43.rb +8 -0
  82. data/test/temp_44.rb +0 -0
  83. data/test/temp_48.rb +7 -0
  84. data/test/temp_49.rb +7 -0
  85. data/test/temp_5.rb +7 -0
  86. data/test/temp_59.rb +7 -0
  87. data/test/temp_6.rb +7 -0
  88. data/test/temp_60.rb +7 -0
  89. data/test/temp_68.rb +239 -0
  90. data/test/temp_7.rb +7 -0
  91. data/test/temp_70.rb +7 -0
  92. data/test/temp_71.rb +7 -0
  93. data/test/temp_72.rb +13 -0
  94. data/test/temp_73.rb +7 -0
  95. data/test/temp_74.rb +7 -0
  96. data/test/temp_76.rb +7 -0
  97. data/test/temp_77.rb +13 -0
  98. data/test/temp_79.rb +7 -0
  99. data/test/temp_8.rb +14 -0
  100. data/test/temp_81.rb +14 -0
  101. data/test/temp_83.rb +0 -0
  102. data/test/temp_84.rb +7 -0
  103. data/test/temp_85.rb +7 -0
  104. data/test/temp_86.rb +14 -0
  105. data/test/temp_87.rb +7 -0
  106. data/test/temp_88.rb +7 -0
  107. data/test/temp_89.rb +7 -0
  108. data/test/temp_9.rb +14 -0
  109. data/test/temp_90.rb +0 -0
  110. data/test/temp_91.rb +7 -0
  111. data/test/temp_92.rb +7 -0
  112. data/test/temp_93.rb +7 -0
  113. data/test/temp_94.rb +7 -0
  114. data/test/temp_95.rb +7 -0
  115. data/test/temp_96.rb +0 -0
  116. data/test/temp_97.rb +0 -0
  117. data/test/temp_98.rb +7 -0
  118. data/test/temp_99.rb +7 -0
  119. data/test/test_concretize.rb +132 -0
  120. data/test/test_concretize_all.rb +15 -0
  121. data/test/test_crystalize_block.rb +73 -0
  122. data/test/test_files/test.rb +615 -0
  123. data/test/test_files/vmode_test.rb +73 -0
  124. data/test/test_files/warn_test.rb +35 -0
  125. data/test/test_syntax.rb +25 -0
  126. metadata +268 -0
@@ -0,0 +1,615 @@
1
+ # this file contains code that uses many different node types and everything in
2
+ # here works with Ruby2CExtension
3
+
4
+ BEGIN {puts "begin1"}
5
+ BEGIN {puts "begin2"}
6
+
7
+ p self
8
+ puts
9
+ p 1,1.2,(p 23;-1),:sym,1...1,1..1
10
+ p [1,2],"oij\0iuj","",[1,[2,[3,4]]]
11
+ begin
12
+ p 1,*[2,3]
13
+ end while false
14
+ p({:a=>[1], :b=>[2]}.values_at(:a, :b))
15
+ p [1,2,3].index(2)
16
+ a=b="hello"
17
+ puts a, b + " you"
18
+ p(@a=7)
19
+ p($a=6)
20
+ xx=$a=$b=@c=@d=xxx=5
21
+ p [$a,$b,@c,@d,xx,xxx]
22
+ for a in 0..1
23
+ a = (a == 0 ? :a : :b)
24
+ unless a == :b
25
+ puts "a"
26
+ else
27
+ puts "not a"
28
+ end
29
+ end
30
+ p(if puts
31
+ else
32
+ end)
33
+ def m(a)
34
+ p a
35
+ end
36
+ m 1 + 2
37
+ m [1,2,3].first
38
+ m 2.between?(1, 5)
39
+ p method(:m)
40
+
41
+ p [1111111111111222222333345342323, /ab/i, /cd/m, /xx/n]
42
+
43
+ __send__(:p, true.__id__, false.__send__(:inspect), "abc".__send__(:[], 1), 2.equal?(3), nil.nil?, 1.nil?)
44
+
45
+ def m1(a,b=[],*c)
46
+ p a,b,c
47
+ end
48
+ m1(1,2,3,4,5)
49
+ m1 3
50
+ def m2(*)
51
+ p "STAR"
52
+ end
53
+ m2 1,2,3
54
+
55
+ a="hello"
56
+ def a.a
57
+ p self
58
+ end
59
+ a.a
60
+
61
+ public
62
+
63
+ def fib(n)
64
+ if n < 2
65
+ n
66
+ else
67
+ fib(n - 1) + fib(n - 2)
68
+ end
69
+ end
70
+
71
+ p fib(10)
72
+
73
+ case
74
+ when 1 == 1
75
+ p "woo"
76
+ when *[false, true]
77
+ p (1..3).inspect
78
+ else
79
+ p "uhh"
80
+ end
81
+
82
+ for a in 0...7
83
+ case a
84
+ when true, false
85
+ p "bool"
86
+ when nil
87
+ p "nil"
88
+ when 0
89
+ p "null"
90
+ when 3, *[1,2]
91
+ p "1 2 3"
92
+ when 4, 5
93
+ p "4 5"
94
+ else
95
+ p 6
96
+ end
97
+ end
98
+
99
+ case true
100
+ when false
101
+ p "false"
102
+ when true
103
+ p "true"
104
+ end
105
+
106
+ case 2.0
107
+ when 1, nil
108
+ p 1
109
+ when 2
110
+ p 2
111
+ when 3
112
+ p 3
113
+ end
114
+
115
+ case "a"
116
+ when /a/
117
+ p "good"
118
+ else
119
+ p "bad"
120
+ end
121
+
122
+ a = 1,3
123
+ p a
124
+ p [__FILE__, __LINE__]
125
+
126
+ a = [1,nil,3]
127
+
128
+ a[0]+=2
129
+ a[1]||=4
130
+ a[2]&&=5
131
+
132
+ p a
133
+
134
+ a = Object.new
135
+ def a.method_missing(*args) p args; end
136
+
137
+ a[1,*[2,3]]
138
+ a[1,*[2,3]]=4
139
+ a[1,*[2,3]]||=4
140
+
141
+ class AliasTest
142
+ def foo
143
+ p "afoo"
144
+ end
145
+
146
+ alias afoo foo
147
+ undef foo
148
+ end
149
+
150
+ $at = AliasTest.new
151
+ alias $aat $at
152
+ $aat.afoo
153
+
154
+ a = Struct.new(:aa).new
155
+
156
+ a.aa=3
157
+ a.aa+=2
158
+ p a.aa
159
+ a.aa||=raise
160
+ p a.aa
161
+ a.aa&&=8
162
+ p a.aa
163
+
164
+ Object::AAA=5
165
+ BBB=6
166
+ p [AAA,BBB,::AAA,::BBB,Object::AAA,Object::Object::BBB]
167
+
168
+ p [:"a#{1+2}b#{"123".inspect}", "str#{:sym}xx", /a#{2}b#{3}c/, /a#{2}b#{3}c/o, `echo #{2+3}`, `echo 23`.chomp, /null\000null/]
169
+
170
+ def ct
171
+ def argv
172
+ ::ARGV
173
+ end
174
+ end
175
+
176
+ ct
177
+ p argv
178
+ ct
179
+
180
+ class AA < String
181
+ def rev
182
+ reverse
183
+ end
184
+ end
185
+ p AA.new("abc").rev
186
+
187
+ class A
188
+ @@var = :A
189
+ C = :CA
190
+ end
191
+
192
+ class B
193
+ @@var = :B
194
+ C = :CB
195
+
196
+ a = A.new
197
+ class ::A
198
+ p [@@var, C] # => [:A, :CA]
199
+ def foo
200
+ [@@var, C]
201
+ end
202
+ end
203
+ def a.bar
204
+ [@@var, C]
205
+ end
206
+ class << a
207
+ p [@@var, C] # => [:B, :CB]
208
+ def baz
209
+ [@@var, C]
210
+ end
211
+ end
212
+ p a.foo # => [:A, :CA]
213
+ p a.bar # => [:B, :CB]
214
+ p a.baz # => [:B, :CB]
215
+ p [@@var, ::A::C, C, class << a;C;end] # => [:B, :CA, :CB, :CB]
216
+ class << a
217
+ @@var = :ASing # this changes B's @@var
218
+ C = :CASing # this creates a new C for a's sing. class
219
+ end
220
+ p [@@var, ::A::C, C, class << a;C;end] # => [:ASing, :CA, :CB, :CASing]
221
+ p a.foo # => [:A, :CA]
222
+ p a.bar # => [:ASing, :CB]
223
+ p a.baz # => [:ASing, :CASing]
224
+ end
225
+
226
+ class F; FF = 3;end
227
+ FF = 4
228
+ class G < F; p FF; end # should be 3, not 4
229
+
230
+ def pt
231
+ p Proc.new[]
232
+ end
233
+ pt { 'Proc.new ok!' }
234
+
235
+ a,@b,$c,(D,*e),*f = [1,2,3,[4,5,6,7],8,9,10]
236
+ p [a,@b,$c,D,e,f]
237
+ a,((@b,$c),(DDD,*e)),*f = [1,[[2,3],[4,5,6,7]],8,9,10]
238
+ p [a,@b,$c,DDD,e,f]
239
+ a,b = 2
240
+ p [a,b]
241
+ *b=1,2
242
+ p b
243
+
244
+ a=[1,2,3]
245
+ a[5],a[7]=4, 6
246
+ p a
247
+ class << a
248
+ attr_accessor :c, :d
249
+ end
250
+ a.c,a.d=7,8
251
+ p [a.c,a.d]
252
+
253
+ p [1,2,3].map { |a| a+1 }
254
+
255
+ def yield_t(a)
256
+ yield a, a+1
257
+ end
258
+
259
+ p(yield_t(23) { |a, b| a+b })
260
+
261
+ p "abc".instance_eval { reverse }
262
+ p proc { |xx| xx }[24]
263
+
264
+ END { p "END" }
265
+ def end_t
266
+ at_exit { p "at_exit" }
267
+ end
268
+ end_t
269
+ end_t
270
+
271
+ class SupA
272
+ def test(*arg)
273
+ p "SupA#test", arg
274
+ yield 23
275
+ end
276
+ end
277
+ class SupB < SupA
278
+ def test(*a)
279
+ p a
280
+ super
281
+ super()
282
+ super(a)
283
+ super { |b| p b+1 }
284
+ super() { |b| p b+2 }
285
+ super(a) { |b| p b+3 }
286
+ end
287
+ end
288
+ SupB.new.test { |a| p a }
289
+ SupB.new.test(23) { |a| p a }
290
+
291
+ for i in 1..9
292
+ p i
293
+ end
294
+
295
+ def sqrt(x)
296
+ x = x.to_f
297
+ average = lambda { |a, b| (a+b)/2 }
298
+ impr = lambda { |g| average[g, x/g] }
299
+ good_en = lambda { |g| (g*g - x).abs < 0.001 }
300
+ try = lambda { |g| good_en[g] ? g : try[impr[g]] }
301
+ try[1.0]
302
+ end
303
+
304
+ p sqrt(2)
305
+
306
+
307
+ def my_while(cond)
308
+ if cond
309
+ yield
310
+ retry
311
+ end
312
+ end
313
+
314
+ i=3
315
+ my_while((i-=1)>0) { p i }
316
+
317
+ p (11..20).map { |i| (i%4==0)..(i%3==0) ? i : nil }
318
+ p (11..20).map { |i| (i%4==0)...(i%3==0) ? i : nil }
319
+
320
+ "a" =~ /(a)/
321
+ p [
322
+ defined? ""=~//,
323
+ defined? yield,
324
+ defined? self,
325
+ defined? nil,
326
+ defined? true,
327
+ defined? false,
328
+ defined? a=5,
329
+ defined? a,
330
+ defined? $a,
331
+ defined? $udef,
332
+ defined? @c,
333
+ defined? @udef,
334
+ defined? A,
335
+ defined? Udef,
336
+ defined? @@udef,
337
+ defined? ::A,
338
+ defined? ::Udef,
339
+ defined? $1,
340
+ defined? $9,
341
+ defined? $',
342
+ ]
343
+
344
+ class AAAAAA
345
+ xx=5
346
+ proc { |yy|
347
+ begin
348
+ @@a||=xx
349
+ @@a||=yy
350
+ @a||=5
351
+ @a||=6
352
+ $f||=5
353
+ $f||=6
354
+ a||=5
355
+ a||=6
356
+ p [@@a, @a, $f, a]
357
+ @@a&&=5
358
+ @@a&&=6
359
+ @a&&=5
360
+ @a&&=6
361
+ $f&&=5
362
+ $f&&=6
363
+ a&&=5
364
+ a&&=6
365
+ p [@@a, @a, $f, a]
366
+ ensure
367
+ p "in ensure"
368
+ end
369
+ }[6]
370
+ end
371
+
372
+ class AEx < RuntimeError;end
373
+ class BEx < RuntimeError;end
374
+ class CEx < RuntimeError;end
375
+
376
+ ex = AEx
377
+ p(begin
378
+ p "in body"
379
+ ex && raise(ex.new)
380
+ p "not raised"
381
+ rescue TypeError, AEx
382
+ p "in AEx"
383
+ ex = BEx
384
+ retry
385
+ rescue *[TypeError, BEx] => b
386
+ p "in BEx #{b}"
387
+ ex = CEx
388
+ retry
389
+ rescue
390
+ p "in rescue"
391
+ ex = nil
392
+ retry
393
+ else
394
+ "res"
395
+ ensure
396
+ p "in ensure"
397
+ end)
398
+
399
+ ex = AEx
400
+ begin
401
+ begin
402
+ p "in body"
403
+ raise ex
404
+ rescue AEx
405
+ p "in AEx"
406
+ ex = BEx
407
+ retry
408
+ end
409
+ rescue BEx
410
+ p "in BEx"
411
+ else
412
+ p "in else: BUG!"
413
+ end
414
+
415
+ begin
416
+ begin
417
+ raise
418
+ rescue 1
419
+ 2
420
+ end
421
+ rescue => e
422
+ p e
423
+ end
424
+
425
+ def cf1
426
+ begin
427
+ return 5
428
+ ensure
429
+ puts "ensure"
430
+ end
431
+ 6
432
+ end
433
+ p cf1
434
+
435
+ def cf2
436
+ begin
437
+ while true
438
+ begin
439
+ return 5555
440
+ ensure
441
+ puts "ensure"
442
+ end
443
+ end
444
+ ensure
445
+ puts "ensure"
446
+ end
447
+ 6
448
+ end
449
+ p cf2
450
+
451
+ def cf22
452
+ begin
453
+ while true
454
+ begin
455
+ break 5555
456
+ ensure
457
+ puts "ensure"
458
+ end
459
+ end
460
+ ensure
461
+ puts "ensure"
462
+ end + 6
463
+ end
464
+ p cf22
465
+
466
+ def cf3
467
+ 1.instance_eval {
468
+ begin
469
+ break
470
+ ensure
471
+ puts "ensure"
472
+ end
473
+ }
474
+ end
475
+ p cf3
476
+
477
+ def cf4
478
+ i = 0
479
+ 5.times {
480
+ begin
481
+ break if i == 3
482
+ i+=1
483
+ puts "xxx"
484
+ begin
485
+ redo
486
+ ensure
487
+ puts "ensure"
488
+ while true
489
+ break
490
+ end
491
+ end
492
+ ensure
493
+ puts "ensure"
494
+ end
495
+ }
496
+ i
497
+ end
498
+ p cf4
499
+
500
+ def cf5
501
+ i = 0
502
+ 5.instance_eval {
503
+ begin
504
+ next
505
+ ensure
506
+ puts "ensure"
507
+ end
508
+ }
509
+ end
510
+ p cf5
511
+
512
+ def cf6
513
+ i = 0
514
+ 5.instance_eval {
515
+ begin
516
+ next 24
517
+ rescue
518
+ puts "bug"
519
+ end
520
+ }
521
+ end
522
+ p cf6
523
+
524
+ def cf61
525
+ i = 0
526
+ 5.instance_eval {
527
+ begin
528
+ raise
529
+ rescue
530
+ next 24
531
+ end
532
+ }
533
+ end
534
+ p cf61
535
+
536
+ def cf7
537
+ loop {
538
+ begin
539
+ break
540
+ rescue
541
+ puts "bug"
542
+ ensure
543
+ puts "ensure"
544
+ end
545
+ }
546
+ 23
547
+ end
548
+ p cf7
549
+
550
+ def cf71
551
+ loop {
552
+ begin
553
+ raise
554
+ rescue
555
+ break
556
+ ensure
557
+ puts "ensure"
558
+ end
559
+ }
560
+ 23
561
+ end
562
+ p cf71
563
+
564
+ def cf8
565
+ while true
566
+ begin
567
+ return 1234
568
+ rescue
569
+ puts "bug"
570
+ ensure
571
+ puts "ensure"
572
+ end
573
+ end
574
+ 23
575
+ end
576
+ p cf8
577
+
578
+ def cf81
579
+ while true
580
+ begin
581
+ raise
582
+ rescue
583
+ return 1234
584
+ ensure
585
+ puts "ensure"
586
+ end
587
+ end
588
+ 23
589
+ end
590
+ p cf81
591
+
592
+ def cf9
593
+ i = 0
594
+ 5.times {
595
+ begin
596
+ break if i == 3
597
+ i+=1
598
+ puts "xxx"
599
+ begin
600
+ raise
601
+ rescue
602
+ while true
603
+ puts "yyy"
604
+ break
605
+ end
606
+ redo
607
+ end
608
+ ensure
609
+ puts "ensure"
610
+ end
611
+ }
612
+ i
613
+ end
614
+ p cf9
615
+