mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-07-06 01:52:04 +00:00
Implement comparision operator overloads (#63)
This commit is contained in:
@ -2400,7 +2400,16 @@ export class Compiler extends DiagnosticEmitter {
|
||||
expr = module.createBinary(BinaryOp.LtU32, leftExpr, rightExpr);
|
||||
break;
|
||||
}
|
||||
case TypeKind.USIZE: { // TODO: check operator overload
|
||||
case TypeKind.USIZE: { // check operator overload
|
||||
if (this.currentType.is(TypeFlags.REFERENCE)) {
|
||||
let classInstance = assert(this.currentType.classReference);
|
||||
let operatorName = classInstance.prototype.fnLessThan;
|
||||
if (operatorName != null) {
|
||||
expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// fall-through
|
||||
expr = module.createBinary(
|
||||
this.options.isWasm64
|
||||
? BinaryOp.LtU64
|
||||
@ -2479,7 +2488,16 @@ export class Compiler extends DiagnosticEmitter {
|
||||
expr = module.createBinary(BinaryOp.GtU32, leftExpr, rightExpr);
|
||||
break;
|
||||
}
|
||||
case TypeKind.USIZE: { // TODO: check operator overload
|
||||
case TypeKind.USIZE: { // check operator overload
|
||||
if (this.currentType.is(TypeFlags.REFERENCE)) {
|
||||
let classInstance = assert(this.currentType.classReference);
|
||||
let operatorName = classInstance.prototype.fnGreaterThan;
|
||||
if (operatorName != null) {
|
||||
expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// fall-through
|
||||
expr = module.createBinary(
|
||||
this.options.isWasm64
|
||||
? BinaryOp.GtU64
|
||||
@ -2558,7 +2576,16 @@ export class Compiler extends DiagnosticEmitter {
|
||||
expr = module.createBinary(BinaryOp.LeU32, leftExpr, rightExpr);
|
||||
break;
|
||||
}
|
||||
case TypeKind.USIZE: { // TODO: check operator overload
|
||||
case TypeKind.USIZE: { // check operator overload
|
||||
if (this.currentType.is(TypeFlags.REFERENCE)) {
|
||||
let classInstance = assert(this.currentType.classReference);
|
||||
let operatorName = classInstance.prototype.fnLessThanEquals;
|
||||
if (operatorName != null) {
|
||||
expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// fall-through
|
||||
expr = module.createBinary(
|
||||
this.options.isWasm64
|
||||
? BinaryOp.LeU64
|
||||
@ -2637,7 +2664,16 @@ export class Compiler extends DiagnosticEmitter {
|
||||
expr = module.createBinary(BinaryOp.GeU32, leftExpr, rightExpr);
|
||||
break;
|
||||
}
|
||||
case TypeKind.USIZE: { // TODO: check operator overload
|
||||
case TypeKind.USIZE: { // check operator overload
|
||||
if (this.currentType.is(TypeFlags.REFERENCE)) {
|
||||
let classInstance = assert(this.currentType.classReference);
|
||||
let operatorName = classInstance.prototype.fnGreaterThanEquals;
|
||||
if (operatorName != null) {
|
||||
expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// fall-through
|
||||
expr = module.createBinary(
|
||||
this.options.isWasm64
|
||||
? BinaryOp.GeU64
|
||||
@ -2784,7 +2820,17 @@ export class Compiler extends DiagnosticEmitter {
|
||||
expr = module.createBinary(BinaryOp.NeI32, leftExpr, rightExpr);
|
||||
break;
|
||||
}
|
||||
case TypeKind.USIZE: // TODO: check operator overload
|
||||
case TypeKind.USIZE: {// check operator overload
|
||||
if (this.currentType.is(TypeFlags.REFERENCE)) {
|
||||
let classInstance = assert(this.currentType.classReference);
|
||||
let operatorName = classInstance.prototype.fnNotEquals;
|
||||
if (operatorName != null) {
|
||||
expr = this.compileOperatorOverload(classInstance, operatorName, leftExpr, rightExpr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// fall-through
|
||||
}
|
||||
case TypeKind.ISIZE: {
|
||||
expr = module.createBinary(
|
||||
this.options.isWasm64
|
||||
|
Reference in New Issue
Block a user