about summary refs log tree commit diff stats
path: root/apps/ex3.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-02-09 17:29:52 -0800
committerKartik Agaram <vc@akkartik.com>2020-02-09 17:29:52 -0800
commit7b1786be403e0917db787383360623a7a8ca7ad3 (patch)
treea9acda3220bde8f1b56db4c6226eff4fad3eccb3 /apps/ex3.subx
parentab6a6ed9976f2d21792feccdbcf73aa046c55c99 (diff)
downloadmu-7b1786be403e0917db787383360623a7a8ca7ad3.tar.gz
5998 - redo code-generation for 'break'
I've been saying that we can convert this:

  {
    var x: int
    break-if-=
    ...
  }

..into this:

  {
    68/push 0/imm32
    {
      0f 84/jump-if-= break/disp32
      ...
    }
    81 0/subop/add %esp 4/imm32
  }

All subsequent instructions go into a nested block, so that they can be
easily skipped without skipping the stack cleanup.

However, I've been growing aware that this is a special case. Most of the
time we can't use this trick:
  for loops
  for non-local breaks
  for non-local loops

In most cases we need to figure out all the intervening variables on the
stack and emit code to clean them up.

And now it turns out even for local breaks like above, the trick doesn't
work. Consider what happens when there's a loop later in the block:

  {
    var x: int
    break-if-=
    ...
  }

If we emitted a nested block for the break, the local loop would become
non-local. So we replace one kind of state with another.

Easiest course of action is to just emit the exact same cleanup code for
all conditional branches.
Diffstat (limited to 'apps/ex3.subx')
0 files changed, 0 insertions, 0 deletions