<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Christo Crause via fpc-devel <<a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>> schrieb am Di., 19. Jan. 2021, 05:37:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jan 17, 2021 at 3:51 PM Florian Klämpfl via fpc-devel <<a href="mailto:fpc-devel@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-devel@lists.freepascal.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Am 08.01.21 um 22:00 schrieb Christo Crause via fpc-devel:<br>
> On Sun, Oct 4, 2020 at 1:49 PM Christo Crause <<a href="mailto:christo.crause@gmail.com" target="_blank" rel="noreferrer">christo.crause@gmail.com</a> <br>
> <mailto:<a href="mailto:christo.crause@gmail.com" target="_blank" rel="noreferrer">christo.crause@gmail.com</a>>> wrote:<br>> var<br>
>    w: word = $BEEF; section '.eeprom';<br>
>    b: byte;<br>
> <br>
> procedure doSomething(constref tmp: word);<br>
> begin<br>
>    b := hi(tmp);<br>
> end;<br>
> <br>
> begin<br>
>    doSomething(w);<br>
> end.<br>
> <br>
> At the moment there doesn't appear to be a way to do this without <br>
> changing or adding something to the compiler.  One idea could be to <br>
> define new types identifying types in a specific address space, such as <br>
> Teepromword. In this case the above example could be written as:<br>
> var<br>
>    w: Teepromword = $BEEF;<br>
>    b: byte;<br>
> <br>
> procedure doSomething(constref tmp: word); overload;<br>
> begin<br>
>    b := hi(tmp);<br>
> end;<br>
> <br>
> procedure doSomething(constref tmp: Teepromword); overload;<br>
> begin<br>
>    b := hi(tmp);<br>
> end;<br>
> <br>
> begin<br>
>    doSomething(w);<br>
> end.<br>
> <br>
> This way the compiler knows how to generate appropriate access based on <br>
> the parameter type. It however leads to lots of code duplication.  Which <br>
> got me thinking about generics - could this be handled internally in the <br>
> compiler via generics?  It isn't clear to me how to tackle these issues <br>
> so any advice would be appreciated.<br>
<br>
I would simply not allow to use such references as independent pointers. <br>
This causes too much bloat. They can be used in assignments and <br>
expressions and that's it.<br></blockquote><div><br></div><div>I have given up on that idea.  I'm now busy working on Jonas's suggestion of section specific pointers (example: <a href="https://github.com/ccrause/freepascal/wiki/Better-support-for-address-spaces-in-FPC#section-pointer-example" target="_blank" rel="noreferrer">https://github.com/ccrause/freepascal/wiki/Better-support-for-address-spaces-in-FPC#section-pointer-example</a>).</div><div><br></div><div>At the moment it introduces no runtime overhead (other than the required access instructions of course), <br></div><div>but to make it work across units is problematic.  I suspect an extra field is required to store the section information associated with a pointer type (at least the way I've implemented it) in a ppu.  If unit A defining such a pointer and a procedure using it is as parameter is called from unit B, it works if both units are compiled together.  If unit A is already compiled and unit B is recompiled (symbols loaded from ppu) it doesn't carry the section information across and the compiler cannot determine which overloaded procedure to call.</div></div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">It isn't that hard. You essentially need to make sure that the necessary information is written in tpointerdef.ppuwrite and read again in tpointerdef.ppuload. You also need to increase the PPULongVersion in unit ppu and adjust the code in the ppudump utility. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>