OLD | NEW |
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 1958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1969 // this. It stays on the stack while we update the iterator. | 1969 // this. It stays on the stack while we update the iterator. |
1970 VisitForStackValue(expr->expression()); | 1970 VisitForStackValue(expr->expression()); |
1971 | 1971 |
1972 switch (expr->yield_kind()) { | 1972 switch (expr->yield_kind()) { |
1973 case Yield::SUSPEND: | 1973 case Yield::SUSPEND: |
1974 // Pop value from top-of-stack slot; box result into result register. | 1974 // Pop value from top-of-stack slot; box result into result register. |
1975 EmitCreateIteratorResult(false); | 1975 EmitCreateIteratorResult(false); |
1976 __ push(result_register()); | 1976 __ push(result_register()); |
1977 // Fall through. | 1977 // Fall through. |
1978 case Yield::INITIAL: { | 1978 case Yield::INITIAL: { |
1979 VisitForStackValue(expr->generator_object()); | 1979 Label suspend, continuation, post_runtime, resume; |
| 1980 |
| 1981 __ jmp(&suspend); |
| 1982 |
| 1983 __ bind(&continuation); |
| 1984 __ jmp(&resume); |
| 1985 |
| 1986 __ bind(&suspend); |
| 1987 VisitForAccumulatorValue(expr->generator_object()); |
| 1988 ASSERT(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); |
| 1989 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), |
| 1990 Smi::FromInt(continuation.pos())); |
| 1991 __ movq(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); |
| 1992 __ movq(rcx, rsi); |
| 1993 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx, |
| 1994 kDontSaveFPRegs); |
| 1995 __ lea(rbx, Operand(rbp, StandardFrameConstants::kExpressionsOffset)); |
| 1996 __ cmpq(rsp, rbx); |
| 1997 __ j(equal, &post_runtime); |
| 1998 __ push(rax); // generator object |
1980 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); | 1999 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
1981 __ movq(context_register(), | 2000 __ movq(context_register(), |
1982 Operand(rbp, StandardFrameConstants::kContextOffset)); | 2001 Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 2002 __ bind(&post_runtime); |
1983 | 2003 |
1984 Label resume; | |
1985 __ CompareRoot(result_register(), Heap::kTheHoleValueRootIndex); | |
1986 __ j(not_equal, &resume); | |
1987 __ pop(result_register()); | 2004 __ pop(result_register()); |
1988 EmitReturnSequence(); | 2005 EmitReturnSequence(); |
1989 | 2006 |
1990 __ bind(&resume); | 2007 __ bind(&resume); |
1991 context()->Plug(result_register()); | 2008 context()->Plug(result_register()); |
1992 break; | 2009 break; |
1993 } | 2010 } |
1994 | 2011 |
1995 case Yield::FINAL: { | 2012 case Yield::FINAL: { |
1996 VisitForAccumulatorValue(expr->generator_object()); | 2013 VisitForAccumulatorValue(expr->generator_object()); |
1997 __ Move(FieldOperand(result_register(), | 2014 __ Move(FieldOperand(result_register(), |
1998 JSGeneratorObject::kContinuationOffset), | 2015 JSGeneratorObject::kContinuationOffset), |
1999 Smi::FromInt(JSGeneratorObject::kGeneratorClosed)); | 2016 Smi::FromInt(JSGeneratorObject::kGeneratorClosed)); |
2000 // Pop value from top-of-stack slot, box result into result register. | 2017 // Pop value from top-of-stack slot, box result into result register. |
2001 EmitCreateIteratorResult(true); | 2018 EmitCreateIteratorResult(true); |
2002 EmitUnwindBeforeReturn(); | 2019 EmitUnwindBeforeReturn(); |
2003 EmitReturnSequence(); | 2020 EmitReturnSequence(); |
2004 break; | 2021 break; |
2005 } | 2022 } |
2006 | 2023 |
2007 case Yield::DELEGATING: { | 2024 case Yield::DELEGATING: { |
2008 VisitForStackValue(expr->generator_object()); | 2025 VisitForStackValue(expr->generator_object()); |
2009 | 2026 |
2010 // Initial stack layout is as follows: | 2027 // Initial stack layout is as follows: |
2011 // [sp + 1 * kPointerSize] iter | 2028 // [sp + 1 * kPointerSize] iter |
2012 // [sp + 0 * kPointerSize] g | 2029 // [sp + 0 * kPointerSize] g |
2013 | 2030 |
2014 Label l_catch, l_try, l_resume, l_next, l_call, l_loop; | 2031 Label l_catch, l_try, l_suspend, l_continuation, l_resume; |
| 2032 Label l_next, l_call, l_loop; |
2015 // Initial send value is undefined. | 2033 // Initial send value is undefined. |
2016 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); | 2034 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
2017 __ jmp(&l_next); | 2035 __ jmp(&l_next); |
2018 | 2036 |
2019 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } | 2037 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } |
2020 __ bind(&l_catch); | 2038 __ bind(&l_catch); |
2021 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); | 2039 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); |
2022 __ LoadRoot(rcx, Heap::kthrow_stringRootIndex); // "throw" | 2040 __ LoadRoot(rcx, Heap::kthrow_stringRootIndex); // "throw" |
2023 __ push(rcx); | 2041 __ push(rcx); |
2024 __ push(Operand(rsp, 2 * kPointerSize)); // iter | 2042 __ push(Operand(rsp, 2 * kPointerSize)); // iter |
2025 __ push(rax); // exception | 2043 __ push(rax); // exception |
2026 __ jmp(&l_call); | 2044 __ jmp(&l_call); |
2027 | 2045 |
2028 // try { received = %yield result } | 2046 // try { received = %yield result } |
2029 // Shuffle the received result above a try handler and yield it without | 2047 // Shuffle the received result above a try handler and yield it without |
2030 // re-boxing. | 2048 // re-boxing. |
2031 __ bind(&l_try); | 2049 __ bind(&l_try); |
2032 __ pop(rax); // result | 2050 __ pop(rax); // result |
2033 __ PushTryHandler(StackHandler::CATCH, expr->index()); | 2051 __ PushTryHandler(StackHandler::CATCH, expr->index()); |
2034 const int handler_size = StackHandlerConstants::kSize; | 2052 const int handler_size = StackHandlerConstants::kSize; |
2035 __ push(rax); // result | 2053 __ push(rax); // result |
2036 __ push(Operand(rsp, (0 + 1) * kPointerSize + handler_size)); // g | 2054 __ jmp(&l_suspend); |
| 2055 __ bind(&l_continuation); |
| 2056 __ jmp(&l_resume); |
| 2057 __ bind(&l_suspend); |
| 2058 const int generator_object_depth = kPointerSize + handler_size; |
| 2059 __ movq(rax, Operand(rsp, generator_object_depth)); |
| 2060 __ push(rax); // g |
| 2061 ASSERT(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); |
| 2062 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), |
| 2063 Smi::FromInt(l_continuation.pos())); |
| 2064 __ movq(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); |
| 2065 __ movq(rcx, rsi); |
| 2066 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx, |
| 2067 kDontSaveFPRegs); |
2037 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); | 2068 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
2038 __ movq(context_register(), | 2069 __ movq(context_register(), |
2039 Operand(rbp, StandardFrameConstants::kContextOffset)); | 2070 Operand(rbp, StandardFrameConstants::kContextOffset)); |
2040 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); | |
2041 __ j(not_equal, &l_resume); | |
2042 __ pop(rax); // result | 2071 __ pop(rax); // result |
2043 EmitReturnSequence(); | 2072 EmitReturnSequence(); |
2044 __ bind(&l_resume); // received in rax | 2073 __ bind(&l_resume); // received in rax |
2045 __ PopTryHandler(); | 2074 __ PopTryHandler(); |
2046 | 2075 |
2047 // receiver = iter; f = 'next'; arg = received; | 2076 // receiver = iter; f = 'next'; arg = received; |
2048 __ bind(&l_next); | 2077 __ bind(&l_next); |
2049 __ LoadRoot(rcx, Heap::knext_stringRootIndex); // "next" | 2078 __ LoadRoot(rcx, Heap::knext_stringRootIndex); // "next" |
2050 __ push(rcx); | 2079 __ push(rcx); |
2051 __ push(Operand(rsp, 2 * kPointerSize)); // iter | 2080 __ push(Operand(rsp, 2 * kPointerSize)); // iter |
(...skipping 2828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4880 *context_length = 0; | 4909 *context_length = 0; |
4881 return previous_; | 4910 return previous_; |
4882 } | 4911 } |
4883 | 4912 |
4884 | 4913 |
4885 #undef __ | 4914 #undef __ |
4886 | 4915 |
4887 } } // namespace v8::internal | 4916 } } // namespace v8::internal |
4888 | 4917 |
4889 #endif // V8_TARGET_ARCH_X64 | 4918 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |