diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/lib94/lib94.hpp | 122 |
1 files changed, 64 insertions, 58 deletions
diff --git a/include/lib94/lib94.hpp b/include/lib94/lib94.hpp index 1d061ec..3ca0c7b 100644 --- a/include/lib94/lib94.hpp +++ b/include/lib94/lib94.hpp @@ -1,5 +1,5 @@ -#ifndef LIB94_HPP -#define LIB94_HPP +#ifndef LIB94_LIB94_HPP +#define LIB94_LIB94_HPP #include <filesystem> #include <optional> @@ -7,82 +7,88 @@ #include <string> #include <random> #include <vector> -#include <queue> +#include <deque> #include <set> -#ifndef CORE_SIZE -#define CORE_SIZE 8000 +#ifndef LIB94_CORE_SIZE +#define LIB94_CORE_SIZE 8000 #endif -typedef uint32_t number_t; +namespace lib94 { -enum opcode : uint8_t { - DAT, MOV, ADD, SUB, - MUL, DIV, MOD, JMP, - JMZ, JMN, DJN, SEQ, - SNE, SLT, SPL, NOP -}; + typedef int_least32_t number_t; -enum modifier : uint8_t { - A, B, AB, BA, - F, X, I -}; + enum opcode : uint8_t { + DAT, MOV, ADD, SUB, + MUL, DIV, MOD, JMP, + JMZ, JMN, DJN, SEQ, + SNE, SLT, SPL, NOP + }; -enum mode : uint8_t { - IMMEDIATE, DIRECT, - A_INDIRECT, B_INDIRECT, - A_DECREMENT, B_DECREMENT, - A_INCREMENT, B_INCREMENT -}; + enum modifier : uint8_t { + A, B, AB, BA, + F, X, I + }; -struct instruction { - opcode op; - modifier mod; - mode amode; - mode bmode; - number_t anumber; - number_t bnumber; -}; + enum mode : uint8_t { + IMMEDIATE, DIRECT, + A_INDIRECT, B_INDIRECT, + A_DECREMENT, B_DECREMENT, + A_INCREMENT, B_INCREMENT + }; -struct warrior { - std::string name; - std::string author; + struct instruction { + opcode op; + modifier mod; + mode amode; + mode bmode; + number_t anumber; + number_t bnumber; + }; - number_t org; + struct warrior { + std::string name; + std::string author; - std::vector<instruction> instructions; -}; + number_t org; -void seed_prng(uint_fast64_t seed); + std::vector<instruction> instructions; + }; -std::variant<warrior *, std::string> compile_warrior(std::string source); -bool save_warrior(const warrior &w, const std::filesystem::path &to); -std::optional<warrior *> load_warrior(const std::filesystem::path &from); + void seed_prng(uint_fast64_t seed); -void clear_core(const instruction &background); -void clear_core_random(); + std::string instruction_to_string(const instruction &instr); -//warrior pointers need to remain valid for other -//functions to return valid things during the round -bool init_round(const std::vector<const warrior *> &warriors); + std::variant<warrior *, std::string> compile_warrior(std::string source); + bool save_warrior(const warrior &w, const std::filesystem::path &to); + std::optional<warrior *> load_warrior(const std::filesystem::path &from); -size_t alive_warrior_count(); + void clear_core(const instruction &background); + void clear_core_random(); -//asserts that there is a next warrior -const warrior *get_next_warrior(); -const std::queue<number_t> &get_processes(const warrior *for_warrior); -//asserts that there is a next process -number_t get_next_process(const warrior *for_warrior); + //warrior pointers need to remain valid for other + //functions to return valid things during the round + bool init_round(const warrior *const *warriors, size_t count); -const std::set<number_t> &get_modified_addresses(); -void clear_modified_addresses(); + size_t alive_warrior_count(); -const instruction &get_instruction(number_t address); + //asserts that there is a next warrior + const warrior *get_next_warrior(); + const std::deque<number_t> &get_processes(const warrior *for_warrior); + //asserts that there is a next process + number_t get_next_process(const warrior *for_warrior); -//asserts that there is a next warrior -void single_step(); + const std::set<number_t> &get_written_addresses(); + const std::set<number_t> &get_read_addresses(); + const std::set<number_t> &get_executed_addresses(); + void clear_address_sets(); -const warrior *run_until_warrior_death(); -const warrior *run_until_winner(); + const instruction &get_instruction(number_t address); + + //assumes that there is a next warrior + //returns a warrior if it dies + const warrior *single_step(); + +} #endif |