olofson / audiality2

A realtime scripted modular audio engine for video games and musical applications.
http://audiality.org/
zlib License
79 stars 5 forks source link

A2S 'switch' construct #278

Open olofson opened 8 years ago

olofson commented 8 years ago

A2S needs a 'switch' construct, to avoid 'if' chains and similar constructs, for cleaner code and faster execution.

Desired features:

The syntax should probably be something like this:

switch x {
    1:  XIsOne
    2 3 4:  DoSomething x
    5 {
        debug 5
        Five
    }
    6..9:   InRange x
    A:  XEqualsA
    *:  debug x
}

Note that both "N:" and "N {...}" are already existing constructs that mean completely different things in other contexts, but within a 'switch', there probably isn't much risk of confusion. It's not ideal, but what are the (reasonable) options?

On the VM side, this should probably be implemented as one generic SWITCH instruction, which supports mixed value, range, and register cases, and at least one optimized instruction for the "values only" case.