<div dir="ltr">Hi Alistair,<div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 22, 2018 at 11:32 AM, Alistair Grant <span dir="ltr"><<a href="mailto:akgrant0710@gmail.com" target="_blank">akgrant0710@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>
Hi Everyone,<br>
<br>
VMMaker plugin C generation allows the option: pragma to be used to<br>
conditionally compile methods in specific VMs, e.g.:<br>
<br>
<br>
primitiveForPharoOnWin32<br>
    <option: #_WIN32><br>
    <option: #PharoVM><br>
<br>
    ^self doStuff<br>
<br>
<br>
<br>
will generate C code along the lines of:<br>
<br>
#if _WIN32 && PharoVM<br>
sqInt primitiveForPharoOnWin32()<br>
{ ... }<br>
#endif<br>
<br>
<br>
The problem is that on non Win32 platforms this will cause a compiler<br>
error as _WIN32 isn't defined, and the resulting directive is invalid.<br>
<br>
Modifying TMethod>><wbr>outputConditionalDefineFor:on: to generate:<br>
<br>
#if defined(_WIN32) && defined(PharoVM)<br>
sqInt primitiveForPharoOnWin32()<br>
{ ... }<br>
#endif<br>
<br>
<br>
avoids the problem.<br></blockquote><div><br></div><div>Alas no; it's wrong.  If -DPharoVM=0 then defined(PharoVM) is still true.  I would rather see</div><div><br></div><div><span style="color:rgb(0,0,0);font-size:12.800000190734863px">primitiveForPharoOnWin32</span><br style="color:rgb(0,0,0);font-size:12.800000190734863px"><span style="color:rgb(0,0,0);font-size:12.800000190734863px">    <option: #_WIN32></span><br style="color:rgb(0,0,0);font-size:12.800000190734863px"><span style="color:rgb(0,0,0);font-size:12.800000190734863px">    <option: #PharoVM></span><br style="color:rgb(0,0,0);font-size:12.800000190734863px"><br style="color:rgb(0,0,0);font-size:12.800000190734863px"><span style="color:rgb(0,0,0);font-size:12.800000190734863px">    ^self doStuff</span><br style="color:rgb(0,0,0);font-size:12.800000190734863px"><br style="color:rgb(0,0,0);font-size:12.800000190734863px">=><br style="color:rgb(0,0,0);font-size:12.800000190734863px"><br style="color:rgb(0,0,0);font-size:12.800000190734863px"><span style="color:rgb(0,0,0);font-size:12.800000190734863px">#if _WIN32</span></div><div><span style="color:rgb(0,0,0);font-size:12.800000190734863px"># if PharoVM</span><br style="color:rgb(0,0,0);font-size:12.800000190734863px"><span style="color:rgb(0,0,0);font-size:12.800000190734863px">sqInt primitiveForPharoOnWin32()</span><br style="color:rgb(0,0,0);font-size:12.800000190734863px"><span style="color:rgb(0,0,0);font-size:12.800000190734863px">{ ... }</span><br style="color:rgb(0,0,0);font-size:12.800000190734863px"><span style="color:rgb(0,0,0);font-size:12.800000190734863px"># endif /* </span><span style="color:rgb(0,0,0);font-size:12.800000190734863px">PharoVM</span><span style="color:rgb(0,0,0);font-size:12.800000190734863px"> */</span><br style="color:rgb(0,0,0);font-size:12.800000190734863px"><span style="color:rgb(0,0,0);font-size:12.800000190734863px">#endif /* _WIN32 */</span><br></div><div><span style="color:rgb(0,0,0);font-size:12.800000190734863px"><br></span></div><div><font color="#000000"><span style="font-size:12.800000190734863px">which should work: </span></font>(C99, 6.10.1p4) "After all replacements due to macro expansion and the defined unary operator have been performed, all remaining identifiers (including those lexically identical to keywords) are replaced with the pp-number 0"  So in fact, that #if _WIN32 && PharoVM causes an error is a bug (or is it a side effect of _WIN32 not being considered a keyword?), but we have to live in a buggy world.</div><div><font color="#000000"><span style="font-size:12.800000190734863px"><br></span></font></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<br>
Any comment or opposition to me submitting this change?<br></blockquote><div><br></div><div>If you can generate and test the nested solution I outlined then feel free.  BTW, I *love* to see </div><div><br></div><div>#if FIRSTLEVEL</div><div>#<space>if SECONDLEVEL</div><div>#<tab>if THIRDLEVEL</div>#<tab><space><space>if FOURTHLEVEL</div><div class="gmail_quote"><br></div><div class="gmail_quote"><div>etc.  So feel free to add a (dynamic or inst var in CCodeGenerator). variable maintaining the nesting.  VMMaker.oscog assumes tabs are every 4 spaces. This should be written down and ideally added as editor metadata to the source files.  But I may not, and perhaps should not, be able to get my own way on this.</div><div><br></div><div>But if adding</div><div><br></div><div>#if !defined(_WIN32)</div><div># define _WIN32 0</div><div>#endif</div><div><br></div><div>somewhere that might be better.  Alas if falls foul of the same defined(_WIN32) trap.  I wonder, does</div><div><br></div><div><span style="color:rgb(0,0,0);font-size:12.800000190734863px">#if defined(_WIN32) && defined(PharoVM) && (</span><span style="color:rgb(0,0,0);font-size:12.800000190734863px">_WIN32 && PharoVM)</span><br style="color:rgb(0,0,0);font-size:12.800000190734863px"><span style="color:rgb(0,0,0);font-size:12.800000190734863px">sqInt primitiveForPharoOnWin32()</span><br style="color:rgb(0,0,0);font-size:12.800000190734863px"><span style="color:rgb(0,0,0);font-size:12.800000190734863px">{ ... }</span><br style="color:rgb(0,0,0);font-size:12.800000190734863px"><span style="color:rgb(0,0,0);font-size:12.800000190734863px">#endif</span><br></div><div><span style="color:rgb(0,0,0);font-size:12.800000190734863px"><br></span></div><div><span style="color:rgb(0,0,0);font-size:12.800000190734863px">work?  And when you say it doesn't work, on which </span><font color="#000000"><span style="font-size:12.800000190734863px">platform/compiler combinations are you talking of?</span></font></div><div><span style="color:rgb(0,0,0);font-size:12.800000190734863px"><br></span></div></div><div class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</div></div>