Am 08.01.21 um 22:00 schrieb Christo Crause via fpc-devel:
On Sun, Oct 4, 2020 at 1:49 PM Christo Crause <christo.cra...@gmail.com <mailto:christo.cra...@gmail.com>> wrote:

    FPC can use the section modifier to specify which address space
    should be used for data.


I've made some progress in certain areas (basically static variables), the following type of AVR code example works:
var
   w: word = $BEEF; section '.eeprom';
   b: byte;
begin
   b := hi(w);
end.

However I see problems with propagating section information through reference type parameters. I'm not sure how to propagate the section information of the variable "w" through the parameter into the procedure of the following example:
var
   w: word = $BEEF; section '.eeprom';
   b: byte;

procedure doSomething(constref tmp: word);
begin
   b := hi(tmp);
end;

begin
   doSomething(w);
end.

At the moment there doesn't appear to be a way to do this without changing or adding something to the compiler.  One idea could be to define new types identifying types in a specific address space, such as Teepromword. In this case the above example could be written as:
var
   w: Teepromword = $BEEF;
   b: byte;

procedure doSomething(constref tmp: word); overload;
begin
   b := hi(tmp);
end;

procedure doSomething(constref tmp: Teepromword); overload;
begin
   b := hi(tmp);
end;

begin
   doSomething(w);
end.

This way the compiler knows how to generate appropriate access based on the parameter type. It however leads to lots of code duplication.  Which got me thinking about generics - could this be handled internally in the compiler via generics?  It isn't clear to me how to tackle these issues so any advice would be appreciated.

I would simply not allow to use such references as independent pointers. This causes too much bloat. They can be used in assignments and expressions and that's it.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to