README added

This commit is contained in:
starcells committed 2026-09-14 21:01:48 +08:00
1 parent 7c57f4e628
commit bef8310558
6 files changed
+111 -17

No files matched your search

+13 -4
View File
@@ -1,5 +1,6 @@
#include "r8asm/r8asm.hh"
#include <algorithm>
#include <cstddef>
#include <iostream>
#include <limits>
#include <list>
@@ -60,6 +61,13 @@ std::string peel(std::string &str) { // Peel the first word from string.
#undef EMPTY_CHARS
#undef OPERATORS
void r8asm::ast::set_cell_size(size_t cell_size) {
CELL_SIZE = cell_size;
scopes = {{{"_CELL_SIZE", cell_size},
{"_CELL_MAX", (1 << cell_size) - 1},
{"_ROL_STEP", cell_size - 1}}};
}
r8asm::general_data r8asm::ast::expand_node_to_data(const ast_node &node) {
general_data to_return = 0;
switch (node.type) {
@@ -248,7 +256,7 @@ r8asm::ast_node r8asm::ast::expand_node_to_ins(const ast_node &node) {
ror
*/
data d = expand_node_to_data(node.children[0]);
for (auto i = 0; i < CELL_SIZE; i++) {
for (auto i = 0; i < scopes[0].at("_CELL_SIZE"); i++) {
if (d & 1)
to_return.children.push_back(ROT8_NODE("flb"));
to_return.children.push_back(ROT8_NODE("ror"));
@@ -404,8 +412,8 @@ r8asm::ast_node r8asm::parse(const token_stream &stream) {
filename += tp->value;
// now tp points at RQUOTE
import_file(
filename); // TODO: check whether the file is open successfully
import_file(filename, main_tree.CELL_SIZE); // TODO: check whether the
// file is open successfully
} break;
default:
break;
@@ -692,9 +700,10 @@ r8asm::token_stream::lex(const std::string &char_stream) {
}
#undef OPERATORS
bool r8asm::import_file(const std::string &filename) {
bool r8asm::import_file(const std::string &filename, size_t cell_size) {
for (const auto &token_it : parse(token_stream(filename)).children) {
main_tree.root.children.push_back(token_it);
}
main_tree.set_cell_size(cell_size);
return true; // TODO: ERROR CHECK
}