Commit 08eed80c authored by Mike Stanton's avatar Mike Stanton Committed by Commit Bot

[Torque] Rename modules to namespaces

BUG=v8:7793

Change-Id: Ibcf16998ef9a44ae899a2536ccf02af1b7b7193d
Reviewed-on: https://chromium-review.googlesource.com/c/1333410
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57469}
parent bd0a7fd6
......@@ -930,7 +930,7 @@ torque_files = [
"third_party/v8/builtins/array-sort.tq",
]
torque_modules = [
torque_namespaces = [
"base",
"array",
"iterator",
......@@ -957,10 +957,10 @@ action("run_torque") {
outputs = [
"$target_gen_dir/torque-generated/builtin-definitions-from-dsl.h",
]
foreach(module, torque_modules) {
foreach(namespace, torque_namespaces) {
outputs += [
"$target_gen_dir/torque-generated/builtins-$module-from-dsl-gen.cc",
"$target_gen_dir/torque-generated/builtins-$module-from-dsl-gen.h",
"$target_gen_dir/torque-generated/builtins-$namespace-from-dsl-gen.cc",
"$target_gen_dir/torque-generated/builtins-$namespace-from-dsl-gen.h",
]
}
......@@ -992,10 +992,10 @@ v8_source_set("torque_generated_initializers") {
}
sources = []
foreach(module, torque_modules) {
foreach(namespace, torque_namespaces) {
sources += [
"$target_gen_dir/torque-generated/builtins-$module-from-dsl-gen.cc",
"$target_gen_dir/torque-generated/builtins-$module-from-dsl-gen.h",
"$target_gen_dir/torque-generated/builtins-$namespace-from-dsl-gen.cc",
"$target_gen_dir/torque-generated/builtins-$namespace-from-dsl-gen.h",
]
}
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module array {
namespace array {
macro ConvertToRelativeIndex(index: Number, length: Number): Number {
return index < 0 ? Max(index + length, 0) : Min(index, length);
}
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module array {
namespace array {
transitioning macro ArrayForEachTorqueContinuation(
context: Context, o: JSReceiver, len: Number, callbackfn: Callable,
thisArg: Object, initialK: Number): Object {
......@@ -74,8 +74,7 @@ module array {
transitioning macro VisitAllElements<FixedArrayType: type>(
context: Context, a: JSArray, len: Smi, callbackfn: Callable,
thisArg: Object): void
labels Bailout(Smi) {
thisArg: Object): void labels Bailout(Smi) {
let k: Smi = 0;
const map: Map = a.map;
......@@ -136,8 +135,8 @@ module array {
}
// https://tc39.github.io/ecma262/#sec-array.prototype.foreach
transitioning javascript builtin ArrayForEach(
context: Context, receiver: Object, ...arguments): Object {
transitioning javascript builtin
ArrayForEach(context: Context, receiver: Object, ...arguments): Object {
try {
if (IsNullOrUndefined(receiver)) {
goto NullOrUndefinedError;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module array {
namespace array {
type LoadJoinElementFn = builtin(Context, JSReceiver, Number) => Object;
// Fast C call to write a fixed array (see Buffer.fixedArray) to a single
......@@ -12,8 +12,8 @@ module array {
FixedArray, intptr, String, String): String;
extern macro ArrayBuiltinsAssembler::CallArrayJoin(
Context, constexpr bool, JSReceiver, String, Number, Object, Object):
String
Context, constexpr bool, JSReceiver, String, Number, Object,
Object): String
labels IfException(Object);
transitioning builtin LoadJoinElement<T: type>(
......@@ -98,8 +98,8 @@ module array {
// Calculates the running total length of the resulting string. If the
// calculated length exceeds the maximum string length (see
// String::kMaxLength), throws a range error.
macro AddStringLength(implicit context: Context)(
lenA: intptr, lenB: intptr): intptr {
macro AddStringLength(implicit context: Context)(lenA: intptr, lenB: intptr):
intptr {
try {
const length: intptr = TryIntPtrAdd(lenA, lenB) otherwise IfOverflow;
if (length > kStringMaxLength) goto IfOverflow;
......@@ -217,8 +217,8 @@ module array {
return Buffer{fixedArray, index, totalStringLength, buffer.isOneByte};
}
macro BufferJoin(implicit context: Context)(
buffer: Buffer, sep: String): String {
macro BufferJoin(implicit context: Context)(buffer: Buffer, sep: String):
String {
assert(IsValidPositiveSmi(buffer.totalStringLength));
if (buffer.totalStringLength == 0) return kEmptyString;
......@@ -526,8 +526,8 @@ module array {
}
// https://tc39.github.io/ecma262/#sec-array.prototype.join
transitioning javascript builtin ArrayPrototypeJoin(
context: Context, receiver: Object, ...arguments): Object {
transitioning javascript builtin
ArrayPrototypeJoin(context: Context, receiver: Object, ...arguments): Object {
const separator: Object = arguments[0];
return CycleProtectedArrayJoin(
false, receiver, separator, Undefined, Undefined);
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module array {
namespace array {
macro LoadWithHoleCheck<Elements: type>(
elements: FixedArrayBase, index: Smi): Object
labels IfHole;
......
......@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module array {
namespace array {
// https://tc39.github.io/ecma262/#sec-array.of
transitioning javascript builtin ArrayOf(implicit context: Context)(
receiver: Object, ...arguments): Object {
transitioning javascript builtin
ArrayOf(implicit context: Context)(receiver: Object, ...arguments): Object {
// 1. Let len be the actual number of arguments passed to this function.
const len: Smi = Convert<Smi>(arguments.length);
......
......@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module array {
namespace array {
macro LoadElement<ElementsAccessor: type, T: type>(
elements: FixedArrayBase, index: Smi): T;
LoadElement<FastPackedSmiElements, Smi>(
elements: FixedArrayBase, index: Smi): Smi {
LoadElement<FastPackedSmiElements, Smi>(elements: FixedArrayBase, index: Smi):
Smi {
const elems: FixedArray = UnsafeCast<FixedArray>(elements);
return UnsafeCast<Smi>(elems[index]);
}
......@@ -70,8 +70,8 @@ module array {
}
}
transitioning macro GenericArrayReverse(
context: Context, receiver: Object): Object {
transitioning macro GenericArrayReverse(context: Context, receiver: Object):
Object {
// 1. Let O be ? ToObject(this value).
const object: JSReceiver = ToObject_Inline(context, receiver);
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module array {
namespace array {
macro HandleSimpleArgumentsSlice(
context: Context, args: JSArgumentsObjectWithLength, start: Smi,
count: Smi): JSArray
......@@ -82,8 +82,8 @@ module array {
}
macro HandleFastSlice(
context: Context, o: Object, startNumber: Number, countNumber: Number):
JSArray
context: Context, o: Object, startNumber: Number,
countNumber: Number): JSArray
labels Bailout {
const start: Smi = Cast<Smi>(startNumber) otherwise Bailout;
const count: Smi = Cast<Smi>(countNumber) otherwise Bailout;
......@@ -118,8 +118,8 @@ module array {
}
// https://tc39.github.io/ecma262/#sec-array.prototype.slice
transitioning javascript builtin ArraySlice(
context: Context, receiver: Object, ...arguments): Object {
transitioning javascript builtin
ArraySlice(context: Context, receiver: Object, ...arguments): Object {
// Handle array cloning case if the receiver is a fast array.
if (arguments.length == 0) {
typeswitch (receiver) {
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module array {
namespace array {
// Given {elements}, we want to create a non-zero length array of type
// FixedArrayType. Most of this behavior is outsourced to ExtractFixedArray(),
// but the special case of wanting to have a FixedDoubleArray when given a
......@@ -54,8 +54,7 @@ module array {
macro FastSplice<FixedArrayType: type, ElementType: type>(
args: constexpr Arguments, a: JSArray, length: Smi, newLength: Smi,
lengthDelta: Smi, actualStart: Smi, insertCount: Smi,
actualDeleteCount: Smi): void
labels Bailout {
actualDeleteCount: Smi): void labels Bailout {
// Make sure elements are writable.
EnsureWriteableFastElements(a);
......@@ -349,8 +348,8 @@ module array {
}
// https://tc39.github.io/ecma262/#sec-array.prototype.splice
transitioning javascript builtin ArraySplice(
context: Context, receiver: Object, ...arguments): Object {
transitioning javascript builtin
ArraySplice(context: Context, receiver: Object, ...arguments): Object {
// 1. Let O be ? ToObject(this value).
const o: JSReceiver = ToObject(context, receiver);
......
......@@ -2,12 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module array {
namespace array {
extern builtin ArrayUnshift(Context, JSFunction, Object, int32);
macro TryFastArrayUnshift(
context: Context, receiver: Object, arguments: constexpr Arguments):
never
context: Context, receiver: Object, arguments: constexpr Arguments): never
labels Slow {
const array: FastJSArray = Cast<FastJSArray>(receiver) otherwise Slow;
EnsureWriteableFastElements(array);
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module array {
namespace array {
// Naming convention from elements.cc. We have a similar intent but implement
// fastpaths using generics instead of using a class hierarchy for elements
// kinds specific implementations.
......
......@@ -374,8 +374,8 @@ extern operator '<=' macro BranchIfNumberLessThanOrEqual(Number, Number): never
extern operator '>' macro BranchIfNumberGreaterThan(Number, Number): never
labels Taken, NotTaken;
extern operator '>=' macro BranchIfNumberGreaterThanOrEqual(Number, Number):
never
extern operator '>=' macro BranchIfNumberGreaterThanOrEqual(
Number, Number): never
labels Taken, NotTaken;
extern operator '==' macro WordEqual(Object, Object): bool;
......@@ -938,8 +938,7 @@ extern macro BranchIfFastJSArrayForCopy(Object, Context): never
labels Taken, NotTaken;
extern macro BranchIfNotFastJSArray(Object, Context): never
labels Taken, NotTaken;
macro BranchIfNotFastJSArrayForCopy(implicit context: Context)(o: Object):
never
macro BranchIfNotFastJSArrayForCopy(implicit context: Context)(o: Object): never
labels Taken, NotTaken {
BranchIfFastJSArrayForCopy(o, context) otherwise NotTaken, Taken;
}
......@@ -1017,7 +1016,7 @@ extern macro GetNumberDictionaryNumberOfElements(NumberDictionary): Smi;
extern macro BasicLoadNumberDictionaryElement(NumberDictionary, intptr): Object
labels NotData, IfHole;
extern macro BasicStoreNumberDictionaryElement(NumberDictionary, intptr, Object)
labels NotData, IfHole, ReadOnly;
labels NotData, IfHole, ReadOnly;
extern macro IsFastElementsKind(ElementsKind): bool;
extern macro IsDoubleElementsKind(ElementsKind): bool;
......@@ -1165,9 +1164,8 @@ LoadElementNoHole<FixedDoubleArray>(a: JSArray, index: Smi): Object
}
}
extern macro TransitionElementsKind(JSObject, Map, ElementsKind, ElementsKind):
void
labels Bailout;
extern macro TransitionElementsKind(
JSObject, Map, ElementsKind, ElementsKind): void labels Bailout;
extern macro IsCallable(HeapObject): bool;
extern macro IsJSArray(HeapObject): bool;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module data_view {
namespace data_view {
extern operator '.buffer'
macro LoadJSArrayBufferViewBuffer(JSArrayBufferView): JSArrayBuffer;
extern operator '.byte_length'
......@@ -68,8 +68,8 @@ module data_view {
return IsDetachedBuffer(view.buffer);
}
macro ValidateDataView(
context: Context, o: Object, method: String): JSDataView {
macro ValidateDataView(context: Context, o: Object, method: String):
JSDataView {
try {
return Cast<JSDataView>(o) otherwise CastError;
}
......@@ -345,8 +345,8 @@ module data_view {
return result;
}
macro MakeBigInt(
lowWord: uint32, highWord: uint32, signed: constexpr bool): BigInt {
macro MakeBigInt(lowWord: uint32, highWord: uint32, signed: constexpr bool):
BigInt {
// A BigInt digit has the platform word size, so we only need one digit
// on 64-bit platforms but may need two on 32-bit.
if constexpr (Is64()) {
......@@ -537,8 +537,8 @@ module data_view {
extern macro TruncateFloat64ToFloat32(float64): float32;
extern macro TruncateFloat64ToWord32(float64): uint32;
extern macro DataViewBuiltinsAssembler::StoreWord8(
RawPtr, uintptr, uint32): void;
extern macro DataViewBuiltinsAssembler::StoreWord8(RawPtr, uintptr, uint32):
void;
macro StoreDataView8(buffer: JSArrayBuffer, offset: uintptr, value: uint32) {
StoreWord8(buffer.backing_store, offset, value & 0xFF);
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module iterator {
namespace iterator {
extern macro IteratorBuiltinsAssembler::GetIteratorMethod(
implicit context: Context)(Object): Object;
extern macro IteratorBuiltinsAssembler::GetIterator(
......@@ -26,8 +26,8 @@ module iterator {
extern macro IteratorBuiltinsAssembler::IterableToList(
implicit context: Context)(Object, Object): JSArray;
extern builtin IterableToListMayPreserveHoles(implicit context: Context)(
Object, Object);
extern builtin IterableToListWithSymbolLookup(implicit context: Context)(
Object);
extern builtin IterableToListMayPreserveHoles(implicit context:
Context)(Object, Object);
extern builtin IterableToListWithSymbolLookup(implicit context:
Context)(Object);
}
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module typed_array {
namespace typed_array {
extern runtime TypedArraySortFast(Context, Object): JSTypedArray;
extern macro TypedArrayBuiltinsAssembler::ValidateTypedArray(
Context, Object, constexpr string): JSTypedArray;
......
......@@ -63,7 +63,7 @@ namespace torque {
V(SpecializationDeclaration) \
V(ExternConstDeclaration) \
V(StructDeclaration) \
V(ModuleDeclaration) \
V(NamespaceDeclaration) \
V(ConstDeclaration)
#define AST_CALLABLE_NODE_KIND_LIST(V) \
......@@ -151,11 +151,11 @@ struct Statement : AstNode {
DEFINE_AST_NODE_INNER_BOILERPLATE(Statement)
};
class Module;
class Namespace;
struct ModuleDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(ModuleDeclaration)
ModuleDeclaration(SourcePosition pos, std::string name,
struct NamespaceDeclaration : Declaration {
DEFINE_AST_NODE_LEAF_BOILERPLATE(NamespaceDeclaration)
NamespaceDeclaration(SourcePosition pos, std::string name,
std::vector<Declaration*> declarations)
: Declaration(kKind, pos),
declarations(std::move(declarations)),
......
......@@ -99,7 +99,8 @@ void CSAGenerator::EmitInstruction(
instruction.external_name + ").code()))");
}
void CSAGenerator::EmitInstruction(const ModuleConstantInstruction& instruction,
void CSAGenerator::EmitInstruction(
const NamespaceConstantInstruction& instruction,
Stack<std::string>* stack) {
const Type* type = instruction.constant->type();
std::vector<std::string> results;
......
......@@ -41,26 +41,26 @@ class Declarable {
public:
virtual ~Declarable() = default;
enum Kind {
kModule,
kNamespace,
kMacro,
kBuiltin,
kRuntimeFunction,
kGeneric,
kTypeAlias,
kExternConstant,
kModuleConstant
kNamespaceConstant
};
Kind kind() const { return kind_; }
bool IsModule() const { return kind() == kModule; }
bool IsNamespace() const { return kind() == kNamespace; }
bool IsMacro() const { return kind() == kMacro; }
bool IsBuiltin() const { return kind() == kBuiltin; }
bool IsRuntimeFunction() const { return kind() == kRuntimeFunction; }
bool IsGeneric() const { return kind() == kGeneric; }
bool IsTypeAlias() const { return kind() == kTypeAlias; }
bool IsExternConstant() const { return kind() == kExternConstant; }
bool IsModuleConstant() const { return kind() == kModuleConstant; }
bool IsValue() const { return IsExternConstant() || IsModuleConstant(); }
bool IsScope() const { return IsModule() || IsCallable(); }
bool IsNamespaceConstant() const { return kind() == kNamespaceConstant; }
bool IsValue() const { return IsExternConstant() || IsNamespaceConstant(); }
bool IsScope() const { return IsNamespace() || IsCallable(); }
bool IsCallable() const {
return IsMacro() || IsBuiltin() || IsRuntimeFunction();
}
......@@ -143,11 +143,11 @@ class Scope : public Declarable {
std::unordered_map<std::string, std::vector<Declarable*>> declarations_;
};
class Module : public Scope {
class Namespace : public Scope {
public:
DECLARE_DECLARABLE_BOILERPLATE(Module, module);
explicit Module(const std::string& name)
: Scope(Declarable::kModule), name_(name) {}
DECLARE_DECLARABLE_BOILERPLATE(Namespace, namespace);
explicit Namespace(const std::string& name)
: Scope(Declarable::kNamespace), name_(name) {}
const std::string& name() const { return name_; }
std::string ExternalName() const {
return CamelifyString(name()) + "BuiltinsFromDSLAssembler";
......@@ -163,11 +163,11 @@ class Module : public Scope {
std::stringstream source_stream_;
};
inline Module* CurrentModule() {
inline Namespace* CurrentNamespace() {
Scope* scope = CurrentScope::Get();
while (true) {
if (Module* m = Module::DynamicCast(scope)) {
return m;
if (Namespace* n = Namespace::DynamicCast(scope)) {
return n;
}
scope = scope->ParentScope();
}
......@@ -196,21 +196,21 @@ class Value : public Declarable {
base::Optional<VisitResult> value_;
};
class ModuleConstant : public Value {
class NamespaceConstant : public Value {
public:
DECLARE_DECLARABLE_BOILERPLATE(ModuleConstant, constant);
DECLARE_DECLARABLE_BOILERPLATE(NamespaceConstant, constant);
const std::string& constant_name() const { return constant_name_; }
Expression* body() { return body_; }
std::string ExternalAssemblerName() const {
return Module::cast(ParentScope())->ExternalName();
return Namespace::cast(ParentScope())->ExternalName();
}
private:
friend class Declarations;
explicit ModuleConstant(std::string constant_name, const Type* type,
explicit NamespaceConstant(std::string constant_name, const Type* type,
Expression* body)
: Value(Declarable::kModuleConstant, type, constant_name),
: Value(Declarable::kNamespaceConstant, type, constant_name),
constant_name_(std::move(constant_name)),
body_(body) {}
......
......@@ -143,7 +143,7 @@ void DeclarationVisitor::Visit(TorqueMacroDeclaration* decl,
}
void DeclarationVisitor::Visit(ConstDeclaration* decl) {
Declarations::DeclareModuleConstant(
Declarations::DeclareNamespaceConstant(
decl->name, Declarations::GetType(decl->type), decl->expression);
}
......@@ -272,10 +272,10 @@ void DeclarationVisitor::DeclareSpecializedTypes(const SpecializationKey& key) {
Signature DeclarationVisitor::MakeSpecializedSignature(
const SpecializationKey& key) {
CurrentScope::Scope generic_scope(key.generic->ParentScope());
// Create a temporary fake-module just to temporarily declare the
// Create a temporary fake-namespace just to temporarily declare the
// specialization aliases for the generic types to create a signature.
Module tmp_module("_tmp");
CurrentScope::Scope tmp_module_scope(&tmp_module);
Namespace tmp_namespace("_tmp");
CurrentScope::Scope tmp_namespace_scope(&tmp_namespace);
DeclareSpecializedTypes(key);
return MakeSignature(key.generic->declaration()->callable->signature.get());
}
......
......@@ -22,24 +22,24 @@ namespace torque {
class DeclarationVisitor : public FileVisitor {
public:
void Visit(Ast* ast) {
CurrentScope::Scope current_namespace(GlobalContext::GetDefaultModule());
CurrentScope::Scope current_namespace(GlobalContext::GetDefaultNamespace());
for (Declaration* child : ast->declarations()) Visit(child);
}
void Visit(Declaration* decl);
Module* GetOrCreateModule(const std::string& name) {
std::vector<Module*> existing_modules = FilterDeclarables<Module>(
Namespace* GetOrCreateNamespace(const std::string& name) {
std::vector<Namespace*> existing_namespaces = FilterDeclarables<Namespace>(
Declarations::TryLookupShallow(QualifiedName(name)));
if (existing_modules.empty()) {
return Declarations::DeclareModule(name);
if (existing_namespaces.empty()) {
return Declarations::DeclareNamespace(name);
}
DCHECK_EQ(1, existing_modules.size());
return existing_modules.front();
DCHECK_EQ(1, existing_namespaces.size());
return existing_namespaces.front();
}
void Visit(ModuleDeclaration* decl) {
CurrentScope::Scope current_scope(GetOrCreateModule(decl->name));
void Visit(NamespaceDeclaration* decl) {
CurrentScope::Scope current_scope(GetOrCreateNamespace(decl->name));
for (Declaration* child : decl->declarations) Visit(child);
}
......
......@@ -50,7 +50,7 @@ void CheckAlreadyDeclared(const std::string& name, const char* new_type) {
std::vector<Declarable*> Declarations::LookupGlobalScope(
const std::string& name) {
std::vector<Declarable*> d =
GlobalContext::GetDefaultModule()->Lookup(QualifiedName(name));
GlobalContext::GetDefaultNamespace()->Lookup(QualifiedName(name));
if (d.empty()) {
std::stringstream s;
s << "cannot find \"" << name << "\" in global scope";
......@@ -138,8 +138,8 @@ Generic* Declarations::LookupUniqueGeneric(const QualifiedName& name) {
"generic");
}
Module* Declarations::DeclareModule(const std::string& name) {
return Declare(name, std::unique_ptr<Module>(new Module(name)));
Namespace* Declarations::DeclareNamespace(const std::string& name) {
return Declare(name, std::unique_ptr<Namespace>(new Namespace(name)));
}
const AbstractType* Declarations::DeclareAbstractType(
......@@ -174,7 +174,7 @@ Macro* Declarations::CreateMacro(
base::Optional<std::string> external_assembler_name, Signature signature,
bool transitioning, base::Optional<Statement*> body) {
if (!external_assembler_name) {
external_assembler_name = CurrentModule()->ExternalName();
external_assembler_name = CurrentNamespace()->ExternalName();
}
return RegisterDeclarable(std::unique_ptr<Macro>(
new Macro(std::move(external_name), std::move(readable_name),
......@@ -239,11 +239,10 @@ void Declarations::DeclareExternConstant(const std::string& name,
Declare(name, std::unique_ptr<Declarable>(result));
}
ModuleConstant* Declarations::DeclareModuleConstant(const std::string& name,
const Type* type,
Expression* body) {
NamespaceConstant* Declarations::DeclareNamespaceConstant(
const std::string& name, const Type* type, Expression* body) {
CheckAlreadyDeclared<Value>(name, "constant");
ModuleConstant* result = new ModuleConstant(name, type, body);
NamespaceConstant* result = new NamespaceConstant(name, type, body);
Declare(name, std::unique_ptr<Declarable>(result));
return result;
}
......
......@@ -72,7 +72,7 @@ class Declarations {
static std::vector<Generic*> LookupGeneric(const std::string& name);
static Generic* LookupUniqueGeneric(const QualifiedName& name);
static Module* DeclareModule(const std::string& name);
static Namespace* DeclareNamespace(const std::string& name);
static const AbstractType* DeclareAbstractType(
const std::string& name, bool transient, const std::string& generated,
......@@ -110,7 +110,7 @@ class Declarations {
static void DeclareExternConstant(const std::string& name, const Type* type,
std::string value);
static ModuleConstant* DeclareModuleConstant(const std::string& name,
static NamespaceConstant* DeclareNamespaceConstant(const std::string& name,
const Type* type,
Expression* body);
......
......@@ -19,9 +19,10 @@ class GlobalContext : public ContextualClass<GlobalContext> {
CurrentScope::Scope current_scope(nullptr);
CurrentSourcePosition::Scope current_source_position(
SourcePosition{CurrentSourceFile::Get(), -1, -1});
default_module_ = RegisterDeclarable(base::make_unique<Module>("base"));
default_namespace_ =
RegisterDeclarable(base::make_unique<Namespace>("base"));
}
static Module* GetDefaultModule() { return Get().default_module_; }
static Namespace* GetDefaultNamespace() { return Get().default_namespace_; }
template <class T>
T* RegisterDeclarable(std::unique_ptr<T> d) {
T* ptr = d.get();
......@@ -33,11 +34,11 @@ class GlobalContext : public ContextualClass<GlobalContext> {
return Get().declarables_;
}
static const std::vector<Module*> GetModules() {
std::vector<Module*> result;
static const std::vector<Namespace*> GetNamespaces() {
std::vector<Namespace*> result;
for (auto& declarable : AllDeclarables()) {
if (Module* m = Module::DynamicCast(declarable.get())) {
result.push_back(m);
if (Namespace* n = Namespace::DynamicCast(declarable.get())) {
result.push_back(n);
}
}
return result;
......@@ -49,7 +50,7 @@ class GlobalContext : public ContextualClass<GlobalContext> {
private:
bool verbose_;
Module* default_module_;
Namespace* default_namespace_;
Ast ast_;
std::vector<std::unique_ptr<Declarable>> declarables_;
};
......
......@@ -45,9 +45,9 @@ const Type* ImplementationVisitor::Visit(Statement* stmt) {
return result;
}
void ImplementationVisitor::BeginModuleFile(Module* module) {
std::ostream& source = module->source_stream();
std::ostream& header = module->header_stream();
void ImplementationVisitor::BeginNamespaceFile(Namespace* nspace) {
std::ostream& source = nspace->source_stream();
std::ostream& header = nspace->header_stream();
source << "#include \"src/objects/arguments.h\"\n";
source << "#include \"src/builtins/builtins-utils-gen.h\"\n";
......@@ -58,11 +58,11 @@ void ImplementationVisitor::BeginModuleFile(Module* module) {
source << "#include \"src/objects.h\"\n";
source << "#include \"src/objects/bigint.h\"\n";
for (Module* m : GlobalContext::Get().GetModules()) {
for (Namespace* n : GlobalContext::Get().GetNamespaces()) {
source << "#include \"torque-generated/builtins-" +
DashifyString(m->name()) + "-from-dsl-gen.h\"\n";
if (m != GlobalContext::GetDefaultModule()) {
source << "#include \"src/builtins/builtins-" + DashifyString(m->name()) +
DashifyString(n->name()) + "-from-dsl-gen.h\"\n";
if (n != GlobalContext::GetDefaultNamespace()) {
source << "#include \"src/builtins/builtins-" + DashifyString(n->name()) +
"-gen.h\"\n";
}
}
......@@ -77,7 +77,7 @@ void ImplementationVisitor::BeginModuleFile(Module* module) {
<< "using ScopedCatch = compiler::CodeAssemblerScopedExceptionHandler;\n"
<< "\n";
std::string upper_name(module->name());
std::string upper_name(nspace->name());
transform(upper_name.begin(), upper_name.end(), upper_name.begin(),
::toupper);
std::string headerDefine =
......@@ -91,11 +91,11 @@ void ImplementationVisitor::BeginModuleFile(Module* module) {
<< "namespace internal {\n"
<< "\n";
header << "class " << module->ExternalName()
header << "class " << nspace->ExternalName()
<< ": public TorqueAssembler {\n";
header << " public:\n";
header
<< " explicit " << module->ExternalName()
<< " explicit " << nspace->ExternalName()
<< "(compiler::CodeAssemblerState* state) : TorqueAssembler(state) {}\n";
header << "\n";
......@@ -106,11 +106,11 @@ void ImplementationVisitor::BeginModuleFile(Module* module) {
header << " using SloppyTNode = compiler::SloppyTNode<T>;\n\n";
}
void ImplementationVisitor::EndModuleFile(Module* module) {
std::ostream& source = module->source_stream();
std::ostream& header = module->header_stream();
void ImplementationVisitor::EndNamespaceFile(Namespace* nspace) {
std::ostream& source = nspace->source_stream();
std::ostream& header = nspace->header_stream();
std::string upper_name(module->name());
std::string upper_name(nspace->name());
transform(upper_name.begin(), upper_name.end(), upper_name.begin(),
::toupper);
std::string headerDefine =
......@@ -127,7 +127,7 @@ void ImplementationVisitor::EndModuleFile(Module* module) {
header << "#endif // " << headerDefine << "\n";
}
void ImplementationVisitor::Visit(ModuleConstant* decl) {
void ImplementationVisitor::Visit(NamespaceConstant* decl) {
Signature signature{{}, base::nullopt, {{}, false}, 0, decl->type(), {}};
const std::string& name = decl->name();
......@@ -138,7 +138,7 @@ void ImplementationVisitor::Visit(ModuleConstant* decl) {
header_out() << ";\n";
GenerateFunctionDeclaration(source_out(),
CurrentModule()->ExternalName() + "::", name,
CurrentNamespace()->ExternalName() + "::", name,
signature, {});
source_out() << " {\n";
......@@ -215,7 +215,7 @@ void ImplementationVisitor::Visit(Macro* macro) {
header_out() << ";\n";
GenerateMacroFunctionDeclaration(
source_out(), CurrentModule()->ExternalName() + "::", macro);
source_out(), CurrentNamespace()->ExternalName() + "::", macro);
source_out() << " {\n";
Stack<std::string> lowered_parameters;
......@@ -339,7 +339,7 @@ void ImplementationVisitor::Visit(Builtin* builtin) {
const std::string& name = builtin->ExternalName();
const Signature& signature = builtin->signature();
source_out() << "TF_BUILTIN(" << name << ", "
<< CurrentModule()->ExternalName() << ") {\n";
<< CurrentNamespace()->ExternalName() << ") {\n";
CurrentCallable::Scope current_callable(builtin);
Stack<const Type*> parameter_types;
......@@ -1167,14 +1167,14 @@ const Type* ImplementationVisitor::Visit(ForLoopStatement* stmt) {
}
void ImplementationVisitor::GenerateImplementation(const std::string& dir,
Module* module) {
std::string new_source(module->source());
Namespace* nspace) {
std::string new_source(nspace->source());
std::string base_file_name =
"builtins-" + DashifyString(module->name()) + "-from-dsl-gen";
"builtins-" + DashifyString(nspace->name()) + "-from-dsl-gen";
std::string source_file_name = dir + "/" + base_file_name + ".cc";
ReplaceFileContentsIfDifferent(source_file_name, new_source);
std::string new_header(module->header());
std::string new_header(nspace->header());
std::string header_file_name = dir + "/" + base_file_name + ".h";
ReplaceFileContentsIfDifferent(header_file_name, new_header);
}
......@@ -1197,7 +1197,7 @@ void ImplementationVisitor::GenerateFunctionDeclaration(
std::string return_type_name(signature.return_type->GetGeneratedTypeName());
if (const StructType* struct_type =
StructType::DynamicCast(signature.return_type)) {
o << struct_type->module()->ExternalName() << "::";
o << struct_type->nspace()->ExternalName() << "::";
} else if (macro_prefix != "" && (return_type_name.length() > 5) &&
(return_type_name.substr(0, 5) == "TNode")) {
o << "compiler::";
......@@ -1520,18 +1520,18 @@ LocationReference ImplementationVisitor::GetLocationReference(
}
}
Value* value = Declarations::LookupValue(name);
if (auto* constant = ModuleConstant::DynamicCast(value)) {
if (auto* constant = NamespaceConstant::DynamicCast(value)) {
if (constant->type()->IsConstexpr()) {
return LocationReference::Temporary(
VisitResult(constant->type(), constant->constant_name() + "()"),
"module constant " + expr->name);
"namespace constant " + expr->name);
}
assembler().Emit(ModuleConstantInstruction{constant});
assembler().Emit(NamespaceConstantInstruction{constant});
StackRange stack_range =
assembler().TopRange(LoweredSlotCount(constant->type()));
return LocationReference::Temporary(
VisitResult(constant->type(), stack_range),
"module constant " + expr->name);
"namespace constant " + expr->name);
}
ExternConstant* constant = ExternConstant::cast(value);
return LocationReference::Temporary(constant->value(),
......@@ -2016,11 +2016,11 @@ void ImplementationVisitor::Visit(Declarable* declarable) {
return Visit(Builtin::cast(declarable));
case Declarable::kTypeAlias:
return Visit(TypeAlias::cast(declarable));
case Declarable::kModuleConstant:
return Visit(ModuleConstant::cast(declarable));
case Declarable::kNamespaceConstant:
return Visit(NamespaceConstant::cast(declarable));
case Declarable::kRuntimeFunction:
case Declarable::kExternConstant:
case Declarable::kModule:
case Declarable::kNamespace:
case Declarable::kGeneric:
return;
}
......
......@@ -230,7 +230,7 @@ class ImplementationVisitor : public FileVisitor {
void Visit(TypeAlias* decl);
void Visit(Macro* macro);
void Visit(Builtin* builtin);
void Visit(ModuleConstant* decl);
void Visit(NamespaceConstant* decl);
VisitResult Visit(CallExpression* expr, bool is_tail = false);
const Type* Visit(TailCallStatement* stmt);
......@@ -264,10 +264,10 @@ class ImplementationVisitor : public FileVisitor {
const Type* Visit(DebugStatement* stmt);
const Type* Visit(AssertStatement* stmt);
void BeginModuleFile(Module* module);
void EndModuleFile(Module* module);
void BeginNamespaceFile(Namespace* nspace);
void EndNamespaceFile(Namespace* nspace);
void GenerateImplementation(const std::string& dir, Module* module);
void GenerateImplementation(const std::string& dir, Namespace* nspace);
DECLARE_CONTEXTUAL_VARIABLE(ValueBindingsManager,
BindingsManager<LocalValue>);
......@@ -423,9 +423,9 @@ class ImplementationVisitor : public FileVisitor {
size_t i);
std::string ExternalParameterName(const std::string& name);
std::ostream& source_out() { return CurrentModule()->source_stream(); }
std::ostream& source_out() { return CurrentNamespace()->source_stream(); }
std::ostream& header_out() { return CurrentModule()->header_stream(); }
std::ostream& header_out() { return CurrentNamespace()->header_stream(); }
CfgAssembler& assembler() { return *assembler_; }
......
......@@ -65,8 +65,8 @@ void PushCodePointerInstruction::TypeInstruction(Stack<const Type*>* stack,
stack->Push(type);
}
void ModuleConstantInstruction::TypeInstruction(Stack<const Type*>* stack,
ControlFlowGraph* cfg) const {
void NamespaceConstantInstruction::TypeInstruction(
Stack<const Type*>* stack, ControlFlowGraph* cfg) const {
stack->PushMany(LowerType(constant->type()));
}
......
......@@ -20,7 +20,7 @@ class Block;
class Builtin;
class ControlFlowGraph;
class Macro;
class ModuleConstant;
class NamespaceConstant;
class RuntimeFunction;
#define TORQUE_INSTRUCTION_LIST(V) \
......@@ -30,7 +30,7 @@ class RuntimeFunction;
V(PushUninitializedInstruction) \
V(PushCodePointerInstruction) \
V(CallCsaMacroInstruction) \
V(ModuleConstantInstruction) \
V(NamespaceConstantInstruction) \
V(CallCsaMacroAndBranchInstruction) \
V(CallBuiltinInstruction) \
V(CallRuntimeInstruction) \
......@@ -179,12 +179,12 @@ struct PushCodePointerInstruction : InstructionBase {
const Type* type;
};
struct ModuleConstantInstruction : InstructionBase {
struct NamespaceConstantInstruction : InstructionBase {
TORQUE_INSTRUCTION_BOILERPLATE()
explicit ModuleConstantInstruction(ModuleConstant* constant)
explicit NamespaceConstantInstruction(NamespaceConstant* constant)
: constant(constant) {}
ModuleConstant* constant;
NamespaceConstant* constant;
};
struct CallCsaMacroInstruction : InstructionBase {
......
......@@ -439,7 +439,7 @@ base::Optional<ParseResult> MakeTorqueBuiltinDeclaration(
base::Optional<ParseResult> MakeConstDeclaration(
ParseResultIterator* child_results) {
auto name = child_results->NextAs<std::string>();
if (!IsValidModuleConstName(name)) {
if (!IsValidNamespaceConstName(name)) {
NamingConventionError("Constant", name, "kUpperCamelCase");
}
......@@ -485,15 +485,15 @@ base::Optional<ParseResult> MakeTypeDeclaration(
return ParseResult{result};
}
base::Optional<ParseResult> MakeModuleDeclaration(
base::Optional<ParseResult> MakeNamespaceDeclaration(
ParseResultIterator* child_results) {
auto name = child_results->NextAs<std::string>();
if (!IsSnakeCase(name)) {
NamingConventionError("Module", name, "snake_case");
NamingConventionError("Namespace", name, "snake_case");
}
auto declarations = child_results->NextAs<std::vector<Declaration*>>();
Declaration* result =
MakeNode<ModuleDeclaration>(std::move(name), std::move(declarations));
MakeNode<NamespaceDeclaration>(std::move(name), std::move(declarations));
return ParseResult{result};
}
......@@ -1462,12 +1462,12 @@ struct TorqueGrammar : Grammar {
MakeStructDeclaration)};
// Result: Declaration*
Symbol moduleDeclaration = {
Rule({Token("module"), &identifier, Token("{"),
Symbol namespaceDeclaration = {
Rule({Token("namespace"), &identifier, Token("{"),
List<Declaration*>(&declaration), Token("}")},
MakeModuleDeclaration)};
MakeNamespaceDeclaration)};
Symbol file = {Rule({&file, &moduleDeclaration}, AddGlobalDeclaration),
Symbol file = {Rule({&file, &namespaceDeclaration}, AddGlobalDeclaration),
Rule({&file, &declaration}, AddGlobalDeclaration), Rule({})};
};
......
......@@ -58,8 +58,8 @@ int WrappedMain(int argc, const char** argv) {
DeclarationVisitor().Visit(GlobalContext::Get().ast());
ImplementationVisitor visitor;
for (Module* module : GlobalContext::Get().GetModules()) {
visitor.BeginModuleFile(module);
for (Namespace* n : GlobalContext::Get().GetNamespaces()) {
visitor.BeginNamespaceFile(n);
}
visitor.VisitAllDeclarables();
......@@ -68,9 +68,9 @@ int WrappedMain(int argc, const char** argv) {
output_header_path += "/builtin-definitions-from-dsl.h";
visitor.GenerateBuiltinDefinitions(output_header_path);
for (Module* module : GlobalContext::Get().GetModules()) {
visitor.EndModuleFile(module);
visitor.GenerateImplementation(output_directory, module);
for (Namespace* n : GlobalContext::Get().GetNamespaces()) {
visitor.EndNamespaceFile(n);
visitor.GenerateImplementation(output_directory, n);
}
}
......
......@@ -30,7 +30,7 @@ class TypeOracle : public ContextualClass<TypeOracle> {
static const StructType* GetStructType(
const std::string& name, const std::vector<NameAndType>& fields) {
StructType* result = new StructType(CurrentModule(), name, fields);
StructType* result = new StructType(CurrentNamespace(), name, fields);
Get().struct_types_.push_back(std::unique_ptr<StructType>(result));
return result;
}
......
......@@ -194,7 +194,7 @@ std::string StructType::ToExplicitString() const {
}
std::string StructType::GetGeneratedTypeName() const {
return module_->ExternalName() + "::" + GetStructName();
return namespace_->ExternalName() + "::" + GetStructName();
}
void PrintSignature(std::ostream& os, const Signature& sig, bool with_names) {
......
......@@ -34,7 +34,7 @@ static const char* const CONST_INT32_TYPE_STRING = "constexpr int32";
static const char* const CONST_FLOAT64_TYPE_STRING = "constexpr float64";
class Value;
class Module;
class Namespace;
class TypeBase {
public:
......@@ -375,20 +375,20 @@ class StructType final : public Type {
ReportError(s.str());
}
const std::string& name() const { return name_; }
Module* module() const { return module_; }
Namespace* nspace() const { return namespace_; }
private:
friend class TypeOracle;
StructType(Module* module, const std::string& name,
StructType(Namespace* nspace, const std::string& name,
const std::vector<NameAndType>& fields)
: Type(Kind::kStructType, nullptr),
module_(module),
namespace_(nspace),
name_(name),
fields_(fields) {}
const std::string& GetStructName() const { return name_; }
Module* module_;
Namespace* namespace_;
std::string name_;
std::vector<NameAndType> fields_;
};
......
......@@ -109,7 +109,7 @@ bool ContainsUpperCase(const std::string& s) {
return std::any_of(s.begin(), s.end(), [](char c) { return isupper(c); });
}
// Torque has some module constants that are used like language level
// Torque has some namespace constants that are used like language level
// keywords, e.g.: 'True', 'Undefined', etc.
// These do not need to follow the default naming convention for constants.
bool IsKeywordLikeName(const std::string& s) {
......@@ -149,7 +149,7 @@ bool IsSnakeCase(const std::string& s) {
return !ContainsUpperCase(s);
}
bool IsValidModuleConstName(const std::string& s) {
bool IsValidNamespaceConstName(const std::string& s) {
if (s.empty()) return false;
if (IsKeywordLikeName(s)) return true;
......
......@@ -42,7 +42,7 @@ void NamingConventionError(const std::string& type, const std::string& name,
bool IsLowerCamelCase(const std::string& s);
bool IsUpperCamelCase(const std::string& s);
bool IsSnakeCase(const std::string& s);
bool IsValidModuleConstName(const std::string& s);
bool IsValidNamespaceConstName(const std::string& s);
bool IsValidTypeName(const std::string& s);
[[noreturn]] void ReportErrorString(const std::string& error);
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module test {
namespace test {
macro ElementsKindTestHelper1(kind: constexpr ElementsKind): bool {
if constexpr ((kind == UINT8_ELEMENTS) || (kind == UINT16_ELEMENTS)) {
return true;
......
......@@ -13,7 +13,7 @@
//
// https://github.com/python/cpython/blob/master/Objects/listsort.txt
module array {
namespace array {
// All accessors bail to the GenericElementsAccessor if assumptions checked
// by "CanUseSameAccessor<>" are violated:
// Generic <- FastPackedSmi
......@@ -539,8 +539,8 @@ module array {
return result;
}
transitioning macro CallMergeAt(
context: Context, sortState: FixedArray, i: Smi)
transitioning macro
CallMergeAt(context: Context, sortState: FixedArray, i: Smi)
labels Bailout {
MergeAt(context, sortState, i);
EnsureSuccess(sortState) otherwise Bailout;
......@@ -803,8 +803,8 @@ module array {
// Merges the two runs at stack indices i and i + 1.
// Returns kFailure if we need to bailout, kSuccess otherwise.
transitioning builtin MergeAt(
context: Context, sortState: FixedArray, i: Smi): Smi {
transitioning builtin
MergeAt(context: Context, sortState: FixedArray, i: Smi): Smi {
const stackSize: Smi = GetPendingRunsSize(sortState);
// We are only allowed to either merge the two top-most runs, or leave
......@@ -882,8 +882,8 @@ module array {
}
}
macro LoadElementsOrTempArray(
useTempArray: Boolean, sortState: FixedArray): HeapObject {
macro LoadElementsOrTempArray(useTempArray: Boolean, sortState: FixedArray):
HeapObject {
return useTempArray == True ? GetTempArray(sortState) :
ReloadElements(sortState);
}
......@@ -1583,8 +1583,8 @@ module array {
// Regardless of invariants, merge all runs on the stack until only one
// remains. This is used at the end of the mergesort.
transitioning macro MergeForceCollapse(
context: Context, sortState: FixedArray)
transitioning macro
MergeForceCollapse(context: Context, sortState: FixedArray)
labels Bailout {
let pendingRuns: FixedArray =
UnsafeCast<FixedArray>(sortState[kPendingRunsIdx]);
......@@ -1627,8 +1627,8 @@ module array {
CanUseSameAccessor<GenericElementsAccessor>;
}
transitioning macro ArrayTimSortImpl(
context: Context, sortState: FixedArray, length: Smi)
transitioning macro
ArrayTimSortImpl(context: Context, sortState: FixedArray, length: Smi)
labels Bailout {
InitializeSortState(sortState);
......@@ -1671,8 +1671,8 @@ module array {
UnsafeCast<FixedArray>(sortState[kPendingRunsIdx]), 0) == length);
}
transitioning builtin ArrayTimSort(
context: Context, sortState: FixedArray, length: Smi): Object {
transitioning builtin
ArrayTimSort(context: Context, sortState: FixedArray, length: Smi): Object {
try {
ArrayTimSortImpl(context, sortState, length)
otherwise Slow;
......@@ -1705,8 +1705,8 @@ module array {
extern runtime PrepareElementsForSort(Context, Object, Number): Smi;
// https://tc39.github.io/ecma262/#sec-array.prototype.sort
transitioning javascript builtin ArrayPrototypeSort(
context: Context, receiver: Object, ...arguments): Object {
transitioning javascript builtin
ArrayPrototypeSort(context: Context, receiver: Object, ...arguments): Object {
// 1. If comparefn is not undefined and IsCallable(comparefn) is false,
// throw a TypeError exception.
const comparefnObj: Object = arguments[0];
......
......@@ -13,8 +13,6 @@ from subprocess import Popen, PIPE
def preprocess(input):
input = re.sub(r'(if\s+)constexpr(\s*\()', r'\1/*COxp*/\2', input)
input = re.sub(r'(\)\s*\:\s*\S+\s+)labels\s+',
r'\1,\n/*_LABELS_HOLD_*/ ', input)
input = re.sub(r'(\s+)operator\s*(\'[^\']+\')', r'\1/*_OPE \2*/', input)
# Mangle typeswitches to look like switch statements with the extra type
......@@ -50,7 +48,7 @@ def preprocess(input):
def postprocess(output):
output = re.sub(r'\/\*COxp\*\/', r'constexpr', output)
output = re.sub(r'(\S+)\s*: type([,>])', r'\1: type\2', output)
output = re.sub(r',([\n ]*)\/\*_LABELS_HOLD_\*\/', r'\1labels', output)
output = re.sub(r'(\n\s*)labels( [A-Z])', r'\1 labels\2', output)
output = re.sub(r'\/\*_OPE \'([^\']+)\'\*\/', r"operator '\1'", output)
output = re.sub(r'\/\*_TYPE\*\/(\s*)switch', r'typeswitch', output)
output = re.sub(r'case (\w+)\:\s*\/\*_TSXDEFERRED_\*\/',
......
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