On Thursday, 19 February 2026 at 15:37:42 UTC, user1234 wrote:
Not very important but I'd like to know if it's possible... so try this with DMD

```d
module runnable;

// The OK part
int ok1(){return 1;}
int ok2(){return 2;}

void OK()
{
    ulong r;
    asm
    {
        xor R8, R8;
        call ok1;
        add R8, RAX;
        call ok2;
        add R8, RAX;
        mov r, R8;
    }
    assert(r == 3);
}

// The NG part
int ng(int i)() => i;
static foreach (i; 1..3)
    alias T = ng!i;

void NG()
{
    ulong r;
    asm
    {
        xor R8, R8;
        call _D8runnable__T2ngVii1ZQiFNaNbNiNfZi;
        add R8, RAX;
        call _D8runnable__T7ngVii2ZQnFNaNbNiNfZi;
        add R8, RAX;
        mov r, R8;
    }
    assert(r == 3);
}

int main()
{
    OK();
    NG();
    return 0;
}
```

so you'll get

Error: function `runnable.NG` label `_D8runnable__T2ngVii1ZQiFNaNbNiNfZi` is undefined Error: function `runnable.NG` label `_D8runnable__T7ngVii2ZQnFNaNbNiNfZi` is undefined

So to keep things simples the idea is to provide a valid function identifier in the asm. I've used compiler explorer to get the __valid__ mangled version (https://godbolt.org/z/WYMqMhnWG). No luck.

Is that even possible ?

I never had any luck meta programming asm blocks; I believe your best option is to mixin the whole block, in which case you cant call templates and I dont think mangled names is the right syntax. I believe youd have to give it a simple local name then call that `alias F1=ng!1;` `call F1;`

looking at my hotreload gist I got this sort of thing working:

```d
// The NG part
int ng(int i)(){return i;}
static foreach (i; 1..3)
    alias T = ng!i;
import std;
import core.stdc.stdlib;
import core.sys.posix.dlfcn;
void NG()
{
auto f=cast(typeof(&ok1))dlsym(null,ng!2.mangleof);//"_D8runnable__T2ngVii1ZQiFNaNbNiNfZi");
    f().writeln;
}
```

Id suggest trying to go this direction https://gist.github.com/crazymonkyyy/e6edc498376da0501c851c8c339eba4b

Reply via email to