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

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: Fix asm nits; rework test suite to test yield* on everything 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
« no previous file with comments | « src/v8natives.js ('k') | test/mjsunit/harmony/generators-iteration.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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; goto l_call; }
1961 __ bind(&l_catch);
1962 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos()));
1963 __ movq(rcx, Operand(rsp, 1 * kPointerSize)); // iter
1964 __ push(rcx); // iter
1965 __ push(rax); // exception
1966 __ movq(rax, rcx); // iter
1967 __ LoadRoot(rcx, Heap::kthrow_stringRootIndex); // "throw"
1968 Handle<Code> throw_ic = isolate()->builtins()->LoadIC_Initialize();
1969 CallIC(throw_ic); // iter.throw in rax
1970 __ jmp(&l_call);
1971
1972 // try { received = yield result.value }
1973 __ bind(&l_try);
1974 __ pop(rax); // result.value
1975 __ PushTryHandler(StackHandler::CATCH, expr->index());
1976 const int handler_size = StackHandlerConstants::kSize;
1977 __ push(rax); // result.value
1978 __ push(Operand(rsp, (0 + 1) * kPointerSize + handler_size)); // g
1979 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1);
1980 __ movq(context_register(),
1981 Operand(rbp, StandardFrameConstants::kContextOffset));
1982 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex);
1983 __ j(not_equal, &l_resume);
1984 EmitReturnIteratorResult(false);
1985 __ bind(&l_resume); // received in rax
1986 __ PopTryHandler();
1987
1988 // receiver = iter; f = iter.send; arg = received;
1989 __ bind(&l_send);
1990 __ movq(rcx, Operand(rsp, 1 * kPointerSize)); // iter
1991 __ push(rcx); // iter
1992 __ push(rax); // received
1993 __ movq(rax, rcx); // iter
1994 __ LoadRoot(rcx, Heap::ksend_stringRootIndex); // "send"
1995 Handle<Code> send_ic = isolate()->builtins()->LoadIC_Initialize();
1996 CallIC(send_ic); // iter.send in rax
1997
1998 // result = f.call(receiver, arg);
1999 __ bind(&l_call);
2000 Label l_call_runtime;
2001 __ JumpIfSmi(rax, &l_call_runtime);
2002 __ CmpObjectType(rax, JS_FUNCTION_TYPE, rbx);
2003 __ j(not_equal, &l_call_runtime);
2004 __ movq(rdi, rax);
2005 ParameterCount count(1);
2006 __ InvokeFunction(rdi, count, CALL_FUNCTION,
2007 NullCallWrapper(), CALL_AS_METHOD);
2008 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
2009 __ jmp(&l_loop);
2010 __ bind(&l_call_runtime);
2011 __ push(rax);
2012 __ CallRuntime(Runtime::kCall, 3);
2013
2014 // val = result.value; if (!result.done) goto l_try;
2015 __ bind(&l_loop);
2016 // result.value
2017 __ push(rax); // save result
2018 __ LoadRoot(rcx, Heap::kvalue_stringRootIndex); // "value"
2019 Handle<Code> value_ic = isolate()->builtins()->LoadIC_Initialize();
2020 CallIC(value_ic); // result.value in rax
2021 __ pop(rbx); // result
2022 __ push(rax); // result.value
2023 __ movq(rax, rbx); // result
2024 __ LoadRoot(rcx, Heap::kdone_stringRootIndex); // "done"
2025 Handle<Code> done_ic = isolate()->builtins()->LoadIC_Initialize();
2026 CallIC(done_ic); // result.done in rax
2027 ToBooleanStub stub(rax);
2028 __ push(rax);
2029 __ CallStub(&stub);
2030 __ testq(rax, rax);
2031 __ j(zero, &l_try);
2032
2033 // result.value
2034 __ pop(rax); // result.value
2035 context()->DropAndPlug(2, rax); // drop iter and g
2036 break;
2037 }
1950 } 2038 }
1951 } 2039 }
1952 2040
1953 2041
1954 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, 2042 void FullCodeGenerator::EmitGeneratorResume(Expression *generator,
1955 Expression *value, 2043 Expression *value,
1956 JSGeneratorObject::ResumeMode resume_mode) { 2044 JSGeneratorObject::ResumeMode resume_mode) {
1957 // The value stays in rax, and is ultimately read by the resumed generator, as 2045 // The value stays in rax, and is ultimately read by the resumed generator, as
1958 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. rbx 2046 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. rbx
1959 // will hold the generator object until the activation has been resumed. 2047 // 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; 4818 *context_length = 0;
4731 return previous_; 4819 return previous_;
4732 } 4820 }
4733 4821
4734 4822
4735 #undef __ 4823 #undef __
4736 4824
4737 } } // namespace v8::internal 4825 } } // namespace v8::internal
4738 4826
4739 #endif // V8_TARGET_ARCH_X64 4827 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/v8natives.js ('k') | test/mjsunit/harmony/generators-iteration.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698