switchJumpTable.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function AsmModuleSwitch() {
  6. "use asm";
  7. function fib(x) {
  8. x = x|0;
  9. switch(x|0) {
  10. case 0: return 1;
  11. case 1: return 1;
  12. case 2: return 2;
  13. case 3: return 3;
  14. case 4: return 5;
  15. case 5: return 8;
  16. case 6: return 13;
  17. case 7: return 21;
  18. case 8: return 34;
  19. case 9: return 55;
  20. }
  21. return -1;
  22. }
  23. return {
  24. fib: fib
  25. };
  26. }
  27. var asmModuleSwitch = AsmModuleSwitch();
  28. WScript.Echo(asmModuleSwitch.fib(0));
  29. WScript.Echo(asmModuleSwitch.fib(1));
  30. WScript.Echo(asmModuleSwitch.fib(2));
  31. WScript.Echo(asmModuleSwitch.fib(3));
  32. WScript.Echo(asmModuleSwitch.fib(4));
  33. WScript.Echo(asmModuleSwitch.fib(5));
  34. WScript.Echo(asmModuleSwitch.fib(6));