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 1919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1930 EmitReturnSequence(); | 1930 EmitReturnSequence(); |
1931 break; | 1931 break; |
1932 } | 1932 } |
1933 | 1933 |
1934 case Yield::DELEGATING: | 1934 case Yield::DELEGATING: |
1935 UNIMPLEMENTED(); | 1935 UNIMPLEMENTED(); |
1936 } | 1936 } |
1937 } | 1937 } |
1938 | 1938 |
1939 | 1939 |
| 1940 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, |
| 1941 Expression *value, |
| 1942 JSGeneratorObject::ResumeMode resume_mode) { |
| 1943 // The value stays in eax, and is ultimately read by the resumed generator, as |
| 1944 // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. ebx |
| 1945 // will hold the generator object until the activation has been resumed. |
| 1946 VisitForStackValue(generator); |
| 1947 VisitForAccumulatorValue(value); |
| 1948 __ pop(ebx); |
| 1949 |
| 1950 // Check generator state. |
| 1951 Label wrong_state, done; |
| 1952 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting <= 0); |
| 1953 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed <= 0); |
| 1954 __ cmp(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), |
| 1955 Immediate(Smi::FromInt(0))); |
| 1956 __ j(less_equal, &wrong_state); |
| 1957 |
| 1958 // Load suspended function and context. |
| 1959 __ mov(esi, FieldOperand(ebx, JSGeneratorObject::kContextOffset)); |
| 1960 __ mov(edi, FieldOperand(ebx, JSGeneratorObject::kFunctionOffset)); |
| 1961 |
| 1962 // Push holes for arguments to generator function. |
| 1963 __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 1964 __ mov(edx, |
| 1965 FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 1966 __ mov(ecx, isolate()->factory()->the_hole_value()); |
| 1967 Label push_argument_holes; |
| 1968 __ bind(&push_argument_holes); |
| 1969 __ push(ecx); |
| 1970 __ sub(edx, Immediate(1)); |
| 1971 __ j(not_carry, &push_argument_holes); |
| 1972 |
| 1973 // Enter a new JavaScript frame, and initialize its slots as they were when |
| 1974 // the generator was suspended. |
| 1975 Label push_frame, resume_frame; |
| 1976 __ bind(&push_frame); |
| 1977 __ call(&resume_frame); |
| 1978 __ jmp(&done); |
| 1979 __ bind(&resume_frame); |
| 1980 __ push(ebp); // Caller's frame pointer. |
| 1981 __ mov(ebp, esp); |
| 1982 __ push(esi); // Callee's context. |
| 1983 __ push(edi); // Callee's JS Function. |
| 1984 |
| 1985 // Load the operand stack size. |
| 1986 __ mov(edx, FieldOperand(ebx, JSGeneratorObject::kOperandStackOffset)); |
| 1987 __ mov(edx, FieldOperand(edx, FixedArray::kLengthOffset)); |
| 1988 __ SmiUntag(edx); |
| 1989 |
| 1990 // If we are sending a value and there is no operand stack, we can jump back |
| 1991 // in directly. |
| 1992 if (resume_mode == JSGeneratorObject::SEND) { |
| 1993 Label slow_resume; |
| 1994 __ cmp(edx, Immediate(0)); |
| 1995 __ j(not_zero, &slow_resume); |
| 1996 __ mov(edx, FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
| 1997 __ mov(ecx, FieldOperand(ebx, JSGeneratorObject::kContinuationOffset)); |
| 1998 __ SmiUntag(ecx); |
| 1999 __ add(edx, ecx); |
| 2000 __ mov(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), |
| 2001 Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting))); |
| 2002 __ jmp(edx); |
| 2003 __ bind(&slow_resume); |
| 2004 } |
| 2005 |
| 2006 // Otherwise, we push holes for the operand stack and call the runtime to fix |
| 2007 // up the stack and the handlers. |
| 2008 Label push_operand_holes, call_resume; |
| 2009 __ bind(&push_operand_holes); |
| 2010 __ sub(edx, Immediate(1)); |
| 2011 __ j(carry, &call_resume); |
| 2012 __ push(ecx); |
| 2013 __ jmp(&push_operand_holes); |
| 2014 __ bind(&call_resume); |
| 2015 __ push(ebx); |
| 2016 __ push(result_register()); |
| 2017 __ Push(Smi::FromInt(resume_mode)); |
| 2018 __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); |
| 2019 // Not reached: the runtime call returns elsewhere. |
| 2020 __ Abort("Generator failed to resume."); |
| 2021 |
| 2022 // Throw error if we attempt to operate on a running generator. |
| 2023 __ bind(&wrong_state); |
| 2024 __ push(ebx); |
| 2025 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); |
| 2026 |
| 2027 __ bind(&done); |
| 2028 context()->Plug(result_register()); |
| 2029 } |
| 2030 |
| 2031 |
1940 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { | 2032 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
1941 SetSourcePosition(prop->position()); | 2033 SetSourcePosition(prop->position()); |
1942 Literal* key = prop->key()->AsLiteral(); | 2034 Literal* key = prop->key()->AsLiteral(); |
1943 ASSERT(!key->handle()->IsSmi()); | 2035 ASSERT(!key->handle()->IsSmi()); |
1944 __ mov(ecx, Immediate(key->handle())); | 2036 __ mov(ecx, Immediate(key->handle())); |
1945 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); | 2037 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
1946 CallIC(ic, RelocInfo::CODE_TARGET, prop->PropertyFeedbackId()); | 2038 CallIC(ic, RelocInfo::CODE_TARGET, prop->PropertyFeedbackId()); |
1947 } | 2039 } |
1948 | 2040 |
1949 | 2041 |
(...skipping 2650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4600 *stack_depth = 0; | 4692 *stack_depth = 0; |
4601 *context_length = 0; | 4693 *context_length = 0; |
4602 return previous_; | 4694 return previous_; |
4603 } | 4695 } |
4604 | 4696 |
4605 #undef __ | 4697 #undef __ |
4606 | 4698 |
4607 } } // namespace v8::internal | 4699 } } // namespace v8::internal |
4608 | 4700 |
4609 #endif // V8_TARGET_ARCH_IA32 | 4701 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |