//----------------------------------------------------------------------------- // // Copyright (C) 2015-2017 David Hill // // See COPYING for license information. // //----------------------------------------------------------------------------- // // Module class. // //----------------------------------------------------------------------------- #ifndef ACSVM__Module_H__ #define ACSVM__Module_H__ #include "ID.hpp" #include "List.hpp" #include "Vector.hpp" #include #include //----------------------------------------------------------------------------| // Types | // namespace ACSVM { // // ModuleName // // Stores a Module's name. Name semantics are user-defined and must provide // a (user-defined) mapping from name to bytecode data. The names are used // internally only for determining if a specific module has already been // loaded. That is, two ModuleNames should compare equal if and only if they // designate the same bytecode data. // class ModuleName { public: ModuleName(String *s_, void *p_, std::size_t i_) : s{s_}, p{p_}, i{i_} {} bool operator == (ModuleName const &name) const {return s == name.s && p == name.p && i == name.i;} bool operator != (ModuleName const &name) const {return s != name.s || p != name.p || i != name.i;} std::size_t hash() const; // String value. May be null. String *s; // Arbitrary pointer value. void *p; // Arbitrary integer value. std::size_t i; }; // // Module // // Represents an ACS bytecode module. // class Module { public: Module(Environment *env, ModuleName const &name); ~Module(); void readBytecode(Byte const *data, std::size_t size); void refStrings() const; void reset(); void resetStrings(); Environment *env; ModuleName name; Vector arrImpV; Vector arrInitV; Vector arrNameV; Vector arrSizeV; Vector codeV; Vector funcNameV; Vector functionV; Vector importV; Vector jumpV; Vector jumpMapV; Vector regImpV; Vector regInitV; Vector regNameV; Vector scrNameV; Vector