mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-13 15:01:28 +00:00
Operator overload preparations
This commit is contained in:
@ -18,13 +18,13 @@ export class Array<T> {
|
||||
}
|
||||
|
||||
@operator("[]")
|
||||
get(index: i32): T {
|
||||
private __get(index: i32): T {
|
||||
assert(index > 0 && index < this.capacity);
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
@operator("[]=")
|
||||
set(index: i32, value: T): void {
|
||||
private __set(index: i32, value: T): void {
|
||||
assert(index > 0 && index < this.capacity);
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
@ -46,12 +46,12 @@ export class CArray<T> {
|
||||
private constructor() {}
|
||||
|
||||
@operator("[]")
|
||||
get(index: usize): T {
|
||||
private __get(index: usize): T {
|
||||
return load<T>(changetype<usize>(this) + index * sizeof<T>());
|
||||
}
|
||||
|
||||
@operator("[]=")
|
||||
set(index: usize, value: T): void {
|
||||
private __set(index: usize, value: T): void {
|
||||
store<T>(changetype<usize>(this) + index * sizeof<T>(), value);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ export class String {
|
||||
this.length = lenght;
|
||||
}
|
||||
|
||||
@operator("[]")
|
||||
charAt(pos: i32): String {
|
||||
assert(this != null);
|
||||
return pos < 0 || pos >= this.length ? EMPTY
|
||||
@ -39,7 +40,7 @@ export class String {
|
||||
}
|
||||
|
||||
@operator("+")
|
||||
concat(other: String): String {
|
||||
concat(other: this): String {
|
||||
assert(this != null);
|
||||
assert(other != null);
|
||||
var thisLen: isize = this.length;
|
||||
@ -59,7 +60,7 @@ export class String {
|
||||
);
|
||||
}
|
||||
|
||||
endsWith(searchString: String, endPosition: i32 = 0x7fffffff): bool {
|
||||
endsWith(searchString: this, endPosition: i32 = 0x7fffffff): bool {
|
||||
assert(this != null);
|
||||
assert(searchString != null);
|
||||
var end: isize = <isize>min<i32>(max<i32>(endPosition, 0), this.length);
|
||||
@ -71,18 +72,18 @@ export class String {
|
||||
}
|
||||
|
||||
@operator("==")
|
||||
equals(other: String): bool {
|
||||
private __eq(other: this): bool {
|
||||
assert(this != null);
|
||||
assert(other != null);
|
||||
return this.length != other.length ? false
|
||||
: !Heap.compare(this.ptr, other.ptr, <usize>this.length);
|
||||
}
|
||||
|
||||
includes(searchString: String, position: i32 = 0): bool {
|
||||
includes(searchString: this, position: i32 = 0): bool {
|
||||
return this.indexOf(searchString, position) != -1;
|
||||
}
|
||||
|
||||
indexOf(searchString: String, position: i32 = 0): i32 {
|
||||
indexOf(searchString: this, position: i32 = 0): i32 {
|
||||
assert(this != null);
|
||||
assert(searchString != null);
|
||||
var pos: isize = position;
|
||||
@ -95,7 +96,7 @@ export class String {
|
||||
return -1;
|
||||
}
|
||||
|
||||
startsWith(searchString: String, position: i32 = 0): bool {
|
||||
startsWith(searchString: this, position: i32 = 0): bool {
|
||||
assert(this != null);
|
||||
assert(searchString != null);
|
||||
var pos: isize = position;
|
||||
|
Reference in New Issue
Block a user