[fpc-devel] Proposal for implementing named address space support

Christo Crause christo.crause at gmail.com
Fri Jan 8 22:00:13 CET 2021


On Sun, Oct 4, 2020 at 1:49 PM Christo Crause <christo.crause at 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.

Best regards,
Christo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20210108/867a8a31/attachment.htm>


More information about the fpc-devel mailing list