ooc-lang / rock

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

Template type instances generated in separate modules do not generate include statements in C code #985

Open alexnask opened 8 years ago

alexnask commented 8 years ago

Here is an example in some code I've been writing:

UnsafeArray.ooc

UnsafeArray: cover template <T> {
    data: T*
    length: Int

    init: func@ (=length) {
        data = gc_malloc(T size * length)
    }

    operator [] (i: Int) -> T {
        data[i]
    }

    operator@ []= (i: Int, t: T) -> T {
        data[i] = t
    }
}

Bitmap.ooc

import ../UnsafeArray

RgbColor: cover {
    r, g, b: UInt8

    init: func@ (=r, =g, =b)
}

Bitmap: class {
    width, height: Int
    data: UnsafeArray<RgbColor>

    pixelCount ::= width * height
    /* ...  */
}

This piece of code generates invalid C code because the generated template instance does not have access to RgbColor's declaration.

Rock should automatically deduce what additional imports are needed and add them to the template type's module.

alexnask commented 8 years ago

Temporary fix is obviously adding imports manually (e.g. import Bitmap in this example)