IL2C icon indicating copy to clipboard operation
IL2C copied to clipboard

cc65 / c89 / c90 compiler support suggestions.

Open zezba9000 opened this issue 5 years ago • 5 comments

To support c89 with try catch you could base your output off "setjmp" && "longjmp".

#include <stdio.h>
#include <setjmp.h>

jmp_buf __threadExceptionBuff;

#define TRY switch(setjmp(__threadExceptionBuff)) { case 0: while(1) {
#define CATCH(x) break; case x:
#define FINALLY break; } default: {
#define TRY_END break; } }
#define THROW(x) longjmp(__threadExceptionBuff, x)

#define EXCEPTION (1)
#define NOT_IMPLEMENTED_EXCEPTION (2)

void Foo()
{
    THROW(NOT_IMPLEMENTED_EXCEPTION);
}

void main()
{
    TRY
    {
        printf("Start\n");
        Foo();
        printf("End\n");
    }
    CATCH (NOT_IMPLEMENTED_EXCEPTION)
    {
        printf("Catch Not Implemented Exception\n");
    }
    CATCH (EXCEPTION)
    {
        printf("Catch Exception\n");
    }
    FINALLY
    {
        printf("Finally\n");
    }

To support c89 local variable scoping rules. You could define all of local variables that live on the stack at the top of each block. Example:

struct A
{
    int x, y;
};

void Foo()
{
    // all local stack objects within this scope get pre-defined up here at the top of the block
    A a;
    A a2;
    int i;

    // Now you can use them normally and this will compile in c89....
    for (i = 0; i != 1; ++i)
    {
        // all local stack objects within this scope get pre-defined up here at the top of the block
        A b;
        float t;
        // do stuff....
    }
}

I use the c65 compiler to test out portability: https://github.com/cc65/cc65

zezba9000 avatar Nov 16 '18 20:11 zezba9000

Ouf, I don't notice this issue. Our discussion is here


Ya, it try block methodology by Dr. Nidito? I know it and the IL2C's based on it. (It's the sample) The .NET CLS has a lot of typed exceptions. We have to identicate the CLS types at runtime. So all CLS types have the runtime-information table. We can choice the runtime type at the exception handler by the table pointer what caught the exception type.

kekyo avatar Nov 16 '18 21:11 kekyo

Thanks @zezba9000 suggests for me to what problem for C89 scope block, I reopen this issue and save for memorize for me ;)

kekyo avatar Nov 16 '18 21:11 kekyo

Ok cool. This is one of the best C# / .NET projects I've seen!

One other suggestion is you might consider adding "tags" to your GitHub project page. I've searched for IL2C on GitHub and Google many times but never found this for some reason.

zezba9000 avatar Nov 16 '18 22:11 zezba9000

Are you explaining it about the "GitHub topics?" I didn't know it! I'll set it.

kekyo avatar Nov 16 '18 22:11 kekyo

Yes the "GitHub topics". Makes it easier for others to find your project :)

zezba9000 avatar Nov 16 '18 22:11 zezba9000