8000 compiler: Fix jump resolver · go-python/gpython@6fa5265 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6fa5265

Browse files
committed
compiler: Fix jump resolver
1 parent 2ece17f commit 6fa5265

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

compile/compile.go

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,13 @@ func (is *Instructions) Add(i Instruction) {
469469
// Returns a boolean as to whether the stream changed
470470
func (is Instructions) Pass(pass int) bool {
471471
addr := uint32(0)
472-
changed := pass == 0
472+
changed := false
473473
for _, i := range is {
474-
i.SetPos(addr)
474+
changed = changed || i.SetPos(addr)
475475
if pass > 0 {
476476
// Only resolve addresses on 2nd pass
477477
if resolver, ok := i.(Resolver); ok {
478-
changed = changed || resolver.Resolve()
478+
resolver.Resolve()
479479
}
480480
}
481481
addr += i.Size()
@@ -502,13 +502,13 @@ done:
502502

503503
type Instruction interface {
504504
Pos() uint32
505-
SetPos(uint32)
505+
SetPos(uint32) bool
506506
Size() uint32
507507
Output() []byte
508508
}
509509

510510
type Resolver interface {
511-
Resolve() bool
511+
Resolve()
512512
}
513513

514514
// Position
@@ -519,9 +519,12 @@ func (p *pos) Pos() uint32 {
519519
return uint32(*p)
520520
}
521521

522-
// Set Position
523-
func (p *pos) SetPos(newPos uint32) {
524-
*p = pos(newPos)
522+
// Set Position - returns changed
523+
func (p *pos) SetPos(newPos uint32) bool {
524+
oldP := *p
525+
newP := pos(newPos)
526+
*p = newP
527+
return oldP != newP
525528
}
526529

527530
// A plain opcode
@@ -588,25 +591,8 @@ type JumpAbs struct {
588591
}
589592

590593
// Set the Arg from the Jump Label
591-
//
592-
// Returns a changed flag
593-
func (o *JumpAbs) Resolve() bool {
594-
newPos := o.Dest.Pos()
595-
changed := o.OpArg.Arg == newPos
596-
o.OpArg.Arg = newPos
597-
return changed
598-
}
599-
600-
// Bytes used in the output stream
601-
func (o *JumpAbs) Size() uint32 {
602-
o.Resolve()
603-
return o.OpArg.Size()
604-
}
605-
606-
// Output
607-
func (o *JumpAbs) Output() []byte {
608-
o.Resolve()
609-
return o.OpArg.Output()
594+
func (o *JumpAbs) Resolve() {
595+
o.OpArg.Arg = o.Dest.Pos()
610596
}
611597

612598
// FIXME Jump Relative

0 commit comments

Comments
 (0)
0