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

[torque] use macro keyword for methods

This makes it obvious that methods are actually macros.
Also, in the future, we might allow methods that are actually builtins.

Bug: v8:7793
Change-Id: Ib641c4b5a222b27c67aa0c31fd3611ed4a11842c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1967330Reviewed-by: 's avatarMichael Stanton <mvstanton@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65455}
parent d2351143
......@@ -147,7 +147,7 @@ namespace array {
// The buffer is maintained and updated by Buffer.constructor, Buffer.Add(),
// Buffer.AddSeparators().
struct Buffer {
Add(implicit context: Context)(
macro Add(implicit context: Context)(
str: String, nofSeparators: intptr, separatorLength: intptr) {
// Add separators if necessary (at the beginning or more than one)
const writeSeparators: bool = this.index == 0 | nofSeparators > 1;
......@@ -161,7 +161,7 @@ namespace array {
IsOneByteStringInstanceType(str.instanceType) & this.isOneByte;
}
AddSeparators(implicit context: Context)(
macro AddSeparators(implicit context: Context)(
nofSeparators: intptr, separatorLength: intptr, write: bool) {
if (nofSeparators == 0 || separatorLength == 0) return;
......
......@@ -91,11 +91,11 @@ namespace array {
}
struct Vector {
ReportSkippedElement() {
macro ReportSkippedElement() {
this.skippedElements = true;
}
CreateJSArray(implicit context: Context)(validLength: Smi): JSArray {
macro CreateJSArray(implicit context: Context)(validLength: Smi): JSArray {
const length: Smi = this.fixedArray.length;
assert(validLength <= length);
let kind: ElementsKind = PACKED_SMI_ELEMENTS;
......@@ -147,7 +147,7 @@ namespace array {
return a;
}
StoreResult(implicit context: Context)(index: Smi, result: JSAny) {
macro StoreResult(implicit context: Context)(index: Smi, result: JSAny) {
typeswitch (result) {
case (s: Smi): {
this.fixedArray.objects[index] = s;
......
......@@ -5,11 +5,11 @@
namespace growable_fixed_array {
// TODO(pwong): Support FixedTypedArrays.
struct GrowableFixedArray {
Push(obj: Object) {
macro Push(obj: Object) {
this.EnsureCapacity();
this.array.objects[this.length++] = obj;
}
ResizeFixedArray(newCapacity: intptr): FixedArray {
macro ResizeFixedArray(newCapacity: intptr): FixedArray {
assert(this.length >= 0);
assert(newCapacity >= 0);
assert(newCapacity >= this.length);
......@@ -17,7 +17,7 @@ namespace growable_fixed_array {
return ExtractFixedArray(
this.array, first, this.length, newCapacity, kFixedArrays);
}
EnsureCapacity() {
macro EnsureCapacity() {
assert(this.length <= this.capacity);
if (this.capacity == this.length) {
// Growth rate is analog to JSObject::NewElementsCapacity:
......@@ -26,7 +26,7 @@ namespace growable_fixed_array {
this.array = this.ResizeFixedArray(this.capacity);
}
}
ToJSArray(implicit context: Context)(): JSArray {
macro ToJSArray(implicit context: Context)(): JSArray {
const nativeContext: NativeContext = LoadNativeContext(context);
const map: Map = LoadJSArrayElementsMap(PACKED_ELEMENTS, nativeContext);
const fixedArray: FixedArray = this.ResizeFixedArray(this.length);
......
......@@ -27,7 +27,7 @@ namespace torque_internal {
}
struct Slice<T: type> {
TryAtIndex(index: intptr):&T labels OutOfBounds {
macro TryAtIndex(index: intptr):&T labels OutOfBounds {
if (Convert<uintptr>(index) < Convert<uintptr>(this.length)) {
return UnsafeNewReference<T>(
this.object, this.offset + index * %SizeOf<T>());
......@@ -36,25 +36,25 @@ namespace torque_internal {
}
}
AtIndex(index: intptr):&T {
macro AtIndex(index: intptr):&T {
return this.TryAtIndex(index) otherwise unreachable;
}
AtIndex(index: uintptr):&T {
macro AtIndex(index: uintptr):&T {
return this.TryAtIndex(Convert<intptr>(index)) otherwise unreachable;
}
AtIndex(index: constexpr int31):&T {
macro AtIndex(index: constexpr int31):&T {
const i: intptr = Convert<intptr>(index);
return this.TryAtIndex(i) otherwise unreachable;
}
AtIndex(index: Smi):&T {
macro AtIndex(index: Smi):&T {
const i: intptr = Convert<intptr>(index);
return this.TryAtIndex(i) otherwise unreachable;
}
Iterator(): SliceIterator<T> {
macro Iterator(): SliceIterator<T> {
const end = this.offset + this.length * %SizeOf<T>();
return SliceIterator<T>{
object: this.object,
......@@ -81,11 +81,11 @@ namespace torque_internal {
}
struct SliceIterator<T: type> {
Empty(): bool {
macro Empty(): bool {
return this.start == this.end;
}
Next():&T labels NoMore {
macro Next():&T labels NoMore {
if (this.Empty()) {
goto NoMore;
} else {
......
......@@ -23,7 +23,7 @@ namespace typed_array {
@export
struct TypedArrayElementsInfo {
// Calculates the number of bytes required for specified number of elements.
CalculateByteLength(length: uintptr): uintptr labels IfInvalid {
macro CalculateByteLength(length: uintptr): uintptr labels IfInvalid {
if (length > kTypedArrayMaxLength) goto IfInvalid;
const maxArrayLength = kArrayBufferMaxByteLength >>> this.sizeLog2;
if (length > maxArrayLength) goto IfInvalid;
......@@ -33,7 +33,7 @@ namespace typed_array {
// Calculates the maximum number of elements supported by a specified number
// of bytes.
CalculateLength(byteLength: uintptr): uintptr labels IfInvalid {
macro CalculateLength(byteLength: uintptr): uintptr labels IfInvalid {
const length = byteLength >>> this.sizeLog2;
if (length > kTypedArrayMaxLength) goto IfInvalid;
return length;
......@@ -41,7 +41,7 @@ namespace typed_array {
// Determines if `bytes` (byte offset or length) cannot be evenly divided by
// element size.
IsUnaligned(bytes: uintptr): bool {
macro IsUnaligned(bytes: uintptr): bool {
// Exploits the fact the element size is a power of 2. Determining whether
// there is remainder (not aligned) can be achieved efficiently with bit
// masking. Shift is safe as sizeLog2 can be 3 at most (see
......@@ -90,20 +90,20 @@ namespace typed_array {
const kStoreFailureArrayDetached: Smi = 1;
struct TypedArrayAccessor {
LoadNumeric(
macro LoadNumeric(
context: Context, array: JSTypedArray, index: uintptr): Numeric {
const loadfn: LoadNumericFn = this.loadNumericFn;
return loadfn(context, array, index);
}
StoreNumeric(
macro StoreNumeric(
context: Context, array: JSTypedArray, index: uintptr, value: Numeric) {
const storefn: StoreNumericFn = this.storeNumericFn;
const result = storefn(context, array, index, value);
assert(result == kStoreSucceded);
}
StoreJSAny(
macro StoreJSAny(
context: Context, array: JSTypedArray, index: uintptr, value: JSAny)
labels IfDetached {
const storefn: StoreJSAnyFn = this.storeJSAnyFn;
......@@ -173,20 +173,20 @@ namespace typed_array {
}
struct AttachedJSTypedArrayWitness {
Get(): AttachedJSTypedArray {
macro Get(): AttachedJSTypedArray {
return this.unstable;
}
GetStable(): JSTypedArray {
macro GetStable(): JSTypedArray {
return this.stable;
}
Recheck() labels Detached {
macro Recheck() labels Detached {
if (IsDetachedBuffer(this.stable.buffer)) goto Detached;
this.unstable = %RawDownCast<AttachedJSTypedArray>(this.stable);
}
Load(implicit context: Context)(k: uintptr): JSAny {
macro Load(implicit context: Context)(k: uintptr): JSAny {
const lf: LoadNumericFn = this.loadfn;
return lf(context, this.unstable, k);
}
......
......@@ -9,7 +9,7 @@ extern class JSArrayIterator extends JSObject {
}
extern class JSArray extends JSObject {
IsEmpty(): bool {
macro IsEmpty(): bool {
return this.length == 0;
}
length: Number;
......@@ -141,11 +141,11 @@ macro TorqueCopyElements(
extern builtin CloneFastJSArray(Context, FastJSArrayForCopy): JSArray;
struct FastJSArrayWitness {
Get(): FastJSArray {
macro Get(): FastJSArray {
return this.unstable;
}
Recheck() labels CastError {
macro Recheck() labels CastError {
if (this.stable.map != this.map) goto CastError;
// We don't need to check elements kind or whether the prototype
// has changed away from the default JSArray prototype, because
......@@ -157,7 +157,7 @@ struct FastJSArrayWitness {
this.unstable = %RawDownCast<FastJSArray>(this.stable);
}
LoadElementNoHole(implicit context: Context)(k: Smi): JSAny
macro LoadElementNoHole(implicit context: Context)(k: Smi): JSAny
labels FoundHole {
if (this.hasDoubles) {
return LoadElementNoHole<FixedDoubleArray>(this.unstable, k)
......@@ -168,7 +168,7 @@ struct FastJSArrayWitness {
}
}
StoreHole(k: Smi) {
macro StoreHole(k: Smi) {
if (this.hasDoubles) {
const elements = Cast<FixedDoubleArray>(this.unstable.elements)
otherwise unreachable;
......@@ -180,7 +180,7 @@ struct FastJSArrayWitness {
}
}
LoadElementOrUndefined(implicit context: Context)(k: Smi): JSAny {
macro LoadElementOrUndefined(implicit context: Context)(k: Smi): JSAny {
try {
return this.LoadElementNoHole(k) otherwise FoundHole;
}
......@@ -189,18 +189,18 @@ struct FastJSArrayWitness {
}
}
EnsureArrayPushable(implicit context: Context)() labels Failed {
macro EnsureArrayPushable(implicit context: Context)() labels Failed {
EnsureArrayPushable(this.map) otherwise Failed;
array::EnsureWriteableFastElements(this.unstable);
this.arrayIsPushable = true;
}
ChangeLength(newLength: Smi) {
macro ChangeLength(newLength: Smi) {
assert(this.arrayIsPushable);
this.unstable.length = newLength;
}
Push(value: JSAny) labels Failed {
macro Push(value: JSAny) labels Failed {
assert(this.arrayIsPushable);
if (this.hasDoubles) {
BuildAppendJSArray(HOLEY_DOUBLE_ELEMENTS, this.unstable, value)
......@@ -217,7 +217,7 @@ struct FastJSArrayWitness {
}
}
MoveElements(dst: intptr, src: intptr, length: intptr) {
macro MoveElements(dst: intptr, src: intptr, length: intptr) {
assert(this.arrayIsPushable);
if (this.hasDoubles) {
const elements: FixedDoubleArray =
......@@ -256,11 +256,11 @@ macro NewFastJSArrayWitness(array: FastJSArray): FastJSArrayWitness {
}
struct FastJSArrayForReadWitness {
Get(): FastJSArrayForRead {
macro Get(): FastJSArrayForRead {
return this.unstable;
}
Recheck() labels CastError {
macro Recheck() labels CastError {
if (this.stable.map != this.map) goto CastError;
// We don't need to check elements kind or whether the prototype
// has changed away from the default JSArray prototype, because
......@@ -272,7 +272,7 @@ struct FastJSArrayForReadWitness {
this.unstable = %RawDownCast<FastJSArrayForRead>(this.stable);
}
LoadElementNoHole(implicit context: Context)(k: Smi): JSAny
macro LoadElementNoHole(implicit context: Context)(k: Smi): JSAny
labels FoundHole {
if (this.hasDoubles) {
return LoadElementNoHole<FixedDoubleArray>(this.unstable, k)
......
......@@ -12,13 +12,13 @@ const kJSPromiseHasHandlerMask: constexpr int31
@generateCppClass
extern class JSPromise extends JSObject {
Status(): PromiseState {
macro Status(): PromiseState {
StaticAssert(kJSPromiseStatusShift == 0);
const status: int32 = Convert<int32>(this.flags) & kJSPromiseStatusMask;
return Convert<PromiseState>(status);
}
SetStatus(status: constexpr PromiseState): void {
macro SetStatus(status: constexpr PromiseState): void {
assert(this.Status() == kPromisePending);
assert(status != kPromisePending);
......@@ -26,11 +26,11 @@ extern class JSPromise extends JSObject {
this.flags = this.flags | mask;
}
HasHandler(): bool {
macro HasHandler(): bool {
return (this.flags & kJSPromiseHasHandlerMask) != 0;
}
SetHasHandler(): void {
macro SetHasHandler(): void {
this.flags |= kJSPromiseHasHandlerMask;
}
......
......@@ -3,7 +3,7 @@
// found in the LICENSE file.
extern class Map extends HeapObject {
PrototypeInfo(): PrototypeInfo labels HasNoPrototypeInfo {
macro PrototypeInfo(): PrototypeInfo labels HasNoPrototypeInfo {
typeswitch (this.transitions_or_prototype_info) {
case (Weak<Map>): {
goto HasNoPrototypeInfo;
......
......@@ -4,17 +4,17 @@
@hasSameInstanceTypeAsParent
extern class RegExpMatchInfo extends FixedArray {
GetStartOfCapture(implicit context: Context)(captureIndex: constexpr int31):
Smi {
macro GetStartOfCapture(implicit context: Context)(captureIndex:
constexpr int31): Smi {
const index: constexpr int31 = GetStartOfCaptureIndex(captureIndex);
return UnsafeCast<Smi>(this.objects[index]);
}
GetEndOfCapture(implicit context: Context)(captureIndex: constexpr int31):
Smi {
macro GetEndOfCapture(implicit context: Context)(captureIndex:
constexpr int31): Smi {
const index: constexpr int31 = GetStartOfCaptureIndex(captureIndex) + 1;
return UnsafeCast<Smi>(this.objects[index]);
}
NumberOfCaptures(implicit context: Context)(): Smi {
macro NumberOfCaptures(implicit context: Context)(): Smi {
return UnsafeCast<Smi>(this.objects[kRegExpMatchInfoNumberOfCapturesIndex]);
}
}
......
......@@ -2104,8 +2104,8 @@ struct TorqueGrammar : Grammar {
Symbol method = {Rule(
{CheckIf(Token("transitioning")),
Optional<std::string>(Sequence({Token("operator"), &externalString})),
&name, &parameterListNoVararg, &optionalReturnType, optionalLabelList,
&block},
Token("macro"), &name, &parameterListNoVararg, &optionalReturnType,
optionalLabelList, &block},
MakeMethodDeclaration)};
// Result: base::Optional<ClassBody*>
......
......@@ -727,10 +727,10 @@ namespace test {
}
struct TestInner {
SetX(newValue: int32) {
macro SetX(newValue: int32) {
this.x = newValue;
}
GetX(): int32 {
macro GetX(): int32 {
return this.x;
}
x: int32;
......@@ -759,7 +759,7 @@ namespace test {
}
class InternalClass extends Struct {
Flip() labels NotASmi {
macro Flip() labels NotASmi {
const tmp = Cast<Smi>(this.b) otherwise NotASmi;
this.b = this.a;
this.a = tmp;
......@@ -781,10 +781,10 @@ namespace test {
}
struct StructWithConst {
TestMethod1(): int32 {
macro TestMethod1(): int32 {
return this.b;
}
TestMethod2(): Object {
macro TestMethod2(): Object {
return this.a;
}
a: Object;
......@@ -803,7 +803,7 @@ namespace test {
}
struct TestIterator {
Next(): Object labels NoMore {
macro Next(): Object labels NoMore {
if (this.count-- == 0) goto NoMore;
return TheHole;
}
......@@ -817,7 +817,7 @@ namespace test {
}
class SmiPair extends Struct {
GetA():&Smi {
macro GetA():&Smi {
return & this.a;
}
a: Smi;
......
......@@ -501,7 +501,7 @@ TEST(Torque, SpecializationRequesters) {
A<T>();
}
struct C<T: type> {
Method() {
macro Method() {
B<T>();
}
}
......
......@@ -15,12 +15,12 @@
namespace array {
class SortState extends Struct {
Compare(implicit context: Context)(x: JSAny, y: JSAny): Number {
macro Compare(implicit context: Context)(x: JSAny, y: JSAny): Number {
const sortCompare: CompareBuiltinFn = this.sortComparePtr;
return sortCompare(context, this.userCmpFn, x, y);
}
CheckAccessor(implicit context: Context)() labels Bailout {
macro CheckAccessor(implicit context: Context)() labels Bailout {
const canUseSameAccessorFn: CanUseSameAccessorFn =
this.canUseSameAccessorFn;
......@@ -31,7 +31,7 @@ namespace array {
}
}
ResetToGenericAccessor() {
macro ResetToGenericAccessor() {
this.loadFn = Load<GenericElementsAccessor>;
this.storeFn = Store<GenericElementsAccessor>;
this.deleteFn = Delete<GenericElementsAccessor>;
......
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