Commit dd5cdcee authored by Daniel Clifford's avatar Daniel Clifford Committed by Commit Bot

[torque] 'bool' is now 'true|false' not 'yes|no'

In the process, rename Boolean constants (i.e. JavaScript constants),
to 'True' and 'False'. This uncovered a bug in the internal handling
of True/False labels was fixed (they shouldn't be Values and Torque
shouldn't conflate Labels with other Declarables, throwing exceptions
when they're improperly used in the wrong context). Furthermore,
the internal labels used for True and False for if statements
have been renamed so that they can't be aliased from user Torque code.

Change-Id: I09dbd2241d2bc2f1daff53862dee1b601810060c
Reviewed-on: https://chromium-review.googlesource.com/1044370Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53026}
parent ea3e9de6
......@@ -86,7 +86,7 @@ module array {
if (elements == newElements) {
let limit: Smi = elements.length;
while (k < limit) {
newElements[k++] = hole;
newElements[k++] = Hole;
}
}
......@@ -173,7 +173,7 @@ module array {
HasPropertyObject(o, from, context, kHasProperty);
// c. If fromPresent is true, then
if (fromPresent == true) {
if (fromPresent == True) {
// i. Let fromValue be ? Get(O, from).
let fromValue: Object = GetProperty(context, o, from);
......@@ -212,7 +212,7 @@ module array {
HasPropertyObject(o, from, context, kHasProperty);
// iv. If fromPresent is true, then
if (fromPresent == true) {
if (fromPresent == True) {
// 1. Let fromValue be ? Get(O, from).
let fromValue: Object = GetProperty(context, o, from);
......@@ -256,7 +256,7 @@ module array {
HasPropertyObject(o, from, context, kHasProperty);
// iv. If fromPresent is true, then
if (fromPresent == true) {
if (fromPresent == True) {
// 1. Let fromValue be ? Get(O, from).
let fromValue: Object = GetProperty(context, o, from);
......
......@@ -38,7 +38,7 @@ type InstanceType extends int32 generates 'TNode<Int32T>';
type ElementsKind generates 'TNode<Int32T>' constexpr 'ElementsKind';
type LanguageMode generates 'TNode<Smi>' constexpr 'LanguageMode';
type ExtractFixedArrayFlags generates
'TNode<Smi>' constexpr 'ExtractFixedArrayFlags';
'TNode<Smi>' constexpr 'ExtractFixedArrayFlags';
type MessageTemplate;
type HasPropertyFlag generates 'HasPropertyLookupMode';
......@@ -82,13 +82,13 @@ const kDetachedOperation: MessageTemplate =
const kBadSortComparisonFunction: MessageTemplate =
'MessageTemplate::kBadSortComparisonFunction';
const hole: Oddball = 'TheHoleConstant()';
const null: Oddball = 'NullConstant()';
const undefined: Oddball = 'UndefinedConstant()';
const true: Boolean = 'TrueConstant()';
const false: Boolean = 'FalseConstant()';
const yes: constexpr bool = 'true';
const no: constexpr bool = 'false';
const Hole: Oddball = 'TheHoleConstant()';
const Null: Oddball = 'NullConstant()';
const Undefined: Oddball = 'UndefinedConstant()';
const True: Boolean = 'TrueConstant()';
const False: Boolean = 'FalseConstant()';
const true: constexpr bool = 'true';
const false: constexpr bool = 'false';
const strict: constexpr LanguageMode = 'LanguageMode::kStrict';
const sloppy: constexpr LanguageMode = 'LanguageMode::kSloppy';
......@@ -141,15 +141,16 @@ extern operator '>=' macro IntPtrGreaterThanOrEqual(intptr, intptr): bool;
extern operator '==' macro Float64Equal(float64, float64): bool;
extern operator
'<' macro BranchIfNumberLessThan(Number, Number): never labels True, False;
'<' macro BranchIfNumberLessThan(Number, Number): never labels Taken, NotTaken;
extern operator
'<=' macro BranchIfNumberLessThanOrEqual(Number, Number): never labels True,
False;
'<=' macro BranchIfNumberLessThanOrEqual(Number, Number): never labels Taken,
NotTaken;
extern operator
'>' macro BranchIfNumberGreaterThan(Number, Number): never labels True, False;
'>' macro BranchIfNumberGreaterThan(Number, Number): never labels Taken,
NotTaken;
extern operator '>=' macro BranchIfNumberGreaterThanOrEqual(Number, Number):
never labels True,
False;
never labels Taken,
NotTaken;
extern operator '==' macro WordEqual(Object, Object): bool;
extern operator '!=' macro WordNotEqual(Object, Object): bool;
......@@ -215,8 +216,9 @@ extern operator 'convert<>' macro SmiTag(intptr): Smi;
extern operator 'convert<>' macro SmiFromInt32(int32): Smi;
extern operator 'convert<>' macro SmiUntag(Smi): intptr;
extern macro BranchIfFastJSArray(Object, Context): never labels True, False;
extern macro BranchIfNotFastJSArray(Object, Context): never labels True, False;
extern macro BranchIfFastJSArray(Object, Context): never labels Taken, NotTaken;
extern macro BranchIfNotFastJSArray(Object, Context): never labels Taken,
NotTaken;
extern macro IsPrototypeInitialArrayPrototype(Context, Map): bool;
extern macro IsNoElementsProtectorCellInvalid(): bool;
......@@ -278,7 +280,7 @@ macro HasPropertyObject(
return HasProperty(cast<HeapObject>(o) otherwise CastError, p, c, f);
}
label CastError {
return false;
return False;
}
}
......
......@@ -21,7 +21,7 @@ module typed_array {
b: Object): Number labels Detached {
// a. Let v be ? ToNumber(? Call(comparefn, undefined, x, y)).
let v: Number =
ToNumber_Inline(context, Call(context, comparefn, undefined, a, b));
ToNumber_Inline(context, Call(context, comparefn, Undefined, a, b));
// b. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
if (IsDetachedBuffer(array.buffer)) goto Detached;
......@@ -164,12 +164,12 @@ module typed_array {
Store(context, array, kind, low_end, element);
low_end++;
} else if (order > 0) {
let break_for: bool = no;
let break_for: bool = false;
while (order > 0) {
high_start--;
if (high_start == idx) {
break_for = yes;
break_for = true;
break;
}
......@@ -226,8 +226,8 @@ module typed_array {
context: Context, receiver: Object, ...arguments): JSTypedArray {
// 1. If comparefn is not undefined and IsCallable(comparefn) is false,
// throw a TypeError exception.
let comparefn_obj: Object = arguments.length > 0 ? arguments[0] : undefined;
if (comparefn_obj != undefined && !TaggedIsCallable(comparefn_obj)) {
let comparefn_obj: Object = arguments.length > 0 ? arguments[0] : Undefined;
if (comparefn_obj != Undefined && !TaggedIsCallable(comparefn_obj)) {
ThrowTypeError(context, kBadSortComparisonFunction, comparefn_obj);
}
......@@ -240,7 +240,7 @@ module typed_array {
ValidateTypedArray(context, obj, kTypedArrayProtoSort);
// Default sorting is done in C++ using std::sort
if (comparefn_obj == undefined) {
if (comparefn_obj == Undefined) {
return TypedArraySortFast(context, obj);
}
......
......@@ -44,9 +44,7 @@ class Declarable {
bool IsVariable() const { return kind() == kVariable; }
bool IsMacroList() const { return kind() == kMacroList; }
bool IsConstant() const { return kind() == kConstant; }
bool IsValue() const {
return IsVariable() || IsConstant() || IsParameter() || IsLabel();
}
bool IsValue() const { return IsVariable() || IsConstant() || IsParameter(); }
virtual const char* type_name() const { return "<<unknown>>"; }
private:
......@@ -55,11 +53,11 @@ class Declarable {
#define DECLARE_DECLARABLE_BOILERPLATE(x, y) \
static x* cast(Declarable* declarable) { \
assert(declarable->Is##x()); \
DCHECK(declarable->Is##x()); \
return static_cast<x*>(declarable); \
} \
static const x* cast(const Declarable* declarable) { \
assert(declarable->Is##x()); \
DCHECK(declarable->Is##x()); \
return static_cast<const x*>(declarable); \
} \
const char* type_name() const override { return #y; }
......@@ -140,11 +138,11 @@ class Variable : public Value {
bool defined_;
};
class Label : public Value {
class Label : public Declarable {
public:
void AddVariable(Variable* var) { parameters_.push_back(var); }
std::string GetSourceName() const { return source_name_; }
std::string GetValueForDeclaration() const override { return name(); }
std::string name() const { return name_; }
std::string generated() const { return generated_; }
Variable* GetParameter(size_t i) const { return parameters_[i]; }
size_t GetParameterCount() const { return parameters_.size(); }
const std::vector<Variable*>& GetParameters() const { return parameters_; }
......@@ -156,12 +154,13 @@ class Label : public Value {
private:
friend class Declarations;
explicit Label(const std::string& name)
: Value(Declarable::kLabel, Type(),
"label_" + name + "_" + std::to_string(next_id_++)),
source_name_(name),
: Declarable(Declarable::kLabel),
name_(name),
generated_("label_" + name + "_" + std::to_string(next_id_++)),
used_(false) {}
std::string source_name_;
std::string name_;
std::string generated_;
std::vector<Variable*> parameters_;
static size_t next_id_;
bool used_;
......
......@@ -51,6 +51,17 @@ Value* Declarations::LookupValue(SourcePosition pos, const std::string& name) {
return Value::cast(d);
}
Label* Declarations::LookupLabel(SourcePosition pos, const std::string& name) {
Declarable* d = Lookup(pos, name);
if (!d->IsLabel()) {
std::stringstream s;
s << "declaration \"" << name << "\" is not a Label at "
<< PositionAsString(pos);
ReportError(s.str());
}
return Label::cast(d);
}
Macro* Declarations::LookupMacro(SourcePosition pos, const std::string& name,
const TypeVector& types) {
Declarable* declarable = Lookup(name);
......@@ -71,7 +82,7 @@ Macro* Declarations::LookupMacro(SourcePosition pos, const std::string& name,
return nullptr;
}
Builtin* Declarations::LookupBuiltin(const SourcePosition& pos,
Builtin* Declarations::LookupBuiltin(SourcePosition pos,
const std::string& name) {
Declarable* declarable = Lookup(name);
if (declarable != nullptr) {
......
......@@ -38,7 +38,9 @@ class Declarations {
Macro* LookupMacro(SourcePosition pos, const std::string& name,
const TypeVector& types);
Builtin* LookupBuiltin(const SourcePosition& pos, const std::string& name);
Builtin* LookupBuiltin(SourcePosition pos, const std::string& name);
Label* LookupLabel(SourcePosition pos, const std::string& name);
Type DeclareType(SourcePosition pos, const std::string& name,
const std::string& generated,
......
......@@ -38,12 +38,12 @@ class FileVisitor {
Declarations* declarations() { return global_context_.declarations(); }
protected:
static constexpr const char* kTrueLabelName = "True";
static constexpr const char* kFalseLabelName = "False";
static constexpr const char* kReturnValueVariable = "return";
static constexpr const char* kConditionValueVariable = "condition";
static constexpr const char* kDoneLabelName = "done";
static constexpr const char* kForIndexValueVariable = "for_index";
static constexpr const char* kTrueLabelName = "_True";
static constexpr const char* kFalseLabelName = "_False";
static constexpr const char* kReturnValueVariable = "_return";
static constexpr const char* kConditionValueVariable = "_condition";
static constexpr const char* kDoneLabelName = "_done";
static constexpr const char* kForIndexValueVariable = "_for_index";
Module* CurrentModule() const { return module_; }
......
This diff is collapsed.
......@@ -135,8 +135,6 @@ class ImplementationVisitor : public FileVisitor {
Type Visit(DebugStatement* stmt);
Type Visit(AssertStatement* stmt);
Label* GetLabel(SourcePosition pos, const std::string& label);
void GenerateImplementation(const std::string& dir, Module* module);
private:
......
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