Module: CastOff::Compiler::SimpleIR
- Includes:
- Instruction
- Included in:
- Translator::CFG, Translator::CFG::Alias, Translator::CFG::BasicBlock, Translator::CFG::Condition, Translator::CFG::Guards, Translator::CFG::Information
- Defined in:
- lib/cast_off/compile/ir/sub_ir.rb,
lib/cast_off/compile/ir/call_ir.rb,
lib/cast_off/compile/ir/jump_ir.rb,
lib/cast_off/compile/ir/operand.rb,
lib/cast_off/compile/ir/guard_ir.rb,
lib/cast_off/compile/ir/param_ir.rb,
lib/cast_off/compile/ir/return_ir.rb,
lib/cast_off/compile/ir/simple_ir.rb
Defined Under Namespace
Classes: Argument, CallIR, CastOffFetchArgs, CheckincludearrayCase, CheckincludearrayPre, CheckincludearrayWhen, ClassVariable, Concatarray, Concatstrings, ConstWrapper, Defined, Duparray, DynamicVariable, ExpandarrayLoop, ExpandarrayPostLoop, ExpandarrayPostSplat, ExpandarrayPre, ExpandarraySplat, Getspecial, GlobalVariable, GuardIR, IR, InstanceVariable, InvokeIR, JumpGuard, JumpIR, Literal, LocalVariable, LoopIR, LoopKey, Newarray, Newhash, Newrange, OptRegexpmatch1, OptRegexpmatch2, ParamIR, Pointer, Putstring, ReturnIR, Self, Splatarray, Stack, StandardGuard, SubIR, TmpBuffer, TmpVariable, Toregexp, Tostring, TypeContainer, VMInsnIR, Variable, YieldIR
Constant Summary collapse
- SupportLoopInstruction =
{ MethodWrapper.new(ClassWrapper.new(Array, true), :map) => 'Array_map', MethodWrapper.new(ClassWrapper.new(Array, true), :map!) => 'Array_map_bang', MethodWrapper.new(ClassWrapper.new(Array, true), :each) => 'Array_each', MethodWrapper.new(ClassWrapper.new(Fixnum, true), :times) => 'Fixnum_times', }
- SPLATCALL_LIMIT =
25
Constants included from Instruction
Instruction::BlockSeparator, Instruction::BranchInstruction, Instruction::IgnoreInstruction, Instruction::JumpOrReturnInstruction, Instruction::SupportInstruction, Instruction::TypeInfoUser, Instruction::VM_CALL_ARGS_BLOCKARG_BIT, Instruction::VM_CALL_ARGS_SPLAT_BIT, Instruction::VM_CALL_FCALL_BIT, Instruction::VM_CALL_OPT_SEND_BIT, Instruction::VM_CALL_SUPER_BIT, Instruction::VM_CALL_TAILCALL_BIT, Instruction::VM_CALL_TAILRECURSION_BIT, Instruction::VM_CALL_VCALL_BIT
Instance Method Summary collapse
Methods included from Util
Instance Method Details
#block_argument_is_unsupported(translator, insn) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 32 def block_argument_is_unsupported(translator, insn) raise UnsupportedError.new("\nCurrently, CastOff doesn't support method and block invocation with a block argument.\n------------------------------------------------------------------------------\nTarget file is (\#{translator.target_name()}).\nCall site is (\#{insn}).\n EOS\nend\n") |
#generate_ir(cfg, insns, depth) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 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 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 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 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 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 447 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 493 494 495 496 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 532 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 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
# File 'lib/cast_off/compile/ir/simple_ir.rb', line 42 def generate_ir(cfg, insns, depth) irs = [] translator = cfg.translator stack = Stack.new(depth) insns.each do |insn| bug() unless stack.depth == insn.depth op = insn.op argv = insn.argv case op when :send, :opt_plus, :opt_minus, :opt_mult, :opt_div, :opt_mod, :opt_lt, :opt_le, :opt_gt, :opt_ge, :opt_neq, :opt_eq, :opt_ltlt, :opt_aref, :opt_length, :opt_size, :opt_not, :opt_succ fcall = false flags = 0 case op when :send id = argv[0] argc = argv[1] blockiseq = argv[2] bug() if blockiseq # should be convert to cast_off_prep, ... flags = argv[3] fcall = (flags & VM_CALL_FCALL_BIT) != 0 bug() if flags & VM_CALL_OPT_SEND_BIT != 0 # VM_CALL_OPT_SEND_BIT is set at the vm_call_method bug() if flags & VM_CALL_SUPER_BIT != 0 # VM_CALL_SUPER_BIT is set at the invokesuper #VM_CALL_VCALL_BIT: variable or call, 要検討 when :opt_plus id = "+".intern argc = 1 when :opt_minus id = "-".intern argc = 1 when :opt_mult id = "*".intern argc = 1 when :opt_div id = "/".intern argc = 1 when :opt_mod id = "%".intern argc = 1 when :opt_lt id = "<".intern argc = 1 when :opt_le id = "<=".intern argc = 1 when :opt_gt id = ">".intern argc = 1 when :opt_ge id = ">=".intern argc = 1 when :opt_neq id = "!=".intern argc = 1 when :opt_eq id = "==".intern argc = 1 when :opt_ltlt id = "<<".intern argc = 1 when :opt_aref id = "[]".intern argc = 1 when :opt_length id = :length argc = 0 when :opt_size id = :size argc = 0 when :opt_not id = "!".intern argc = 0 when :opt_succ id = :succ argc = 0 else bug() end if (flags & VM_CALL_ARGS_BLOCKARG_BIT) != 0 blockarg = TmpVariable.new(stack.pop()) else blockarg = nil end args = [] argc.times { args << TmpVariable.new(stack.pop()) } if fcall stack.pop(); irs << SubIR.new(Self.new(translator, insn.iseq), TmpVariable.new(stack.push()), InsnInfo.new([:putself], insn.iseq, -1, -1, true), cfg) end recv = TmpVariable.new(stack.pop()) recv.is_also(insn.ic_class) if insn.ic_class param = [] param << ParamIR.new(recv, insn, cfg) param += args.reverse.map{|arg| ParamIR.new(arg, insn, cfg)} if blockarg param << ParamIR.new(blockarg, insn, cfg) argc += 1 end irs += param irs << InvokeIR.new(id, flags, param, argc + 1, TmpVariable.new(stack.push()), insn, cfg) when :invokeblock num = argv[0] flags = argv[1] block_argument_is_unsupported(translator, insn) if flags & VM_CALL_ARGS_BLOCKARG_BIT != 0 args = [] num.times { args << TmpVariable.new(stack.pop()) } param = [] param += args.reverse.map{|arg| ParamIR.new(arg, insn, cfg)} irs += param irs << YieldIR.new(flags, param, num, TmpVariable.new(stack.push()), insn, cfg) when :putnil irs << SubIR.new(Literal.new(nil, translator), TmpVariable.new(stack.push()), insn, cfg) when :putself irs << SubIR.new(Self.new(translator, insn.iseq), TmpVariable.new(stack.push()), insn, cfg) when :putstring obj = argv[0] param = [] param << ParamIR.new(Literal.new(obj, translator), insn, cfg) irs += param irs << Putstring.new(param, 1, TmpVariable.new(stack.push()), insn, cfg) when :putobject obj = argv[0] irs << SubIR.new(Literal.new(obj, translator), TmpVariable.new(stack.push()), insn, cfg) when :newarray argc = argv[0] args = [] argc.times { args << TmpVariable.new(stack.pop()) } param = args.reverse.map{|arg| ParamIR.new(arg, insn, cfg)} irs += param irs << Newarray.new(param, argc, TmpVariable.new(stack.push()), insn, cfg) when :newhash argc = argv[0] args = [] argc.times { args << TmpVariable.new(stack.pop()) } param = args.reverse.map{|arg| ParamIR.new(arg, insn, cfg)} irs += param irs << Newhash.new(param, argc, TmpVariable.new(stack.push()), insn, cfg) when :duparray obj = argv[0] param = [] param << ParamIR.new(Literal.new(obj, translator), insn, cfg) irs += param irs << Duparray.new(param, 1, TmpVariable.new(stack.push()), insn, cfg) when :tostring param = [] param << ParamIR.new(TmpVariable.new(stack.pop()), insn, cfg) irs += param irs << Tostring.new(param, 1, TmpVariable.new(stack.push()), insn, cfg) when :toregexp cnt = argv[1] args = [] cnt.times { args << TmpVariable.new(stack.pop()) } param = args.reverse.map{|arg| ParamIR.new(arg, insn, cfg)} irs += param irs << Toregexp.new(param, cnt, TmpVariable.new(stack.push()), insn, cfg) when :concatstrings argc = argv[0] args = [] argc.times { args << TmpVariable.new(stack.pop()) } param = args.reverse.map{|arg| ParamIR.new(arg, insn, cfg)} irs += param irs << Concatstrings.new(param, argc, TmpVariable.new(stack.push()), insn, cfg) when :concatarray argc = 2 args = [] argc.times { args << TmpVariable.new(stack.pop()) } param = args.reverse.map{|arg| ParamIR.new(arg, insn, cfg)} irs += param irs << Concatarray.new(param, argc, TmpVariable.new(stack.push()), insn, cfg) when :newrange flag = argv[0] argc = 2 args = [] argc.times { args << TmpVariable.new(stack.pop()) } param = args.reverse.map{|arg| ParamIR.new(arg, insn, cfg)} irs += param irs << Newrange.new(param, argc, TmpVariable.new(stack.push()), insn, cfg) when :opt_regexpmatch1 r = argv[0] argc = 2 param = [] param << ParamIR.new(Literal.new(r, translator), insn, cfg) param << ParamIR.new(TmpVariable.new(stack.pop()), insn, cfg) irs += param irs << OptRegexpmatch1.new(param, argc, TmpVariable.new(stack.push()), insn, cfg) when :opt_regexpmatch2 argc = 2 param = [] param << ParamIR.new(TmpVariable.new(stack.pop()), insn, cfg) param << ParamIR.new(TmpVariable.new(stack.pop()), insn, cfg) irs += param irs << OptRegexpmatch2.new(param, argc, TmpVariable.new(stack.push()), insn, cfg) when :expandarray num, flag = *argv is_splat = (flag & 0x01) != 0 op = :expandarray_pre # param が Array かどうかという情報は使用しないので、ガードは不要 = InsnInfo.new([op], insn.iseq, -1, -1, true) param = [] param << ParamIR.new(TmpVariable.new(stack.pop()), , cfg) irs += param irs << ExpandarrayPre.new(param, 1, TmpVariable.new(stack.push()), , cfg) depth = stack.pop() if is_splat ary_depth = depth + num + 1 else ary_depth = depth + num end irs << SubIR.new(TmpVariable.new(depth), TmpVariable.new(ary_depth), , cfg) if flag & 0x02 != 0 # post: ..., nil ,ary[-1], ..., ary[0..-num] # top op = :expandarray_post_loop num.times do |i| # param は Array だと分かっているので、ガードは不要 = InsnInfo.new([op, num, i], insn.iseq, -1, -1, true) param = [] param << ParamIR.new(TmpVariable.new(ary_depth), , cfg) irs += param irs << ExpandarrayPostLoop.new(param, 1, TmpVariable.new(stack.push()), , cfg) end op = :expandarray_post_splat if is_splat # param は Array だと分かっているので、ガードは不要 = InsnInfo.new([op, num], insn.iseq, -1, -1, true) param = [] param << ParamIR.new(TmpVariable.new(ary_depth), , cfg) irs += param irs << ExpandarrayPostSplat.new(param, 1, TmpVariable.new(stack.push()), , cfg) end else # normal: ary[num..-1], ary[num-2], ary[num-3], ..., ary[0] # top op = :expandarray_splat if is_splat # param は Array だと分かっているので、ガードは不要 = InsnInfo.new([op, num], insn.iseq, -1, -1, true) param = [] param << ParamIR.new(TmpVariable.new(ary_depth), , cfg) irs += param irs << ExpandarraySplat.new(param, 1, TmpVariable.new(stack.push()), , cfg) end op = :expandarray_loop num.times do |i| # param は Array だと分かっているので、ガードは不要 = InsnInfo.new([op, num - i - 1], insn.iseq, -1, -1, true) param = [] param << ParamIR.new(TmpVariable.new(ary_depth), , cfg) irs += param irs << ExpandarrayLoop.new(param, 1, TmpVariable.new(stack.push()), , cfg) end end when :splatarray param = [] param << ParamIR.new(TmpVariable.new(stack.pop()), insn, cfg) irs += param irs << Splatarray.new(param, 1, TmpVariable.new(stack.push()), insn, cfg) when :checkincludearray flag = argv[0] op = :checkincludearray_pre # param が Array かどうかという情報は使用しないので、ガードは不要 checkincludearray_pre_insn = InsnInfo.new([op], insn.iseq, -1, -1, true) param = [] param << ParamIR.new(TmpVariable.new(stack.pop()), checkincludearray_pre_insn, cfg) # ary irs += param irs << CheckincludearrayPre.new(param, 1, TmpVariable.new(stack.push()), checkincludearray_pre_insn, cfg) if flag == true op = :checkincludearray_case # ary は Array だと分かっているので、ガードは不要 # obj の型情報は使用しないので、ガードは不要 checkincludearray_case_insn = InsnInfo.new([op], insn.iseq, -1, -1, true) param = [] param << ParamIR.new(TmpVariable.new(stack.pop()), checkincludearray_case_insn, cfg) # ary param << ParamIR.new(TmpVariable.new(stack.pop()), checkincludearray_case_insn, cfg) # obj stack.push() # obj irs += param irs << CheckincludearrayCase.new(param, 2, TmpVariable.new(stack.push()), checkincludearray_case_insn, cfg) #result elsif flag == false op = :checkincludearray_when # ary は Array だと分かっているので、ガードは不要 checkincludearray_when_insn = InsnInfo.new([op], insn.iseq, -1, -1, true) param = [] param << ParamIR.new(TmpVariable.new(stack.pop()), checkincludearray_when_insn, cfg) # ary stack.pop() # obj result_depth = stack.push() # result irs += param irs << CheckincludearrayWhen.new(param, 1, TmpVariable.new(result_depth), checkincludearray_when_insn, cfg) irs << SubIR.new(TmpVariable.new(result_depth), TmpVariable.new(stack.push()), checkincludearray_when_insn, cfg) else bug() end when :cast_off_decl_arg if translator.inline_block? irs << SubIR.new(Argument.new(*argv), LocalVariable.new(*argv), insn, cfg) else irs << SubIR.new(Argument.new(*argv), DynamicVariable.new(*argv), insn, cfg) end when :cast_off_decl_var if translator.inline_block? irs << SubIR.new(Literal.new(nil, translator), LocalVariable.new(*argv), insn, cfg) else ir = SubIR.new(Literal.new(nil, translator), DynamicVariable.new(*argv), insn, cfg) ir.vanish() irs << ir end when :cast_off_getconst irs << SubIR.new(ConstWrapper.new(*argv, translator), TmpVariable.new(stack.push()), insn, cfg) when :cast_off_getgvar irs << SubIR.new(GlobalVariable.new(*argv, translator), TmpVariable.new(stack.push()), insn, cfg) when :cast_off_getcvar irs << SubIR.new(ClassVariable.new(*argv), TmpVariable.new(stack.push()), insn, cfg) when :cast_off_getivar irs << SubIR.new(InstanceVariable.new(*argv), TmpVariable.new(stack.push()), insn, cfg) when :cast_off_getlvar irs << SubIR.new(LocalVariable.new(*argv), TmpVariable.new(stack.push()), insn, cfg) when :cast_off_getdvar irs << SubIR.new(DynamicVariable.new(*argv), TmpVariable.new(stack.push()), insn, cfg) when :getdynamic, :setdynamic bug() when :cast_off_setgvar irs << SubIR.new(TmpVariable.new(stack.pop()), GlobalVariable.new(*argv, translator), insn, cfg) when :cast_off_setcvar irs << SubIR.new(TmpVariable.new(stack.pop()), ClassVariable.new(*argv), insn, cfg) when :cast_off_setivar irs << SubIR.new(TmpVariable.new(stack.pop()), InstanceVariable.new(*argv), insn, cfg) when :cast_off_setlvar irs << SubIR.new(TmpVariable.new(stack.pop()), LocalVariable.new(*argv), insn, cfg) when :cast_off_setdvar irs << SubIR.new(TmpVariable.new(stack.pop()), DynamicVariable.new(*argv), insn, cfg) when :getspecial type = insn.argv.last bug() if type == 0 unless translator.configuration.allow_builtin_variable_incompatibility? raise(UnsupportedError.new("\n$&, $`, $\\, $+, $0...$9 are incompatible.\nIf you want to use these variables, use CastOff.allow_builtin_variable_incompatibility(true).\n EOS\n end\n param = []\n irs << Getspecial.new(param, 0, TmpVariable.new(stack.push()), insn, cfg)\n when :jump, :cast_off_enter_block, :cast_off_leave_block\n bug(\"op = \#{op}, depth = \#{stack.depth}\") if op == :cast_off_leave_block && (stack.depth - 1) != insn.iseq.depth\n irs << JumpIR.new(nil, insn, cfg)\n when :cast_off_break_block\n bug(\"op = \#{op}, depth = \#{stack.depth}\") if (stack.depth - 1) != insn.iseq.depth\n d = stack.pop()\n stack.push()\n irs << SubIR.new(TmpVariable.new(d), TmpVariable.new(stack.push()), insn, cfg)\n irs << JumpIR.new(TmpVariable.new(stack.pop()), insn, cfg)\n when :branchunless, :branchif, :cast_off_continue_loop\n target = argv[0]\n irs << JumpIR.new(TmpVariable.new(stack.pop()), insn, cfg)\n when :pop\n stack.pop()\n when :adjuststack\n # same as popn instruction\n num = argv[0]\n num.times { stack.pop() }\n when :setn\n # deep <-----------------------\n # e.g. num = 3, [:a, :b, :c, :d] => [:d, :b, :c, :d]\n num = argv[0]\n dst = stack.pop() - num\n src = stack.push()\n irs << SubIR.new(TmpVariable.new(src), TmpVariable.new(dst), insn, cfg)\n when :dupn\n # deep <-----------------------\n # e.g. [:a, :b, :c] => [:a, :b, :c, :a, :b, :c]\n num = argv[0]\n num.times do\n depth = stack.push()\n irs << SubIR.new(TmpVariable.new(depth - num), TmpVariable.new(depth), insn, cfg)\n end\n when :dup\n depth = stack.push()\n irs << SubIR.new(TmpVariable.new(depth - 1), TmpVariable.new(depth), insn, cfg)\n when :swap\n tmp = stack.push()\n stack.pop()\n v0 = tmp - 1\n v1 = tmp - 2\n irs << SubIR.new(TmpVariable.new(v0), TmpVariable.new(tmp), insn, cfg)\n irs << SubIR.new(TmpVariable.new(v1), TmpVariable.new(v0), insn, cfg)\n irs << SubIR.new(TmpVariable.new(tmp), TmpVariable.new(v1), insn, cfg)\n when :topn\n n = argv[0]\n dst = stack.push()\n irs << SubIR.new(TmpVariable.new(dst - n - 1), TmpVariable.new(dst), insn, cfg)\n when :throw\n type, state, flag, level = insn.get_throw_info()\n if flag != 0\n bug()\n else\n case type\n when :return\n irs << ReturnIR.new(TmpVariable.new(stack.pop()), ReturnIR::ThrowObj.new(type, argv[0], state, flag, level), insn, cfg)\n else\n bug()\n end\n end\n when :cast_off_prep\n # stack \u306B\u306F argc + 1 \u7A4D\u307E\u308C\u3066\u3044\u308B\n depth = argv[0]\n loop_args = argv[1]\n send_insn = argv[2]\n send_argv = send_insn.argv\n send_id = send_argv[0]\n send_argc = send_argv[1]\n send_flags = send_argv[3]\n fcall = (send_flags & VM_CALL_FCALL_BIT) != 0\n bug() if send_flags & VM_CALL_OPT_SEND_BIT != 0 # VM_CALL_OPT_SEND_BIT is set at the vm_call_method\n bug() if send_flags & VM_CALL_SUPER_BIT != 0 # VM_CALL_SUPER_BIT is set at the invokesuper\n block_argument_is_unsupported(translator, insn) if send_flags & VM_CALL_ARGS_BLOCKARG_BIT != 0\n #VM_CALL_VCALL_BIT: variable or call, \u8981\u691C\u8A0E\n raise UnsupportedError.new(<<-EOS) if send_flags & VM_CALL_ARGS_SPLAT_BIT != 0\n\nCurrently, CastOff doesn't support a method invocation which takes a splat argument (like *arg) and which takes a block.\n------------------------------------------------------------------------------------------------------------------------\nTarget file is (\#{translator.target_name()}).\nCall site is (\#{insn}).\n EOS\n\n send_args = []\n send_argc.times { send_args << TmpVariable.new(stack.pop()) }\n\n if fcall\n stack.pop();\n irs << SubIR.new(Self.new(translator, insn.iseq), TmpVariable.new(stack.push()), InsnInfo.new([:putself], insn.iseq, -1, -1, true), cfg)\n end\n recv = TmpVariable.new(stack.pop())\n param = []\n param << ParamIR.new(recv, insn, cfg)\n param += send_args.reverse.map{|arg| ParamIR.new(arg, insn, cfg)}\n\n # loop \u306E\u305F\u3081\u306E key object \u3092\u8FD4\u3059, reciever \u30AA\u30D6\u30B8\u30A7\u30AF\u30C8 + context (map \u306E\u5834\u5408\u306F\u8FD4\u308A\u5024\u306E\u914D\u5217 + \u5E30\u7D0D\u5909\u6570)\n # rb_ary_each_context_t \u307F\u305F\u3044\u306A\u306E\u3092\u4F5C\u308B\n # block = true \u3060\u3063\u305F\u5834\u5408\u3001recv \u3068 id \u304B\u3089\u95A2\u6570\u540D\u3092\u7279\u5B9A\u3057\u3066\u3001\u305D\u308C\u7528\u306E\u95A2\u6570\u3092\u547C\u3076\u3002\u8FD4\u308A\u5024\u306F loopkey\n # loopkey \u306F cast_off_ary_each_context_t \u307F\u305F\u3044\u306A\u69CB\u9020\u4F53\n loopkey = LoopKey.new(send_id, depth, loop_args, insn, cfg.translator)\n translator.loopkey[depth] = loopkey\n irs += param\n irs << LoopIR.new(loopkey, op, param, send_argc + 1, TmpVariable.new(stack.push()), insn, cfg)\n when :cast_off_loop\n depth = argv[0]\n send_insn = argv[2]\n send_argv = send_insn.argv\n send_id = send_argv[0]\n\n # loopkey \u3092\u5F15\u6570\u3067\u6E21\u3059\u3002\u8FD4\u308A\u5024\u306F true(\u30EB\u30FC\u30D7\u7D99\u7D9A) or false(\u30EB\u30FC\u30D7\u7D42\u4E86)\n loopkey = translator.loopkey[depth]\n bug() unless loopkey\n param = []\n param << ParamIR.new(TmpVariable.new(stack.pop()), insn, cfg)\n irs += param\n irs << LoopIR.new(loopkey, op, param, 1, TmpVariable.new(stack.push()), insn, cfg)\n when :cast_off_cont\n depth = argv[0]\n args = argv[1]\n if translator.inline_block?\n args.each_with_index{|arg, i| irs << SubIR.new(TmpBuffer.new(i), LocalVariable.new(*arg), insn, cfg)}\n else\n args.each_with_index{|arg, i| irs << SubIR.new(TmpBuffer.new(i), DynamicVariable.new(*arg), insn, cfg)}\n end\n loopkey = translator.loopkey[depth]\n loopkey.block_iseq = insn.iseq\n insn.iseq.set_loopkey(loopkey)\n insn.iseq.use_temporary_c_ary(args.size())\n when :cast_off_finl\n depth = argv[0]\n send_insn = argv[2]\n send_argv = send_insn.argv\n send_id = send_argv[0]\n loopkey = translator.loopkey[depth]\n bug() unless loopkey\n param = []\n irs << LoopIR.new(loopkey, op, param, 0, TmpVariable.new(stack.push()), insn, cfg)\n when :cast_off_fetch_args\n param = []\n if argv[0]\n args = argv[0].last\n if translator.inline_block?\n args.map!{|arg| LocalVariable.new(*arg).to_name() }\n else\n args.map!{|arg| DynamicVariable.new(*arg).to_name() }\n end\n end\n irs << CastOffFetchArgs.new(param, 0, TmpVariable.new(stack.push()), insn, cfg)\n when :cast_off_handle_optional_args\n irs << JumpIR.new(TmpVariable.new(stack.pop()), insn, cfg)\n when :leave\n depth = stack.pop()\n unless depth == 0\n if translator.inline_block?\n # throw => leave\n else\n bug()\n end\n end\n irs << ReturnIR.new(TmpVariable.new(depth), nil, insn, cfg)\n when :defined\n t = argv[0]\n case t\n when DEFINED_IVAR, DEFINED_GVAR, DEFINED_FUNC, DEFINED_CONST\n # ok\n when DEFINED_IVAR2\n bug(\"unexpected defined instruction\")\n when DEFINED_CVAR\n raise(UnsupportedError.new(\"Currently, CastOff cannot handle defined instruction for class variable\"))\n when DEFINED_METHOD\n raise(UnsupportedError.new(\"Currently, CastOff cannot handle defined instruction for methods\"))\n when DEFINED_YIELD\n raise(UnsupportedError.new(\"Currently, CastOff cannot handle defined instruction for yield\"))\n when DEFINED_REF\n raise(UnsupportedError.new(\"Currently, CastOff cannot handle defined instruction for global-variable\"))\n when DEFINED_ZSUPER\n raise(UnsupportedError.new(\"Currently, CastOff cannot handle defined instruction for super\"))\n else\n bug()\n end\n\n param = []\n param << ParamIR.new(TmpVariable.new(stack.pop()), insn, cfg)\n irs += param\n irs << Defined.new(param, 1, TmpVariable.new(stack.push()), insn, cfg)\n else\n raise(UnsupportedError, \"unsupported RubyVM instruction \#{insn} \")\n end\n unless stack.depth == insn.depth + insn.stack_usage()\n bug(\"stack.depth = \#{stack.depth}, insn.depth = \#{insn.depth + insn.stack_usage()}, insn = \#{insn}\\n\#{irs.join(\"\\n\")}\\n\")\n end\n end\n irs\nend\n")) |