Commit eded148c authored by lrn@chromium.org's avatar lrn@chromium.org

Fast-codegen: Arguments object working on all platforms.

This time it's true.

Review URL: http://codereview.chromium.org/405033


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3369 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f2f00d0d
This diff is collapsed.
......@@ -1171,6 +1171,26 @@ void MacroAssembler::Abort(const char* msg) {
}
void MacroAssembler::LoadContext(Register dst, int context_chain_length) {
if (context_chain_length > 0) {
// Move up the chain of contexts to the context containing the slot.
ldr(dst, MemOperand(cp, Context::SlotOffset(Context::CLOSURE_INDEX)));
// Load the function context (which is the incoming, outer context).
ldr(dst, FieldMemOperand(dst, JSFunction::kContextOffset));
for (int i = 1; i < context_chain_length; i++) {
ldr(dst, MemOperand(dst, Context::SlotOffset(Context::CLOSURE_INDEX)));
ldr(dst, FieldMemOperand(dst, JSFunction::kContextOffset));
}
// The context may be an intermediate context, not a function context.
ldr(dst, MemOperand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX)));
} else { // Slot is in the current function context.
// The context may be an intermediate context, not a function context.
ldr(dst, MemOperand(cp, Context::SlotOffset(Context::FCONTEXT_INDEX)));
}
}
#ifdef ENABLE_DEBUGGER_SUPPORT
CodePatcher::CodePatcher(byte* address, int instructions)
: address_(address),
......
......@@ -104,6 +104,8 @@ class MacroAssembler: public Assembler {
// Align the stack by optionally pushing a Smi zero.
void AlignStack(int offset);
void LoadContext(Register dst, int context_chain_length);
// ---------------------------------------------------------------------------
// JavaScript invokes
......
......@@ -599,11 +599,6 @@ CodeGenSelector::CodeGenTag CodeGenSelector::Select(FunctionLiteral* fun) {
}
}
if (scope->arguments() != NULL) {
if (FLAG_trace_bailout) PrintF("function uses 'arguments'\n");
return NORMAL;
}
has_supported_syntax_ = true;
VisitDeclarations(scope->declarations());
if (!has_supported_syntax_) return NORMAL;
......@@ -802,7 +797,17 @@ void CodeGenSelector::VisitVariableProxy(VariableProxy* expr) {
BAILOUT("Lookup slot");
}
} else {
BAILOUT("access to arguments object");
#ifdef DEBUG
// Only remaining possibility is a property where the object is
// a slotted variable and the key is a smi.
Property* property = rewrite->AsProperty();
ASSERT_NOT_NULL(property);
Variable* object = property->obj()->AsVariableProxy()->AsVariable();
ASSERT_NOT_NULL(object);
ASSERT_NOT_NULL(object->slot());
ASSERT_NOT_NULL(property->key()->AsLiteral());
ASSERT(property->key()->AsLiteral()->handle()->IsSmi());
#endif
}
}
}
......@@ -886,12 +891,21 @@ void CodeGenSelector::VisitAssignment(Assignment* expr) {
// All global variables are supported.
if (!var->is_global()) {
if (var->slot() == NULL) {
// This is a parameter that has rewritten to an arguments access.
BAILOUT("non-global/non-slot assignment");
}
Slot::Type type = var->slot()->type();
if (type == Slot::LOOKUP) {
BAILOUT("Lookup slot");
Property* property = var->AsProperty();
if (property == NULL) {
BAILOUT("non-global/non-slot/non-property assignment");
}
if (property->obj()->AsSlot() == NULL) {
BAILOUT("variable rewritten to property non slot object assignment");
}
if (property->key()->AsLiteral() == NULL) {
BAILOUT("variable rewritten to property non literal key assignment");
}
} else {
Slot::Type type = var->slot()->type();
if (type == Slot::LOOKUP) {
BAILOUT("Lookup slot");
}
}
}
} else if (prop != NULL) {
......
......@@ -56,14 +56,21 @@ class FastCodeGenerator: public AstVisitor {
private:
int SlotOffset(Slot* slot);
void Move(Expression::Context destination, Register source);
void Move(Expression::Context destination, Slot* source);
void Move(Expression::Context destination, Slot* source, Register scratch);
void Move(Expression::Context destination, Literal* source);
void Move(Slot* dst, Register source, Register scratch1, Register scratch2);
void Move(Register dst, Slot* source);
// Templated to allow for Operand on intel and MemOperand on ARM.
template <typename MemoryLocation>
MemoryLocation CreateSlotOperand(Slot* slot, Register scratch);
// Drop the TOS, and store source to destination.
// If destination is TOS, just overwrite TOS with source.
void DropAndMove(Expression::Context destination, Register source);
void DropAndMove(Expression::Context destination,
Register source,
int drop_count = 1);
// Test the JavaScript value in source as if in a test context, compile
// control flow to a pair of labels.
......
This diff is collapsed.
......@@ -1192,6 +1192,26 @@ Handle<Code> MacroAssembler::ResolveBuiltin(Builtins::JavaScript id,
}
void MacroAssembler::LoadContext(Register dst, int context_chain_length) {
if (context_chain_length > 0) {
// Move up the chain of contexts to the context containing the slot.
mov(dst, Operand(esi, Context::SlotOffset(Context::CLOSURE_INDEX)));
// Load the function context (which is the incoming, outer context).
mov(dst, FieldOperand(dst, JSFunction::kContextOffset));
for (int i = 1; i < context_chain_length; i++) {
mov(dst, Operand(dst, Context::SlotOffset(Context::CLOSURE_INDEX)));
mov(dst, FieldOperand(dst, JSFunction::kContextOffset));
}
// The context may be an intermediate context, not a function context.
mov(dst, Operand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX)));
} else { // Slot is in the current function context.
// The context may be an intermediate context, not a function context.
mov(dst, Operand(esi, Context::SlotOffset(Context::FCONTEXT_INDEX)));
}
}
void MacroAssembler::Ret() {
ret(0);
}
......
......@@ -96,6 +96,8 @@ class MacroAssembler: public Assembler {
// argument in register esi.
void LeaveExitFrame(ExitFrame::Mode mode);
// Find the function context up the context chain.
void LoadContext(Register dst, int context_chain_length);
// ---------------------------------------------------------------------------
// JavaScript invokes
......
This diff is collapsed.
......@@ -2235,6 +2235,25 @@ void MacroAssembler::AllocateHeapNumber(Register result,
}
void MacroAssembler::LoadContext(Register dst, int context_chain_length) {
if (context_chain_length > 0) {
// Move up the chain of contexts to the context containing the slot.
movq(dst, Operand(rsi, Context::SlotOffset(Context::CLOSURE_INDEX)));
// Load the function context (which is the incoming, outer context).
movq(rax, FieldOperand(rax, JSFunction::kContextOffset));
for (int i = 1; i < context_chain_length; i++) {
movq(dst, Operand(dst, Context::SlotOffset(Context::CLOSURE_INDEX)));
movq(dst, FieldOperand(dst, JSFunction::kContextOffset));
}
// The context may be an intermediate context, not a function context.
movq(dst, Operand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX)));
} else { // context is the current function context.
// The context may be an intermediate context, not a function context.
movq(dst, Operand(rsi, Context::SlotOffset(Context::FCONTEXT_INDEX)));
}
}
CodePatcher::CodePatcher(byte* address, int size)
: address_(address), size_(size), masm_(address, size + Assembler::kGap) {
// Create a new macro assembler pointing to the address of the code to patch.
......
......@@ -548,6 +548,9 @@ class MacroAssembler: public Assembler {
// occurred.
void IllegalOperation(int num_arguments);
// Find the function context up the context chain.
void LoadContext(Register dst, int context_chain_length);
// ---------------------------------------------------------------------------
// Runtime calls
......
// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Testing basic functionality of the arguments object.
// Introduced to ensure that the fast compiler does the right thing.
// The arguments object itself.
assertEquals(42, function(){ return arguments;}(42)[0],
"return arguments value");
assertEquals(42, function(){ return arguments;}(42)[0],
"arguments in plain value context");
assertEquals(42, function(){ arguments;return 42}(37),
"arguments in effect context");
assertEquals(42, function(){ if(arguments)return 42;}(),
"arguments in a boolean context");
assertEquals(42, function(){ return arguments || true;}(42)[0],
"arguments in a short-circuit boolean context - or");
assertEquals(true, function(){ return arguments && [true];}(42)[0],
"arguments in a short-circuit boolean context - and");
assertEquals(42, function(){ arguments = 42; return 42;}(),
"arguments assignment");
// Properties of the arguments object.
assertEquals(42, function(){ return arguments[0]; }(42),
"args[0] value returned");
assertEquals(42, function(){ arguments[0]; return 42}(),
"args[0] value ignored");
assertEquals(42, function(){ if (arguments[0]) return 42; }(37),
"args[0] to boolean");
assertEquals(42, function(){ return arguments[0] || "no"; }(42),
"args[0] short-circuit boolean or true");
assertEquals(42, function(){ return arguments[0] || 42; }(0),
"args[0] short-circuit boolean or false");
assertEquals(37, function(){ return arguments[0] && 37; }(42),
"args[0] short-circuit boolean and true");
assertEquals(0, function(){ return arguments[0] && 42; }(0),
"args[0] short-circuit boolean and false");
assertEquals(42, function(){ arguments[0] = 42; return arguments[0]; }(37),
"args[0] assignment");
// Link between arguments and parameters.
assertEquals(42, function(a) { arguments[0] = 42; return a; }(37),
"assign args[0]->a");
assertEquals(42, function(a) { a = 42; return arguments[0]; }(37),
"assign a->args[0]");
assertEquals(54, function(a, b) { arguments[1] = 54; return b; }(42, 37),
"assign args[1]->b:b");
assertEquals(54, function(a, b) { b = 54; return arguments[1]; }(42, 47),
"assign b->args[1]:b");
assertEquals(42, function(a, b) { arguments[1] = 54; return a; }(42, 37),
"assign args[1]->b:a");
assertEquals(42, function(a, b) { b = 54; return arguments[0]; }(42, 47),
"assign b->args[1]:a");
// Capture parameters in nested contexts.
assertEquals(33,
function(a,b) {
return a + arguments[0] +
function(b){ return a + b + arguments[0]; }(b); }(7,6),
"captured parameters");
assertEquals(42, function(a) {
arguments[0] = 42;
return function(b){ return a; }();
}(37),
"capture value returned");
assertEquals(42,
function(a) {
arguments[0] = 26;
return function(b){ a; return 42; }();
}(37),
"capture value ignored");
assertEquals(42,
function(a) {
arguments[0] = 26;
return function(b){ if (a) return 42; }();
}(37),
"capture to boolean");
assertEquals(42,
function(a) {
arguments[0] = 42;
return function(b){ return a || "no"; }();
}(37),
"capture short-circuit boolean or true");
assertEquals(0,
function(a) {
arguments[0] = 0;
return function(b){ return a && 42; }();
}(37),
"capture short-circuit boolean and false");
// Deeply nested.
assertEquals(42,
function(a,b) {
return arguments[2] +
function(){
return b +
function() {
return a;
}();
}();
}(7,14,21),
"deep nested capture");
// Assignment to captured parameters.
assertEquals(42, function(a,b) {
arguments[1] = 11;
return a + function(){ a = b; return a; }() + a;
}(20, 37), "captured assignment");
// Inside non-function scopes.
assertEquals(42,
function(a) {
arguments[0] = 20;
with ({ b : 22 }) { return a + b; }
}(37),
"a in with");
assertEquals(42,
function(a) {
with ({ b : 22 }) { return arguments[0] + b; }
}(20),
"args in with");
assertEquals(42,
function(a) {
arguments[0] = 20;
with ({ b : 22 }) {
return function() { return a; }() + b; }
}(37),
"captured a in with");
assertEquals(42,
function(a) {
arguments[0] = 12;
with ({ b : 22 }) {
return function f() {
try { throw 8 } catch(e) { return e + a };
}() + b;
}
}(37),
"in a catch in a named function captured a in with ");
// Escaping arguments.
function weirdargs(a,b,c) { if (!a) return arguments;
return [b[2],c]; }
var args1 = weirdargs(false, null, 40);
var res = weirdargs(true, args1, 15);
assertEquals(40, res[0], "return old args element");
assertEquals(15, res[1], "return own args element");
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment