Class: TypeProf::Core::Builtin
- Inherits:
-
Object
- Object
- TypeProf::Core::Builtin
- Defined in:
- lib/typeprof/core/builtin.rb
Instance Method Summary collapse
- #array_aref(changes, node, ty, a_args, ret) ⇒ Object
- #array_aset(changes, node, ty, a_args, ret) ⇒ Object
- #array_push(changes, node, ty, a_args, ret) ⇒ Object
- #class_new(changes, node, ty, a_args, ret) ⇒ Object
- #deploy ⇒ Object
- #hash_aref(changes, node, ty, a_args, ret) ⇒ Object
- #hash_aset(changes, node, ty, a_args, ret) ⇒ Object
-
#initialize(genv) ⇒ Builtin
constructor
A new instance of Builtin.
- #object_class(changes, node, ty, a_args, ret) ⇒ Object
- #proc_call(changes, node, ty, a_args, ret) ⇒ Object
Constructor Details
#initialize(genv) ⇒ Builtin
Returns a new instance of Builtin.
3 4 5 |
# File 'lib/typeprof/core/builtin.rb', line 3 def initialize(genv) @genv = genv end |
Instance Method Details
#array_aref(changes, node, ty, a_args, ret) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/typeprof/core/builtin.rb', line 36 def array_aref(changes, node, ty, a_args, ret) if a_args.positionals.size == 1 case ty when Type::Array idx = node.positional_args[0] if idx.is_a?(AST::IntegerNode) idx = idx.lit else idx = nil end vtx = ty.get_elem(@genv, idx) changes.add_edge(@genv, vtx, ret) true else false end else false end end |
#array_aset(changes, node, ty, a_args, ret) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/typeprof/core/builtin.rb', line 57 def array_aset(changes, node, ty, a_args, ret) if a_args.positionals.size == 2 case ty when Type::Array val = a_args.positionals[1] idx = node.positional_args[0] if idx.is_a?(AST::IntegerNode) && ty.get_elem(@genv, idx.lit) changes.add_edge(@genv, val, ty.get_elem(@genv, idx.lit)) else changes.add_edge(@genv, val, ty.get_elem(@genv)) end true else false end else false end end |
#array_push(changes, node, ty, a_args, ret) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/typeprof/core/builtin.rb', line 77 def array_push(changes, node, ty, a_args, ret) if a_args.positionals.size == 1 if ty.is_a?(Type::Array) val = a_args.positionals[0] changes.add_edge(@genv, val, ty.get_elem(@genv)) end recv = Source.new(ty) changes.add_edge(@genv, recv, ret) else false end end |
#class_new(changes, node, ty, a_args, ret) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/typeprof/core/builtin.rb', line 7 def class_new(changes, node, ty, a_args, ret) type_param_vtxs = ty.mod.type_params.map { Vertex.new(node) } temp_instance_ty = Type::Instance.new(@genv, ty.mod, type_param_vtxs) recv = Source.new(temp_instance_ty) changes.add_method_call_box(@genv, recv, :initialize, a_args, false) changes.add_edge(@genv, recv, ret) true end |
#deploy ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/typeprof/core/builtin.rb', line 136 def deploy { class_new: [[:Class], false, :new], object_class: [[:Object], false, :class], proc_call: [[:Proc], false, :call], array_aref: [[:Array], false, :[]], array_aset: [[:Array], false, :[]=], array_push: [[:Array], false, :<<], hash_aref: [[:Hash], false, :[]], hash_aset: [[:Hash], false, :[]=], }.each do |key, (cpath, singleton, mid)| me = @genv.resolve_method(cpath, singleton, mid) me.builtin = method(key) end end |
#hash_aref(changes, node, ty, a_args, ret) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/typeprof/core/builtin.rb', line 90 def hash_aref(changes, node, ty, a_args, ret) if a_args.positionals.size == 1 case ty when Type::Hash, Type::Record idx = node.positional_args[0] idx = idx.is_a?(AST::SymbolNode) ? idx.lit : nil value = ty.get_value(idx) if value changes.add_edge(@genv, value, ret) else # Return untyped for unknown fields changes.add_edge(@genv, Source.new(), ret) end true else false end else false end end |
#hash_aset(changes, node, ty, a_args, ret) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/typeprof/core/builtin.rb', line 112 def hash_aset(changes, node, ty, a_args, ret) if a_args.positionals.size == 2 case ty when Type::Hash val = a_args.positionals[1] idx = node.positional_args[0] if idx.is_a?(AST::SymbolNode) && ty.get_value(idx.lit) # TODO: how to handle new key? changes.add_edge(@genv, val, ty.get_value(idx.lit)) else # TODO: literal_pairs will not be updated changes.add_edge(@genv, a_args.positionals[0], ty.get_key) changes.add_edge(@genv, val, ty.get_value) end changes.add_edge(@genv, val, ret) true else false end else false end end |
#object_class(changes, node, ty, a_args, ret) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/typeprof/core/builtin.rb', line 16 def object_class(changes, node, ty, a_args, ret) ty = ty.base_type(@genv) mod = ty.is_a?(Type::Instance) ? ty.mod : @genv.mod_class ty = Type::Singleton.new(@genv, mod) vtx = Source.new(ty) changes.add_edge(@genv, vtx, ret) true end |
#proc_call(changes, node, ty, a_args, ret) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/typeprof/core/builtin.rb', line 25 def proc_call(changes, node, ty, a_args, ret) case ty when Type::Proc ty.block.accept_args(@genv, changes, a_args.positionals) ty.block.add_ret(@genv, changes, ret) true else false end end |