Writing a (dis-)assembler for 8-bit code in D - blog posts

Petar Petar
Tue Apr 20 17:58:07 UTC 2021


On Tuesday, 20 April 2021 at 15:37:25 UTC, Brian wrote:
> On Tuesday, 20 April 2021 at 15:26:28 UTC, Petar Kirov 
> [ZombineDev] wrote:
>> Not sure if that's quite what you want, but you can use 
>> [`pragma(msg, typeOrValueKnownAtCompileTime)`][1] [²][2] to 
>> print stuff at CT.
>
> I suppose what I want to do is traverse the compiler's 
> transformation of the mixin. The mixin page suggests it 
> performs that work at semantic evaluation time.
>
> ~Brian

`-vcg-ast` is your friend then! See for example: 
https://run.dlang.io/is/RlX9Ks

Other than using the compiler frontend as a library (which is 
possible, but not yet straightforward), and the above mentioned 
switch, the typical way most people check the generated code is 
by simply printing the string that is being mixed-in (either at 
compile-time with `pragma(msg)`, or at run-time). Unlike some 
languages, where macros are essentially a separate language, in 
D, if you can call a function at compile-time you can certainly 
call it at run-time as well. So to check that 
`mixin(generateSomeCode())` does what you want, you can simply 
unit test `generateSomeCode` as usual.


More information about the Digitalmars-d mailing list