You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.0 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #pragma once
  2. #include <charconv>
  3. #include <concepts>
  4. #include <functional>
  5. #include <memory>
  6. #include <optional>
  7. #include <set>
  8. #include <sstream>
  9. #include <stack>
  10. #include <string>
  11. #include <utility>
  12. #include <variant>
  13. #include <vector>
  14. #include "molasses/lexer.h"
  15. #include "parser_types.h"
  16. enum class architecture_t {
  17. x86_64_linux,
  18. x86_linux
  19. };
  20. #if defined(__x86_64__) && __linux__
  21. constexpr architecture_t architecture = architecture_t::x86_64_linux;
  22. constexpr size_t architecture_ptr_size = 8;
  23. #elif defined(__i386) || defined(__i386__) || defined(i386) && __linux__
  24. constexpr architecture_t architecture = architecture_t::x86_linux;
  25. constexpr size_t architecture_ptr_size = 4;
  26. #endif
  27. namespace molasses {
  28. std::vector<std::string> operator>>(std::vector<std::string> current_stack, const operation& next_op);
  29. struct parser_context {
  30. std::vector<std::shared_ptr<type>> types;
  31. std::vector<std::shared_ptr<operation>> operations;
  32. std::vector<std::shared_ptr<procedure_operation>> procedures;
  33. [[nodiscard]] std::shared_ptr<type> lookup_type(const std::string&) const;
  34. [[nodiscard]] std::shared_ptr<operation> lookup_operation(const std::string&) const;
  35. };
  36. struct generate_context {
  37. lexed_output lexer;
  38. parser_context parser;
  39. std::vector<std::shared_ptr<procedure_operation>> procedures;
  40. };
  41. std::optional<int32_t> try_parse_int32(const std::string& str);
  42. generate_context parse(parser_context, const lexed_output&);
  43. std::vector<std::string> generate(const generate_context&);
  44. parser_context register_integers(parser_context);
  45. template<architecture_t Arch = architecture>
  46. parser_context register_i32_operations(parser_context);
  47. bool type_check(
  48. const parser_context& parser_state,
  49. const lexed_output& lexer_state,
  50. const std::vector<symbol>& consumed_stream,
  51. std::vector<std::string> execution_input,
  52. const std::vector<std::string>& execution_output,
  53. const std::vector<std::pair<size_t, size_t>>& sub_bodies
  54. );
  55. }