kekyo / IL2C

IL2C - A translator for ECMA-335 CIL/MSIL to C language.
Apache License 2.0
403 stars 36 forks source link

No static constructor is generated, though referenced, C compiler fails #97

Closed cyborgyn closed 2 years ago

cyborgyn commented 3 years ago

Consider the following case:

    class Program
    {
        static string category = "category";
    }

C code generated with a call to static constructor, which is not generated:

static struct Program_STATIC_FIELDS_DECL__ /* IL2C_STATIC_FIELDS */
{
    IL2C_STATIC_FIELDS* pNext__;
    const uint16_t objRefCount__;
    const uint16_t valueCount__;
    //-------------------- objref
    System_String* category;
} Program_STATIC_FIELDS__ = { NULL, 1, 0 };

System_String** Program_category_HANDLER__(void)
{
    if (il2c_unlikely__(Program_STATIC_FIELDS_initializerCount__ != *il2c_initializer_count))
    {
        Program_STATIC_FIELDS_initializerCount__ = *il2c_initializer_count;
        il2c_register_static_fields(&Program_STATIC_FIELDS__);
        Program__cctor();
    }
    return &Program_STATIC_FIELDS__.category;
}

Thus C compiler fails with Program__cctor(); is not declared.

kekyo commented 2 years ago

@cyborgyn Sorry for the very delay. I understood #100 work and imported it with cherry-pick. 2cbb6f1da780acb289fb9f98d7b4adda99fd06c3

Related #98