Instruction.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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(Add) \
  12. O(Sub) \
  13. O(Mul) \
  14. O(Div) \
  15. O(Mod) \
  16. O(Exp) \
  17. O(GreaterThan) \
  18. O(GreaterThanEquals) \
  19. O(LessThan) \
  20. O(LessThanEquals) \
  21. O(AbstractInequals) \
  22. O(AbstractEquals) \
  23. O(NewString) \
  24. O(NewObject) \
  25. O(GetVariable) \
  26. O(SetVariable) \
  27. O(PutById) \
  28. O(GetById) \
  29. O(Jump) \
  30. O(JumpIfFalse) \
  31. O(JumpIfTrue) \
  32. O(Call) \
  33. O(EnterScope) \
  34. O(Return) \
  35. O(BitwiseAnd) \
  36. O(BitwiseOr) \
  37. O(BitwiseXor)
  38. namespace JS::Bytecode {
  39. class Instruction {
  40. public:
  41. enum class Type {
  42. #define __BYTECODE_OP(op) \
  43. op,
  44. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  45. #undef __BYTECODE_OP
  46. };
  47. Type type() const { return m_type; }
  48. size_t length() const;
  49. String to_string() const;
  50. void execute(Bytecode::Interpreter&) const;
  51. static void destroy(Instruction&);
  52. protected:
  53. explicit Instruction(Type type)
  54. : m_type(type)
  55. {
  56. }
  57. private:
  58. Type m_type {};
  59. };
  60. }