Implement comparision operator overloads (#63)

This commit is contained in:
Max Graey
2018-04-04 01:01:59 +03:00
committed by Daniel Wirtz
parent 5823e35f37
commit 37825fc84d
5 changed files with 844 additions and 34 deletions

View File

@ -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