ooc-lang / rock

:ocean: self-hosted ooc compiler that generates c99
http://ooc-lang.org/
MIT License
401 stars 40 forks source link

Wrong cast to non scalar type, and some other problems. #986

Open cNoNim opened 8 years ago

cNoNim commented 8 years ago

I try build rock in Visual Studio 2015, but got several bugs which i don't understand. I can fix that manually in C source, but I think it's wrong.

I tried minimize broken code, and:

Handler: interface {
    onHandle: func
}

DefaultHandler: class implements Handler {
    init: func
    onHandle: func
}

Foo : class {
    handler: Handler { get set }
    init: func {
        handler = DefaultHandler new()
    }
}

main: func {
    foo := Foo new()
    foo handler onHandle()
}

in C source I got... example:

Handler__reference test_temp__Foo___gethandler__(test_temp__Foo* this) {
    return (Handler__reference) ((test_temp__FooClass *)((lang_types__Object *)this)->class)->__gethandler__((test_temp__Foo*)this);
}

Handler_reference is struct, and I think such cast is GCC extension not allowed in C99, and in Visual C.

Next. In some places uses structs without member, is also GCC extension imho, and Visual C++ throw

error C2016: C requires that a struct or union has at least one member.

And finally. When I tried minimize broken code, I write:

Handler: interface {
    onHandle: func
}

DefaultHandler: class implements Handler {
    init: func
    onHandle: func
}

main: func {
    handler: Handler
    handler = DefaultHandler new()
    handler onHandle()
}

and got

lang_Numbers__Int main(lang_Numbers__Int __test_temp_argc1, lang_Character__CString* __test_temp_argv2) {
...
    Handler__reference handler = NULL; // 1
    handler = test_temp__DefaultHandler_new(); // 2
    test_temp__Handler_onHandle((Handler__reference) handler); // 3
    return 0;
}

in 1 place struct Handler__reference initialized like pointer in 2 place DefaultHandler * assigned to struct Handler_reference in 3 place we also have cast to non scalar type.

alexnask commented 8 years ago

Hi and thanks for the report.

Interfaces are a known buggy feature and MSVC compatibility has not been tested in a long time.
However, I will take a look into these tomorrow, especially the last issue you pointed out.

cNoNim commented 8 years ago

Hi and thanks for the respond

I can build and test rock on MSVC, and fix not cross-platform places, but first I think need fix GCC specific code.

To build rock on MSVC I change some places:

Then I use --driver=dummy or bootstrap C source and manually add files to MSVC project.

horasal commented 8 years ago

You can also use cmake driver to generate msvc project files.