Added support for assignments to global variables in the toplevel code
generator. We use the normal store IC mechanism with the global
object as the receiver. The following code is generated for 'x=true'
at toplevel.
======== IA32:
27 mov eax,0xf5d06161 ;; object: 0xf5d06161 <true>
32 mov ecx,0xf5d09c35 ;; object: 0xf5d09c35 <String[1]: x>
37 push [esi+0x17]
40 call StoreIC_Initialize (0xf5ce75c0) ;; code: STORE_IC, UNINITIALIZED
45 mov [esp],eax
======== X64:
25 movq rax,0x7f867a7b6199 ;; object: 0x7f867a7b6199 <true>
35 movq rcx,0x7f867a7bae71 ;; object: 0x7f867a7bae71 <String[1]: x>
45 push [rsi+0x2f]
49 call StoreIC_Initialize (0x7f8655929ac0) ;; code: STORE_IC, UNINITIALIZED
54 movq [rsp],rax
======== ARM:
32 e59f0054 ldr r0, [pc, #+84] ;; object: 0xf5b78161 <true>
36 e59f2054 ldr r2, [pc, #+84] ;; object: 0xf5b7bc35 <String[1]: x>
40 e598c017 ldr ip, [r8, #+23]
44 e52dc004 str ip, [sp, #-4]!
48 e1a0e00f mov lr, pc
52 e59ff048 ldr pc, [pc, #+72] ;; debug: statement 0
;; code: STORE_IC, UNINITIALIZED
56 e58d0000 str r0, [sp, #+0]
Review URL: http://codereview.chromium.org/305005
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3095 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-20 13:37:26 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
// Test references and assignments to global variables.
|
|
|
|
var g = 0;
|
|
|
|
|
|
|
|
// Test compilation of a global variable store.
|
|
|
|
assertEquals(1, eval('g = 1'));
|
|
|
|
// Test that the store worked.
|
|
|
|
assertEquals(1, g);
|
|
|
|
|
|
|
|
// Test that patching the IC in the compiled code works.
|
|
|
|
assertEquals(1, eval('g = 1'));
|
|
|
|
assertEquals(1, g);
|
|
|
|
assertEquals(1, eval('g = 1'));
|
|
|
|
assertEquals(1, g);
|
|
|
|
|
|
|
|
// Test a second store.
|
|
|
|
assertEquals("2", eval('g = "2"'));
|
|
|
|
assertEquals("2", g);
|
2009-10-21 09:38:21 +00:00
|
|
|
|
|
|
|
// Test a load.
|
|
|
|
assertEquals("2", eval('g'));
|
|
|
|
|
|
|
|
// Test that patching the IC in the compiled code works.
|
|
|
|
assertEquals("2", eval('g'));
|
|
|
|
assertEquals("2", eval('g'));
|
|
|
|
|
|
|
|
// Test a second load.
|
|
|
|
g = 3;
|
|
|
|
assertEquals(3, eval('g'));
|
2009-11-02 10:22:22 +00:00
|
|
|
|
|
|
|
// Test postfix count operation
|
|
|
|
var t;
|
|
|
|
t = g++;
|
|
|
|
assertEquals(3, t);
|
|
|
|
assertEquals(4, g);
|
|
|
|
|
|
|
|
code = "g--; 1";
|
|
|
|
assertEquals(1, eval(code));
|
|
|
|
assertEquals(3, g);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Test simple assignment to non-deletable and deletable globals.
|
|
|
|
var glo1 = 0;
|
|
|
|
function f1(x) { glo1 = x; }
|
|
|
|
f1(42);
|
|
|
|
assertEquals(glo1, 42);
|
|
|
|
|
|
|
|
glo2 = 0;
|
|
|
|
function f2(x) { glo2 = x; }
|
|
|
|
f2(42);
|
|
|
|
assertEquals(42, glo2);
|