mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 23:12:19 +00:00
Add unary postfix operator overloading (#309)
This commit is contained in:
parent
d864bef1eb
commit
dc4e2060ba
@ -6902,16 +6902,6 @@ export class Compiler extends DiagnosticEmitter {
|
||||
|
||||
switch (expression.operator) {
|
||||
case Token.PLUS_PLUS: {
|
||||
|
||||
// TODO: check operator overload
|
||||
if (currentType.is(TypeFlags.REFERENCE)) {
|
||||
this.error(
|
||||
DiagnosticCode.Operation_not_supported,
|
||||
expression.range
|
||||
);
|
||||
return this.module.createUnreachable();
|
||||
}
|
||||
|
||||
switch (currentType.kind) {
|
||||
case TypeKind.I8:
|
||||
case TypeKind.I16:
|
||||
@ -6927,7 +6917,24 @@ export class Compiler extends DiagnosticEmitter {
|
||||
);
|
||||
break;
|
||||
}
|
||||
case TypeKind.USIZE:
|
||||
case TypeKind.USIZE: {
|
||||
// check operator overload
|
||||
if (this.currentType.is(TypeFlags.REFERENCE)) {
|
||||
let classReference = this.currentType.classReference;
|
||||
if (classReference) {
|
||||
let overload = classReference.lookupOverload(OperatorKind.POSTFIX_INC);
|
||||
if (overload) {
|
||||
calcValue = this.compileUnaryOverload(overload, expression.operand, getValue, expression);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.error(
|
||||
DiagnosticCode.Operation_not_supported,
|
||||
expression.range
|
||||
);
|
||||
return module.createUnreachable();
|
||||
}
|
||||
}
|
||||
case TypeKind.ISIZE: {
|
||||
let options = this.options;
|
||||
calcValue = module.createBinary(
|
||||
@ -6972,16 +6979,6 @@ export class Compiler extends DiagnosticEmitter {
|
||||
break;
|
||||
}
|
||||
case Token.MINUS_MINUS: {
|
||||
|
||||
// TODO: check operator overload
|
||||
if (this.currentType.is(TypeFlags.REFERENCE)) {
|
||||
this.error(
|
||||
DiagnosticCode.Operation_not_supported,
|
||||
expression.range
|
||||
);
|
||||
return this.module.createUnreachable();
|
||||
}
|
||||
|
||||
switch (currentType.kind) {
|
||||
case TypeKind.I8:
|
||||
case TypeKind.I16:
|
||||
@ -6997,7 +6994,24 @@ export class Compiler extends DiagnosticEmitter {
|
||||
);
|
||||
break;
|
||||
}
|
||||
case TypeKind.USIZE:
|
||||
case TypeKind.USIZE: {
|
||||
// check operator overload
|
||||
if (this.currentType.is(TypeFlags.REFERENCE)) {
|
||||
let classReference = this.currentType.classReference;
|
||||
if (classReference) {
|
||||
let overload = classReference.lookupOverload(OperatorKind.POSTFIX_DEC);
|
||||
if (overload) {
|
||||
calcValue = this.compileUnaryOverload(overload, expression.operand, getValue, expression);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.error(
|
||||
DiagnosticCode.Operation_not_supported,
|
||||
expression.range
|
||||
);
|
||||
return module.createUnreachable();
|
||||
}
|
||||
}
|
||||
case TypeKind.ISIZE: {
|
||||
let options = this.options;
|
||||
calcValue = module.createBinary(
|
||||
@ -7061,9 +7075,11 @@ export class Compiler extends DiagnosticEmitter {
|
||||
calcValue, // also tees getValue to tempLocal
|
||||
false
|
||||
);
|
||||
|
||||
this.currentType = tempLocal.type;
|
||||
currentFunction.freeTempLocal(tempLocal);
|
||||
var nativeType = tempLocal.type.toNativeType();
|
||||
|
||||
return module.createBlock(null, [
|
||||
setValue,
|
||||
module.createGetLocal(tempLocal.index, nativeType)
|
||||
|
@ -74,6 +74,7 @@
|
||||
(global $std/operator-overloading/excl (mut i32) (i32.const 0))
|
||||
(global $std/operator-overloading/bres (mut i32) (i32.const 0))
|
||||
(global $std/operator-overloading/incdec (mut i32) (i32.const 0))
|
||||
(global $std/operator-overloading/tmp (mut i32) (i32.const 0))
|
||||
(global $std/operator-overloading/ais1 (mut i32) (i32.const 0))
|
||||
(global $std/operator-overloading/ais2 (mut i32) (i32.const 0))
|
||||
(global $std/operator-overloading/ais (mut i32) (i32.const 0))
|
||||
@ -2213,7 +2214,39 @@
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
(func $start (; 30 ;) (; has Stack IR ;) (type $v)
|
||||
(func $std/operator-overloading/Tester#postInc (; 30 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
|
||||
(call $std/operator-overloading/Tester#constructor
|
||||
(i32.add
|
||||
(i32.load
|
||||
(get_local $0)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.add
|
||||
(i32.load offset=4
|
||||
(get_local $0)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $std/operator-overloading/Tester#postDec (; 31 ;) (; has Stack IR ;) (type $ii) (param $0 i32) (result i32)
|
||||
(call $std/operator-overloading/Tester#constructor
|
||||
(i32.sub
|
||||
(i32.load
|
||||
(get_local $0)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.sub
|
||||
(i32.load offset=4
|
||||
(get_local $0)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $start (; 32 ;) (; has Stack IR ;) (type $v)
|
||||
(local $0 i32)
|
||||
(local $1 i32)
|
||||
(set_global $~lib/allocator/arena/startOffset
|
||||
@ -2266,7 +2299,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 137)
|
||||
(i32.const 147)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2315,7 +2348,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 143)
|
||||
(i32.const 153)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2365,7 +2398,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 149)
|
||||
(i32.const 159)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2415,7 +2448,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 155)
|
||||
(i32.const 165)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2464,7 +2497,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 161)
|
||||
(i32.const 171)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2514,7 +2547,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 167)
|
||||
(i32.const 177)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2564,7 +2597,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 173)
|
||||
(i32.const 183)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2614,7 +2647,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 179)
|
||||
(i32.const 189)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2664,7 +2697,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 185)
|
||||
(i32.const 195)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2697,7 +2730,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 191)
|
||||
(i32.const 201)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2727,7 +2760,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 197)
|
||||
(i32.const 207)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2745,7 +2778,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 201)
|
||||
(i32.const 211)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2766,7 +2799,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 205)
|
||||
(i32.const 215)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2799,7 +2832,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 211)
|
||||
(i32.const 221)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2832,7 +2865,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 217)
|
||||
(i32.const 227)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2865,7 +2898,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 223)
|
||||
(i32.const 233)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2898,7 +2931,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 229)
|
||||
(i32.const 239)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2941,7 +2974,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 234)
|
||||
(i32.const 244)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2984,7 +3017,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 239)
|
||||
(i32.const 249)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3027,7 +3060,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 244)
|
||||
(i32.const 254)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3074,7 +3107,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 249)
|
||||
(i32.const 259)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3127,7 +3160,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 254)
|
||||
(i32.const 264)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3180,7 +3213,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 259)
|
||||
(i32.const 269)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3225,7 +3258,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 264)
|
||||
(i32.const 274)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3240,7 +3273,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 265)
|
||||
(i32.const 275)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3283,7 +3316,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 271)
|
||||
(i32.const 281)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3319,7 +3352,159 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 274)
|
||||
(i32.const 284)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/incdec
|
||||
(call $std/operator-overloading/Tester#constructor
|
||||
(i32.const 0)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/incdec
|
||||
(call $std/operator-overloading/Tester#postInc
|
||||
(tee_local $0
|
||||
(get_global $std/operator-overloading/incdec)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/tmp
|
||||
(get_local $0)
|
||||
)
|
||||
(if
|
||||
(tee_local $0
|
||||
(i32.eqz
|
||||
(i32.load
|
||||
(get_global $std/operator-overloading/tmp)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $0
|
||||
(i32.eq
|
||||
(i32.load offset=4
|
||||
(get_global $std/operator-overloading/tmp)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(get_local $0)
|
||||
)
|
||||
(block
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 289)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(tee_local $0
|
||||
(i32.eq
|
||||
(i32.load
|
||||
(get_global $std/operator-overloading/incdec)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_local $0
|
||||
(i32.eq
|
||||
(i32.load offset=4
|
||||
(get_global $std/operator-overloading/incdec)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(get_local $0)
|
||||
)
|
||||
(block
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 290)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/incdec
|
||||
(call $std/operator-overloading/Tester#postDec
|
||||
(tee_local $0
|
||||
(get_global $std/operator-overloading/incdec)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/tmp
|
||||
(get_local $0)
|
||||
)
|
||||
(if
|
||||
(tee_local $0
|
||||
(i32.eq
|
||||
(i32.load
|
||||
(get_global $std/operator-overloading/tmp)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_local $0
|
||||
(i32.eq
|
||||
(i32.load offset=4
|
||||
(get_global $std/operator-overloading/tmp)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(get_local $0)
|
||||
)
|
||||
(block
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 293)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(tee_local $0
|
||||
(i32.eqz
|
||||
(i32.load
|
||||
(get_global $std/operator-overloading/incdec)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_local $0
|
||||
(i32.eq
|
||||
(i32.load offset=4
|
||||
(get_global $std/operator-overloading/incdec)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(get_local $0)
|
||||
)
|
||||
(block
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 294)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3331,6 +3516,24 @@
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/ais1
|
||||
(call $std/operator-overloading/Tester#constructor
|
||||
(i32.add
|
||||
(i32.load
|
||||
(tee_local $0
|
||||
(get_global $std/operator-overloading/ais1)
|
||||
)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.add
|
||||
(i32.load offset=4
|
||||
(get_local $0)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/ais2
|
||||
(call $std/operator-overloading/Tester#constructor
|
||||
(i32.const 2)
|
||||
@ -3367,7 +3570,7 @@
|
||||
(i32.load
|
||||
(get_global $std/operator-overloading/ais)
|
||||
)
|
||||
(i32.const 3)
|
||||
(i32.const 4)
|
||||
)
|
||||
)
|
||||
(set_local $1
|
||||
@ -3375,7 +3578,7 @@
|
||||
(i32.load offset=4
|
||||
(get_global $std/operator-overloading/ais)
|
||||
)
|
||||
(i32.const 5)
|
||||
(i32.const 6)
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -3387,7 +3590,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 288)
|
||||
(i32.const 314)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3399,6 +3602,24 @@
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/aii1
|
||||
(call $std/operator-overloading/Tester#constructor
|
||||
(i32.add
|
||||
(i32.load
|
||||
(tee_local $1
|
||||
(get_global $std/operator-overloading/aii1)
|
||||
)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.add
|
||||
(i32.load offset=4
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/aii2
|
||||
(call $std/operator-overloading/Tester#constructor
|
||||
(i32.const 2)
|
||||
@ -3435,7 +3656,7 @@
|
||||
(i32.load
|
||||
(get_global $std/operator-overloading/aii)
|
||||
)
|
||||
(i32.const 3)
|
||||
(i32.const 4)
|
||||
)
|
||||
)
|
||||
(set_local $0
|
||||
@ -3443,7 +3664,7 @@
|
||||
(i32.load offset=4
|
||||
(get_global $std/operator-overloading/aii)
|
||||
)
|
||||
(i32.const 5)
|
||||
(i32.const 6)
|
||||
)
|
||||
)
|
||||
)
|
||||
@ -3455,14 +3676,14 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 302)
|
||||
(i32.const 334)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $null (; 31 ;) (; has Stack IR ;) (type $v)
|
||||
(func $null (; 33 ;) (; has Stack IR ;) (type $v)
|
||||
(nop)
|
||||
)
|
||||
)
|
||||
|
@ -128,6 +128,16 @@ class Tester {
|
||||
--this.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
@operator.postfix('++')
|
||||
postInc(): Tester {
|
||||
return new Tester(this.x + 1, this.y + 1);
|
||||
}
|
||||
|
||||
@operator.postfix('--')
|
||||
postDec(): Tester {
|
||||
return new Tester(this.x - 1, this.y - 1);
|
||||
}
|
||||
}
|
||||
|
||||
// check additional
|
||||
@ -273,6 +283,16 @@ assert(incdec.x == 1 && incdec.y == 2);
|
||||
--incdec;
|
||||
assert(incdec.x == 0 && incdec.y == 1);
|
||||
|
||||
incdec = new Tester(0, 1);
|
||||
|
||||
var tmp = incdec++;
|
||||
assert(tmp.x == 0 && tmp.y == 1);
|
||||
assert(incdec.x == 1 && incdec.y == 2);
|
||||
|
||||
tmp = incdec--;
|
||||
assert(tmp.x == 1 && tmp.y == 2);
|
||||
assert(incdec.x == 0 && incdec.y == 1);
|
||||
|
||||
// check inlined static
|
||||
class TesterInlineStatic {
|
||||
constructor(public x: i32, public y: i32) {
|
||||
@ -281,11 +301,17 @@ class TesterInlineStatic {
|
||||
static add(a: TesterInlineStatic, b: TesterInlineStatic): TesterInlineStatic {
|
||||
return new TesterInlineStatic(a.x + b.x, a.y + b.y);
|
||||
}
|
||||
|
||||
@inline @operator.postfix('++')
|
||||
static postInc(a: TesterInlineStatic): TesterInlineStatic {
|
||||
return new TesterInlineStatic(a.x + 1, a.y + 1);
|
||||
}
|
||||
}
|
||||
var ais1 = new TesterInlineStatic(1, 2);
|
||||
ais1++; // 2, 3
|
||||
var ais2 = new TesterInlineStatic(2, 3);
|
||||
var ais = ais1 + ais2;
|
||||
assert(ais.x == 3 && ais.y == 5);
|
||||
assert(ais.x == 4 && ais.y == 6);
|
||||
|
||||
// check inlined instance
|
||||
class TesterInlineInstance {
|
||||
@ -295,8 +321,14 @@ class TesterInlineInstance {
|
||||
add(b: TesterInlineInstance): TesterInlineInstance {
|
||||
return new TesterInlineInstance(this.x + b.x, this.y + b.y);
|
||||
}
|
||||
|
||||
@inline @operator.postfix('++')
|
||||
postInc(): TesterInlineInstance {
|
||||
return new TesterInlineInstance(this.x + 1, this.y + 1);
|
||||
}
|
||||
}
|
||||
var aii1 = new TesterInlineInstance(1, 2);
|
||||
aii1++; // 2, 3
|
||||
var aii2 = new TesterInlineInstance(2, 3);
|
||||
var aii = aii1 + aii2;
|
||||
assert(aii.x == 3 && aii.y == 5);
|
||||
assert(aii.x == 4 && aii.y == 6);
|
||||
|
@ -78,6 +78,7 @@
|
||||
(global $std/operator-overloading/excl (mut i32) (i32.const 0))
|
||||
(global $std/operator-overloading/bres (mut i32) (i32.const 0))
|
||||
(global $std/operator-overloading/incdec (mut i32) (i32.const 0))
|
||||
(global $std/operator-overloading/tmp (mut i32) (i32.const 0))
|
||||
(global $std/operator-overloading/ais1 (mut i32) (i32.const 0))
|
||||
(global $std/operator-overloading/ais2 (mut i32) (i32.const 0))
|
||||
(global $std/operator-overloading/ais (mut i32) (i32.const 0))
|
||||
@ -2404,7 +2405,41 @@
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
(func $std/operator-overloading/TesterInlineStatic#constructor (; 30 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
|
||||
(func $std/operator-overloading/Tester#postInc (; 30 ;) (type $ii) (param $0 i32) (result i32)
|
||||
(call $std/operator-overloading/Tester#constructor
|
||||
(i32.const 0)
|
||||
(i32.add
|
||||
(i32.load
|
||||
(get_local $0)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.add
|
||||
(i32.load offset=4
|
||||
(get_local $0)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $std/operator-overloading/Tester#postDec (; 31 ;) (type $ii) (param $0 i32) (result i32)
|
||||
(call $std/operator-overloading/Tester#constructor
|
||||
(i32.const 0)
|
||||
(i32.sub
|
||||
(i32.load
|
||||
(get_local $0)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.sub
|
||||
(i32.load offset=4
|
||||
(get_local $0)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $std/operator-overloading/TesterInlineStatic#constructor (; 32 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
|
||||
(local $3 i32)
|
||||
(tee_local $0
|
||||
(if (result i32)
|
||||
@ -2431,7 +2466,7 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $std/operator-overloading/TesterInlineInstance#constructor (; 31 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
|
||||
(func $std/operator-overloading/TesterInlineInstance#constructor (; 33 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
|
||||
(local $3 i32)
|
||||
(tee_local $0
|
||||
(if (result i32)
|
||||
@ -2458,7 +2493,7 @@
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $start (; 32 ;) (type $v)
|
||||
(func $start (; 34 ;) (type $v)
|
||||
(local $0 i32)
|
||||
(local $1 i32)
|
||||
(set_global $~lib/allocator/arena/startOffset
|
||||
@ -2520,7 +2555,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 137)
|
||||
(i32.const 147)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2570,7 +2605,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 143)
|
||||
(i32.const 153)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2620,7 +2655,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 149)
|
||||
(i32.const 159)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2670,7 +2705,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 155)
|
||||
(i32.const 165)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2720,7 +2755,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 161)
|
||||
(i32.const 171)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2770,7 +2805,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 167)
|
||||
(i32.const 177)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2820,7 +2855,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 173)
|
||||
(i32.const 183)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2870,7 +2905,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 179)
|
||||
(i32.const 189)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2920,7 +2955,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 185)
|
||||
(i32.const 195)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2957,7 +2992,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 191)
|
||||
(i32.const 201)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -2994,7 +3029,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 197)
|
||||
(i32.const 207)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3017,7 +3052,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 201)
|
||||
(i32.const 211)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3040,7 +3075,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 205)
|
||||
(i32.const 215)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3077,7 +3112,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 211)
|
||||
(i32.const 221)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3114,7 +3149,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 217)
|
||||
(i32.const 227)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3151,7 +3186,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 223)
|
||||
(i32.const 233)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3188,7 +3223,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 229)
|
||||
(i32.const 239)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3231,7 +3266,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 234)
|
||||
(i32.const 244)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3274,7 +3309,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 239)
|
||||
(i32.const 249)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3317,7 +3352,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 244)
|
||||
(i32.const 254)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3363,7 +3398,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 249)
|
||||
(i32.const 259)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3415,7 +3450,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 254)
|
||||
(i32.const 264)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3467,7 +3502,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 259)
|
||||
(i32.const 269)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3510,7 +3545,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 264)
|
||||
(i32.const 274)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3527,7 +3562,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 265)
|
||||
(i32.const 275)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3569,7 +3604,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 271)
|
||||
(i32.const 281)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3604,7 +3639,158 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 274)
|
||||
(i32.const 284)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/incdec
|
||||
(call $std/operator-overloading/Tester#constructor
|
||||
(i32.const 0)
|
||||
(i32.const 0)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/tmp
|
||||
(block (result i32)
|
||||
(set_global $std/operator-overloading/incdec
|
||||
(call $std/operator-overloading/Tester#postInc
|
||||
(tee_local $0
|
||||
(get_global $std/operator-overloading/incdec)
|
||||
)
|
||||
)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(if (result i32)
|
||||
(tee_local $0
|
||||
(i32.eq
|
||||
(i32.load
|
||||
(get_global $std/operator-overloading/tmp)
|
||||
)
|
||||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
(i32.eq
|
||||
(i32.load offset=4
|
||||
(get_global $std/operator-overloading/tmp)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(block
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 289)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(if (result i32)
|
||||
(tee_local $0
|
||||
(i32.eq
|
||||
(i32.load
|
||||
(get_global $std/operator-overloading/incdec)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.eq
|
||||
(i32.load offset=4
|
||||
(get_global $std/operator-overloading/incdec)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(block
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 290)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/tmp
|
||||
(block (result i32)
|
||||
(set_global $std/operator-overloading/incdec
|
||||
(call $std/operator-overloading/Tester#postDec
|
||||
(tee_local $0
|
||||
(get_global $std/operator-overloading/incdec)
|
||||
)
|
||||
)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(if (result i32)
|
||||
(tee_local $0
|
||||
(i32.eq
|
||||
(i32.load
|
||||
(get_global $std/operator-overloading/tmp)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
(i32.eq
|
||||
(i32.load offset=4
|
||||
(get_global $std/operator-overloading/tmp)
|
||||
)
|
||||
(i32.const 2)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(block
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 293)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
(if
|
||||
(i32.eqz
|
||||
(if (result i32)
|
||||
(tee_local $0
|
||||
(i32.eq
|
||||
(i32.load
|
||||
(get_global $std/operator-overloading/incdec)
|
||||
)
|
||||
(i32.const 0)
|
||||
)
|
||||
)
|
||||
(i32.eq
|
||||
(i32.load offset=4
|
||||
(get_global $std/operator-overloading/incdec)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
)
|
||||
(block
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 294)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3617,6 +3803,28 @@
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/ais1
|
||||
(block $std/operator-overloading/TesterInlineStatic.postInc|inlined.0 (result i32)
|
||||
(set_local $0
|
||||
(get_global $std/operator-overloading/ais1)
|
||||
)
|
||||
(call $std/operator-overloading/TesterInlineStatic#constructor
|
||||
(i32.const 0)
|
||||
(i32.add
|
||||
(i32.load
|
||||
(get_local $0)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.add
|
||||
(i32.load offset=4
|
||||
(get_local $0)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/ais2
|
||||
(call $std/operator-overloading/TesterInlineStatic#constructor
|
||||
(i32.const 0)
|
||||
@ -3661,14 +3869,14 @@
|
||||
(i32.load
|
||||
(get_global $std/operator-overloading/ais)
|
||||
)
|
||||
(i32.const 3)
|
||||
(i32.const 4)
|
||||
)
|
||||
)
|
||||
(i32.eq
|
||||
(i32.load offset=4
|
||||
(get_global $std/operator-overloading/ais)
|
||||
)
|
||||
(i32.const 5)
|
||||
(i32.const 6)
|
||||
)
|
||||
(get_local $1)
|
||||
)
|
||||
@ -3677,7 +3885,7 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 288)
|
||||
(i32.const 314)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
@ -3690,6 +3898,28 @@
|
||||
(i32.const 2)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/aii1
|
||||
(block $std/operator-overloading/TesterInlineInstance#postInc|inlined.0 (result i32)
|
||||
(set_local $1
|
||||
(get_global $std/operator-overloading/aii1)
|
||||
)
|
||||
(call $std/operator-overloading/TesterInlineInstance#constructor
|
||||
(i32.const 0)
|
||||
(i32.add
|
||||
(i32.load
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
(i32.add
|
||||
(i32.load offset=4
|
||||
(get_local $1)
|
||||
)
|
||||
(i32.const 1)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
(set_global $std/operator-overloading/aii2
|
||||
(call $std/operator-overloading/TesterInlineInstance#constructor
|
||||
(i32.const 0)
|
||||
@ -3734,14 +3964,14 @@
|
||||
(i32.load
|
||||
(get_global $std/operator-overloading/aii)
|
||||
)
|
||||
(i32.const 3)
|
||||
(i32.const 4)
|
||||
)
|
||||
)
|
||||
(i32.eq
|
||||
(i32.load offset=4
|
||||
(get_global $std/operator-overloading/aii)
|
||||
)
|
||||
(i32.const 5)
|
||||
(i32.const 6)
|
||||
)
|
||||
(get_local $0)
|
||||
)
|
||||
@ -3750,13 +3980,13 @@
|
||||
(call $~lib/env/abort
|
||||
(i32.const 0)
|
||||
(i32.const 8)
|
||||
(i32.const 302)
|
||||
(i32.const 334)
|
||||
(i32.const 0)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
)
|
||||
)
|
||||
(func $null (; 33 ;) (type $v)
|
||||
(func $null (; 35 ;) (type $v)
|
||||
)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user