July 06, 2016
On Wednesday, 6 July 2016 at 08:16:32 UTC, Rory McGuire wrote:
> Thought as much, wondered if the ideas about how they work were being shared; often one idea sparks another.

sure, some ideas flows; mostly very high-level. for example, proper fallback to the original interpreter was invented by Stefan, but i was faster to make it work. ;-)

after all, we aren't competitors. he is still working hard on full implementation, and i am just having some fun, investigating creation of DMD backends by the way.
July 07, 2016
just... can't... stop...

some current statistics:

druntime
total interpreted calls: 27,146
total complied calls   : 1,330

phobos
total interpreted calls: 6,492,826
total complied calls   : 19,975

i can't do function calls from compiled code yet, so number of compiled calls is low, and no speedup can be seen. also, i can do only integer math and string concatenation.

yes, phobos has ALOT of CTFE! ;-)

this is statistics from "make -f posix.mak unittest" (yes, i can pass all unittests too!)

still, not that bad for a toy implementation! ;-)
July 07, 2016
yay. ackemann(3, 7) in 70 milliseconds! and it does TCO.

default interpreter is unable to execute that -- recursion is too deep.
July 07, 2016
On Tuesday, 10 May 2016 at 00:36:21 UTC, Walter Bright wrote:
> On 5/9/2016 2:32 PM, Andrej Mitrovic via Digitalmars-d-announce wrote:
>> On 5/9/16, Stefan Koch via Digitalmars-d-announce
>> <digitalmars-d-announce@puremagic.com> wrote:
>>> I was shocked to discover that the PowExpression actually depends
>>> on phobos!
>>
>> I seem to remember having to implement diagnostics in DMD asking for
>> the user to import std.math. I'm fairly confident it had something to
>> do with power expressions.
>>
>> Yah, it's a mess. :)
>>
>
> The pow stuff should just be done in dmd without reference to the library.

I just made a PR to fix it for ctfe.
It's a hack but then again ...
The whole handling of PowExp is a hack.
July 07, 2016
On Thursday, 7 July 2016 at 13:55:44 UTC, Stefan Koch wrote:
>
> I just made a PR to fix it for ctfe.
> It's a hack but then again ...
> The whole handling of PowExp is a hack.

Clarification now it works on Literals.
It is still not available at ctfe and the full non-hackish fix will take a while.
July 08, 2016
On Thursday, 7 July 2016 at 17:47:28 UTC, Stefan Koch wrote:
> On Thursday, 7 July 2016 at 13:55:44 UTC, Stefan Koch wrote:
>>
>> I just made a PR to fix it for ctfe.
>> It's a hack but then again ...
>> The whole handling of PowExp is a hack.
>
> Clarification now it works on Literals.
> It is still not available at ctfe and the full non-hackish fix will take a while.

I forgot to mention I posted a short article about the CTFE design on my blog.
https://codesoldier.blogspot.com

Feel free to comment or give suggestions.
July 08, 2016
On Friday, 8 July 2016 at 11:32:10 UTC, Stefan Koch wrote:
> I forgot to mention I posted a short article about the CTFE design on my blog.
> https://codesoldier.blogspot.com
>
> Feel free to comment or give suggestions.

Thanks! Posts like these are always interesting to read. I noticed a few mistakes:

I have been working a rewrite -> I have been working on a rewrite
complicated corer-case -> complicated corner-case
that have to handled correctly -> that have to be handled correctly
a cononical from -> a canonical from
July 08, 2016
On Friday, 8 July 2016 at 12:17:29 UTC, Rene Zwanenburg wrote:
> On Friday, 8 July 2016 at 11:32:10 UTC, Stefan Koch wrote:
>> I forgot to mention I posted a short article about the CTFE design on my blog.
>> https://codesoldier.blogspot.com
>>
>> Feel free to comment or give suggestions.
>
> Thanks! Posts like these are always interesting to read. I noticed a few mistakes:
>
> I have been working a rewrite -> I have been working on a rewrite
> complicated corer-case -> complicated corner-case
> that have to handled correctly -> that have to be handled correctly
> a cononical from -> a canonical from

I addressed the spelling mistakes.
Thanks for pointed them out.
Also more complex SwitchStatements work now.


July 09, 2016
On Friday, 8 July 2016 at 23:31:38 UTC, Stefan Koch wrote:
and mine is segfaulting in some bizarre ways (i failed my basic ++ and -- math, and so the stack ;-).

still, it is almost working, with support for both compiled and interpreted function calls, almost full range of integer math and some string ops. druntime still compiles and passes unittests, but phobos segfaulted somewhere deep in my CTFE engine. i really need to re-check all added opcodes and codegen.

writing that was surprisingly easy. and sometimes simply surprisingly: "how did you came to me with this, DMD?! eh? aha, i see now, thank you, grep." ;-)

some stats: virtual machine is <30KB of code now. compiler is ~70KB, but there is alot of copypasta in there (you know, it happens when the code grows organically).

if someone is interested in interop between frontend and backend, writing engine like this is a nice way to make yourself familiar, as CTFE interpreter effectively gets already semanticed AST, with most things correctly lowered and so on. so you only have to copy dummy CtfeCompiler from dinterpret.d (it only count vars there, otherwise doing nothing), and start extending it.

even when we'll get new shiny engine from Stefan, i still recommend to anyone who wish to understand how compiled and processed code looks inside the frontend at least try to implement some simple bytecode compiler. with some care seeing that you are effectively replacing compiler parts, and it is still able to compile complex unittests is... yeah, go find the word. ;-)
July 09, 2016
p.s. it is, btw, completely possible to add at least something like "ctfe tracer" (something like old basic "trace on" command), or even some kind of gdb-like debugger to ctfe engine.

it won't, of course, find it's way into mainline, but may still be a fun project to do.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18