fixes, cleanup, some copies removed

This commit is contained in:
ProgramSnail 2024-12-15 16:19:54 +03:00
parent 2589f6166f
commit d90a8cf89f
16 changed files with 373 additions and 666 deletions

View file

@ -3,6 +3,7 @@
#include <ostream>
extern "C" {
#include "parser.h"
#include "utils.h"
}
@ -46,29 +47,12 @@ enum class Cmd : int8_t {
Bytefile *read_file(const char *fname);
static inline int ip_read_int(char **ip, const Bytefile &bf) {
if (*ip + sizeof(int) > bf.code_ptr + bf.code_size) {
failure("last command is invalid, int parameter can not be read\n");
}
*ip += sizeof(int);
return *(int *)((*ip) - sizeof(int));
}
static inline uint8_t ip_read_byte(char **ip, const Bytefile &bf) {
if (*ip + sizeof(char) > bf.code_ptr + bf.code_size) {
failure("last command is invalid, byte parameter can not be read\n");
}
return *(*ip)++;
}
static inline uint8_t ip_read_byte_unsafe(char **ip) { return *(*ip)++; }
static inline const char *ip_read_string(char **ip, const Bytefile &bf) {
return get_string(&bf, ip_read_int(ip, bf));
}
std::pair<Cmd, uint8_t> parse_command(char **ip, const Bytefile &bf);
std::pair<Cmd, uint8_t> parse_command(char **ip, const Bytefile &bf,
std::pair<Cmd, uint8_t> parse_command(char **ip, const Bytefile *bf);
std::pair<Cmd, uint8_t> parse_command(char **ip, const Bytefile *bf,
std::ostream &out);
std::pair<Cmd, uint8_t> parse_command_name(char **ip, const Bytefile *bf);
bool is_command_name(char *ip, const Bytefile *bf, Cmd cmd);
void print_file(const Bytefile &bf, std::ostream &out);