audiality2 icon indicating copy to clipboard operation
audiality2 copied to clipboard

A2S 'switch' construct

Open olofson opened this issue 8 years ago • 0 comments

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

Desired features:

  • Clean, simple syntax
  • Multiple values per case
  • Range cases
  • Variable cases

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.

olofson avatar Nov 23 '16 12:11 olofson