Improved branch compilation

This commit is contained in:
2024-07-07 21:55:32 +02:00
parent 6aad74d6dd
commit ee16774fe7
9 changed files with 160 additions and 113 deletions

View File

@ -57,7 +57,12 @@ func (a Assembler) Finalize() ([]byte, []byte) {
Position: Address(len(code) - size),
Size: uint8(size),
Resolve: func() Address {
destination := labels[label.Name]
destination, exists := labels[label.Name]
if !exists {
panic("unknown call label")
}
distance := destination - nextInstructionAddress
return Address(distance)
},
@ -100,7 +105,12 @@ func (a Assembler) Finalize() ([]byte, []byte) {
Position: Address(len(code) - size),
Size: uint8(size),
Resolve: func() Address {
destination := labels[label.Name]
destination, exists := labels[label.Name]
if !exists {
panic("unknown jump label")
}
distance := destination - nextInstructionAddress
return Address(distance)
},