Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/x64/full-codegen-x64.cc

Issue 14582007: Implement yield* (delegating yield) (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1927 matching lines...) Expand 10 before | Expand all | Expand 10 after
1938 1938
1939 case Yield::FINAL: { 1939 case Yield::FINAL: {
1940 VisitForAccumulatorValue(expr->generator_object()); 1940 VisitForAccumulatorValue(expr->generator_object());
1941 __ Move(FieldOperand(result_register(), 1941 __ Move(FieldOperand(result_register(),
1942 JSGeneratorObject::kContinuationOffset), 1942 JSGeneratorObject::kContinuationOffset),
1943 Smi::FromInt(0)); 1943 Smi::FromInt(0));
1944 EmitReturnIteratorResult(true); 1944 EmitReturnIteratorResult(true);
1945 break; 1945 break;
1946 } 1946 }
1947 1947
1948 case Yield::DELEGATING: 1948 case Yield::DELEGATING: {
1949 UNIMPLEMENTED(); 1949 VisitForStackValue(expr->generator_object());
1950
1951 // Initial stack layout is as follows:
1952 // [sp + 1 * kPointerSize] iter
1953 // [sp + 0 * kPointerSize] g
1954
1955 Label l_catch, l_try, l_resume, l_send, l_call, l_loop;
1956 // Initial send value is undefined.
1957 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex);
1958 __ jmp(&l_send);
1959
1960 // catch (e) { receiver = iter; f = iter.throw; arg = e; }
1961 __ bind(&l_catch);
1962 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos()));
1963 __ push(Operand(rsp, 1 * kPointerSize)); // iter
1964 __ push(rax); // exception
1965 __ movq(rax, Operand(rsp, 3 * kPointerSize)); // iter
1966 __ LoadRoot(rcx, Heap::kthrow_stringRootIndex); // "throw"
1967 Handle<Code> throw_ic = isolate()->builtins()->LoadIC_Initialize();
1968 CallIC(throw_ic); // iter.throw in rax
1969 __ jmp(&l_call);
1970
1971 // try { received = yield result.value }
1972 __ bind(&l_try);
1973 __ pop(rax); // result.value
1974 __ PushTryHandler(StackHandler::CATCH, expr->index());
1975 const int handler_size = StackHandlerConstants::kSize;
1976 __ push(rax); // result.value
1977 __ push(Operand(rsp, (0 + 1) * kPointerSize + handler_size)); // g
1978 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
1979 __ movq(context_register(),
1980 Operand(rbp, StandardFrameConstants::kContextOffset));
1981 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex);
1982 __ j(not_equal, &l_resume);
1983 EmitReturnIteratorResult(false);
1984 __ bind(&l_resume); // received in rax
1985 __ PopTryHandler();
1986
1987 // receiver = iter; f = iter.send; arg = received;
1988 __ bind(&l_send);
1989 __ push(Operand(rsp, 1 * kPointerSize)); // iter
1990 __ push(rax); // received
1991 __ movq(rax, Operand(rsp, 3 * kPointerSize)); // iter
1992 __ LoadRoot(rcx, Heap::ksend_stringRootIndex); // "send"
1993 Handle<Code> send_ic = isolate()->builtins()->LoadIC_Initialize();
1994 CallIC(send_ic); // iter.send in rax
1995
1996 // result = f.call(receiver, arg);
1997 __ bind(&l_call);
1998 Label l_call_runtime;
1999 __ JumpIfSmi(rax, &l_call_runtime);
2000 __ CmpObjectType(rax, JS_FUNCTION_TYPE, rbx);
2001 __ j(not_equal, &l_call_runtime);
2002 __ movq(rdi, rax);
2003 ParameterCount count(1);
2004 __ InvokeFunction(rdi, count, CALL_FUNCTION,
2005 NullCallWrapper(), CALL_AS_METHOD);
2006 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
2007 __ jmp(&l_loop);
2008 __ bind(&l_call_runtime);
2009 __ push(rax);
2010 __ CallRuntime(Runtime::kCall, 3);
2011
2012 // val = result.value; if (!result.done) goto l_try;
2013 __ bind(&l_loop);
2014 // result.value
2015 __ push(rax); // save result
2016 __ LoadRoot(rcx, Heap::kvalue_stringRootIndex); // "value"
2017 Handle<Code> value_ic = isolate()->builtins()->LoadIC_Initialize();
2018 CallIC(value_ic); // result.value in rax
2019 __ pop(rbx); // result
2020 __ push(rax); // result.value
2021 __ movq(rax, rbx); // result
2022 __ LoadRoot(rcx, Heap::kdone_stringRootIndex); // "done"
2023 Handle<Code> done_ic = isolate()->builtins()->LoadIC_Initialize();
2024 CallIC(done_ic); // result.done in rax
2025 ToBooleanStub stub(rax);
2026 __ push(rax);
2027 __ CallStub(&stub);
2028 __ testq(rax, rax);
2029 __ j(zero, &l_try);
2030
2031 // result.value
2032 __ pop(rax); // result.value
2033 context()->DropAndPlug(2, rax); // drop iter and g
2034 break;
2035 }
1950 } 2036 }
1951 } 2037 }
1952 2038
1953 2039
1954 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, 2040 void FullCodeGenerator::EmitGeneratorResume(Expression *generator,
1955 Expression *value, 2041 Expression *value,
1956 JSGeneratorObject::ResumeMode resume_mode) { 2042 JSGeneratorObject::ResumeMode resume_mode) {
1957 // The value stays in rax, and is ultimately read by the resumed generator, as 2043 // The value stays in rax, and is ultimately read by the resumed generator, as
1958 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. rbx 2044 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. rbx
1959 // will hold the generator object until the activation has been resumed. 2045 // will hold the generator object until the activation has been resumed.
(...skipping 2770 matching lines...) Expand 10 before | Expand all | Expand 10 after
4730 *context_length = 0; 4816 *context_length = 0;
4731 return previous_; 4817 return previous_;
4732 } 4818 }
4733 4819
4734 4820
4735 #undef __ 4821 #undef __
4736 4822
4737 } } // namespace v8::internal 4823 } } // namespace v8::internal
4738 4824
4739 #endif // V8_TARGET_ARCH_X64 4825 #endif // V8_TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698