45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
#pragma once
|
|
#include <unordered_map>
|
|
#include <functional>
|
|
#include <variant>
|
|
#include "Parser.h"
|
|
#include "Common.h"
|
|
|
|
namespace NVL::Environment {
|
|
enum class Type { Procedure, Number, String, Array, Nil };
|
|
|
|
struct Variable {
|
|
Type type;
|
|
std::variant<Number, String, std::vector<Variable>, std::function<Variable(std::vector<Variable>)>> value;
|
|
// Most things will have length 1 (including string); this is mostly for function arity and array length
|
|
u32 length;
|
|
bool operator==(const Variable& other) const;
|
|
Variable(); // Makes Nil, length 0
|
|
Variable(Type t); // Reserved for Nil
|
|
Variable(const Number& v);
|
|
Variable(const String& v);
|
|
Variable(const std::vector<Variable>& v);
|
|
Variable(const std::function<Variable(std::vector<Variable>)>& v, u32 l);
|
|
};
|
|
|
|
class Environment {
|
|
private:
|
|
std::unordered_map<String, Variable> env{};
|
|
public:
|
|
void enter(const String& name, Variable p);
|
|
void set(const String& name, Variable p);
|
|
Variable& get(const String& name);
|
|
bool exists(const String& name);
|
|
};
|
|
|
|
extern Environment ENVIRONMENT;
|
|
|
|
Variable Eval(const Parse::Object& obj);
|
|
Variable Apply(const Parse::Command& c);
|
|
void EvalScene(const Parse::Scene & s);
|
|
|
|
struct Markup {
|
|
u32 begin, end;
|
|
std::vector<std::pair<String, std::vector<String>>> efs;
|
|
} UnpackMarkupVariable(const Variable& m);
|
|
}
|