1
0
Fork 0
mirror of https://gitlab.com/niansa/pilang3.git synced 2025-03-06 20:49:20 +01:00
pilang3/include/pilang.hpp
2021-02-01 13:46:04 +01:00

66 lines
1.8 KiB
C++

#include <string>
#include <vector>
#include <unordered_map>
#include <variant>
#include <exception>
#include <memory>
#include <functional>
namespace Pilang3 {
using integer_type = int64_t;
namespace exceptions {
class langException : public std::exception {};
class BadInteger : public langException {};
class BadArgs : public langException {};
class NoSuchCommand : public langException {};
class NoSuchVariable : public langException {};
}
class Environment;
class Evaluation;
struct Variable;
using SharedVariable = std::shared_ptr<Variable>;
using SharedEvaluation = std::shared_ptr<Evaluation>;
struct Variable {
enum Type {
id_string,
id_integer,
id_reference,
id_evaluation,
id_type [[maybe_unused]],
id_any [[maybe_unused]],
id_null [[maybe_unused]]
} type;
using Data = std::variant<std::string, integer_type, SharedVariable, Type, SharedEvaluation>;
Data data;
};
using Cmdargs = std::vector<Variable>;
using Cmdfnc = std::function<Variable (Environment&, Cmdargs&)>;
using Cmddesc = std::tuple<Cmdfnc, uint16_t, std::vector<Variable::Type>, bool>;
extern std::unordered_map<std::string, Cmddesc> builtinCmds;
class Environment {
public:
std::unordered_map<std::string, SharedVariable> globalVars;
void *anybuf = nullptr;
};
class Evaluation {
public:
Cmdargs arguments;
Cmdfnc command = nullptr;
std::string command_name;
ssize_t exprlen;
Evaluation(Environment& env, const std::string &expression, const bool autoeval = true);
Variable execute(Environment& env);
};
};