On Wednesday, 23 May 2018 at 14:25:44 UTC, Steven Schveighoffer wrote:

How do I know I'm in a function?

I don't think you're ever actually "in a function". The code is just data passing through the compiler. I think what your may be asking is "How do I know I'm working on a function?". That depends on what stage in the the code->binary translation process your at (parsing, semantic, {not sure about others}). Usually this is done with a `visit(` method. grep for `visit(FuncDeclaration` or `visit(FuncExp`. You may be deep in the body of a function, processing some other expression, though. For that, you'll want to turn on the logging features in DMD when you do a build so you can see output each time an expression is visited; grep for `LOGSEMANTIC`.


How do I know I'm in a template?

Same principle as above. grep for `visit(TemplateInstance` or `visit(TemplateDeclaration`.

What module am I in?

grep `visit(Module`, maybe?

I think for all of my answers above, you can also navigate up the AST using the `.parent` property of a symbol; see the dmd.dsymbol.Dsybmol class.

How do I know what has been run?

I'd say by turning on logging in the various source files.

What is the proper way to generate lowered code?

You're basically writing D code with D code. The `Expression` class and it's derived classes are where its at. See my failed attempt at lowering array literals to template here: https://github.com/dlang/dmd/pull/8245/files

Also my Binary Assignment Operators PR is an exemplary exercise in lowering: https://github.com/dlang/dmd/pull/7079/files

Hope that helps at least a little. It'll probably just generate more questions, but keep them coming.

Mike

Reply via email to