#ifndef DLANG_VM_HPP #define DLANG_VM_HPP #include #include #include "lexer.hpp" #include "parser.hpp" #include "compiler.hpp" #include "plugins.hpp" inline ModuleManager* pluginManager = nullptr; #define DEBUG_MODE 0 #define VERSION "{DEVBUILD}" using ByteCodeArray = std::vector; class DlangVM { public: Stack stack; NamedList globals; List strings; List loadedPlugins; private: Stack _callStack; private: std::string GetString(const ByteCodeArray& bytecode, size_t& ip); std::string GetRealString(const ByteCodeArray& bytecode, size_t& ip); void Execute(std::vector 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 table); void SetField(const std::string& key); StackValue GetField(const std::string& key, bool popTable = true); StackValue GetTableKeys(); void PushList(std::shared_ptr 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