Commit e87e3b1f authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] named arguments for constructors

This changes the syntax for constructing structs and classes to explicitly
mention the fieldnames, similar to JavaScript object literals.
The fields still have to be listed in the same order as in the struct/class
declaration.
As in Javascript, {foo: foo} can be abbreviated as {foo}.

Example:

macro NewJSArray(implicit context: Context)(
    map: Map, elements: FixedArrayBase): JSArray {
  return new JSArray{
    map,
    properties_or_hash: kEmptyFixedArray,
    elements,
    length: elements.length
  };
}

Drive-by cleanup: Make struct and class constructors follow the same pattern
                  in the parser and the AST.

Bug: v8:9018 v8:7793
Change-Id: I22ff7f68270e4f406aa80731a709d41ea52f52bb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1551999Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60622}
parent ecec2c61
...@@ -43,12 +43,16 @@ namespace arguments { ...@@ -43,12 +43,16 @@ namespace arguments {
const adaptor: ArgumentsAdaptorFrame = const adaptor: ArgumentsAdaptorFrame =
Cast<ArgumentsAdaptorFrame>(frame.caller) Cast<ArgumentsAdaptorFrame>(frame.caller)
otherwise return ArgumentsInfo{frame, argumentCount, formalParameterCount}; otherwise return ArgumentsInfo{
frame,
argument_count: argumentCount,
formal_parameter_count: formalParameterCount
};
return ArgumentsInfo{ return ArgumentsInfo{
adaptor, frame: adaptor,
Convert<bint>(adaptor.length), argument_count: Convert<bint>(adaptor.length),
formalParameterCount formal_parameter_count: formalParameterCount
}; };
} }
} }
...@@ -219,10 +219,10 @@ namespace array_join { ...@@ -219,10 +219,10 @@ namespace array_join {
Signed(len); Signed(len);
assert(cappedBufferSize > 0); assert(cappedBufferSize > 0);
return Buffer{ return Buffer{
AllocateZeroedFixedArray(cappedBufferSize), fixedArray: AllocateZeroedFixedArray(cappedBufferSize),
0, index: 0,
0, totalStringLength: 0,
IsOneByteStringInstanceType(sep.instanceType) isOneByte: IsOneByteStringInstanceType(sep.instanceType)
}; };
} }
......
...@@ -173,7 +173,12 @@ namespace array_map { ...@@ -173,7 +173,12 @@ namespace array_map {
AllocateFixedArrayWithHoles( AllocateFixedArrayWithHoles(
SmiUntag(length), kAllowLargeObjectAllocation) : SmiUntag(length), kAllowLargeObjectAllocation) :
kEmptyFixedArray; kEmptyFixedArray;
return Vector{fixedArray, true, true, false}; return Vector{
fixedArray,
onlySmis: true,
onlyNumbers: true,
skippedElements: false
};
} }
transitioning macro FastArrayMap(implicit context: Context)( transitioning macro FastArrayMap(implicit context: Context)(
......
...@@ -157,13 +157,17 @@ extern class JSObject extends JSReceiver { elements: FixedArrayBase; } ...@@ -157,13 +157,17 @@ extern class JSObject extends JSReceiver { elements: FixedArrayBase; }
macro NewJSObject( macro NewJSObject(
map: Map, properties: FixedArrayBase | Smi, map: Map, properties: FixedArrayBase | Smi,
elements: FixedArrayBase): JSObject { elements: FixedArrayBase): JSObject {
return new JSObject{map, properties, elements}; return new JSObject{map, properties_or_hash: properties, elements};
} }
macro NewJSObject(implicit context: Context)(): JSObject { macro NewJSObject(implicit context: Context)(): JSObject {
const objectFunction: JSFunction = GetObjectFunction(); const objectFunction: JSFunction = GetObjectFunction();
const map: Map = Cast<Map>(objectFunction.prototype_or_initial_map) const map: Map = Cast<Map>(objectFunction.prototype_or_initial_map)
otherwise unreachable; otherwise unreachable;
return new JSObject{map, kEmptyFixedArray, kEmptyFixedArray}; return new JSObject{
map,
properties_or_hash: kEmptyFixedArray,
elements: kEmptyFixedArray
};
} }
extern class JSFunction extends JSObject { extern class JSFunction extends JSObject {
...@@ -187,11 +191,11 @@ extern class JSProxyRevocableResult extends JSObject { ...@@ -187,11 +191,11 @@ extern class JSProxyRevocableResult extends JSObject {
macro NewJSProxyRevocableResult(implicit context: Context)( macro NewJSProxyRevocableResult(implicit context: Context)(
proxy: JSProxy, revoke: JSFunction): JSProxyRevocableResult { proxy: JSProxy, revoke: JSFunction): JSProxyRevocableResult {
return new JSProxyRevocableResult{ return new JSProxyRevocableResult{
GetProxyRevocableResultMap(), // HeapObject.map map: GetProxyRevocableResultMap(),
kEmptyFixedArray, // JSReceiver.properties_or_hash properties_or_hash: kEmptyFixedArray,
kEmptyFixedArray, // JSObject.elements elements: kEmptyFixedArray,
proxy, // JSProxyRevocableResult.proxy proxy,
revoke // JSProxyRevocableResult.revoke revoke
}; };
} }
...@@ -222,15 +226,20 @@ extern class JSArray extends JSObject { ...@@ -222,15 +226,20 @@ extern class JSArray extends JSObject {
macro NewJSArray(implicit context: Context)( macro NewJSArray(implicit context: Context)(
map: Map, elements: FixedArrayBase): JSArray { map: Map, elements: FixedArrayBase): JSArray {
return new JSArray{map, kEmptyFixedArray, elements, elements.length}; return new JSArray{
map,
properties_or_hash: kEmptyFixedArray,
elements,
length: elements.length
};
} }
macro NewJSArray(implicit context: Context)(): JSArray { macro NewJSArray(implicit context: Context)(): JSArray {
return new JSArray{ return new JSArray{
GetFastPackedSmiElementsJSArrayMap(), map: GetFastPackedSmiElementsJSArrayMap(),
kEmptyFixedArray, properties_or_hash: kEmptyFixedArray,
kEmptyFixedArray, elements: kEmptyFixedArray,
0 length: 0
}; };
} }
...@@ -424,8 +433,12 @@ extern class JSTypedArray extends JSArrayBufferView { ...@@ -424,8 +433,12 @@ extern class JSTypedArray extends JSArrayBufferView {
Convert<uintptr>(externalPointer) >= Convert<uintptr>(backingStore)); Convert<uintptr>(externalPointer) >= Convert<uintptr>(backingStore));
this.buffer = buffer; this.buffer = buffer;
this.elements = new this.elements = new FixedTypedArrayBase{
FixedTypedArrayBase{map, length, basePointer, externalPointer}; map,
length,
base_pointer: basePointer,
external_pointer: externalPointer
};
} }
length: Smi; length: Smi;
...@@ -2047,12 +2060,12 @@ struct FastJSArrayWitness { ...@@ -2047,12 +2060,12 @@ struct FastJSArrayWitness {
macro NewFastJSArrayWitness(array: FastJSArray): FastJSArrayWitness { macro NewFastJSArrayWitness(array: FastJSArray): FastJSArrayWitness {
let kind = array.map.elements_kind; let kind = array.map.elements_kind;
return FastJSArrayWitness{ return FastJSArrayWitness{
array, stable: array,
array, unstable: array,
array.map, map: array.map,
!IsElementsKindLessThanOrEqual(kind, HOLEY_ELEMENTS), hasDoubles: !IsElementsKindLessThanOrEqual(kind, HOLEY_ELEMENTS),
IsElementsKindLessThanOrEqual(kind, HOLEY_SMI_ELEMENTS), hasSmis: IsElementsKindLessThanOrEqual(kind, HOLEY_SMI_ELEMENTS),
false arrayIsPushable: false
}; };
} }
......
...@@ -14,17 +14,17 @@ namespace collections { ...@@ -14,17 +14,17 @@ namespace collections {
typeswitch (a.elements) { typeswitch (a.elements) {
case (elements: FixedArray): { case (elements: FixedArray): {
return KeyValuePair{ return KeyValuePair{
length > 0 ? array::LoadElementOrUndefined(elements, 0) : key: length > 0 ? array::LoadElementOrUndefined(elements, 0) :
Undefined, Undefined,
length > 1 ? array::LoadElementOrUndefined(elements, 1) : value: length > 1 ? array::LoadElementOrUndefined(elements, 1) :
Undefined Undefined
}; };
} }
case (elements: FixedDoubleArray): { case (elements: FixedDoubleArray): {
return KeyValuePair{ return KeyValuePair{
length > 0 ? array::LoadElementOrUndefined(elements, 0) : key: length > 0 ? array::LoadElementOrUndefined(elements, 0) :
Undefined, Undefined,
length > 1 ? array::LoadElementOrUndefined(elements, 1) : value: length > 1 ? array::LoadElementOrUndefined(elements, 1) :
Undefined Undefined
}; };
} }
...@@ -49,8 +49,8 @@ namespace collections { ...@@ -49,8 +49,8 @@ namespace collections {
} }
label Generic { label Generic {
return KeyValuePair{ return KeyValuePair{
GetProperty(o, Convert<Smi>(0)), key: GetProperty(o, Convert<Smi>(0)),
GetProperty(o, Convert<Smi>(1)) value: GetProperty(o, Convert<Smi>(1))
}; };
} }
} }
......
...@@ -40,6 +40,6 @@ namespace growable_fixed_array { ...@@ -40,6 +40,6 @@ namespace growable_fixed_array {
} }
macro NewGrowableFixedArray(): GrowableFixedArray { macro NewGrowableFixedArray(): GrowableFixedArray {
return GrowableFixedArray{kEmptyFixedArray, 0, 0}; return GrowableFixedArray{array: kEmptyFixedArray, capacity: 0, length: 0};
} }
} }
...@@ -111,9 +111,9 @@ namespace typed_array { ...@@ -111,9 +111,9 @@ namespace typed_array {
AttachedJSTypedArrayWitness { AttachedJSTypedArrayWitness {
const kind = array.elements_kind; const kind = array.elements_kind;
return AttachedJSTypedArrayWitness{ return AttachedJSTypedArrayWitness{
array, stable: array,
array, unstable: array,
GetLoadFnForElementsKind(kind) loadfn: GetLoadFnForElementsKind(kind)
}; };
} }
......
...@@ -291,18 +291,20 @@ struct CallExpression : Expression { ...@@ -291,18 +291,20 @@ struct CallExpression : Expression {
std::vector<std::string> labels; std::vector<std::string> labels;
}; };
struct NameAndExpression {
Identifier* name;
Expression* expression;
};
struct StructExpression : Expression { struct StructExpression : Expression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(StructExpression) DEFINE_AST_NODE_LEAF_BOILERPLATE(StructExpression)
StructExpression(SourcePosition pos, StructExpression(SourcePosition pos, TypeExpression* type,
std::vector<std::string> namespace_qualification, std::vector<NameAndExpression> initializers)
std::string name, std::vector<Expression*> expressions)
: Expression(kKind, pos), : Expression(kKind, pos),
namespace_qualification(std::move(namespace_qualification)), type(type),
name(std::move(name)), initializers(std::move(initializers)) {}
expressions(std::move(expressions)) {} TypeExpression* type;
std::vector<std::string> namespace_qualification; std::vector<NameAndExpression> initializers;
std::string name;
std::vector<Expression*> expressions;
}; };
struct LogicalOrExpression : Expression { struct LogicalOrExpression : Expression {
...@@ -410,10 +412,12 @@ struct AssumeTypeImpossibleExpression : Expression { ...@@ -410,10 +412,12 @@ struct AssumeTypeImpossibleExpression : Expression {
struct NewExpression : Expression { struct NewExpression : Expression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(NewExpression) DEFINE_AST_NODE_LEAF_BOILERPLATE(NewExpression)
NewExpression(SourcePosition pos, TypeExpression* type, NewExpression(SourcePosition pos, TypeExpression* type,
std::vector<Expression*> parameters) std::vector<NameAndExpression> initializers)
: Expression(kKind, pos), type(type), parameters(parameters) {} : Expression(kKind, pos),
type(type),
initializers(std::move(initializers)) {}
TypeExpression* type; TypeExpression* type;
std::vector<Expression*> parameters; std::vector<NameAndExpression> initializers;
}; };
struct ParameterList { struct ParameterList {
......
...@@ -54,9 +54,11 @@ enum class ParseResultHolderBase::TypeId { ...@@ -54,9 +54,11 @@ enum class ParseResultHolderBase::TypeId {
kLabelBlockPtr, kLabelBlockPtr,
kOptionalLabelBlockPtr, kOptionalLabelBlockPtr,
kNameAndTypeExpression, kNameAndTypeExpression,
kNameAndExpression,
kClassFieldExpression, kClassFieldExpression,
kStructFieldExpression, kStructFieldExpression,
kStdVectorOfNameAndTypeExpression, kStdVectorOfNameAndTypeExpression,
kStdVectorOfNameAndExpression,
kStdVectorOfClassFieldExpression, kStdVectorOfClassFieldExpression,
kStdVectorOfStructFieldExpression, kStdVectorOfStructFieldExpression,
kIncrementDecrementOperator, kIncrementDecrementOperator,
......
...@@ -1250,10 +1250,11 @@ VisitResult ImplementationVisitor::Visit(StatementExpression* expr) { ...@@ -1250,10 +1250,11 @@ VisitResult ImplementationVisitor::Visit(StatementExpression* expr) {
} }
InitializerResults ImplementationVisitor::VisitInitializerResults( InitializerResults ImplementationVisitor::VisitInitializerResults(
const std::vector<Expression*>& expressions) { const std::vector<NameAndExpression>& initializers) {
InitializerResults result; InitializerResults result;
for (auto e : expressions) { for (const NameAndExpression& initializer : initializers) {
result.results.push_back(Visit(e)); result.names.push_back(initializer.name);
result.results.push_back(Visit(initializer.expression));
} }
return result; return result;
} }
...@@ -1271,12 +1272,18 @@ size_t ImplementationVisitor::InitializeAggregateHelper( ...@@ -1271,12 +1272,18 @@ size_t ImplementationVisitor::InitializeAggregateHelper(
} }
} }
for (auto f : aggregate_type->fields()) { for (Field f : aggregate_type->fields()) {
if (current == initializer_results.results.size()) { if (current == initializer_results.results.size()) {
ReportError("insufficient number of initializers for ", ReportError("insufficient number of initializers for ",
aggregate_type->name()); aggregate_type->name());
} }
VisitResult current_value = initializer_results.results[current]; VisitResult current_value = initializer_results.results[current];
Identifier* fieldname = initializer_results.names[current];
if (fieldname->value != f.name_and_type.name) {
CurrentSourcePosition::Scope scope(fieldname->pos);
ReportError("Expected fieldname \"", f.name_and_type.name,
"\" instead of \"", fieldname->value, "\"");
}
if (aggregate_type->IsClassType()) { if (aggregate_type->IsClassType()) {
allocate_result.SetType(aggregate_type); allocate_result.SetType(aggregate_type);
GenerateCopy(allocate_result); GenerateCopy(allocate_result);
...@@ -1320,7 +1327,7 @@ VisitResult ImplementationVisitor::Visit(NewExpression* expr) { ...@@ -1320,7 +1327,7 @@ VisitResult ImplementationVisitor::Visit(NewExpression* expr) {
} }
InitializerResults initializer_results = InitializerResults initializer_results =
VisitInitializerResults(expr->parameters); VisitInitializerResults(expr->initializers);
// Output the code to generate an uninitialized object of the class size in // Output the code to generate an uninitialized object of the class size in
// the GC heap. // the GC heap.
...@@ -1692,18 +1699,15 @@ VisitResult ImplementationVisitor::GenerateCopy(const VisitResult& to_copy) { ...@@ -1692,18 +1699,15 @@ VisitResult ImplementationVisitor::GenerateCopy(const VisitResult& to_copy) {
return to_copy; return to_copy;
} }
VisitResult ImplementationVisitor::Visit(StructExpression* decl) { VisitResult ImplementationVisitor::Visit(StructExpression* expr) {
StackScope stack_scope(this); StackScope stack_scope(this);
const Type* raw_type = Declarations::LookupType( const Type* raw_type = Declarations::GetType(expr->type);
QualifiedName(decl->namespace_qualification, decl->name));
if (!raw_type->IsStructType()) { if (!raw_type->IsStructType()) {
std::stringstream s; ReportError(*raw_type, " is not a struct but used like one");
s << decl->name << " is not a struct but used like one ";
ReportError(s.str());
} }
InitializerResults initialization_results = InitializerResults initialization_results =
ImplementationVisitor::VisitInitializerResults(decl->expressions); ImplementationVisitor::VisitInitializerResults(expr->initializers);
const StructType* struct_type = StructType::cast(raw_type); const StructType* struct_type = StructType::cast(raw_type);
// Push uninitialized 'this' // Push uninitialized 'this'
......
...@@ -140,6 +140,7 @@ class LocationReference { ...@@ -140,6 +140,7 @@ class LocationReference {
}; };
struct InitializerResults { struct InitializerResults {
std::vector<Identifier*> names;
std::vector<VisitResult> results; std::vector<VisitResult> results;
}; };
...@@ -261,7 +262,7 @@ class ImplementationVisitor : public FileVisitor { ...@@ -261,7 +262,7 @@ class ImplementationVisitor : public FileVisitor {
const Type* Visit(Statement* stmt); const Type* Visit(Statement* stmt);
InitializerResults VisitInitializerResults( InitializerResults VisitInitializerResults(
const std::vector<Expression*>& expressions); const std::vector<NameAndExpression>& expressions);
size_t InitializeAggregateHelper( size_t InitializeAggregateHelper(
const AggregateType* aggregate_type, VisitResult allocate_result, const AggregateType* aggregate_type, VisitResult allocate_result,
......
...@@ -79,6 +79,10 @@ V8_EXPORT_PRIVATE const ParseResultTypeId ...@@ -79,6 +79,10 @@ V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<NameAndTypeExpression>::id = ParseResultHolder<NameAndTypeExpression>::id =
ParseResultTypeId::kNameAndTypeExpression; ParseResultTypeId::kNameAndTypeExpression;
template <> template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<NameAndExpression>::id =
ParseResultTypeId::kNameAndExpression;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<ClassFieldExpression>::id = ParseResultHolder<ClassFieldExpression>::id =
ParseResultTypeId::kClassFieldExpression; ParseResultTypeId::kClassFieldExpression;
...@@ -91,6 +95,10 @@ V8_EXPORT_PRIVATE const ParseResultTypeId ...@@ -91,6 +95,10 @@ V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<NameAndTypeExpression>>::id = ParseResultHolder<std::vector<NameAndTypeExpression>>::id =
ParseResultTypeId::kStdVectorOfNameAndTypeExpression; ParseResultTypeId::kStdVectorOfNameAndTypeExpression;
template <> template <>
V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<NameAndExpression>>::id =
ParseResultTypeId::kStdVectorOfNameAndExpression;
template <>
V8_EXPORT_PRIVATE const ParseResultTypeId V8_EXPORT_PRIVATE const ParseResultTypeId
ParseResultHolder<std::vector<ClassFieldExpression>>::id = ParseResultHolder<std::vector<ClassFieldExpression>>::id =
ParseResultTypeId::kStdVectorOfClassFieldExpression; ParseResultTypeId::kStdVectorOfClassFieldExpression;
...@@ -270,10 +278,11 @@ base::Optional<ParseResult> MakeMethodCall(ParseResultIterator* child_results) { ...@@ -270,10 +278,11 @@ base::Optional<ParseResult> MakeMethodCall(ParseResultIterator* child_results) {
this_arg, args, otherwise)}; this_arg, args, otherwise)};
} }
base::Optional<ParseResult> MakeNew(ParseResultIterator* child_results) { base::Optional<ParseResult> MakeNewExpression(
TypeExpression* type = child_results->NextAs<TypeExpression*>(); ParseResultIterator* child_results) {
auto args = child_results->NextAs<std::vector<Expression*>>(); auto type = child_results->NextAs<TypeExpression*>();
Expression* result = MakeNode<NewExpression>(type, args); auto initializers = child_results->NextAs<std::vector<NameAndExpression>>();
Expression* result = MakeNode<NewExpression>(type, std::move(initializers));
return ParseResult{result}; return ParseResult{result};
} }
...@@ -1007,13 +1016,10 @@ base::Optional<ParseResult> MakeElementAccessExpression( ...@@ -1007,13 +1016,10 @@ base::Optional<ParseResult> MakeElementAccessExpression(
base::Optional<ParseResult> MakeStructExpression( base::Optional<ParseResult> MakeStructExpression(
ParseResultIterator* child_results) { ParseResultIterator* child_results) {
auto namespace_qualification = auto type = child_results->NextAs<TypeExpression*>();
child_results->NextAs<std::vector<std::string>>(); auto initializers = child_results->NextAs<std::vector<NameAndExpression>>();
auto name = child_results->NextAs<std::string>();
auto expressions = child_results->NextAs<std::vector<Expression*>>();
Expression* result = Expression* result =
MakeNode<StructExpression>(std::move(namespace_qualification), MakeNode<StructExpression>(type, std::move(initializers));
std::move(name), std::move(expressions));
return ParseResult{result}; return ParseResult{result};
} }
...@@ -1102,6 +1108,26 @@ base::Optional<ParseResult> MakeNameAndType( ...@@ -1102,6 +1108,26 @@ base::Optional<ParseResult> MakeNameAndType(
return ParseResult{NameAndTypeExpression{name, type}}; return ParseResult{NameAndTypeExpression{name, type}};
} }
base::Optional<ParseResult> MakeNameAndExpression(
ParseResultIterator* child_results) {
auto name = child_results->NextAs<Identifier*>();
auto expression = child_results->NextAs<Expression*>();
return ParseResult{NameAndExpression{name, expression}};
}
base::Optional<ParseResult> MakeNameAndExpressionFromExpression(
ParseResultIterator* child_results) {
auto expression = child_results->NextAs<Expression*>();
if (auto* id = IdentifierExpression::DynamicCast(expression)) {
if (!id->generic_arguments.empty() ||
!id->namespace_qualification.empty()) {
ReportError("expected a plain identifier without qualification");
}
return ParseResult{NameAndExpression{id->name, id}};
}
ReportError("Constructor parameters need to be named.");
}
base::Optional<ParseResult> MakeClassField(ParseResultIterator* child_results) { base::Optional<ParseResult> MakeClassField(ParseResultIterator* child_results) {
auto weak = child_results->NextAs<bool>(); auto weak = child_results->NextAs<bool>();
auto const_qualified = child_results->NextAs<bool>(); auto const_qualified = child_results->NextAs<bool>();
...@@ -1308,8 +1334,8 @@ struct TorqueGrammar : Grammar { ...@@ -1308,8 +1334,8 @@ struct TorqueGrammar : Grammar {
// Result: NameAndTypeExpression // Result: NameAndTypeExpression
Symbol nameAndType = {Rule({&name, Token(":"), &type}, MakeNameAndType)}; Symbol nameAndType = {Rule({&name, Token(":"), &type}, MakeNameAndType)};
Symbol* optionalArraySpecifier = { Symbol* optionalArraySpecifier =
Optional<std::string>(Sequence({Token("["), &identifier, Token("]")}))}; Optional<std::string>(Sequence({Token("["), &identifier, Token("]")}));
Symbol classField = { Symbol classField = {
Rule({CheckIf(Token("weak")), CheckIf(Token("const")), &name, Rule({CheckIf(Token("weak")), CheckIf(Token("const")), &name,
...@@ -1385,16 +1411,21 @@ struct TorqueGrammar : Grammar { ...@@ -1385,16 +1411,21 @@ struct TorqueGrammar : Grammar {
Symbol callExpression = {Rule( Symbol callExpression = {Rule(
{&identifierExpression, &argumentList, optionalOtherwise}, MakeCall)}; {&identifierExpression, &argumentList, optionalOtherwise}, MakeCall)};
// Result: Expression*
Symbol callMethodExpression = { Symbol callMethodExpression = {
Rule({&primaryExpression, Token("."), &identifier, &argumentList, Rule({&primaryExpression, Token("."), &identifier, &argumentList,
optionalOtherwise}, optionalOtherwise},
MakeMethodCall)}; MakeMethodCall)};
Symbol initializerList = {Rule( // Result: NameAndExpression
{Token("{"), List<Expression*>(expression, Token(",")), Token("}")})}; Symbol namedExpression = {
Rule({&name, Token(":"), expression}, MakeNameAndExpression),
Rule({expression}, MakeNameAndExpressionFromExpression)};
Symbol newExpression = { // Result: std::vector<NameAndExpression>
Rule({Token("new"), &type, &initializerList}, MakeNew)}; Symbol initializerList = {
Rule({Token("{"), List<NameAndExpression>(&namedExpression, Token(",")),
Token("}")})};
// Result: Expression* // Result: Expression*
Symbol intrinsicCallExpression = {Rule( Symbol intrinsicCallExpression = {Rule(
...@@ -1404,7 +1435,6 @@ struct TorqueGrammar : Grammar { ...@@ -1404,7 +1435,6 @@ struct TorqueGrammar : Grammar {
// Result: Expression* // Result: Expression*
Symbol primaryExpression = { Symbol primaryExpression = {
Rule({&newExpression}),
Rule({&callExpression}), Rule({&callExpression}),
Rule({&callMethodExpression}), Rule({&callMethodExpression}),
Rule({&intrinsicCallExpression}), Rule({&intrinsicCallExpression}),
...@@ -1412,10 +1442,8 @@ struct TorqueGrammar : Grammar { ...@@ -1412,10 +1442,8 @@ struct TorqueGrammar : Grammar {
CastParseResult<LocationExpression*, Expression*>), CastParseResult<LocationExpression*, Expression*>),
Rule({&decimalLiteral}, MakeNumberLiteralExpression), Rule({&decimalLiteral}, MakeNumberLiteralExpression),
Rule({&stringLiteral}, MakeStringLiteralExpression), Rule({&stringLiteral}, MakeStringLiteralExpression),
Rule( Rule({&simpleType, &initializerList}, MakeStructExpression),
{List<std::string>(Sequence({&identifier, Token("::")})), &identifier, Rule({Token("new"), &simpleType, &initializerList}, MakeNewExpression),
Token("{"), List<Expression*>(expression, Token(",")), Token("}")},
MakeStructExpression),
Rule({Token("("), expression, Token(")")})}; Rule({Token("("), expression, Token(")")})};
// Result: Expression* // Result: Expression*
......
...@@ -123,7 +123,7 @@ DEFINE_CONTEXTUAL_VARIABLE(LintErrorStatus) ...@@ -123,7 +123,7 @@ DEFINE_CONTEXTUAL_VARIABLE(LintErrorStatus)
[[noreturn]] void ReportErrorString(const std::string& error, [[noreturn]] void ReportErrorString(const std::string& error,
bool print_position) { bool print_position) {
if (print_position) std::cerr << CurrentPositionAsString() << ": "; if (print_position) std::cerr << CurrentPositionAsString() << ": ";
std::cerr << ": Torque error: " << error << "\n"; std::cerr << "Torque error: " << error << "\n";
v8::base::OS::Abort(); v8::base::OS::Abort();
} }
......
...@@ -278,22 +278,29 @@ namespace test { ...@@ -278,22 +278,29 @@ namespace test {
} }
macro TestStruct2(implicit context: Context)(): TestStructA { macro TestStruct2(implicit context: Context)(): TestStructA {
return TestStructA{UnsafeCast<FixedArray>(kEmptyFixedArray), 27, 31}; return TestStructA{
indexes: UnsafeCast<FixedArray>(kEmptyFixedArray),
i: 27,
k: 31
};
} }
macro TestStruct3(implicit context: Context)(): TestStructA { macro TestStruct3(implicit context: Context)(): TestStructA {
let a: TestStructA = let a: TestStructA =
TestStructA{UnsafeCast<FixedArray>(kEmptyFixedArray), 13, 5}; TestStructA{indexes: UnsafeCast<FixedArray>(kEmptyFixedArray), i: 13, k: 5};
let b: TestStructA = a; let b: TestStructA = a;
let c: TestStructA = TestStruct2(); let c: TestStructA = TestStruct2();
a.i = TestStruct1(c); a.i = TestStruct1(c);
a.k = a.i; a.k = a.i;
let d: TestStructB; let d: TestStructB;
d.x = a; d.x = a;
d = TestStructB{a, 7}; d = TestStructB{x: a, y: 7};
let e: TestStructA = d.x; let e: TestStructA = d.x;
let f: Smi = let f: Smi = TestStructA{
TestStructA{UnsafeCast<FixedArray>(kEmptyFixedArray), 27, 31}.i; indexes: UnsafeCast<FixedArray>(kEmptyFixedArray),
i: 27,
k: 31
}.i;
f = TestStruct2().i; f = TestStruct2().i;
return a; return a;
} }
...@@ -304,7 +311,7 @@ namespace test { ...@@ -304,7 +311,7 @@ namespace test {
} }
macro TestStruct4(implicit context: Context)(): TestStructC { macro TestStruct4(implicit context: Context)(): TestStructC {
return TestStructC{TestStruct2(), TestStruct2()}; return TestStructC{x: TestStruct2(), y: TestStruct2()};
} }
macro TestStructInLabel(implicit context: Context)(): never macro TestStructInLabel(implicit context: Context)(): never
...@@ -751,7 +758,7 @@ namespace test { ...@@ -751,7 +758,7 @@ namespace test {
macro TestStructConstructor(implicit context: Context)() { macro TestStructConstructor(implicit context: Context)() {
// Test default constructor // Test default constructor
let a: TestOuter = TestOuter{5, TestInner{6, 7}, 8}; let a: TestOuter = TestOuter{a: 5, b: TestInner{x: 6, y: 7}, c: 8};
assert(a.a == 5); assert(a.a == 5);
assert(a.b.x == 6); assert(a.b.x == 6);
assert(a.b.y == 7); assert(a.b.y == 7);
...@@ -811,7 +818,7 @@ namespace test { ...@@ -811,7 +818,7 @@ namespace test {
} }
macro NewInternalClass(x: Smi): InternalClass { macro NewInternalClass(x: Smi): InternalClass {
return new InternalClass{x, x + 1}; return new InternalClass{a: x, b: x + 1};
} }
macro TestInternalClass(implicit context: Context)() { macro TestInternalClass(implicit context: Context)() {
...@@ -833,8 +840,8 @@ namespace test { ...@@ -833,8 +840,8 @@ namespace test {
} }
macro TestConstInStructs() { macro TestConstInStructs() {
const x = StructWithConst{Null, 1}; const x = StructWithConst{a: Null, b: 1};
let y = StructWithConst{Null, 1}; let y = StructWithConst{a: Null, b: 1};
y.a = Undefined; y.a = Undefined;
const copy = x; const copy = x;
} }
......
...@@ -135,19 +135,19 @@ namespace array { ...@@ -135,19 +135,19 @@ namespace array {
return new SortState{ return new SortState{
receiver, receiver,
map, initialReceiverMap: map,
initialReceiverLength, initialReceiverLength,
comparefn, userCmpFn: comparefn,
sortComparePtr, sortComparePtr,
loadFn, loadFn,
storeFn, storeFn,
canUseSameAccessorFn, canUseSameAccessorFn,
kSuccess, bailoutStatus: kSuccess,
kMinGallopWins, minGallop: kMinGallopWins,
0, pendingRunsSize: 0,
AllocateZeroedFixedArray(Convert<intptr>(kMaxMergePending)), pendingRuns: AllocateZeroedFixedArray(Convert<intptr>(kMaxMergePending)),
AllocateZeroedFixedArray(Convert<intptr>(sortLength)), workArray: AllocateZeroedFixedArray(Convert<intptr>(sortLength)),
kEmptyFixedArray tempArray: kEmptyFixedArray
}; };
} }
......
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