2024-12-13 13:32:50 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <ostream>
|
2025-02-23 15:10:22 +03:00
|
|
|
#include <vector>
|
2024-12-13 13:32:50 +03:00
|
|
|
|
|
|
|
|
extern "C" {
|
2024-12-15 16:19:54 +03:00
|
|
|
#include "parser.h"
|
2024-12-13 13:32:50 +03:00
|
|
|
#include "utils.h"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum class Cmd : int8_t {
|
|
|
|
|
BINOP,
|
|
|
|
|
CONST,
|
|
|
|
|
STRING,
|
|
|
|
|
SEXP,
|
|
|
|
|
STI,
|
|
|
|
|
STA,
|
|
|
|
|
JMP,
|
|
|
|
|
END,
|
|
|
|
|
RET,
|
|
|
|
|
DROP,
|
|
|
|
|
DUP,
|
|
|
|
|
SWAP,
|
|
|
|
|
ELEM,
|
|
|
|
|
LD,
|
|
|
|
|
LDA,
|
|
|
|
|
ST,
|
|
|
|
|
CJMPz,
|
|
|
|
|
CJMPnz,
|
|
|
|
|
BEGIN,
|
|
|
|
|
CBEGIN,
|
|
|
|
|
CLOSURE,
|
|
|
|
|
CALLC,
|
|
|
|
|
CALL,
|
|
|
|
|
TAG,
|
|
|
|
|
ARRAY,
|
|
|
|
|
FAIL,
|
|
|
|
|
LINE,
|
2025-03-02 15:05:09 +03:00
|
|
|
BUILTIN,
|
2024-12-13 13:32:50 +03:00
|
|
|
PATT,
|
2025-01-20 23:13:42 +03:00
|
|
|
// NOTE: no longer used
|
|
|
|
|
// Lread,
|
|
|
|
|
// Lwrite,
|
|
|
|
|
// Llength,
|
|
|
|
|
// Lstring,
|
|
|
|
|
// Barray,
|
2024-12-13 13:32:50 +03:00
|
|
|
EXIT,
|
|
|
|
|
_UNDEF_,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Bytefile *read_file(const char *fname);
|
|
|
|
|
|
2024-12-15 16:19:54 +03:00
|
|
|
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);
|
2024-12-13 13:32:50 +03:00
|
|
|
|
2024-12-15 16:19:54 +03:00
|
|
|
std::pair<Cmd, uint8_t> parse_command_name(char **ip, const Bytefile *bf);
|
2024-12-13 13:32:50 +03:00
|
|
|
|
2024-12-15 16:19:54 +03:00
|
|
|
bool is_command_name(char *ip, const Bytefile *bf, Cmd cmd);
|
2024-12-15 03:33:46 +03:00
|
|
|
|
|
|
|
|
void print_file(const Bytefile &bf, std::ostream &out);
|