Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import {
getBlockChildCount,
getBlockChildAt,
getBlockName,
getLocalSetValue,
getGlobalGetName,
isGlobalMutable,
getSideEffects,
Expand Down Expand Up @@ -9231,11 +9230,12 @@ export class Compiler extends DiagnosticEmitter {
let flow = this.currentFlow;

// make a getter for the expression (also obtains the type)
let getValue = this.compileExpression( // reports
const getValueOriginal = this.compileExpression( // reports
expression.operand,
contextualType.exceptVoid,
Constraints.None
);
let getValue: ExpressionRef;

// if the value isn't dropped, a temp. local is required to remember the original value,
// except if a static overload is found, which reverses the use of a temp. (see below)
Expand All @@ -9244,24 +9244,25 @@ export class Compiler extends DiagnosticEmitter {
tempLocal = flow.getTempLocal(this.currentType);
getValue = module.local_tee(
tempLocal.index,
getValue,
getValueOriginal,
this.currentType.isManaged
);
} else {
getValue = getValueOriginal;
}

let expr: ExpressionRef;

switch (expression.operator) {
case Token.Plus_Plus: {

// check operator overload
let classReference = this.currentType.getClassOrWrapper(this.program);
if (classReference) {
let overload = classReference.lookupOverload(OperatorKind.PostfixInc);
if (overload) {
let isInstance = overload.is(CommonFlags.Instance);
if (tempLocal && !isInstance) { // revert: static overload simply returns
getValue = getLocalSetValue(getValue);
getValue = getValueOriginal;
tempLocal = null;
}
expr = this.compileUnaryOverload(overload, expression.operand, getValue, expression);
Expand Down Expand Up @@ -9337,19 +9338,18 @@ export class Compiler extends DiagnosticEmitter {
break;
}
case Token.Minus_Minus: {

// check operator overload
let classReference = this.currentType.getClassOrWrapper(this.program);
if (classReference) {
let overload = classReference.lookupOverload(OperatorKind.PostfixDec);
if (overload) {
let isInstance = overload.is(CommonFlags.Instance);
if (tempLocal && !isInstance) { // revert: static overload simply returns
getValue = getLocalSetValue(getValue);
getValue = getValueOriginal;
tempLocal = null;
}
expr = this.compileUnaryOverload(overload, expression.operand, getValue, expression);
if (overload.is(CommonFlags.Instance)) break;
if (isInstance) break;
return expr; // here
}
}
Expand Down
5 changes: 0 additions & 5 deletions tests/compiler/std/operator-overloading.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -6190,11 +6190,6 @@
block $std/operator-overloading/TesterInlineStatic.postInc|inlined.0 (result i32)
global.get $~lib/memory/__stack_pointer
global.get $std/operator-overloading/ais1
local.set $9
global.get $~lib/memory/__stack_pointer
local.get $9
i32.store
local.get $9
local.tee $3
i32.store offset=16
i32.const 0
Expand Down
3 changes: 0 additions & 3 deletions tests/compiler/std/operator-overloading.release.wat
Original file line number Diff line number Diff line change
Expand Up @@ -4550,9 +4550,6 @@
global.get $~lib/memory/__stack_pointer
global.get $std/operator-overloading/ais1
local.tee $0
i32.store
global.get $~lib/memory/__stack_pointer
local.get $0
i32.store offset=16
global.get $~lib/memory/__stack_pointer
local.get $0
Expand Down
Loading