Instruction.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Forward.h>
  8. #include <LibJS/Forward.h>
  9. #define ENUMERATE_BYTECODE_OPS(O) \
  10. O(Load) \
  11. O(LoadImmediate) \
  12. O(Store) \
  13. O(Add) \
  14. O(Sub) \
  15. O(Mul) \
  16. O(Div) \
  17. O(Mod) \
  18. O(Exp) \
  19. O(GreaterThan) \
  20. O(GreaterThanEquals) \
  21. O(LessThan) \
  22. O(LessThanEquals) \
  23. O(AbstractInequals) \
  24. O(AbstractEquals) \
  25. O(TypedInequals) \
  26. O(TypedEquals) \
  27. O(NewBigInt) \
  28. O(NewString) \
  29. O(NewObject) \
  30. O(GetVariable) \
  31. O(SetVariable) \
  32. O(PutById) \
  33. O(GetById) \
  34. O(Jump) \
  35. O(JumpIfFalse) \
  36. O(JumpIfTrue) \
  37. O(JumpIfNotNullish) \
  38. O(Call) \
  39. O(EnterScope) \
  40. O(Return) \
  41. O(BitwiseAnd) \
  42. O(BitwiseOr) \
  43. O(BitwiseXor) \
  44. O(BitwiseNot) \
  45. O(Not) \
  46. O(UnaryPlus) \
  47. O(UnaryMinus) \
  48. O(Typeof) \
  49. O(LeftShift) \
  50. O(RightShift) \
  51. O(UnsignedRightShift) \
  52. O(In) \
  53. O(InstanceOf) \
  54. O(ConcatString)
  55. namespace JS::Bytecode {
  56. class Instruction {
  57. public:
  58. enum class Type {
  59. #define __BYTECODE_OP(op) \
  60. op,
  61. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  62. #undef __BYTECODE_OP
  63. };
  64. Type type() const { return m_type; }
  65. size_t length() const;
  66. String to_string() const;
  67. void execute(Bytecode::Interpreter&) const;
  68. static void destroy(Instruction&);
  69. protected:
  70. explicit Instruction(Type type)
  71. : m_type(type)
  72. {
  73. }
  74. private:
  75. Type m_type {};
  76. };
  77. }