Improved code quality

This commit is contained in:
2025-02-20 16:55:17 +01:00
parent 9779476fe7
commit 36d0142573
12 changed files with 51 additions and 37 deletions

View File

@ -24,7 +24,7 @@ func (c *compiler) call(x asm.Instruction) {
}
distance := destination - (pointer.Position + Address(pointer.Size))
return Address(distance)
return distance
}
c.codePointers = append(c.codePointers, pointer)

View File

@ -40,7 +40,7 @@ func (c *compiler) jump(x asm.Instruction) {
}
distance := destination - (pointer.Position + Address(pointer.Size))
return Address(distance)
return distance
}
c.codePointers = append(c.codePointers, pointer)

View File

@ -40,7 +40,7 @@ restart:
case 0xEB: // JMP
jump = []byte{0xE9}
default:
panic(fmt.Errorf("failed to increase pointer size for instruction 0x%x", opCode))
panic(fmt.Sprintf("failed to increase pointer size for instruction 0x%x", opCode))
}
pointer.Position += Address(len(jump) - int(pointer.OpSize))
@ -90,9 +90,10 @@ restart:
for _, pointer := range c.dllPointers {
destination := importsStart + pointer.Resolve()
delta := destination - Address(c.codeStart+pointer.Position+Address(pointer.Size))
from := c.codeStart + pointer.Position + Address(pointer.Size)
offset := destination - from
slice := c.code[pointer.Position : pointer.Position+4]
binary.LittleEndian.PutUint32(slice, uint32(delta))
binary.LittleEndian.PutUint32(slice, uint32(offset))
}
}
}