[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-dev] [commit] switch inlined




switch is now inlined when possible. In order to be inlined, the matching values must be literal Integers, Floats, Chars, Symbols and the functions must have no variables or arguments. It uses a hash lookup internally so it should scale to any number of clauses.

{
	switch (x,
		\a, { 123 },
		\b, { 456 },
		\c, { 789 },
		{ 135 }
	).postln;
}.def.dumpByteCodes;

BYTECODES: (29)
  0   01 19    PushInstVarX 'x'
  2   40       PushLiteral instance of Array (04C8F850, size=16, set=04)
  3   8F 1C       ControlOpcode
  5   2C 7B    PushInt 123
  7   FC 00 0F JumpFwd 15  (25)
 10   2D 01 C8 PushInt 456
 13   FC 00 09 JumpFwd 9  (25)
 16   2D 03 15 PushInt 789
 19   FC 00 03 JumpFwd 3  (25)
 22   2D 00 87 PushInt 135
 25   B0       TailCallReturnFromFunction
 26   C1 3A    SendSpecialMsg 'postln'
 28   F2       BlockReturn
a FunctionDef in closed FunctionDef