Index: src/x64/full-codegen-x64.cc |
diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc |
index 24591657927d0eeacfa290c578a2df53400ccffc..30ad8039ac753e190d6b55075685670b9365e11b 100644 |
--- a/src/x64/full-codegen-x64.cc |
+++ b/src/x64/full-codegen-x64.cc |
@@ -1945,8 +1945,96 @@ void FullCodeGenerator::VisitYield(Yield* expr) { |
break; |
} |
- case Yield::DELEGATING: |
- UNIMPLEMENTED(); |
+ case Yield::DELEGATING: { |
+ VisitForStackValue(expr->generator_object()); |
+ |
+ // Initial stack layout is as follows: |
+ // [sp + 1 * kPointerSize] iter |
+ // [sp + 0 * kPointerSize] g |
+ |
+ Label l_catch, l_try, l_resume, l_send, l_call, l_loop; |
+ // Initial send value is undefined. |
+ __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
+ __ jmp(&l_send); |
+ |
+ // catch (e) { receiver = iter; f = iter.throw; arg = e; goto l_call; } |
+ __ bind(&l_catch); |
+ handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); |
+ __ movq(rcx, Operand(rsp, 1 * kPointerSize)); // iter |
+ __ push(rcx); // iter |
+ __ push(rax); // exception |
+ __ movq(rax, rcx); // iter |
+ __ LoadRoot(rcx, Heap::kthrow_stringRootIndex); // "throw" |
+ Handle<Code> throw_ic = isolate()->builtins()->LoadIC_Initialize(); |
+ CallIC(throw_ic); // iter.throw in rax |
+ __ jmp(&l_call); |
+ |
+ // try { received = yield result.value } |
+ __ bind(&l_try); |
+ __ pop(rax); // result.value |
+ __ PushTryHandler(StackHandler::CATCH, expr->index()); |
+ const int handler_size = StackHandlerConstants::kSize; |
+ __ push(rax); // result.value |
+ __ push(Operand(rsp, (0 + 1) * kPointerSize + handler_size)); // g |
+ __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
+ __ movq(context_register(), |
+ Operand(rbp, StandardFrameConstants::kContextOffset)); |
+ __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); |
+ __ j(not_equal, &l_resume); |
+ EmitReturnIteratorResult(false); |
+ __ bind(&l_resume); // received in rax |
+ __ PopTryHandler(); |
+ |
+ // receiver = iter; f = iter.send; arg = received; |
+ __ bind(&l_send); |
+ __ movq(rcx, Operand(rsp, 1 * kPointerSize)); // iter |
+ __ push(rcx); // iter |
+ __ push(rax); // received |
+ __ movq(rax, rcx); // iter |
+ __ LoadRoot(rcx, Heap::ksend_stringRootIndex); // "send" |
+ Handle<Code> send_ic = isolate()->builtins()->LoadIC_Initialize(); |
+ CallIC(send_ic); // iter.send in rax |
+ |
+ // result = f.call(receiver, arg); |
+ __ bind(&l_call); |
+ Label l_call_runtime; |
+ __ JumpIfSmi(rax, &l_call_runtime); |
+ __ CmpObjectType(rax, JS_FUNCTION_TYPE, rbx); |
+ __ j(not_equal, &l_call_runtime); |
+ __ movq(rdi, rax); |
+ ParameterCount count(1); |
+ __ InvokeFunction(rdi, count, CALL_FUNCTION, |
+ NullCallWrapper(), CALL_AS_METHOD); |
+ __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
+ __ jmp(&l_loop); |
+ __ bind(&l_call_runtime); |
+ __ push(rax); |
+ __ CallRuntime(Runtime::kCall, 3); |
+ |
+ // val = result.value; if (!result.done) goto l_try; |
+ __ bind(&l_loop); |
+ // result.value |
+ __ push(rax); // save result |
+ __ LoadRoot(rcx, Heap::kvalue_stringRootIndex); // "value" |
+ Handle<Code> value_ic = isolate()->builtins()->LoadIC_Initialize(); |
+ CallIC(value_ic); // result.value in rax |
+ __ pop(rbx); // result |
+ __ push(rax); // result.value |
+ __ movq(rax, rbx); // result |
+ __ LoadRoot(rcx, Heap::kdone_stringRootIndex); // "done" |
+ Handle<Code> done_ic = isolate()->builtins()->LoadIC_Initialize(); |
+ CallIC(done_ic); // result.done in rax |
+ ToBooleanStub stub(rax); |
+ __ push(rax); |
+ __ CallStub(&stub); |
+ __ testq(rax, rax); |
+ __ j(zero, &l_try); |
+ |
+ // result.value |
+ __ pop(rax); // result.value |
+ context()->DropAndPlug(2, rax); // drop iter and g |
+ break; |
+ } |
} |
} |