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.
data/lib/ytljit/vm.rb CHANGED
@@ -177,7 +177,7 @@ LocalVarNode
177
177
  @my_element_node = nil
178
178
  @type_inference_proc = cs
179
179
  @decided_signature = nil
180
- @is_escape = false
180
+ @is_escape = nil
181
181
 
182
182
  @ti_observer = {}
183
183
  @ti_observee = []
@@ -265,28 +265,34 @@ LocalVarNode
265
265
  end
266
266
  end
267
267
 
268
+ def marge_element_node(dst, src)
269
+ res = dst
270
+ regnode = dst[0]
271
+ src.each do |sele|
272
+ if !res.include?(sele) then
273
+ res.push sele
274
+ end
275
+ end
276
+
277
+ res
278
+ end
279
+
268
280
  def marge_type(dst, src)
269
281
  res = dst
270
282
  src.each do |sele|
271
- if sele.is_a?(Array) then
272
- if !res.include?(sele) then
273
- res.push sele
274
- end
275
- else
276
- if res.all? {|e| e.ruby_type != sele.ruby_type or
277
- e.boxed != sele.boxed } then
278
- res.push sele
279
- elsif sele.have_element? and sele.element_type then
280
- # Replace type object which have more collect element type
281
- res.each_with_index do |rele, i|
282
- if rele == sele and rele.element_type == nil then
283
- res[i] = sele
284
- end
283
+ if res.all? {|e| e.ruby_type != sele.ruby_type or
284
+ e.boxed != sele.boxed } then
285
+ res.push sele
286
+ elsif sele.have_element? and sele.element_type then
287
+ # Replace type object which have more collect element type
288
+ res.each_with_index do |rele, i|
289
+ if rele == sele and rele.element_type == nil then
290
+ res[i] = sele
285
291
  end
286
292
  end
287
293
  end
288
294
  end
289
-
295
+
290
296
  res
291
297
  end
292
298
 
@@ -314,18 +320,15 @@ LocalVarNode
314
320
 
315
321
  dtlist = dst.element_node_list
316
322
  stlist = src.element_node_list
323
+
317
324
  orgsize = dtlist.size
318
- dst.element_node_list = marge_type(dtlist, stlist)
325
+ dst.element_node_list = marge_element_node(dtlist, stlist)
319
326
  if orgsize != dtlist.size then
320
327
  dst.ti_changed
321
328
  context.convergent = false
322
329
  end
323
-
324
- if src.is_escape then
325
- if dst.is_escape != true then
326
- dst.is_escape = src.is_escape
327
- end
328
- end
330
+
331
+ dst.set_escape_node(src.is_escape)
329
332
  end
330
333
 
331
334
  def same_type(dst, src, dsig, ssig, context)
@@ -361,14 +364,26 @@ LocalVarNode
361
364
  end
362
365
  end
363
366
 
364
- def set_escape_node_backward(value = true, visitnode = {})
367
+ ESCAPE_LEVEL = {
368
+ nil => -1,
369
+ :not_export => 5,
370
+ :local_export => 6,
371
+ :global_export => 10
372
+ }
373
+
374
+ def set_escape_node(value)
375
+ if ESCAPE_LEVEL[@is_escape] < ESCAPE_LEVEL[value] then
376
+ @is_escape = value
377
+ end
378
+ end
379
+
380
+ def set_escape_node_backward(value, visitnode = {})
365
381
  if visitnode[self] then
366
382
  return
367
383
  end
368
384
 
369
- if @is_escape != true then
370
- @is_escape = value
371
- end
385
+ set_escape_node(value)
386
+
372
387
  visitnode[self] = true
373
388
  @ti_observee.each do |rec|
374
389
  rec.set_escape_node_backward(value, visitnode)
@@ -389,10 +404,11 @@ LocalVarNode
389
404
  same_type(orgnode, enode, orgsig, encsig, context)
390
405
  end
391
406
  if index != nil then
392
- @element_node_list.each do |sig, orgsig, orgnode, orgindex|
393
- if orgindex == index and
407
+ @element_node_list.each do |orgslf, orgsig, orgnode, orgindex|
408
+ if orgslf == curslf and
409
+ orgindex == index and
394
410
  orgnode != enode then
395
- # same_type(orgnode, enode, orgsig, sig, context)
411
+ same_type(orgnode, enode, orgsig, encsig, context)
396
412
  end
397
413
  end
398
414
  end
@@ -421,7 +437,7 @@ LocalVarNode
421
437
 
422
438
  case tlist.size
423
439
  when 0
424
- RubyType::DefaultType0.new
440
+ RubyType::DefaultType0.new # .to_unbox
425
441
 
426
442
  when 1
427
443
  tlist[0]
@@ -506,17 +522,20 @@ LocalVarNode
506
522
  (@type.element_type == nil or
507
523
  @type.element_type == {}) then
508
524
  local_cache[self] = @type
509
- etype = {}
525
+ etype2 = {}
526
+ etype = nil
510
527
  @element_node_list.each do |ele|
511
528
  sig = ele[1]
512
529
  slf = ele[0]
513
530
  if sig == cursig then
514
531
  node = ele[2]
532
+ node.type = nil
515
533
  tt = node.decide_type_once(sig, local_cache)
516
- etype[ele[3]] ||= []
517
- curidx = etype[ele[3]]
518
- if !curidx.include?(tt) then
534
+ etype2[ele[3]] ||= []
535
+ curidx = etype2[ele[3]]
536
+ if tt.ruby_type != Object and !curidx.include?(tt) then
519
537
  curidx.push tt
538
+ etype = etype2
520
539
  end
521
540
  end
522
541
  end
@@ -620,9 +639,10 @@ LocalVarNode
620
639
  # eval 1st arg(self)
621
640
  slfnode = @arguments[2]
622
641
  context = slfnode.compile(context)
623
-
624
- context.ret_node.decide_type_once(context.to_signature)
625
- rtype = context.ret_node.type
642
+
643
+ rnode = context.ret_node
644
+ # rnode.type = nil
645
+ rtype = rnode.decide_type_once(context.to_signature)
626
646
  if !rtype.boxed then
627
647
  context = rtype.gen_unboxing(context)
628
648
  end
@@ -641,7 +661,9 @@ LocalVarNode
641
661
  res.push args[1].decide_type_once(ynode.signature(context))
642
662
  context.pop_signature
643
663
  else
664
+ # args[1].type = nil
644
665
  res.push args[1].decide_type_once(cursig)
666
+ # args[2].type = nil
645
667
  slf = args[2].decide_type_once(cursig)
646
668
  end
647
669
  res.push slf
@@ -667,7 +689,7 @@ LocalVarNode
667
689
  casm.mov(FUNC_ARG[0], rarg.size) # argc
668
690
  casm.mov(FUNC_ARG[1], TMPR2) # argv
669
691
  end
670
- context.set_reg_content(FUNC_ARG[0].dst_opecode, nil)
692
+ context.set_reg_content(FUNC_ARG[0].dst_opecode, true)
671
693
  context.set_reg_content(FUNC_ARG[1].dst_opecode, TMPR2)
672
694
 
673
695
  # Method Select
@@ -732,12 +754,11 @@ LocalVarNode
732
754
  else
733
755
  # other arg.
734
756
  context = arg.compile(context)
735
- context.ret_node.decide_type_once(sig)
736
757
  rnode = context.ret_node
737
- rtype = rnode.type
738
- if rnode.is_escape != true then
758
+ rtype = rnode.decide_type_once(sig)
759
+ # if rnode.is_escape != :global_export then
739
760
  context = rtype.gen_boxing(context)
740
- end
761
+ # end
741
762
  casm = context.assembler
742
763
  casm.with_retry do
743
764
  casm.mov(FUNC_ARG[argpos], context.ret_reg)
@@ -797,7 +818,7 @@ LocalVarNode
797
818
  casm.mov(TMPR, fstentry)
798
819
  casm.mov(handoff, TMPR)
799
820
  end
800
- context.set_reg_content(handoff, nil)
821
+ context.set_reg_content(handoff, true)
801
822
  end
802
823
 
803
824
  # push prev env
@@ -841,7 +862,7 @@ LocalVarNode
841
862
  entry = @arguments[1].code_space.var_base_immidiate_address
842
863
  casm.mov(FUNC_ARG_YTL[1], entry)
843
864
  end
844
- context.set_reg_content(FUNC_ARG_YTL[1].dst_opecode, nil)
865
+ context.set_reg_content(FUNC_ARG_YTL[1].dst_opecode, true)
845
866
 
846
867
  # self
847
868
  # Method Select
@@ -1385,10 +1406,13 @@ LocalVarNode
1385
1406
  context.pop_signature
1386
1407
 
1387
1408
  if @klassclass_node then
1388
- @klassclass_node.collect_candidate_type(context, signode, sig)
1389
- else
1390
- context
1409
+ context = @klassclass_node.collect_candidate_type(context,
1410
+ signode, sig)
1391
1411
  end
1412
+
1413
+ set_escape_node(:not_export)
1414
+
1415
+ context
1392
1416
  end
1393
1417
 
1394
1418
  def compile(context)
@@ -1414,7 +1438,7 @@ LocalVarNode
1414
1438
  asm.mov(FUNC_ARG_YTL[2], var_klassclass)
1415
1439
  end
1416
1440
  context.set_reg_content(FUNC_ARG_YTL[0].dst_opecode, BPR)
1417
- context.set_reg_content(FUNC_ARG_YTL[1].dst_opecode, nil)
1441
+ context.set_reg_content(FUNC_ARG_YTL[1].dst_opecode, true)
1418
1442
  context.set_reg_content(FUNC_ARG_YTL[2].dst_opecode, self)
1419
1443
  add = cs.var_base_address
1420
1444
  context = gen_call(context, add, 3)
@@ -1433,6 +1457,7 @@ LocalVarNode
1433
1457
  include MethodTopCodeGen
1434
1458
  @@frame_struct_tab = {}
1435
1459
  @@local_object_area = Runtime::Arena.new
1460
+ @@global_object_area = Runtime::Arena.new
1436
1461
  @@unwind_proc = CodeSpace.new
1437
1462
  @@nothing_proc = CodeSpace.new
1438
1463
 
@@ -1461,6 +1486,8 @@ LocalVarNode
1461
1486
 
1462
1487
  # Dummy for marshal
1463
1488
  @op_var_value_instaces = nil
1489
+
1490
+ @modified_global_var = nil
1464
1491
  end
1465
1492
 
1466
1493
  attr_accessor :init_node
@@ -1520,7 +1547,9 @@ LocalVarNode
1520
1547
  init_unwind_proc
1521
1548
  add_code_space(nil, @@unwind_proc)
1522
1549
  end
1523
- super(context)
1550
+ context = super(context)
1551
+ @modified_global_var = context.modified_global_var
1552
+ context
1524
1553
  end
1525
1554
 
1526
1555
  def collect_candidate_type(context, signode, sig)
@@ -1538,20 +1567,29 @@ LocalVarNode
1538
1567
  super(context, signode, sig)
1539
1568
  end
1540
1569
 
1541
- def get_arena_address
1570
+ def get_global_arena_address
1571
+ ar = @@global_object_area
1572
+ ar.raw_address
1573
+ end
1574
+
1575
+ def get_global_arena_end_address
1576
+ ar = @@global_object_area
1577
+ ar.body_address + ar.size
1578
+ end
1579
+
1580
+ def get_local_arena_address
1542
1581
  ar = @@local_object_area
1543
- # 2 means used and size
1544
1582
  ar.raw_address
1545
1583
  end
1546
1584
 
1547
- def get_arena_end_address
1585
+ def get_local_arena_end_address
1548
1586
  ar = @@local_object_area
1549
1587
  (ar.body_address + ar.size) & (~0xf)
1550
1588
  end
1551
1589
 
1552
1590
  def compile_init(context)
1553
1591
  addr = lambda {
1554
- get_arena_end_address
1592
+ get_local_arena_end_address
1555
1593
  }
1556
1594
  aa = OpVarImmidiateAddress.new(addr)
1557
1595
  asm = context.assembler
@@ -1565,6 +1603,13 @@ LocalVarNode
1565
1603
  if @init_node then
1566
1604
  context = @init_node.compile(context)
1567
1605
  end
1606
+ @modified_global_var.each_with_index do |dmy, i|
1607
+ @@global_object_area[i + 1] = 4
1608
+ =begin
1609
+ p @@global_object_area
1610
+ p dmy[0]
1611
+ =end
1612
+ end
1568
1613
  super(context)
1569
1614
  end
1570
1615
 
@@ -1880,11 +1925,13 @@ LocalVarNode
1880
1925
 
1881
1926
  # Set result of method/block
1882
1927
  class SetResultNode<BaseNode
1928
+ include NodeUtil
1883
1929
  include HaveChildlenMixin
1884
1930
 
1885
1931
  def initialize(parent, valnode)
1886
1932
  super(parent)
1887
1933
  @value_node = valnode
1934
+ @class_top_node = search_class_top
1888
1935
  end
1889
1936
 
1890
1937
  attr :value_node
@@ -1900,10 +1947,11 @@ LocalVarNode
1900
1947
  same_type(self, @value_node, cursig, cursig, context)
1901
1948
  same_type(@value_node, self, cursig, cursig, context)
1902
1949
 
1950
+ # @type = nil
1903
1951
  rtype = decide_type_once(cursig)
1904
1952
  rrtype = rtype.ruby_type
1905
1953
  if !rtype.boxed and rrtype != Fixnum and rrtype != Float then
1906
- set_escape_node_backward(:export_object)
1954
+ set_escape_node_backward(:local_export)
1907
1955
  else
1908
1956
  set_escape_node_backward(:not_export)
1909
1957
  end
@@ -1952,9 +2000,9 @@ LocalVarNode
1952
2000
  end
1953
2001
 
1954
2002
  def collect_candidate_type(context)
2003
+ cursig = context.to_signature
1955
2004
  @local_label.come_from.values.each do |vnode|
1956
2005
  if vnode then
1957
- cursig = context.to_signature
1958
2006
  same_type(self, vnode, cursig, cursig, context)
1959
2007
  end
1960
2008
  end
@@ -2362,6 +2410,7 @@ LocalVarNode
2362
2410
 
2363
2411
  # Literal
2364
2412
  class LiteralNode<BaseNode
2413
+ include NodeUtil
2365
2414
  include TypeListWithoutSignature
2366
2415
 
2367
2416
  def initialize(parent, val)
@@ -2374,10 +2423,12 @@ LocalVarNode
2374
2423
 
2375
2424
  def collect_candidate_type(context)
2376
2425
  sig = context.to_signature
2377
- if @type_list != [[], []] then
2378
- @type = decide_type_once(sig)
2379
- elsif @type == nil then
2380
- @type = RubyType::BaseType.from_object(@value)
2426
+ if @type == nil then
2427
+ if @type_list != [[], []] then
2428
+ @type = decide_type_once(sig)
2429
+ else
2430
+ @type = RubyType::BaseType.from_object(@value)
2431
+ end
2381
2432
  end
2382
2433
 
2383
2434
  case @value
@@ -2388,6 +2439,13 @@ LocalVarNode
2388
2439
  @element_node_list[0][2].add_type(sig, etype)
2389
2440
  end
2390
2441
 
2442
+ when Hash
2443
+ add_type(sig, @type)
2444
+ @value.each do |key, value|
2445
+ vtype = RubyType::BaseType.from_object(value)
2446
+ @element_node_list[0][2].add_type(sig, vtype)
2447
+ end
2448
+
2391
2449
  when Range
2392
2450
  @type = @type.to_box
2393
2451
  add_type(sig, @type)
@@ -2466,6 +2524,10 @@ LocalVarNode
2466
2524
  def get_constant_value
2467
2525
  [@value]
2468
2526
  end
2527
+
2528
+ # def type=(val)
2529
+ # val
2530
+ # end
2469
2531
  end
2470
2532
 
2471
2533
  class ClassValueNode<BaseNode
@@ -2572,7 +2634,7 @@ LocalVarNode
2572
2634
  asm.mov(PTMPR, prevenv)
2573
2635
  asm.mov(PTMPR, slfarg)
2574
2636
  end
2575
- context.set_reg_content(PTMPR, nil)
2637
+ context.set_reg_content(PTMPR, true)
2576
2638
  context.ret_reg2 = PTMPR
2577
2639
 
2578
2640
  context.ret_reg = @frame_info.offset_arg(1, BPR)
@@ -2610,7 +2672,9 @@ LocalVarNode
2610
2672
  def compile(context)
2611
2673
  context = super(context)
2612
2674
  addr = lambda {
2613
- address_of(@name)
2675
+ a = address_of(@name)
2676
+ $symbol_table[a] = @name
2677
+ a
2614
2678
  }
2615
2679
  context.ret_reg = OpVarMemAddress.new(addr)
2616
2680
  context.ret_node = self
@@ -2690,6 +2754,7 @@ LocalVarNode
2690
2754
  end
2691
2755
  if recobj then
2692
2756
  addr = recobj.method_address_of(@name)
2757
+ $symbol_table[addr] = @name
2693
2758
  if addr then
2694
2759
  if variable_argument?(recobj.method(@name).parameters) then
2695
2760
  @calling_convention = :c_vararg
@@ -2742,17 +2807,20 @@ LocalVarNode
2742
2807
  mth = rklass.instance_method(@name)
2743
2808
  @ruby_reciever = rtype.ruby_type_raw
2744
2809
  rescue NameError
2810
+ #=begin
2745
2811
  p @parent.debug_info
2746
2812
  p sig
2747
2813
  p @name
2748
2814
  p @reciever.class
2749
- p @reciever.instance_eval {@type_list }
2815
+ # p @reciever.instance_eval {@type_list }
2816
+ p type_list(sig)
2750
2817
  =begin
2751
2818
  mc = @reciever.get_send_method_node(context.to_signature)[0]
2752
2819
  iv = mc.end_nodes[0].parent.value_node
2753
2820
  p iv.instance_eval {@name}
2754
2821
  p iv.instance_eval {@type_list}
2755
2822
  =end
2823
+ return :c_fixarg
2756
2824
  raise
2757
2825
  end
2758
2826
  end
@@ -2776,6 +2844,7 @@ LocalVarNode
2776
2844
  asm.with_retry do
2777
2845
  asm.mov(PTMPR, slfop)
2778
2846
  end
2847
+ context.set_reg_content(PTMPR, true)
2779
2848
  context.ret_reg2 = PTMPR
2780
2849
  mtop = @reciever.search_method_with_super(@name)[0]
2781
2850
  if mtop then
@@ -2798,7 +2867,9 @@ LocalVarNode
2798
2867
  end
2799
2868
  if recobj then
2800
2869
  addr = lambda {
2801
- recobj.method_address_of(@name)
2870
+ a = recobj.method_address_of(@name)
2871
+ $symbol_table[a] = @name
2872
+ a
2802
2873
  }
2803
2874
  if addr.call then
2804
2875
  context.ret_reg = OpVarMemAddress.new(addr)
@@ -2818,9 +2889,9 @@ LocalVarNode
2818
2889
  rnode = context.ret_node
2819
2890
  rtype = rnode.decide_type_once(context.to_signature)
2820
2891
  if @calling_convention != :ytl then
2821
- if rnode.is_escape != true then
2892
+ # if rnode.is_escape != :global_export then
2822
2893
  context = rtype.gen_boxing(context)
2823
- end
2894
+ # end
2824
2895
  rtype = rtype.to_box
2825
2896
  elsif !rtype.boxed then
2826
2897
  context = rtype.gen_unboxing(context)
@@ -2834,11 +2905,15 @@ LocalVarNode
2834
2905
  # Can't type inference. Dynamic method search
2835
2906
  mnval = @name.address
2836
2907
  addr = lambda {
2837
- address_of("rb_obj_class")
2908
+ a = address_of("rb_obj_class")
2909
+ $symbol_table[a] = "rb_obj_class"
2910
+ a
2838
2911
  }
2839
2912
  objclass = OpVarMemAddress.new(addr)
2840
2913
  addr = lambda {
2841
- address_of("ytl_method_address_of_raw")
2914
+ a = address_of("ytl_method_address_of_raw")
2915
+ $symbol_table[a] = "ytl_method_address_of_raw"
2916
+ a
2842
2917
  }
2843
2918
  addrof = OpVarMemAddress.new(addr)
2844
2919
 
@@ -2853,23 +2928,24 @@ LocalVarNode
2853
2928
  asm.mov(FUNC_ARG[0], RETR)
2854
2929
  asm.mov(FUNC_ARG[1], mnval)
2855
2930
  end
2856
- context.set_reg_content(FUNC_ARG[0], nil)
2857
- context.set_reg_content(FUNC_ARG[1], nil)
2931
+ context.set_reg_content(FUNC_ARG[0], true)
2932
+ context.set_reg_content(FUNC_ARG[1], true)
2858
2933
  context = gen_save_thepr(context)
2859
2934
  asm.with_retry do
2860
2935
  asm.call_with_arg(addrof, 2)
2861
2936
  asm.mov(TMPR2, RETR)
2862
2937
  asm.pop(PTMPR)
2863
2938
  end
2864
- context.set_reg_content(FUNC_ARG_YTL[0].dst_opecode, nil)
2939
+ context.set_reg_content(PTMPR, true)
2940
+ context.set_reg_content(FUNC_ARG_YTL[0].dst_opecode, true)
2865
2941
  context.set_reg_content(FUNC_ARG_YTL[1].dst_opecode, self)
2866
2942
  context.ret_reg2 = PTMPR
2867
2943
 
2868
2944
  context.end_arg_reg
2869
2945
 
2870
2946
  context.ret_node = self
2871
- context.set_reg_content(RETR, nil)
2872
- context.set_reg_content(TMPR2, nil)
2947
+ context.set_reg_content(RETR, true)
2948
+ context.set_reg_content(TMPR2, true)
2873
2949
  context.set_reg_content(PTMPR, @reciever)
2874
2950
  context.ret_reg = TMPR2
2875
2951
 
@@ -2882,11 +2958,13 @@ LocalVarNode
2882
2958
  asm.mov(XMM0, recval)
2883
2959
  end
2884
2960
  end
2961
+ context.set_reg_content(XMM0, true)
2885
2962
  context.ret_reg2 = XMM0
2886
2963
  else
2887
2964
  asm.with_retry do
2888
2965
  asm.mov(PTMPR, recval)
2889
2966
  end
2967
+ context.set_reg_content(PTMPR, @reciever)
2890
2968
  context.ret_reg2 = PTMPR
2891
2969
  end
2892
2970
 
@@ -2909,6 +2987,7 @@ LocalVarNode
2909
2987
  asm.with_retry do
2910
2988
  asm.mov(PTMPR, recval)
2911
2989
  end
2990
+ context.set_reg_content(TMPR2, @reciever)
2912
2991
  context.ret_reg2 = PTMPR
2913
2992
  end
2914
2993
 
@@ -2918,10 +2997,15 @@ LocalVarNode
2918
2997
  rrec = rrec.value
2919
2998
  end
2920
2999
  if rrec.class == Module then
2921
- name = @name
2922
- rrec.send(:method_address_of, name)
3000
+ a = rrec.send(:method_address_of, @name)
3001
+ $symbol_table[a] = @name
3002
+ a
3003
+ elsif rrec then
3004
+ a = rrec.method_address_of(@name)
3005
+ $symbol_table[a] = @name
3006
+ a
2923
3007
  else
2924
- rrec.method_address_of(@name)
3008
+ 4
2925
3009
  end
2926
3010
  }
2927
3011
  if addr.call then
@@ -3117,9 +3201,9 @@ LocalVarNode
3117
3201
  decide_type_once(sig)
3118
3202
  rtype = @val.decide_type_once(context.to_signature)
3119
3203
  if @type.boxed then
3120
- if @val.is_escape != true then
3204
+ # if @val.is_escape != :global_export then
3121
3205
  context = rtype.gen_boxing(context)
3122
- end
3206
+ # end
3123
3207
  else
3124
3208
  context = rtype.gen_unboxing(context)
3125
3209
  end
@@ -3238,10 +3322,16 @@ LocalVarNode
3238
3322
  cursig = context.to_signature
3239
3323
  same_type(self, @val, cursig, cursig, context)
3240
3324
  # same_type(@val, self, cursig, cursig, context)
3325
+ @val.type = nil
3241
3326
  rtype = @val.decide_type_once(cursig)
3242
3327
  rrtype = rtype.ruby_type
3243
- if cursig[2].boxed and rrtype != Fixnum and rrtype != Float then
3244
- @val.set_escape_node_backward(true)
3328
+ if rrtype != Fixnum and rrtype != Float then
3329
+ if cursig[2].boxed then
3330
+ @val.set_escape_node_backward(:global_export)
3331
+ # @class_top.set_escape_node(:global_export)
3332
+ else
3333
+ @val.set_escape_node_backward(:local_export)
3334
+ end
3245
3335
  end
3246
3336
  @body.collect_candidate_type(context)
3247
3337
  end
@@ -3256,6 +3346,108 @@ LocalVarNode
3256
3346
  end
3257
3347
  end
3258
3348
 
3349
+ # Global Variable
3350
+ class GlobalVarRefNode<VariableRefCommonNode
3351
+ include NodeUtil
3352
+ include TypeListWithoutSignature
3353
+ include UnboxedArrayUtil
3354
+ def initialize(parent, name)
3355
+ super(parent)
3356
+ @name = name
3357
+ @assign_nodes = nil
3358
+ @offset = nil
3359
+ end
3360
+
3361
+ def collect_info(context)
3362
+ @assign_nodes = context.modified_global_var[@name]
3363
+ context
3364
+ end
3365
+
3366
+ def collect_candidate_type(context)
3367
+ @offset = @assign_nodes[0].offset
3368
+ sig = context.to_signature
3369
+ same_type(self, @assign_nodes[0], sig, sig, context)
3370
+ context
3371
+ end
3372
+
3373
+ def compile(context)
3374
+ sig = context.to_signature
3375
+ asm = context.assembler
3376
+ context.start_using_reg(TMPR2)
3377
+ asm.with_retry do
3378
+ asm.mov(TMPR2, context.top_node.get_global_arena_end_address)
3379
+ end
3380
+ context.set_reg_content(TMPR2, true)
3381
+ context = gen_ref_element(context, nil, -@offset)
3382
+ context.end_using_reg(TMPR2)
3383
+ rtype = decide_type_once(sig)
3384
+ if rtype.ruby_type == Float and !rtype.boxed then
3385
+ asm.with_retry do
3386
+ asm.mov(XMM0, context.ret_reg)
3387
+ end
3388
+ context.ret_reg = XMM0
3389
+ else
3390
+ asm.with_retry do
3391
+ asm.mov(RETR, context.ret_reg)
3392
+ end
3393
+ context.ret_reg = RETR
3394
+ end
3395
+ context
3396
+ end
3397
+ end
3398
+
3399
+ class GlobalVarAssignNode<VariableRefCommonNode
3400
+ include NodeUtil
3401
+ include HaveChildlenMixin
3402
+ include TypeListWithoutSignature
3403
+ include UnboxedArrayUtil
3404
+ def initialize(parent, name, value)
3405
+ super(parent)
3406
+ @name = name
3407
+ @value = value
3408
+ @assign_nodes = nil
3409
+ @offset = nil
3410
+ end
3411
+
3412
+ attr :offset
3413
+
3414
+ def collect_info(context)
3415
+ context = @value.collect_info(context)
3416
+ if context.modified_global_var[@name] == nil then
3417
+ context.modified_global_var[@name] = []
3418
+ @offset = context.modified_global_var.keys.size - 1
3419
+ end
3420
+ @assign_nodes = context.modified_global_var[@name]
3421
+ @assign_nodes.push self
3422
+ @body.collect_info(context)
3423
+ end
3424
+
3425
+ def collect_candidate_type(context)
3426
+ sig = context.to_signature
3427
+ context = @value.collect_candidate_type(context)
3428
+ same_type(@assign_nodes[0], @value, sig, sig, context)
3429
+ same_type(self, @assign_nodes[0], sig, sig, context)
3430
+ if @offset == nil then
3431
+ @offset = @assign_nodes[0].offset
3432
+ end
3433
+ @body.collect_candidate_type(context)
3434
+ end
3435
+
3436
+ def compile(context)
3437
+ sig = context.to_signature
3438
+ asm = context.assembler
3439
+ context.start_using_reg(TMPR2)
3440
+ asm.with_retry do
3441
+ asm.mov(TMPR2, context.top_node.get_global_arena_end_address)
3442
+ end
3443
+ context.set_reg_content(TMPR2, :foo)
3444
+ contet = gen_set_element(context, nil, -@offset, @value)
3445
+ context.end_using_reg(TMPR2)
3446
+ @body.compile(context)
3447
+ end
3448
+ end
3449
+
3450
+ # Constant
3259
3451
  class ConstantRefNode<VariableRefCommonNode
3260
3452
  include NodeUtil
3261
3453
  include TypeListWithoutSignature