Skip to content

Conversation

HerrCai0907
Copy link
Member

In original code, getLocalSetValue cannot get the original expression accurately. For managed objects, the original expression will be wrapped in a layer of tostack, and will be wrapped in another layer of tostack when called. Although the subsequent nested tostack can be eliminated, this brings some readability issues.

@HerrCai0907
Copy link
Member Author

The original behaviour

class Bar {
  v: i32 = 0;
  @operator.postfix("++")
  static postfix_inc(bar: Bar): string {
    bar.v++;
    return "i++";
  }
}

export function _start(): void {
  let a = new Bar();
  let c = a++;
  trace(`a.v = ${a.v} ${c}`);
}
(call $assembly/index/Bar.postfix_inc
 (call $~lib/rt/__tostack
  (call $~lib/rt/__tostack
   (local.get $0)
  )
 )
)

Copy link
Member

@CountBleck CountBleck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but don't abbreviate getValueOriginal to getValueOrigin

@HerrCai0907 HerrCai0907 merged commit ade022e into AssemblyScript:main Sep 19, 2025
14 checks passed
@HerrCai0907 HerrCai0907 deleted the refactor/unary branch September 19, 2025 16:25
HerrCai0907 added a commit to HerrCai0907/assemblyscript that referenced this pull request Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants