beginning of compiler
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#include "Assembler.hpp"
|
||||
|
||||
namespace spider {
|
||||
|
||||
Assembler::Assembler() {}
|
||||
|
||||
Assembler::~Assembler() {}
|
||||
|
||||
Assembler::Error Assembler::loadFile(const fs::path& path) {
|
||||
// check if path exists
|
||||
fs::path abs_path = fs::canonical(path);
|
||||
if(!fs::exists(abs_path)) return Error::FILE_NOT_FOUND;
|
||||
|
||||
// check if recursive
|
||||
if(fstack.contains(abs_path)) return Error::FILE_RECURSIVE_LOAD;
|
||||
auto ir = fstack.insert(abs_path);
|
||||
|
||||
// Actually load!
|
||||
levels.emplace_back(Level {
|
||||
.reader = std::make_unique<TextReader>(new FileTextReader(abs_path.string())),
|
||||
.source = abs_path.string(),
|
||||
});
|
||||
parseCurrentLevel();
|
||||
|
||||
// alright!
|
||||
fstack.erase(ir.first);
|
||||
return Error::SUCCESS;
|
||||
}
|
||||
|
||||
void Assembler::parseCurrentLevel() {
|
||||
auto& lvl = levels.back();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <spider/compiler/common.hpp>
|
||||
|
||||
#include <spider/compiler/text/TextReader.hpp>
|
||||
|
||||
#include <spider/compiler/tokens/RootToken.hpp>
|
||||
|
||||
namespace spider {
|
||||
|
||||
/**
|
||||
* The spider assembler, capable of
|
||||
* converting text into bytecode.
|
||||
*/
|
||||
class Assembler {
|
||||
public:
|
||||
enum class Error {
|
||||
SUCCESS,
|
||||
FILE_NOT_FOUND, FILE_RECURSIVE_LOAD,
|
||||
};
|
||||
struct Level {
|
||||
uptr<TextReader> reader;
|
||||
RootToken root;
|
||||
std::string source;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
set<fs::path> fstack;
|
||||
deque<Level> levels;
|
||||
|
||||
public:
|
||||
|
||||
Assembler();
|
||||
|
||||
~Assembler();
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Attempts to load a file, fails if it
|
||||
* doesn't exist.
|
||||
*/
|
||||
Error loadFile(const fs::path& path);
|
||||
|
||||
private:
|
||||
|
||||
void parseCurrentLevel();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
namespace spider {
|
||||
|
||||
/**
|
||||
* A disassembler, capable of converting bytecode into
|
||||
* readable text.
|
||||
*/
|
||||
class Disassembler {};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user