<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>"constexpr" is essentially to C++ as "pure" would be to FPC.
Some of the methods that involve pointers and var parameters
(which is probably the closest equivalent to the "&"
parameters in C++) may be flagged as impure because they can't be
dereferenced at compile time. Nevertheless, a function that
simply returns a formatted string, rather than writing directly to
an output stream, is certainly doable.</p>
<p>There will likely be a lot of experimentation and trial and error
in its development, but I'll try to at least make it consistent.</p>
<p>I don't quite know how to use generic advanced records yet so
that specific operators are tied to them (can someone enlighten
me?), but to use a vector addition operator as an example, you
could probably write it akin to this:</p>
<p><tt><b>type</b></tt><tt><br>
</tt><tt> TVector4 = </tt><tt><b>packed </b></tt><tt><b>record</b></tt><tt><br>
</tt><tt> X, Y, Z, W: Single;</tt><tt><br>
</tt><tt> </tt><tt><b>end</b></tt><tt>;</tt><tt><br>
</tt><tt><br>
</tt><tt><b>operator </b></tt><tt>+(LHS, RHS: TVector4) Result:
TVector4; </tt><tt><b>vectorcall</b></tt><tt>; </tt><tt><b>pure</b></tt><tt>;</tt><tt><br>
</tt><tt><b>begin</b></tt><tt><br>
</tt><tt> Result.X := LHS.X + RHS.X;</tt><tt><br>
</tt><tt> Result.Y := LHS.Y + RHS.Y;</tt><tt><br>
</tt><tt> Result.Z := LHS.Z + RHS.Z;</tt><tt><br>
</tt><tt> Result.W := LHS.W + RHS.W;</tt><tt><br>
</tt><tt><b>end</b></tt><tt>;</tt><tt><br>
</tt></p>
<p>In theory, this would behave as expected, and with some additions
to the compiler under x86 systems, the 4 commands can be collapsed
into a single ADDPS instruction (so long as 'vectorcall' is used)
that it may then be able to inline in the case of non-constant
inputs (although this would have to be done at the node level).
I'm not sure how well it would work on other platforms - I don't
know enough about machine codes outside of the x86 family.</p>
<p>There is a fair bit of overlap between pure and inline routines
and they may internally end up sharing the node tree that gets
stored in the PPU file, although you wouldn't want to inline a
particularly complex function, while a short function that deals
with pointers cannot be made pure. There are also situations
where a function is pure in the sense of being a mathematical
function, but are impossible to inline (e.g. the <a
moz-do-not-send="true"
href="https://en.wikipedia.org/wiki/Ackermann_function">Ackermann
function</a>).</p>
<p>Note I'm using the directive '<b>pure</b>' because Pascal has
traditionally been a language used for programming tuition and
hence has relatively intuitive keywords, so if you see '<b>pure</b>',
you know it's a <a moz-do-not-send="true"
href="https://en.wikipedia.org/wiki/Pure_function">pure function</a>
analogous to a mathematical function. If anyone has a better
directive name, go for it! (Note that because it's a directive, it
won't cause code to fail to compile if you happen to have a unit
or identifier named 'pure').<br>
</p>
<p>Gareth aka. Kit<br>
</p>
<div class="moz-cite-prefix">On 24/06/2019 17:53, Ben Grasset wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAL4d7Fgw49i41A2J_LzCcTbkOg4v=1ZM7M4b7hmF2kqDNAutoA@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div dir="ltr">On Sat, Jun 22, 2019 at 4:36 PM J. Gareth Moreton
<<a href="mailto:gareth@moreton-family.com"
moz-do-not-send="true">gareth@moreton-family.com</a>>
wrote:<br>
</div>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
I've noticed you're particularly keen on pure functions...
what's the <br>
main use that you envision for them?<br>
</blockquote>
<div><br>
</div>
<div>I'm not the same person of course, but I'm pretty excited
about them in regards to the initialization of constants.</div>
<div><br>
</div>
<div>E.G. I'd love to (eventually, at least) be able to write
something roughly <a
href="https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAKxAEZSAbAQwDtRkBSAJgCFufSAZ1QBXYskwgA5NwDMeFsgYisAag6yAwnlSCCxTEwC2G7BwAMAQQuWRghcFV70IFKIIa%2BVuw6cEXILr6hiayXtZWBJhGAA7MUepaBACeMZgsxpiqACqmfsQiyASqAGqYyLLqAOzhqjmqAB6kqsnNAF6eNnVoLHqYDTHEpe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YSZhl1QIFB8GtggXBCBIclZB04W3o%2BoYRq2Xq/x4MaJo2aaQFkBauF22RzFoYS5qqWhE6hCTGGkQ62pN6RLuu26Q8emBEECeiYnor7QW9/76EwfAgToUgAHcARiKXDakFrM9J86RtUBvCAQRpzct62lFYRx7YKR3g/u0PSBmvjzC4YTZET79/1oOa5q4cxZChNODuNrvs6EXO7s62f9q4Q/TvO6fz4OBnYfVkBhKAA"
moz-do-not-send="true">equivalent to this</a> in Pascal,
where ultimately the structs (or records in Pascal's case)
simply don't directly exist at all at runtime as they're
just completely boiled down to their values.</div>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-devel maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
</blockquote>
<div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br />
<table style="border-top: 1px solid #D3D4DE;">
<tr>
<td style="width: 55px; padding-top: 13px;"><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif" alt="" width="46" height="29" style="width: 46px; height: 29px;" /></a></td>
<td style="width: 470px; padding-top: 12px; color: #41424e; font-size: 13px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;">Virus-free. <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient" target="_blank" style="color: #4453ea;">www.avast.com</a>
</td>
</tr>
</table><a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"> </a></div></body>
</html>