NouVeL/NVL/Director.cpp

46 lines
1.3 KiB
C++

#include "Director.h"
namespace NVL::Director {
Director::Director(const Compiler::NVLGraph& g) :
g(g), current_position(0), active(true), description(g.nodes[0].description), current_node(g.nodes[0]) {
for (const String& s : g.static_refs)
resolve.push_back(Environment::ENVIRONMENT.get(s));
}
Environment::Variable Director::CollectVariable(const Environment::Variable& v) {
if (v.type == Environment::Type::StaticReference)
return this->resolve[static_cast<u16>(std::get<Number>(v.value))];
else if (v.type == Environment::Type::Array) {
Vector<Environment::Variable> a{};
for (const auto& x : std::get<Vector<Environment::Variable>>(v.value))
a.push_back(CollectVariable(x));
return Environment::Variable(a);
}
else
return v;
}
void Director::Advance() {
if (current_position >= current_node.sequence.size()) {
this->active = false;
return;
}
const auto& cmd = this->current_node.sequence[current_position];
Vector<Environment::Variable> args{};
for (u32 i = 1; i < cmd.size(); i++) {
args.push_back(CollectVariable(cmd[i]));
}
std::get<std::function<Environment::Variable(Vector<Environment::Variable>)>>(CollectVariable(cmd[0]).value)(args);
this->current_position++;
}
void Director::GetBacklog() {
}
void Director::Save() {
}
void Director::Load() {
}
void Director::Jump() {
}
}