ytljit 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -167,16 +167,17 @@ module YTLJit
167
167
 
168
168
  def get_send_method_node(cursig)
169
169
  mt = nil
170
+ # @arguments[2].type = nil
170
171
  slf = @arguments[2].decide_type_once(cursig)
171
- if slf.instance_of?(RubyType::DefaultType0) then
172
- # Chaos
173
- end
174
-
175
172
  if is_fcall or is_vcall then
176
173
  mt = @func.method_top_node(@class_top, nil)
177
-
174
+
178
175
  else
179
-
176
+ if slf.instance_of?(RubyType::DefaultType0) then
177
+ # Chaos
178
+ # raise "chaos"
179
+ end
180
+
180
181
  mt = @func.method_top_node(@class_top, slf)
181
182
  end
182
183
 
@@ -221,35 +222,27 @@ module YTLJit
221
222
  end
222
223
 
223
224
  def search_signature(cursig)
224
- metsigent = nil
225
225
  @method_signature.each do |tabent|
226
226
  if cursig == tabent[0] then
227
- metsigent = tabent
227
+ return tabent
228
228
  end
229
229
  end
230
- metsigent
230
+ nil
231
231
  end
232
232
 
233
233
  def check_signature_changed(context, signat, metsigent, cursig)
234
234
  if metsigent then
235
235
  if metsigent[1][1] != signat[1] then
236
- if metsigent[1][1].ruby_type < signat[1].ruby_type then
237
- signat[1] = metsigent[1][1]
238
- false
239
- else
240
- type_list(cursig)[1] = []
241
- ti_reset
242
- ti_del_link
243
- context.convergent = false
244
- metsigent[1] = signat
245
- true
246
- end
236
+ # Why not push, because it excepted type inference about
237
+ # this signature after. So reduce search loop.
238
+ @method_signature.unshift [cursig, signat]
239
+ context.convergent = false
240
+ signat[1].ruby_type < metsigent[1][1].ruby_type
247
241
  else
248
242
  false
249
243
  end
244
+
250
245
  else
251
- # Why not push, because it excepted type inference about
252
- # this signature after. So reduce search loop.
253
246
  @method_signature.unshift [cursig, signat]
254
247
  false
255
248
  end
@@ -280,23 +273,50 @@ module YTLJit
280
273
  context = @func.collect_candidate_type(context)
281
274
 
282
275
  signat = signature(context)
283
- check_signature_changed(context, signat, metsigent, cursig)
276
+ changed = check_signature_changed(context, signat, metsigent, cursig)
277
+ =begin
278
+ if changed then
279
+ @arguments.each do |arg|
280
+ arg.type = nil
281
+ end
282
+ signat = signature(context)
283
+ end
284
+ =end
284
285
 
285
286
  mt, slf = get_send_method_node(cursig)
286
287
  if mt then
287
- same_type(self, mt, cursig, signat, context)
288
- same_type(mt, self, signat, cursig, context)
288
+ if changed then
289
+ mt.type_list(metsigent[1])[1] = []
290
+ mt.ti_reset
291
+ end
289
292
 
290
293
  context = mt.collect_candidate_type(context, @arguments, signat)
291
294
 
295
+ same_type(self, mt, cursig, signat, context)
296
+
292
297
  context.push_signature(@arguments, mt)
293
298
  if blknode.is_a?(TopNode) then
294
299
  # Have block
295
300
  mt.yield_node.map do |ynode|
296
- yargs = ynode.arguments
301
+ yargs = ynode.arguments.dup
297
302
  ysignat = ynode.signature(context)
298
303
 
299
304
  same_type(ynode, blknode, signat, ysignat, context)
305
+
306
+ # inherit self from caller node
307
+ yargs[2] = context.current_method_signature_node[-2][2]
308
+ ysignat[2] = cursig[2]
309
+ if yargs[2].decide_type_once(cursig).ruby_type == Object then
310
+ context.current_method_signature_node.reverse.each {|e0|
311
+ if e0[2].class == SendNewArenaNode then
312
+ if yargs[2].type then
313
+ yargs[2] = e0[2]
314
+ ysignat[2] = yargs[2].type
315
+ end
316
+ break
317
+ end
318
+ }
319
+ end
300
320
  context = blknode.collect_candidate_type(context,
301
321
  yargs, ysignat)
302
322
 
@@ -507,23 +527,23 @@ module YTLJit
507
527
  end
508
528
 
509
529
  class SendAllocateNode<SendNode
530
+ include UnboxedObjectUtil
531
+
510
532
  add_special_send_node :allocate
511
533
 
512
534
  def collect_candidate_type_regident(context, slf)
513
535
  slfnode = @arguments[2]
536
+ cursig = context.to_signature
514
537
  if slf.ruby_type.is_a?(Class) then
538
+ tt = nil
515
539
  case slfnode
516
540
  when ConstantRefNode
517
541
  clstop = slfnode.value_node
518
542
  case clstop
519
543
  when ClassTopNode
520
544
  tt = RubyType::BaseType.from_ruby_class(clstop.klass_object)
521
- tt = tt.to_box
522
- add_type(context.to_signature, tt)
523
545
  when LiteralNode
524
546
  tt = RubyType::BaseType.from_ruby_class(clstop.value)
525
- tt = tt.to_box
526
- add_type(context.to_signature, tt)
527
547
  else
528
548
  raise "Unkown node type in constant #{slfnode.value_node.class}"
529
549
  end
@@ -531,9 +551,32 @@ module YTLJit
531
551
  else
532
552
  raise "Unkonwn node type #{@arguments[2].class} "
533
553
  end
554
+
555
+ clt = ClassTopNode.get_class_top_node(tt.ruby_type_raw)
556
+ if context.options[:compile_array_as_uboxed] and
557
+ @is_escape and @is_escape != :global_export and
558
+ (clt and !clt.body.is_a?(DummyNode)) then
559
+ tt = tt.to_unbox
560
+ elsif type_list(cursig)[0].include?(tt.to_unbox) then
561
+ type_list(cursig)[0] = []
562
+ end
563
+
564
+ add_type(cursig, tt)
534
565
  end
535
566
  context
536
567
  end
568
+
569
+ def compile(context)
570
+ rtype = decide_type_once(context.to_signature)
571
+ rrtype = rtype.ruby_type
572
+ if !rtype.boxed then
573
+ clt = ClassTopNode.get_class_top_node(rrtype)
574
+ mivl = clt.end_nodes[0].modified_instance_var.keys
575
+ compile_object_unboxed(context, mivl.size)
576
+ else
577
+ super
578
+ end
579
+ end
537
580
  end
538
581
 
539
582
  class SendInitializeNode<SendNode
@@ -564,6 +607,7 @@ module YTLJit
564
607
  end
565
608
 
566
609
  context.ret_reg = RETR
610
+ context.set_reg_content(RETR, self)
567
611
  context.ret_node = self
568
612
  context.end_using_reg(PTMPR)
569
613
  context.end_using_reg(TMPR2)
@@ -574,6 +618,8 @@ module YTLJit
574
618
  end
575
619
 
576
620
  class SendNewNode<SendNode
621
+ include UnboxedArrayUtil
622
+
577
623
  add_special_send_node :new
578
624
 
579
625
  def initialize(parent, func, arguments, op_flag, seqno)
@@ -610,14 +656,16 @@ module YTLJit
610
656
 
611
657
  def collect_candidate_type_regident(context, slf)
612
658
  slfnode = @arguments[2]
659
+ cursig = context.to_signature
613
660
 
614
661
  if slf.ruby_type.is_a?(Class) then
662
+ @is_escape = search_class_top.is_escape
663
+ @allocmethod.is_escape = @is_escape
615
664
  case slfnode
616
665
  when ConstantRefNode
617
666
  context = @initmethod.collect_candidate_type(context)
618
667
  clstop = slfnode.value_node
619
668
  tt = nil
620
- sig = context.to_signature
621
669
  case clstop
622
670
  when ClassTopNode
623
671
  tt = RubyType::BaseType.from_ruby_class(clstop.klass_object)
@@ -629,18 +677,28 @@ module YTLJit
629
677
  raise "Unkown node type in constant #{slfnode.value_node.class}"
630
678
  end
631
679
 
680
+ clt = ClassTopNode.get_class_top_node(tt.ruby_type_raw)
681
+ if context.options[:compile_array_as_uboxed] and
682
+ @is_escape and @is_escape != :global_export and
683
+ (clt and !clt.body.is_a?(DummyNode)) then
684
+ tt = tt.to_unbox
685
+ elsif type_list(cursig)[0].include?(tt.to_unbox) then
686
+ type_list(cursig)[0] = []
687
+ end
688
+
632
689
  # set element type
633
690
  if tt.ruby_type == Range then
634
691
  tt.args = @arguments[3..-1]
635
- add_element_node(tt, sig, @arguments[3], [0], context)
636
- add_element_node(tt, sig, @arguments[4], [1], context)
692
+ add_element_node(tt, cursig, @arguments[3], [0], context)
693
+ add_element_node(tt, cursig, @arguments[4], [1], context)
637
694
 
638
695
  elsif tt.ruby_type == Array then
639
696
  if context.options[:compile_array_as_uboxed] and
640
697
  @element_node_list.size > 1 and
641
698
  @element_node_list[1..-1].all? {|e|
642
699
  e[3]
643
- } then
700
+ } and
701
+ @is_escape and @is_escape != :global_export then
644
702
  tt = tt.to_unbox
645
703
  end
646
704
  if @arguments[4] then
@@ -648,15 +706,15 @@ module YTLJit
648
706
  if siz and false then
649
707
  # Here is buggy yet Fix me
650
708
  siz[0].times do |i|
651
- add_element_node(tt, sig, @arguments[4], [i], context)
709
+ add_element_node(tt, cursig, @arguments[4], [i], context)
652
710
  end
653
711
  else
654
- add_element_node(tt, sig, @arguments[4], nil, context)
712
+ add_element_node(tt, cursig, @arguments[4], nil, context)
655
713
  end
656
714
  end
657
715
  end
658
716
 
659
- add_type(sig, tt)
717
+ add_type(cursig, tt)
660
718
  else
661
719
  raise "Unkonwn node type #{@arguments[2].class} "
662
720
  end
@@ -692,33 +750,19 @@ module YTLJit
692
750
  context
693
751
  end
694
752
 
695
- def compile_array_unboxed(context)
696
- siz = ((@element_node_list[1..-1].max_by {|a| a[3][0]})[3][0]) + 1
697
- context = gen_alloca(context, siz)
698
- asm = context.assembler
699
- asm.with_retry do
700
- (siz - 1).times do |i|
701
- off = OpIndirect.new(THEPR, i * 8)
702
- asm.mov(TMPR, OpImmidiateMachineWord.new(4))
703
- asm.mov(off, TMPR)
704
- end
705
- end
706
- context.ret_node = self
707
- context
708
- end
709
-
710
753
  def compile(context)
711
- @arguments[2].decide_type_once(context.to_signature)
712
- rtype = @arguments[2].type
754
+ rtype = @arguments[2].decide_type_once(context.to_signature)
713
755
  rrtype = rtype.ruby_type
714
756
  if rrtype.is_a?(Class) then
715
757
  ctype = decide_type_once(context.to_signature)
716
758
  crtype = ctype.ruby_type
717
- if @is_escape != true and crtype == Range then
759
+ if @is_escape != :global_export and
760
+ crtype == Range then
718
761
  return compile_range(context)
719
762
 
720
763
  elsif crtype == Array and
721
- !ctype.boxed and @is_escape != true then
764
+ !ctype.boxed and
765
+ @is_escape != :global_export then
722
766
  return compile_array_unboxed(context)
723
767
 
724
768
  elsif @initmethod.func.calling_convention(context) then
@@ -758,7 +802,8 @@ module YTLJit
758
802
  rtype = decide_type_once(context.to_signature)
759
803
  rrtype = rtype.ruby_type
760
804
  if rtype.is_a?(RubyType::DefaultType0) or
761
- @class_top.search_method_with_super(@func.name, rrtype)[0] then
805
+ rrtype == Array or
806
+ @class_top.search_method_with_super(@func.name, rrtype)[0] then
762
807
  return super(context)
763
808
  end
764
809
 
@@ -796,6 +841,7 @@ module YTLJit
796
841
  rtype = decide_type_once(context.to_signature)
797
842
  rrtype = rtype.ruby_type
798
843
  if rtype.is_a?(RubyType::DefaultType0) or
844
+ rrtype == Array or
799
845
  @class_top.search_method_with_super(@func.name, rrtype)[0] then
800
846
  return super(context)
801
847
  end
@@ -804,8 +850,10 @@ module YTLJit
804
850
  context = gen_arithmetic_operation(context, :sub, TMPR2, TMPR)
805
851
  elsif rrtype == Float then
806
852
  context = gen_arithmetic_operation(context, :subsd, XMM4, XMM0)
853
+
807
854
  else
808
855
  p debug_info
856
+ p rtype
809
857
  raise "Unkown method #{rtype.ruby_type}##{@func.name}"
810
858
  end
811
859
 
@@ -1003,6 +1051,11 @@ module YTLJit
1003
1051
  asm.sar(DBLHIR, AsmType::MACHINE_WORD.size * 8 - 1)
1004
1052
  asm.idiv(context.ret_reg)
1005
1053
  end
1054
+ asm.and(DBLLOR, DBLLOR)
1055
+ asm.setl(DBLLOR)
1056
+ asm.neg(DBLLOR)
1057
+ asm.xor(DBLHIR, DBLLOR)
1058
+ asm.sub(DBLHIR, DBLLOR)
1006
1059
  asm.mov(DBLLOR, DBLHIR)
1007
1060
  context.end_using_reg(context.ret_reg)
1008
1061
  end
@@ -1021,11 +1074,17 @@ module YTLJit
1021
1074
  add_special_send_node :<<
1022
1075
 
1023
1076
  def collect_candidate_type_regident(context, slf)
1077
+ cursig = context.to_signature
1024
1078
  case [slf.ruby_type]
1025
1079
  when [Fixnum]
1026
- cursig = context.to_signature
1027
1080
  same_type(self, @arguments[2], cursig, cursig, context)
1028
1081
  same_type(self, @arguments[3], cursig, cursig, context)
1082
+
1083
+ when [Array]
1084
+ val = @arguments[3]
1085
+ arg = [slf, cursig, val, nil, context]
1086
+ @arguments[2].add_element_node_backward(arg)
1087
+ same_type(self, val, cursig, cursig, context)
1029
1088
  end
1030
1089
 
1031
1090
  context
@@ -1066,6 +1125,57 @@ module YTLJit
1066
1125
  end
1067
1126
  end
1068
1127
 
1128
+ class SendOrNode<SendNode
1129
+ include ArithmeticOperationUtil
1130
+ include SendUtil
1131
+ add_special_send_node :|
1132
+
1133
+ def collect_candidate_type_regident(context, slf)
1134
+ case [slf.ruby_type]
1135
+ when [Fixnum]
1136
+ cursig = context.to_signature
1137
+ same_type(self, @arguments[2], cursig, cursig, context)
1138
+ same_type(self, @arguments[3], cursig, cursig, context)
1139
+ end
1140
+
1141
+ context
1142
+ end
1143
+ end
1144
+
1145
+ class SendXorNode<SendNode
1146
+ include ArithmeticOperationUtil
1147
+ include SendUtil
1148
+ add_special_send_node :^
1149
+
1150
+ def collect_candidate_type_regident(context, slf)
1151
+ case [slf.ruby_type]
1152
+ when [Fixnum]
1153
+ cursig = context.to_signature
1154
+ same_type(self, @arguments[2], cursig, cursig, context)
1155
+ same_type(self, @arguments[3], cursig, cursig, context)
1156
+ end
1157
+
1158
+ context
1159
+ end
1160
+ end
1161
+
1162
+ class SendLengthNode<SendNode
1163
+ include ArithmeticOperationUtil
1164
+ include SendUtil
1165
+ add_special_send_node :length
1166
+
1167
+ def collect_candidate_type_regident(context, slf)
1168
+ cursig = context.to_signature
1169
+ case [slf.ruby_type]
1170
+ when [Array]
1171
+ tt = RubyType::BaseType.from_ruby_class(Fixnum)
1172
+ add_type(cursig, tt)
1173
+ end
1174
+
1175
+ context
1176
+ end
1177
+ end
1178
+
1069
1179
  class SendCompareNode<SendNode
1070
1180
  include SendUtil
1071
1181
  include CompareOperationUtil
@@ -1197,6 +1307,11 @@ module YTLJit
1197
1307
  case [slf.ruby_type]
1198
1308
  when [Array]
1199
1309
  fixtype = RubyType::BaseType.from_ruby_class(Fixnum)
1310
+ idxtype = @arguments[3].decide_type_once(cursig)
1311
+ if idxtype.ruby_type == Range then
1312
+ same_type(self, @arguments[2], cursig, cursig, context)
1313
+ return context
1314
+ end
1200
1315
  @arguments[3].add_type(cursig, fixtype)
1201
1316
  cidx = @arguments[3].get_constant_value
1202
1317
 
@@ -1205,34 +1320,38 @@ module YTLJit
1205
1320
  slf = @arguments[2].decide_type_once(cursig)
1206
1321
 
1207
1322
  epare = nil
1208
- =begin
1323
+
1209
1324
  @arguments[2].element_node_list.each do |ele|
1210
- if ele[3] == cidx and ele[2] != self and ele[0] == slf then
1325
+ if ele[3] == cidx and ele[2] != self and
1326
+ ele[0] == slf then
1211
1327
  epare2 = ele
1212
1328
  esig = epare2[1]
1213
1329
  enode = epare2[2]
1214
- unless enode.type_list(esig) == [[], []]
1330
+ if enode.type_list(esig) != [[], []] then
1215
1331
  epare = epare2
1216
1332
  same_type(self, enode, cursig, esig, context)
1217
1333
  end
1218
1334
  end
1219
1335
  end
1220
- =end
1336
+
1221
1337
  if epare == nil then
1222
1338
  @arguments[2].element_node_list.each do |ele|
1223
- if ele[3] == nil and ele[2] != self and ele[0] == slf then
1339
+ if ele[3] == nil and ele[2] != self and
1340
+ ele[0] == slf then
1224
1341
  epare2 = ele
1225
1342
  esig = epare2[1]
1226
1343
  enode = epare2[2]
1227
- unless enode.type_list(esig) == [[], []]
1344
+ if enode.type_list(esig) != [[], []] then
1228
1345
  epare = epare2
1229
1346
  same_type(self, enode, cursig, esig, context)
1230
1347
  end
1231
1348
  end
1232
1349
  end
1233
1350
  end
1351
+
1352
+ =begin
1234
1353
  if epare == nil then
1235
- @arguments[2].element_node_list.each do |ele|
1354
+ @arguments[2].element_node_list.reverse.each do |ele|
1236
1355
  if ele[3] == cidx and ele[2] != self and
1237
1356
  ele[0].ruby_type == slf.ruby_type then
1238
1357
  epare2 = ele
@@ -1241,22 +1360,37 @@ module YTLJit
1241
1360
  unless enode.type_list(esig) == [[], []]
1242
1361
  epare = epare2
1243
1362
  same_type(self, enode, cursig, esig, context)
1363
+ break
1244
1364
  end
1245
1365
  end
1246
1366
  end
1247
1367
  end
1368
+
1248
1369
  if epare == nil then
1249
- epare = @arguments[2].element_node_list[0]
1250
- esig = epare[1]
1251
- enode = epare[2]
1252
- same_type(self, enode, cursig, esig, context)
1370
+ nele = @arguments[2].element_node_list.select {|e| e[3] == nil}
1371
+ if nele.size == 1 then
1372
+ epare = @arguments[2].element_node_list[0]
1373
+ esig = epare[1]
1374
+ enode = epare[2]
1375
+ same_type(self, enode, cursig, esig, context)
1376
+ end
1377
+ end
1378
+ =end
1379
+
1380
+ if epare == nil then
1381
+ if slf.have_element? and slf.element_type then
1382
+ add_type(cursig, slf.element_type[nil][0])
1383
+ end
1253
1384
  end
1254
1385
 
1255
1386
  @type = nil
1256
1387
 
1257
1388
  when [Hash]
1258
1389
  cidx = @arguments[3].get_constant_value
1259
- rtype = @arguments[2].decide_type_once(sig)
1390
+ rtype = @arguments[2].decide_type_once(cursig)
1391
+ niltype = RubyType::BaseType.from_ruby_class(NilClass)
1392
+ @arguments[3].type = nil
1393
+ @arguments[3].add_type(cursig, niltype)
1260
1394
  @arguments[2].add_element_node(rtype, cursig, self, cidx, context)
1261
1395
  end
1262
1396
 
@@ -1265,14 +1399,37 @@ module YTLJit
1265
1399
 
1266
1400
  def compile(context)
1267
1401
  sig = context.to_signature
1402
+ asm = context.assembler
1403
+ @arguments[2].type = nil
1268
1404
  rtype = @arguments[2].decide_type_once(sig)
1269
1405
  rrtype = rtype.ruby_type
1270
1406
 
1271
1407
  if rrtype == Array and !rtype.boxed and
1272
- @arguments[2].is_escape != true then
1408
+ @arguments[2].is_escape != :global_export then
1273
1409
  context = gen_ref_element(context, @arguments[2], @arguments[3])
1410
+ rtype = decide_type_once(sig)
1411
+ if rtype.ruby_type == Float and !rtype.boxed then
1412
+ asm.with_retry do
1413
+ asm.mov(XMM0, context.ret_reg)
1414
+ end
1415
+ context.ret_reg = XMM0
1416
+ context.set_reg_content(XMM0, self)
1417
+ else
1418
+ asm.with_retry do
1419
+ asm.mov(RETR, context.ret_reg)
1420
+ end
1421
+ context.ret_reg = RETR
1422
+ context.set_reg_content(RETR, self)
1423
+ end
1274
1424
  @body.compile(context)
1275
1425
  else
1426
+ =begin
1427
+ p @arguments[2].type
1428
+ p @arguments[2].instance_eval {@type_list}
1429
+ p sig
1430
+ p @arguments[2].is_escape
1431
+ p debug_info
1432
+ =end
1276
1433
  super
1277
1434
  end
1278
1435
  end
@@ -1289,7 +1446,7 @@ module YTLJit
1289
1446
  when [Array]
1290
1447
  fixtype = RubyType::BaseType.from_ruby_class(Fixnum)
1291
1448
  val = @arguments[4]
1292
- val.is_escape = :export_object
1449
+ val.is_escape = :local_export
1293
1450
  @arguments[3].add_type(cursig, fixtype)
1294
1451
  cidx = @arguments[3].get_constant_value
1295
1452
  @arguments[2].type = nil
@@ -1319,16 +1476,23 @@ module YTLJit
1319
1476
  enode = epare[2]
1320
1477
  if enode != self then
1321
1478
  same_type(self, enode, cursig, esig, context)
1322
- # same_type(enode, self, esig, sig, context)
1323
1479
  end
1324
1480
  if slf.boxed then
1325
- @arguments[3].set_escape_node_backward(true)
1481
+ @arguments[4].set_escape_node_backward(:global_export)
1482
+ else
1483
+ @arguments[4].set_escape_node_backward(:local_export)
1326
1484
  end
1327
1485
 
1328
1486
  when [Hash]
1329
1487
  cidx = @arguments[3].get_constant_value
1330
- @arguments[2].add_element_node(slf, sig, self, cidx, context)
1331
- @arguments[3].set_escape_node_backward(true)
1488
+ @arguments[2].add_element_node(slf, cursig, self, cidx, context)
1489
+ niltype = RubyType::BaseType.from_ruby_class(NilClass)
1490
+ @arguments[3].type = nil
1491
+ @arguments[3].add_type(cursig, niltype)
1492
+ @arguments[4].type = nil
1493
+ @arguments[4].add_type(cursig, niltype)
1494
+ @arguments[3].set_escape_node_backward(:global_export)
1495
+ @arguments[4].set_escape_node_backward(:global_export)
1332
1496
  end
1333
1497
 
1334
1498
  context
@@ -1339,7 +1503,7 @@ module YTLJit
1339
1503
  rtype = @arguments[2].decide_type_once(sig)
1340
1504
  rrtype = rtype.ruby_type
1341
1505
  if rrtype == Array and !rtype.boxed and
1342
- @arguments[2].is_escape != true then
1506
+ @arguments[2].is_escape != :global_export then
1343
1507
  context = gen_set_element(context,
1344
1508
  @arguments[2],
1345
1509
  @arguments[3],
@@ -1399,6 +1563,34 @@ module YTLJit
1399
1563
  add_type(sig, fixnumtype)
1400
1564
  context
1401
1565
  end
1566
+
1567
+ def compile(context)
1568
+ @arguments[2].decide_type_once(context.to_signature)
1569
+ rtype = @arguments[2].type
1570
+ rrtype = rtype.ruby_type
1571
+ if rrtype == Float then
1572
+ context = gen_eval_self(context)
1573
+ context = rtype.gen_unboxing(context)
1574
+ asm = context.assembler
1575
+ if context.ret_reg.is_a?(OpRegistor) or
1576
+ context.ret_reg.is_a?(OpIndirect) then
1577
+ asm.with_retry do
1578
+ asm.cvttsd2si(RETR, context.ret_reg)
1579
+ end
1580
+ else
1581
+ asm.with_retry do
1582
+ asm.mov(XMM0, context.ret_reg)
1583
+ asm.cvttsd2si(RETR, XMM0)
1584
+ end
1585
+ end
1586
+ context.set_reg_content(RETR, self)
1587
+ context.ret_node = self
1588
+ context.ret_reg = RETR
1589
+ context
1590
+ else
1591
+ super(context)
1592
+ end
1593
+ end
1402
1594
  end
1403
1595
 
1404
1596
  class SendChrNode<SendNode
@@ -1436,6 +1628,7 @@ module YTLJit
1436
1628
  asm.mov(RETR, context.ret_reg)
1437
1629
  asm.neg(RETR)
1438
1630
  end
1631
+ context.set_reg_content(RETR, self)
1439
1632
  context.ret_reg = RETR
1440
1633
  elsif rrtype == Float then
1441
1634
  context.start_using_reg(XMM4)
@@ -1445,6 +1638,7 @@ module YTLJit
1445
1638
  asm.subsd(XMM0, XMM4)
1446
1639
  end
1447
1640
  context.ret_reg = XMM0
1641
+ context.set_reg_content(XMM0, self)
1448
1642
  context.end_using_reg(XMM4)
1449
1643
  end
1450
1644
  context.ret_node = self
@@ -1490,7 +1684,7 @@ module YTLJit
1490
1684
  rrtype = rtype.ruby_type
1491
1685
  decide_type_once(sig)
1492
1686
  if rrtype == Range and !rtype.boxed and
1493
- @arguments[2].is_escape != true then
1687
+ @arguments[2].is_escape != :global_export then
1494
1688
  context = @arguments[2].compile(context)
1495
1689
  slotoff = OpIndirect.new(TMPR, arg_offset)
1496
1690
  asm = context.assembler
@@ -1500,6 +1694,7 @@ module YTLJit
1500
1694
  end
1501
1695
 
1502
1696
  context.ret_reg = RETR
1697
+ context.set_reg_content(RETR, self)
1503
1698
  context.ret_node = self
1504
1699
 
1505
1700
  context
@@ -1565,7 +1760,24 @@ module YTLJit
1565
1760
  class SendPNode<SendSameArgTypeNode
1566
1761
  add_special_send_node :p
1567
1762
  end
1568
-
1763
+
1764
+ class SendDispTypeNode<SendNode
1765
+ add_special_send_node :disp_type
1766
+ def collect_candidate_type_regident(context, slf)
1767
+ sig = context.to_signature
1768
+ p debug_info
1769
+ p sig
1770
+ p @arguments[2].type_list(sig)
1771
+ # p @arguments[2].instance_eval {@type_list}
1772
+ p @arguments[2].class
1773
+ context
1774
+ end
1775
+
1776
+ def compile(context)
1777
+ @body.compile(context)
1778
+ end
1779
+ end
1780
+
1569
1781
  class SendSameSelfTypeNode<SendNode
1570
1782
  def collect_candidate_type_regident(context, slf)
1571
1783
  sig = context.to_signature
@@ -1587,6 +1799,14 @@ module YTLJit
1587
1799
  end
1588
1800
  end
1589
1801
 
1802
+ class SendSortNode<SendSameSelfTypeNode
1803
+ add_special_send_node :sort
1804
+ end
1805
+
1806
+ class SendSortNode<SendSameSelfTypeNode
1807
+ add_special_send_node :uniq!
1808
+ end
1809
+
1590
1810
  class SendMathFuncNode<SendNode
1591
1811
  include SendUtil
1592
1812
  def collect_candidate_type_regident(context, slf)
@@ -1597,7 +1817,12 @@ module YTLJit
1597
1817
  end
1598
1818
 
1599
1819
  def compile_call_func(context, fname)
1600
- fadd = OpMemAddress.new(address_of(fname))
1820
+ addr = lambda {
1821
+ a = address_of(fname)
1822
+ $symbol_table[a] = fname
1823
+ a
1824
+ }
1825
+ fadd = OpVarMemAddress.new(addr)
1601
1826
  context.start_arg_reg(FUNC_FLOAT_ARG)
1602
1827
  context.start_arg_reg
1603
1828
  asm = context.assembler
@@ -1617,7 +1842,7 @@ module YTLJit
1617
1842
  context
1618
1843
  end
1619
1844
 
1620
- def compile2(context)
1845
+ def compile(context)
1621
1846
  @arguments[2].decide_type_once(context.to_signature)
1622
1847
  rtype = @arguments[2].type
1623
1848
  rrtype = rtype.ruby_type
@@ -1626,12 +1851,13 @@ module YTLJit
1626
1851
  return super(context)
1627
1852
  end
1628
1853
 
1854
+ context = @arguments[2].compile(context)
1629
1855
  @arguments[3].decide_type_once(context.to_signature)
1630
1856
  rtype = @arguments[3].type
1631
- rrtype = rtype.ruby_type
1632
1857
  context = @arguments[3].compile(context)
1633
1858
  context = rtype.gen_unboxing(context)
1634
- compile_main(context)
1859
+ context = compile_main(context)
1860
+ @body.compile(context)
1635
1861
  end
1636
1862
  end
1637
1863
 
@@ -1727,26 +1953,31 @@ module YTLJit
1727
1953
  sig = context.to_signature
1728
1954
  rtype = decide_type_once(sig)
1729
1955
  rrtype = rtype.ruby_type
1730
- if rrtype == Array and !rtype.boxed and @is_escape != true then
1956
+ if rrtype == Array and
1957
+ !rtype.boxed and
1958
+ @is_escape != :global_export then
1731
1959
  siz = ((@element_node_list[1..-1].max_by {|a| a[3][0]})[3][0]) + 1
1732
1960
  context = gen_alloca(context, siz)
1733
1961
 
1734
- context.start_arg_reg(TMPR2)
1962
+ context.start_using_reg(TMPR2)
1735
1963
  asm = context.assembler
1736
1964
  asm.with_retry do
1737
1965
  asm.mov(TMPR2, THEPR)
1738
1966
  end
1739
1967
 
1740
1968
  @arguments[1..-1].each_with_index do |anode, idx|
1969
+ context.start_using_reg(TMPR2)
1741
1970
  context = gen_set_element(context, nil, idx, anode)
1971
+ context.end_using_reg(TMPR2)
1742
1972
  end
1743
1973
 
1744
1974
  asm.with_retry do
1745
1975
  asm.mov(RETR, TMPR2)
1746
1976
  end
1747
- context.end_arg_reg(TMPR2)
1977
+ context.end_using_reg(TMPR2)
1748
1978
 
1749
1979
  context.ret_reg = RETR
1980
+ context.set_reg_content(RETR, self)
1750
1981
  context.ret_node = self
1751
1982
  @body.compile(context)
1752
1983
  else