Implemented function pointers as parameters

This commit is contained in:
Eduard Urbach 2025-01-30 23:57:41 +01:00
parent 977028f8ab
commit 699dbe4fd5
Signed by: eduard
GPG key ID: 49226B848C78F6C8
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: