Module: YTLJit::VM::YARVTranslatorSimpleMixin
- Includes:
- Node
- Included in:
- YARVTranslatorCRubyObject, YARVTranslatorSimple
- Defined in:
- lib/ytljit/vm_trans.rb
Instance Method Summary collapse
- #depth_of_block(code) ⇒ Object
-
#get_self_object(context) ⇒ Object
getclassvariable setclassvariable.
- #get_vmnode_from_label(context, label) ⇒ Object
- #visit_block_end(code, ins, context) ⇒ Object
- #visit_block_start(code, ins, context) ⇒ Object
- #visit_branchif(code, ins, context) ⇒ Object
- #visit_branchunless(code, ins, context) ⇒ Object
- #visit_defineclass(code, ins, context) ⇒ Object
- #visit_dup(code, ins, context) ⇒ Object
-
#visit_duparray(code, ins, context) ⇒ Object
concatstrings tostring toregexp newarray.
- #visit_dupn(code, ins, context) ⇒ Object
- #visit_getconstant(code, ins, context) ⇒ Object
-
#visit_getdynamic(code, ins, context) ⇒ Object
getspecial setspecial.
- #visit_getlocal(code, ins, context) ⇒ Object
- #visit_invokeblock(code, ins, context) ⇒ Object
- #visit_invokesuper(code, ins, context) ⇒ Object
- #visit_jump(code, ins, context) ⇒ Object
- #visit_leave(code, ins, context) ⇒ Object
-
#visit_pop(code, ins, context) ⇒ Object
expandarray concatarray splatarray checkincludearray newhash newrange.
- #visit_putiseq(code, ins, context) ⇒ Object
-
#visit_putnil(code, ins, context) ⇒ Object
getglobal setglobal.
- #visit_putobject(code, ins, context) ⇒ Object
- #visit_putself(code, ins, context) ⇒ Object
- #visit_putspecialobject(code, ins, context) ⇒ Object
- #visit_putstring(code, ins, context) ⇒ Object
- #visit_send(code, ins, context) ⇒ Object
- #visit_setconstant(code, ins, context) ⇒ Object
- #visit_setdynamic(code, ins, context) ⇒ Object
- #visit_setlocal(code, ins, context) ⇒ Object
- #visit_setn(code, ins, context) ⇒ Object
- #visit_swap(code, ins, context) ⇒ Object
- #visit_symbol(code, ins, context) ⇒ Object
- #visit_throw(code, ins, context) ⇒ Object
-
#visit_topn(code, ins, context) ⇒ Object
reput.
-
#visit_trace(code, ins, context) ⇒ Object
adjuststack defined.
Instance Method Details
#depth_of_block(code) ⇒ Object
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/ytljit/vm_trans.rb', line 157 def depth_of_block(code) dep = 0 ccode = code while ccode.header['type'] == :block ccode = code.parent dep += 1 end dep end |
#get_self_object(context) ⇒ Object
getclassvariable setclassvariable
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/ytljit/vm_trans.rb', line 222 def get_self_object(context) klass = context.expstack.pop case klass when ConstantRefNode klass = klass.value_node when LiteralNode klass = klass.value if klass == nil then klass = context.current_class_node end when SpecialObjectNode if klass.kind == 3 then klass = context.current_class_node else raise "Unkown special object kind = #{klass.kind}" end else raise "Umkonwn node #{klass.class}" end klass end |
#get_vmnode_from_label(context, label) ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/ytljit/vm_trans.rb', line 106 def get_vmnode_from_label(context, label) curnode = context.current_node nllab = context.local_label_tab[label] if nllab == nil then nllab = LocalLabel.new(curnode, label) context.local_label_tab[label] = nllab end nllab end |
#visit_block_end(code, ins, context) ⇒ Object
154 155 |
# File 'lib/ytljit/vm_trans.rb', line 154 def visit_block_end(code, ins, context) end |
#visit_block_start(code, ins, context) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/ytljit/vm_trans.rb', line 138 def visit_block_start(code, ins, context) mtopnode = context.current_node if !mtopnode.is_a?(TopNode) then oldtop = context.the_top mtopnode = TopTopNode.new(nil, Object) context.the_top = mtopnode oldtop.parent = mtopnode mtopnode.init_node = oldtop end locals = code.header['locals'] args = code.header['misc'][:arg_size] context.current_node = mtopnode.construct_frame_info(locals, args) end |
#visit_branchif(code, ins, context) ⇒ Object
583 584 585 586 587 588 589 590 591 592 593 594 |
# File 'lib/ytljit/vm_trans.rb', line 583 def visit_branchif(code, ins, context) curnode = context.current_node nllab = get_vmnode_from_label(context, ins[1]) cond = context.expstack.pop node = BranchIfNode.new(curnode, cond, nllab) nllab.come_from[node] = nil curnode.body = node context.current_node = node end |
#visit_branchunless(code, ins, context) ⇒ Object
596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'lib/ytljit/vm_trans.rb', line 596 def visit_branchunless(code, ins, context) curnode = context.current_node nllab = get_vmnode_from_label(context, ins[1]) cond = context.expstack.pop node = BranchUnlessNode.new(curnode, cond, nllab) nllab.come_from[node] = nil curnode.body = node context.current_node = node end |
#visit_defineclass(code, ins, context) ⇒ Object
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/ytljit/vm_trans.rb', line 380 def visit_defineclass(code, ins, context) name = ins[1] supklsnode = context.expstack.pop defat = context.expstack.pop clsobj = context.current_class_node.klass_object klassobj = nil begin klassobj = clsobj.const_get(name, true) rescue NameError end if klassobj == nil then klassnode = context.current_class_node.constant_tab[name] if klassnode then klassobj = klassnodne.klass_object else supklass = nil case supklsnode when LiteralNode supklass = supklsnode.value if supklass == nil then supklass = Object end when ConstantRefNode supnode = supklsnode.value_node if supnode.is_a?(ClassTopNode) then supklass = supnode.klass_object else raise "Not class #{supnode.class}" end else raise "Not support #{supklsnode.class}" end case ins[3] when 0 klassobj = Class.new(supklass) when 2 klassobj = Module.new end end clsobj.const_set(name, klassobj) end RubyType::define_wraped_class(klassobj, RubyType::RubyTypeBoxed) cnode = ClassTopNode.new(context.current_class_node, klassobj, name) context.current_class_node.constant_tab[name] = cnode body = VMLib::InstSeqTree.new(code, ins[2]) ncontext = YARVContext.new ncontext.current_file_name = context.current_file_name ncontext.current_node = cnode ncontext.current_class_node = cnode ncontext.top_nodes.push cnode tr = self.class.new([body]) tr.translate(ncontext) curnode = context.current_node cvnode = ClassValueNode.new(curnode, cnode) context.expstack.push cvnode context end |
#visit_dup(code, ins, context) ⇒ Object
356 357 358 |
# File 'lib/ytljit/vm_trans.rb', line 356 def visit_dup(code, ins, context) context.expstack.push context.expstack.last end |
#visit_duparray(code, ins, context) ⇒ Object
concatstrings tostring toregexp newarray
327 328 329 330 |
# File 'lib/ytljit/vm_trans.rb', line 327 def visit_duparray(code, ins, context) nnode = LiteralNode.new(nil, ins[1]) context.expstack.push nnode end |
#visit_dupn(code, ins, context) ⇒ Object
360 361 |
# File 'lib/ytljit/vm_trans.rb', line 360 def visit_dupn(code, ins, context) end |
#visit_getconstant(code, ins, context) ⇒ Object
248 249 250 251 252 253 254 |
# File 'lib/ytljit/vm_trans.rb', line 248 def visit_getconstant(code, ins, context) klass = get_self_object(context) name = ins[1] curnode = context.current_node node = ConstantRefNode.new(curnode, klass, name) context.expstack.push node end |
#visit_getdynamic(code, ins, context) ⇒ Object
getspecial setspecial
181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/ytljit/vm_trans.rb', line 181 def visit_getdynamic(code, ins, context) # + 3 mean prtv_env/pointer to block function/self dep = ins[2] curcode = code dep.times do curcode = curcode.parent end offset = curcode.header['misc'][:local_size] + 3 - ins[1] node = LocalVarRefNode.new(context.current_node, offset, dep) context.expstack.push node end |
#visit_getlocal(code, ins, context) ⇒ Object
168 169 170 171 |
# File 'lib/ytljit/vm_trans.rb', line 168 def visit_getlocal(code, ins, context) dep = depth_of_block(code) visit_getdynamic(code, [:getlocal, ins[1], dep], context) end |
#visit_invokeblock(code, ins, context) ⇒ Object
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
# File 'lib/ytljit/vm_trans.rb', line 497 def visit_invokeblock(code, ins, context) curnode = context.current_node func = YieldNode.new(curnode) numarg = ins[1] op_flag = ins[2] seqno = ins[3] # regular arguments args = [] numarg.times do |i| argele = context.expstack.pop args.push argele end frameinfo = func.frame_info roff = frameinfo.real_offset(0) # offset of prevenv framelayout = frameinfo.frame_layout # self args.push LiteralNode.new(curnode, nil) # block args.push LiteralNode.new(curnode, nil) # perv env args.push LiteralNode.new(curnode, nil) args = args.reverse nnode = SendNode.new(curnode, func, args, op_flag, seqno) func.parent = nnode context.expstack.push nnode context end |
#visit_invokesuper(code, ins, context) ⇒ Object
494 495 |
# File 'lib/ytljit/vm_trans.rb', line 494 def visit_invokesuper(code, ins, context) end |
#visit_jump(code, ins, context) ⇒ Object
568 569 570 571 572 573 574 575 576 577 578 579 580 581 |
# File 'lib/ytljit/vm_trans.rb', line 568 def visit_jump(code, ins, context) curnode = context.current_node nllab = get_vmnode_from_label(context, ins[1]) jpnode = JumpNode.new(curnode, nllab) jpnode.body = nllab val = context.expstack.pop nllab.come_from[jpnode] = val curnode.body = jpnode context.current_node = jpnode context.not_reached_pos = true end |
#visit_leave(code, ins, context) ⇒ Object
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'lib/ytljit/vm_trans.rb', line 533 def visit_leave(code, ins, context) curnode = nil vnode = nil if context.top_nodes.last.name == :initialize then visit_pop(code, ins, context) curnode = context.current_node vnode = SelfRefNode.new(curnode) else curnode = context.current_node vnode = context.expstack.pop end srnode = SetResultNode.new(curnode, vnode) curnode.body = srnode context.current_node = srnode case code.header['type'] when :method nnode = MethodEndNode.new(srnode) when :block nnode = BlockEndNode.new(srnode) when :class nnode = ClassEndNode.new(srnode) when :top nnode = ClassEndNode.new(srnode) end context.top_nodes.last.end_nodes.push nnode srnode.body = nnode end |
#visit_pop(code, ins, context) ⇒ Object
expandarray concatarray splatarray checkincludearray newhash newrange
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/ytljit/vm_trans.rb', line 339 def visit_pop(code, ins, context) node = context.expstack.pop if node == nil then # Maybe push instruction deleted by optimize node = LiteralNode.new(nil, nil) end curnode = context.current_node node.parent = curnode curnode.body = node if node.is_a?(HaveChildlenMixin) then context.current_node = node end context end |
#visit_putiseq(code, ins, context) ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/ytljit/vm_trans.rb', line 289 def visit_putiseq(code, ins, context) body = VMLib::InstSeqTree.new(code, ins[1]) curnode = context.current_node ncontext = YARVContext.new case body.header['type'] when :block mtopnode = BlockTopNode.new(curnode) when :method mtopnode = MethodTopNode.new(curnode, body.header['name'].to_sym) when :class mtopnode = ClassTopNode.new(curnode, body.header['name'].to_sym) when :top raise "Maybe bug not appear top block." end ncontext.current_node = mtopnode ncontext.top_nodes.push mtopnode ncontext.current_file_name = context.current_file_name ncontext.current_class_node = context.current_class_node mname = context.expstack.last ncontext.current_method_name = mname tr = self.class.new([body]) tr.translate(ncontext) context.expstack.push mtopnode end |
#visit_putnil(code, ins, context) ⇒ Object
getglobal setglobal
269 270 271 272 |
# File 'lib/ytljit/vm_trans.rb', line 269 def visit_putnil(code, ins, context) nnode = LiteralNode.new(nil, nil) context.expstack.push nnode end |
#visit_putobject(code, ins, context) ⇒ Object
280 281 282 283 |
# File 'lib/ytljit/vm_trans.rb', line 280 def visit_putobject(code, ins, context) nnode = LiteralNode.new(nil, ins[1]) context.expstack.push nnode end |
#visit_putself(code, ins, context) ⇒ Object
274 275 276 277 278 |
# File 'lib/ytljit/vm_trans.rb', line 274 def visit_putself(code, ins, context) curnode = context.current_node nnode = SelfRefNode.new(curnode) context.expstack.push nnode end |
#visit_putspecialobject(code, ins, context) ⇒ Object
285 286 287 |
# File 'lib/ytljit/vm_trans.rb', line 285 def visit_putspecialobject(code, ins, context) context.expstack.push SpecialObjectNode.new(nil, ins[1]) end |
#visit_putstring(code, ins, context) ⇒ Object
317 318 319 320 |
# File 'lib/ytljit/vm_trans.rb', line 317 def visit_putstring(code, ins, context) nnode = LiteralNode.new(nil, ins[1]) context.expstack.push nnode end |
#visit_send(code, ins, context) ⇒ Object
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
# File 'lib/ytljit/vm_trans.rb', line 448 def visit_send(code, ins, context) blk_iseq = ins[3] curnode = context.current_node numarg = ins[2] seqno = ins[5] # regular arguments arg = [] numarg.times do |i| argele = context.expstack.pop arg.push argele end # self arg.push context.expstack.pop # block if blk_iseq then body = VMLib::InstSeqTree.new(code, blk_iseq) ncontext = YARVContext.new ncontext.current_file_name = context.current_file_name ncontext.current_class_node = context.current_class_node btn = ncontext.current_node = BlockTopNode.new(curnode) ncontext.top_nodes.push btn tr = self.class.new([body]) tr.translate(ncontext) arg.push btn # block else arg.push LiteralNode.new(curnode, nil) # block(dymmy) end # perv env arg.push LiteralNode.new(curnode, nil) arg = arg.reverse func = MethodSelectNode.new(curnode, ins[1]) op_flag = ins[4] sn = SendNode.make_send_node(curnode, func, arg, op_flag, seqno) func.set_reciever(sn) context.expstack.push sn context end |
#visit_setconstant(code, ins, context) ⇒ Object
256 257 258 259 260 261 262 263 264 |
# File 'lib/ytljit/vm_trans.rb', line 256 def visit_setconstant(code, ins, context) klass = get_self_object(context) value = context.expstack.pop name = ins[1] curnode = context.current_node node = ConstantAssignNode.new(curnode, klass, name, value) curnode.body = node context.current_node = node end |
#visit_setdynamic(code, ins, context) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/ytljit/vm_trans.rb', line 193 def visit_setdynamic(code, ins, context) dep = ins[2] curcode = code dep.times do curcode = curcode.parent end val = context.expstack.pop curnode = context.current_node offset = curcode.header['misc'][:local_size] + 3 - ins[1] node = LocalAssignNode.new(curnode, offset, dep, val) if context.expstack[-1] == val then varref = LocalVarRefNode.new(context.current_node, offset, dep) context.expstack[-1] = varref end curnode.body = node context.current_node = node end |
#visit_setlocal(code, ins, context) ⇒ Object
173 174 175 176 |
# File 'lib/ytljit/vm_trans.rb', line 173 def visit_setlocal(code, ins, context) dep = depth_of_block(code) visit_setdynamic(code, [:setlocal, ins[1], dep], context) end |
#visit_setn(code, ins, context) ⇒ Object
371 372 |
# File 'lib/ytljit/vm_trans.rb', line 371 def visit_setn(code, ins, context) end |
#visit_swap(code, ins, context) ⇒ Object
363 364 |
# File 'lib/ytljit/vm_trans.rb', line 363 def visit_swap(code, ins, context) end |
#visit_symbol(code, ins, context) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/ytljit/vm_trans.rb', line 117 def visit_symbol(code, ins, context) context.current_local_label = ins curnode = context.current_node nllab = get_vmnode_from_label(context, ins) unless curnode.is_a?(JumpNode) jmpnode = JumpNode.new(curnode, nllab) nllab.parent = jmpnode val = context.expstack.pop nllab.come_from[jmpnode] = val curnode.body = jmpnode jmpnode.body = nllab context.expstack.push nllab.value_node end context.current_node = nllab end |
#visit_throw(code, ins, context) ⇒ Object
565 566 |
# File 'lib/ytljit/vm_trans.rb', line 565 def visit_throw(code, ins, context) end |
#visit_topn(code, ins, context) ⇒ Object
reput
368 369 |
# File 'lib/ytljit/vm_trans.rb', line 368 def visit_topn(code, ins, context) end |
#visit_trace(code, ins, context) ⇒ Object
adjuststack defined
377 378 |
# File 'lib/ytljit/vm_trans.rb', line 377 def visit_trace(code, ins, context) end |