72 lines
1.8 KiB
C++
72 lines
1.8 KiB
C++
#ifndef DLANG_VM_HPP
|
|
#define DLANG_VM_HPP
|
|
|
|
#include <iostream>
|
|
#include <unordered_map>
|
|
|
|
#include "lexer.hpp"
|
|
#include "parser.hpp"
|
|
#include "compiler.hpp"
|
|
#include "plugins.hpp"
|
|
|
|
inline ModuleManager* pluginManager = nullptr;
|
|
|
|
#define DEBUG_MODE 1
|
|
#define VERSION "v1.0.32"
|
|
|
|
using ByteCodeArray = std::vector<double>;
|
|
|
|
class DlangVM
|
|
{
|
|
public:
|
|
Stack<StackValue, 25> stack;
|
|
NamedList<StackValue> globals;
|
|
List<std::string> strings;
|
|
List<std::string> loadedPlugins;
|
|
private:
|
|
Stack<CallFrame, 25> _callStack;
|
|
|
|
private:
|
|
std::string GetString(const ByteCodeArray& bytecode, size_t& ip);
|
|
std::string GetRealString(const ByteCodeArray& bytecode, size_t& ip);
|
|
void Execute(std::vector<double> bytecode);
|
|
|
|
public:
|
|
StackValue Pop();
|
|
void Pop(double amount);
|
|
|
|
void PushNumber(double number);
|
|
void PushBoolean(bool value);
|
|
void PushString(const std::string& str);
|
|
void PushVar(const std::string& var);
|
|
|
|
void PushCFunction(CFunction func);
|
|
bool CallFunc(double argCount);
|
|
|
|
void PushTable(std::shared_ptr<DlangTable> table);
|
|
void SetField(const std::string& key);
|
|
StackValue GetField(const std::string& key, bool popTable = true);
|
|
StackValue GetTableKeys();
|
|
|
|
void PushList(std::shared_ptr<DlangList> list);
|
|
double PushListIndex();
|
|
void SetListIndex();
|
|
StackValue GetListIndex();
|
|
|
|
double GetSize(); // Function to get size of List, Table and String
|
|
|
|
public:
|
|
DlangVM();
|
|
|
|
void RunString(const std::string& code, ByteCodeArray* extract = nullptr);
|
|
void RunFile(const std::string& fileName, ByteCodeArray* extract = nullptr);
|
|
void RunBinaryFile(const std::string& fileName);
|
|
ByteCodeArray ParseHeader(const ByteCodeArray& bytecode);
|
|
void RunBytecode(const ByteCodeArray& bytecode);
|
|
|
|
public:
|
|
StackValue GetVariable(const std::string& name);
|
|
void SetVariable(const std::string& name, StackValue value);
|
|
};
|
|
|
|
#endif |