MXVM 1.8.1
Virtual Machine, Compiler, and Pascal Frontend
Loading...
Searching...
No Matches
mxvm::Base Class Reference

Base class for instruction storage, variables, labels, and external function registrations. More...

#include <icode.hpp>

Inheritance diagram for mxvm::Base:

Public Member Functions

 Base ()=default
 Base (Base &&other) noexcept
 Move constructor.
 ~Base ()=default
Base & operator= (Base &&other) noexcept
 Move-assignment operator.
void setMainBase (Base *b)
 Set the root program base pointer (used for global variable lookup).
void add_instruction (const Instruction &i)
 Append an instruction to the instruction stream.
void add_label (const std::string &name, uint64_t address, bool f)
 Register a label at the given instruction address.
void add_variable (const std::string &name, const Variable &v)
 Declare a local variable in the symbol table.
void add_global (const std::string &objname, const std::string &name, const Variable &v)
 Declare a global variable scoped to an object.
void add_extern (const std::string &mod, const std::string &name, bool module)
 Register an external function import.
void add_runtime_extern (const std::string &mod_name, const std::string &mod, const std::string &func_name, const std::string &name)
 Register and resolve a runtime-loaded external function.
void add_filename (const std::string &fname)
 Record a source filename for debug/error reporting.
void add_allocated (const std::string &name, Variable &v)
 Track a heap-allocated variable for cleanup.
void add_object (const std::string &name, Program *prog)
 Register a child object program.

Public Attributes

std::string name
std::vector< Instruction > inc
 instruction stream
std::unordered_map< std::string, Variable > vars
 variable symbol table
std::unordered_map< std::string, std::pair< uint64_t, bool > > labels
 label -> (address, is_function)
std::vector< ExternalFunction > external
 declared external function imports
std::unordered_map< std::string, RuntimeFunction > external_functions
 resolved runtime function bindings
std::string assembly_code
 generated assembly output for objects

Static Public Attributes

static Base * base = nullptr
 pointer to the main program base
static std::string root_name
static std::vector< std::string > filenames
static std::unordered_map< std::string, Variable > allocated
 heap-allocated variables
static std::unordered_map< std::string, Program * > object_map
 object name -> Program mapping

Detailed Description

Base class for instruction storage, variables, labels, and external function registrations.

Provides the shared data structures used by both interpreted and compiled programs: instruction list, variable table, label map, external function bindings, and object references.

Definition at line 121 of file icode.hpp.

Constructor & Destructor Documentation

◆ Base() [1/2]

mxvm::Base::Base ( )
default

References Base().

Referenced by Base(), Base(), ~Base(), operator=(), and setMainBase().

◆ Base() [2/2]

mxvm::Base::Base ( Base && other)
noexcept

Move constructor.

Definition at line 72 of file icode.cpp.

References Base(), external, external_functions, inc, labels, name, and vars.

◆ ~Base()

mxvm::Base::~Base ( )
default

References Base().

Member Function Documentation

◆ add_allocated()

void mxvm::Base::add_allocated ( const std::string & name,
Variable & v )

Track a heap-allocated variable for cleanup.

Parameters
nameVariable name
vVariable (with allocation metadata)

Definition at line 90 of file icode.cpp.

References allocated, and name.

◆ add_extern()

void mxvm::Base::add_extern ( const std::string & mod,
const std::string & name,
bool module )

Register an external function import.

Parameters
modModule name
nameFunction symbol name
moduletrue if the import is a module-level extern

Definition at line 266 of file icode.cpp.

References external, and name.

Referenced by mxvm::Program::Program().

◆ add_filename()

void mxvm::Base::add_filename ( const std::string & fname)

Record a source filename for debug/error reporting.

Parameters
fnameFilename to add

Definition at line 257 of file icode.cpp.

References base.

◆ add_global()

void mxvm::Base::add_global ( const std::string & objname,
const std::string & name,
const Variable & v )

Declare a global variable scoped to an object.

Parameters
objnameObject that owns the variable
nameVariable name
vVariable definition

Definition at line 254 of file icode.cpp.

References name.

◆ add_instruction()

void mxvm::Base::add_instruction ( const Instruction & i)

Append an instruction to the instruction stream.

Parameters
iInstruction to add

Definition at line 237 of file icode.cpp.

References inc.

Referenced by mxvm::Program::flatten_inc().

◆ add_label()

void mxvm::Base::add_label ( const std::string & name,
uint64_t address,
bool f )

Register a label at the given instruction address.

Parameters
nameLabel identifier
addressInstruction index the label points to
ftrue if the label marks a function entry

Definition at line 241 of file icode.cpp.

References labels, and name.

Referenced by mxvm::Program::flatten_label().

◆ add_object()

void mxvm::Base::add_object ( const std::string & name,
Program * prog )

Register a child object program.

Parameters
nameObject identifier
progPointer to the object's Program

Definition at line 136 of file icode.cpp.

References base, and name.

◆ add_runtime_extern()

void mxvm::Base::add_runtime_extern ( const std::string & mod_name,
const std::string & mod,
const std::string & func_name,
const std::string & name )

Register and resolve a runtime-loaded external function.

Parameters
mod_nameModule display name
modShared library path
func_nameNative symbol name
nameMXVM-visible function name

Definition at line 273 of file icode.cpp.

References base, and name.

◆ add_variable()

void mxvm::Base::add_variable ( const std::string & name,
const Variable & v )

Declare a local variable in the symbol table.

Parameters
nameVariable name
vVariable definition

Definition at line 246 of file icode.cpp.

References name, and vars.

Referenced by mxvm::Program::add_standard().

◆ operator=()

Base & mxvm::Base::operator= ( Base && other)
noexcept

Move-assignment operator.

Definition at line 76 of file icode.cpp.

References Base(), external, external_functions, inc, labels, name, and vars.

Referenced by mxvm::Program::operator=().

◆ setMainBase()

void mxvm::Base::setMainBase ( Base * b)
inline

Set the root program base pointer (used for global variable lookup).

Parameters
bPointer to the main program's Base

Definition at line 133 of file icode.hpp.

References Base(), and base.

Member Data Documentation

◆ allocated

std::unordered_map< std::string, Variable > mxvm::Base::allocated
static

heap-allocated variables

Definition at line 200 of file icode.hpp.

Referenced by add_allocated().

◆ assembly_code

std::string mxvm::Base::assembly_code

generated assembly output for objects

Definition at line 202 of file icode.hpp.

◆ base

◆ external

◆ external_functions

std::unordered_map<std::string, RuntimeFunction> mxvm::Base::external_functions

resolved runtime function bindings

Definition at line 196 of file icode.hpp.

Referenced by Base(), mxvm::Program::exec_invoke(), mxvm::Program::flatten(), mxvm::Program::flatten_external(), and operator=().

◆ filenames

std::vector< std::string > mxvm::Base::filenames
static

Definition at line 199 of file icode.hpp.

◆ inc

◆ labels

◆ name

std::string mxvm::Base::name

◆ object_map

std::unordered_map< std::string, Program * > mxvm::Base::object_map
static

object name -> Program mapping

Definition at line 201 of file icode.hpp.

Referenced by mxvm::Program::getVariable(), mxvm::Program::isFunctionValid(), and mxvm::Program::isVariable().

◆ root_name

std::string mxvm::Base::root_name
static

Definition at line 198 of file icode.hpp.

Referenced by mxvm::Program::generateCode(), and mxvm::Program::x64_generateCode().

◆ vars

std::unordered_map<std::string, Variable> mxvm::Base::vars

variable symbol table

Definition at line 193 of file icode.hpp.

Referenced by Base(), mxvm::Program::Program(), mxvm::Program::~Program(), add_variable(), mxvm::Program::exec_free(), mxvm::Program::exec_mov(), mxvm::Program::flatten_inc(), mxvm::Program::generateCode(), mxvm::Program::getVariable(), mxvm::Program::isVariable(), mxvm::Program::memoryDump(), mxvm_io_fclose(), mxvm_io_feof(), mxvm_io_fopen(), mxvm_io_fputs(), mxvm_io_fread(), mxvm_io_fseek(), mxvm_io_fsize(), mxvm_io_fwrite(), mxvm_io_mxvm_fgets(), mxvm_io_rand_number(), mxvm_io_seed_random(), mxvm_sdl_blit_surface(), mxvm_sdl_create_render_target(), mxvm_sdl_create_renderer(), mxvm_sdl_create_rgb_surface(), mxvm_sdl_create_texture(), mxvm_sdl_create_window(), mxvm_sdl_get_clipboard_text(), mxvm_sdl_get_event_type(), mxvm_sdl_get_key_code(), mxvm_sdl_get_keyboard_state(), mxvm_sdl_get_mouse_button(), mxvm_sdl_get_mouse_buttons(), mxvm_sdl_get_mouse_state(), mxvm_sdl_get_mouse_x(), mxvm_sdl_get_mouse_y(), mxvm_sdl_get_num_keys(), mxvm_sdl_get_queued_audio_size(), mxvm_sdl_get_relative_mouse_buttons(), mxvm_sdl_get_relative_mouse_state(), mxvm_sdl_get_relative_mouse_x(), mxvm_sdl_get_relative_mouse_y(), mxvm_sdl_get_ticks(), mxvm_sdl_init(), mxvm_sdl_init_text(), mxvm_sdl_is_key_pressed(), mxvm_sdl_load_font(), mxvm_sdl_load_texture(), mxvm_sdl_load_texture_color_key(), mxvm_sdl_load_texture_color_key_rgb(), mxvm_sdl_load_wav(), mxvm_sdl_lock_texture(), mxvm_sdl_open_audio(), mxvm_sdl_poll_event(), mxvm_sdl_queue_audio(), mxvm_sdl_update_texture(), mxvm_std_abs(), mxvm_std_acos(), mxvm_std_argc(), mxvm_std_argv(), mxvm_std_asin(), mxvm_std_atan(), mxvm_std_atan2(), mxvm_std_atof(), mxvm_std_atoi(), mxvm_std_calloc(), mxvm_std_ceil(), mxvm_std_cos(), mxvm_std_cosh(), mxvm_std_exp(), mxvm_std_exp2(), mxvm_std_fabs(), mxvm_std_float_to_int(), mxvm_std_floor(), mxvm_std_fmod(), mxvm_std_hypot(), mxvm_std_int_to_float(), mxvm_std_isalpha(), mxvm_std_isdigit(), mxvm_std_isspace(), mxvm_std_log(), mxvm_std_log10(), mxvm_std_log2(), mxvm_std_malloc(), mxvm_std_memcmp(), mxvm_std_memcpy(), mxvm_std_memmove(), mxvm_std_memset(), mxvm_std_pow(), mxvm_std_rand(), mxvm_std_round(), mxvm_std_sin(), mxvm_std_sinh(), mxvm_std_sqrt(), mxvm_std_system(), mxvm_std_tan(), mxvm_std_tanh(), mxvm_std_tolower(), mxvm_std_toupper(), mxvm_std_trunc(), mxvm_string_copy(), mxvm_string_delete(), mxvm_string_insert(), mxvm_string_inttostr(), mxvm_string_pos(), mxvm_string_snprintf(), mxvm_string_strat(), mxvm_string_strcmp(), mxvm_string_strfind(), mxvm_string_strlen(), mxvm_string_strncat(), mxvm_string_strncpy(), mxvm_string_strtoint(), mxvm_string_substr(), operator=(), mxvm::Program::operator=(), mxvm::Program::validateNames(), and mxvm::Program::x64_generateCode().


The documentation for this class was generated from the following files: