Battle-plan for CTFE
ketmar via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Fri Jul 8 23:13:06 PDT 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. ;-)
More information about the Digitalmars-d-announce
mailing list