Skip to content

Commit

Permalink
修复 break 失效
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Oct 24, 2022
1 parent 0ea49d7 commit 9f998a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions compiler/codegen/func_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ func (self *funcInfo) exitScope(endPC int) {
self.breaks = self.breaks[:len(self.breaks)-1]

a := self.getJmpArgA()
for i := range pendingBreakJmps {
sBx := self.pc() - pendingBreakJmps[i]
for idx := range pendingBreakJmps {
sBx := self.pc() - pendingBreakJmps[idx]
i := (sBx+MAXARG_sBx)<<14 | a<<6 | OP_JMP
self.insts[pendingBreakJmps[i]] = uint32(i)
self.insts[pendingBreakJmps[idx]] = uint32(i)
}

self.scopeLv--
Expand Down
10 changes: 10 additions & 0 deletions test/basic.lk
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ if #long >= 0 and '' {
func(long, #long)
}

while true {
if long != nil {
print('break')
} else {
break
}
os.sleep(100)
long = nil
}

func('' and true and 1 ? 'support ternary exp' : 'unreachable')
func(6 ~/ 2, 6 & 2, 6 / 2)
func(_VERSION, math.pi)
Expand Down

0 comments on commit 9f998a9

Please sign in to comment.