Implemented function pointers as parameters

This commit is contained in:
2025-01-30 23:57:41 +01:00
parent 313302b9c8
commit dd6d1cc16c
5 changed files with 76 additions and 36 deletions

View File

@ -225,24 +225,37 @@ func (a Assembler) Finalize(dlls dll.List) ([]byte, []byte) {
opSize := len(code) - size - start
regLabel := x.Data.(*RegisterLabel)
if !strings.HasPrefix(regLabel.Label, "data_") {
panic("non-data moves not implemented yet")
if strings.HasPrefix(regLabel.Label, "data_") {
dataPointers = append(dataPointers, &Pointer{
Position: Address(len(code) - size),
OpSize: uint8(opSize),
Size: uint8(size),
Resolve: func() Address {
destination, exists := dataLabels[regLabel.Label]
if !exists {
panic("unknown label")
}
return Address(destination)
},
})
} else {
funcPointers = append(funcPointers, &Pointer{
Position: Address(len(code) - size),
OpSize: uint8(opSize),
Size: uint8(size),
Resolve: func() Address {
destination, exists := codeLabels[regLabel.Label]
if !exists {
panic("unknown label")
}
return Address(destination)
},
})
}
dataPointers = append(dataPointers, &Pointer{
Position: Address(len(code) - size),
OpSize: uint8(opSize),
Size: uint8(size),
Resolve: func() Address {
destination, exists := dataLabels[regLabel.Label]
if !exists {
panic("unknown label")
}
return Address(destination)
},
})
}
case NEGATE: