Instruction.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. namespace JS::Bytecode {
  36. class Instruction {
  37. public:
  38. enum class Type {
  39. #define __BYTECODE_OP(op) \
  40. op,
  41. ENUMERATE_BYTECODE_OPS(__BYTECODE_OP)
  42. #undef __BYTECODE_OP
  43. };
  44. Type type() const { return m_type; }
  45. size_t length() const;
  46. String to_string() const;
  47. void execute(Bytecode::Interpreter&) const;
  48. static void destroy(Instruction&);
  49. protected:
  50. explicit Instruction(Type type)
  51. : m_type(type)
  52. {
  53. }
  54. private:
  55. Type m_type {};
  56. };
  57. }