Switch() - hpgDesigns/hpgdesigns-dev.io GitHub Wiki
The implementation of switch() varies from language to language, and, indeed, from release to release in ENIGMA. Throughout its history, ENIGMA has implemented switch in three different ways. R1 and R4 didn't implement it at all; R2 and R3 implemented it according to PHP's specification. Beyond those releases, switch() should be implemented to allow use of C switches, hash lookups, or GM switches.
myContainer mc(1,2,3);
switch (mc)
{
case myContainer(2,3,1):
doSomething();
break;
case myContainer(3,1,2):
doSomethingElse();
break;
case myContainer(1,2,3):
overflow()
default:
break;
}
myContainer mc(1,2,3);
{
myContainer ENIGMA_SWITCHV0 = (mc);
if (ENIGMA_SWITCHV0 == (myContainer(2,3,1))) goto $switch0_case0;
if (ENIGMA_SWITCHV0 == (myContainer(3,1,2))) goto $switch0_case1;
if (ENIGMA_SWITCHV0 == (myContainer(1,2,3))) goto $switch0_case2;
goto $switch0_default;
}
R4 Proposed Implementation
This will be implemented in the next 24 hours.
Input:
switch (mc)
{
case "string":
doSomething();
break;
case 2.5:
doSomethingElse();
break;
case 99:
doAnotherSomethingElse();
case x:
overflow();
default:
doOneMoreThing();
break;
}
Output:
{
const auto $s0value = (mc);
switch (enigma::switch(_hashmc))
{
case 413184: if ($s0value == "string") goto $s0c0; goto $s0nohash;
case 163840: if ($s0value == 2.5) goto $s0c1; goto $s0nohash;
case 99: if (enigma::gswitch() == 99) goto $s0c2; goto $s0nohash;
default: $s0nohash:
if (enigma::gswitch() == x) goto $s0c3;
goto $s0default;
$s0c0:
doSomething();
break;
$s0c1:
doSomethingElse();
break;
$s0c2:
doAnotherSomethingElse();
$s0c3:
overflow();
$s0default:
doOneMoreThing();
break;
}
}