Commit 477495c8 authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[Parser] Track ContainsDot for SMI values.

Ensures SMI values have SMI type even if they have a dot (e.g., 1.0).
Adds SMI_WITH_DOT type to maintain this.

BUG=chromium:638134

Review-Url: https://codereview.chromium.org/2248693005
Cr-Commit-Position: refs/heads/master@{#38698}
parent 3cbb5e48
......@@ -156,6 +156,7 @@ bool AstValue::BooleanValue() const {
case NUMBER_WITH_DOT:
case NUMBER:
return DoubleToBoolean(number_);
case SMI_WITH_DOT:
case SMI:
return smi_ != 0;
case BOOLEAN:
......@@ -195,6 +196,7 @@ void AstValue::Internalize(Isolate* isolate) {
case NUMBER:
value_ = isolate->factory()->NewNumber(number_, TENURED);
break;
case SMI_WITH_DOT:
case SMI:
value_ = handle(Smi::FromInt(smi_), isolate);
break;
......
......@@ -154,10 +154,13 @@ class AstValue : public ZoneObject {
}
bool IsNumber() const {
return type_ == NUMBER || type_ == NUMBER_WITH_DOT || type_ == SMI;
return type_ == NUMBER || type_ == NUMBER_WITH_DOT || type_ == SMI ||
type_ == SMI_WITH_DOT;
}
bool ContainsDot() const { return type_ == NUMBER_WITH_DOT; }
bool ContainsDot() const {
return type_ == NUMBER_WITH_DOT || type_ == SMI_WITH_DOT;
}
const AstRawString* AsString() const {
CHECK_EQ(STRING, type_);
......@@ -167,14 +170,14 @@ class AstValue : public ZoneObject {
double AsNumber() const {
if (type_ == NUMBER || type_ == NUMBER_WITH_DOT)
return number_;
if (type_ == SMI)
if (type_ == SMI || type_ == SMI_WITH_DOT)
return smi_;
UNREACHABLE();
return 0;
}
Smi* AsSmi() const {
CHECK_EQ(SMI, type_);
CHECK(type_ == SMI || type_ == SMI_WITH_DOT);
return Smi::FromInt(smi_);
}
......@@ -186,7 +189,7 @@ class AstValue : public ZoneObject {
bool BooleanValue() const;
bool IsSmi() const { return type_ == SMI; }
bool IsSmi() const { return type_ == SMI || type_ == SMI_WITH_DOT; }
bool IsFalse() const { return type_ == BOOLEAN && !bool_; }
bool IsTrue() const { return type_ == BOOLEAN && bool_; }
bool IsUndefined() const { return type_ == UNDEFINED; }
......@@ -215,6 +218,7 @@ class AstValue : public ZoneObject {
NUMBER,
NUMBER_WITH_DOT,
SMI,
SMI_WITH_DOT,
BOOLEAN,
NULL_TYPE,
UNDEFINED,
......@@ -230,18 +234,13 @@ class AstValue : public ZoneObject {
}
explicit AstValue(double n, bool with_dot) : next_(nullptr) {
if (with_dot) {
type_ = NUMBER_WITH_DOT;
number_ = n;
int int_value;
if (DoubleToSmiInteger(n, &int_value)) {
type_ = with_dot ? SMI_WITH_DOT : SMI;
smi_ = int_value;
} else {
int int_value;
if (DoubleToSmiInteger(n, &int_value)) {
type_ = SMI;
smi_ = int_value;
} else {
type_ = NUMBER;
number_ = n;
}
type_ = with_dot ? NUMBER_WITH_DOT : NUMBER;
number_ = n;
}
}
......
......@@ -185,11 +185,10 @@ parameter count: 1
bytecode array length: 4
bytecodes: [
/* 30 E> */ B(StackCheck),
/* 34 S> */ B(LdaConstant), U8(0),
/* 34 S> */ B(LdaSmi), U8(2),
/* 46 S> */ B(Return),
]
constant pool: [
2,
]
handlers: [
]
......
......@@ -150,12 +150,11 @@ bytecodes: [
/* 30 E> */ B(StackCheck),
/* 42 S> */ B(LdaSmi), U8(13),
B(Star), R(0),
/* 46 S> */ B(LdaConstant), U8(0),
/* 46 S> */ B(LdaSmi), U8(1),
B(Mul), R(0), U8(1),
/* 57 S> */ B(Return),
]
constant pool: [
1,
]
handlers: [
]
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function foo() {
// Generates a forward branch that puts 200 in the constant pool.
var i = 0;
if (i) {
i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0;
i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0;
i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0;
i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0;
i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0;
i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0; i = 0;
i = 0; i = 0; i = 0; i = 0; i = 0; i = 0;
}
// Emit a 200 literal which also ends up in the constant pool.
var j = 0.2e3;
}
foo();
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