soul-lang / SOUL

The SOUL programming language and API
Other
1.71k stars 96 forks source link

Using processor.frequency as buffer or vector size should be allowed but raises error #38

Open DocSunset opened 3 years ago

DocSunset commented 3 years ago

Using the soul command line version 0.9.53, the following minimum example fails to compile with the error:

example.soul:6:11: error: An array size must be a constant
    float[processor.frequency] buffer;

example.soul:

processor example  [[main]]
{
    input stream float audioIn;
    output stream float audioOut;

    float[processor.frequency] buffer; // <<< error occurs here

    void run()
    {
        loop
        {
            audioOut << audioIn;
            advance();
        }
    }
}

Since processor.frequency is described as a compile-time constant in the syntax guide (here), it seems like this should work.

Similarly, changing float[processor.frequency] buffer to float<processor.frequency> buffer also fails, with the error:

simple_delay.soul:6:10: error: Cannot resolve vector size expression in this context
    float<processor.frequency> buffer;

I suppose the sizes should technically be converted to int; doing so doesn't change the errors produced.

I would like to use this in order to have a buffer for delays with a maximum delay time specified (at compile time) in seconds. This requires the buffer size to be an expression using processor.frequency.

julianstorer commented 3 years ago

Yep - absolutely, it should work, and one day we will make it work, but for enormously complicated reasons, it's a really really difficult one to fix.

We've had it on our to-do-list for ages, but... (deep breath...) processor constants are only known at a late stage in the compile process, so they get resolved in HEART code, not SOUL. You're trying to us this constant as part of a type, but the HEART type system is much simpler than the SOUL one, and it can only represent concrete types, not ones that contain unresolved constants.

So despite this seeming like a trivial problem, to get it working means probably about a month's work to completely re-implement the HEART type system (!)

DocSunset commented 3 years ago

Thanks for the clear explanation.