MXVM 1.8.1
Virtual Machine, Compiler, and Pascal Frontend
Loading...
Searching...
No Matches
pascal Namespace Reference

Classes

class  ASTNode
 Abstract base class for all AST nodes. More...
class  ExitNode
 AST node for an exit / halt statement. More...
class  ContinueNode
 AST node for a continue statement. More...
class  BreakNode
 AST node for a break statement. More...
class  BlockNode
 AST node representing a block (declarations + compound statement). More...
class  ProgramNode
 AST node for a complete program (program name + block). More...
class  UnitNode
 AST node for a Pascal unit (separately compiled module). More...
class  VarDeclNode
 AST node for variable declarations (var id1, id2 : type). More...
class  TypeDeclNode
 AST node for a type declaration section. More...
class  TypeAliasNode
 AST node for a type alias (type NewName = ExistingType). More...
class  ConstDeclNode
 AST node for constant declarations (const id = value). More...
class  FuncDeclNode
 AST node for a function declaration. More...
class  ProcDeclNode
 AST node for a procedure declaration. More...
class  ParameterNode
 AST node for a formal parameter list entry. More...
class  CompoundStmtNode
 AST node for a compound statement (begin ... end). More...
class  AssignmentNode
 AST node for an assignment statement (variable := expression). More...
class  SimpleTypeNode
 AST node for a simple (named) type reference. More...
class  ArrayTypeNode
 AST node for an array type (array[lower..upper] of elementType). More...
class  ArrayDeclarationNode
 AST node for a named array variable declaration. More...
class  ArrayTypeDeclarationNode
 AST node for a named array type declaration (type Name = array[...]). More...
class  ArrayAccessNode
 AST node for an array element access (arr[index]). More...
class  ArrayAssignmentNode
 AST node for assigning to an array element (arr[index] := value). More...
class  IfStmtNode
 AST node for an if-then-else statement. More...
class  WhileStmtNode
 AST node for a while loop (while cond do stmt). More...
class  ForStmtNode
 AST node for a for loop (for var := start to/downto end do stmt). More...
class  CaseStmtNode
 AST node for a case statement. More...
class  ProcCallNode
 AST node for a procedure call statement. More...
class  BinaryOpNode
 AST node for a binary operator expression. More...
class  UnaryOpNode
 AST node for a unary operator expression. More...
class  FuncCallNode
 AST node for a function call expression. More...
class  VariableNode
 AST node for a variable reference. More...
class  NumberNode
 AST node for an integer or real numeric literal. More...
class  StringNode
 AST node for a string literal. More...
class  BooleanNode
 AST node for a boolean literal (true / false). More...
class  EmptyStmtNode
 AST node for an empty statement (no-op). More...
class  NilNode
 AST node for the nil literal. More...
class  PointerTypeNode
 AST node for a pointer type declaration (^BaseType). More...
class  PointerDerefNode
 AST node for a pointer dereference (ptr^). More...
class  AddressOfNode
 AST node for an address-of expression (@operand). More...
class  RepeatStmtNode
 AST node for a repeat..until loop. More...
class  EnumTypeDeclNode
 AST node for an enumerated type declaration (type Color = (Red, Green, Blue)). More...
struct  VariantArm
 A single variant arm inside a variant record. More...
class  RecordTypeNode
 AST node for a record type (record ... end). More...
class  RecordDeclarationNode
 AST node for a named record declaration. More...
class  WithStmtNode
 AST node for a with statement (with record do statement). More...
class  GotoStmtNode
 AST node for a goto statement. More...
class  LabelStmtNode
 AST node for a label definition (label: statement). More...
class  SetLiteralNode
 AST node for a set literal [val1, val2, ...]. More...
class  SetTypeNode
 AST node for a set type declaration (set of <base type>). More...
class  FieldAccessNode
 AST node for accessing a record field (record.field). More...
class  ASTVisitor
 Abstract visitor interface for the AST (double-dispatch). More...
struct  ArrayInfo
 Metadata describing a Pascal array's bounds, element type, and sizing. More...
class  BuiltinFunctionHandler
 Abstract handler for a group of built-in functions/procedures. More...
class  BuiltinFunctionRegistry
 Registry of BuiltinFunctionHandler instances. More...
class  IOFunctionHandler
 Built-in handler for I/O procedures (write, writeln, read, readln). More...
class  StdFunctionHandler
 Built-in handler for standard library functions (chr, ord, inc, dec, etc.). More...
class  StringFunctionHandler
 Built-in handler for string library functions (length, copy, concat, etc.). More...
class  SDLFunctionHandler
 Built-in handler for SDL2 bindings. More...
class  FileFunctionHandler
 Built-in handler for Pascal file I/O procedures (assign, reset, rewrite, append, close, eof, eoln). More...
class  CodeGenVisitor
 AST visitor that generates MXVM intermediate code. More...
class  ParseException
 Exception thrown on parse errors. More...
class  PascalParser
 Recursive-descent parser for the Pascal language. More...

Enumerations

enum class  VarType {
  INT , DOUBLE , STRING , CHAR ,
  RECORD , PTR , BOOL , UNKNOWN ,
  ARRAY_INT , ARRAY_DOUBLE , ARRAY_STRING
}
 Enumeration of variable / expression value types. More...

Functions

static std::string rtrim_comment (const std::string &line)
static std::string trim (const std::string &s)
static void locate_sections (const std::vector< std::string > &lines, size_t &dataStart, size_t &dataEnd, size_t &codeStart, size_t &codeEnd)
static std::unordered_set< std::string > collect_used (const std::vector< std::string > &lines, size_t codeStart, size_t codeEnd)
static void sweep_unused_data (std::vector< std::string > &lines)
static std::vector< std::pair< size_t, std::string > > nextNonEmpty (const std::vector< std::string > &code, size_t start, size_t n)
static std::string invertJump (const std::string &j)
static bool parse2 (const std::string &line, const std::string &op, std::string &a, std::string &b)
static bool parse1 (const std::string &line, const std::string &op, std::string &a)
static bool parseJump (const std::string &line, std::string &jop, std::string &label)
static bool isLabelDef (const std::string &line, const std::string &label)
static void foldCmpTest (std::vector< std::string > &code)
static void foldAndTest (std::vector< std::string > &code)
static void foldOrTest (std::vector< std::string > &code)
static bool isRegisterName (const std::string &s)
 Forward declaration — checks whether a name is a hardware register.
static void copyPropagation (std::vector< std::string > &code)
 Copy-propagation peephole pass.
static void foldMovArithMov (std::vector< std::string > &code)
static void peepholeOpt (std::vector< std::string > &code)
std::string mxvmOpt (const std::string &text)
static std::string toLower (const std::string &s)
 Convert a string to lowercase for case-insensitive comparison.

Variables

std::unordered_set< std::string > sdlFunctions
std::unordered_set< std::string > stdFunctions
static std::unordered_set< std::string > fileFunctions

Enumeration Type Documentation

◆ VarType

enum class pascal::VarType
strong

Enumeration of variable / expression value types.

Enumerator
INT 

integer

DOUBLE 

real (floating-point)

STRING 

string value

CHAR 

character value

RECORD 

record (struct)

PTR 

generic pointer

BOOL 

boolean

UNKNOWN 

unresolved type

ARRAY_INT 

array of integers

ARRAY_DOUBLE 

array of doubles

ARRAY_STRING 

array of strings

Definition at line 72 of file icode.hpp.

Function Documentation

◆ collect_used()

std::unordered_set< std::string > pascal::collect_used ( const std::vector< std::string > & lines,
size_t codeStart,
size_t codeEnd )
static

Definition at line 60 of file icode.cpp.

Referenced by sweep_unused_data().

◆ copyPropagation()

void pascal::copyPropagation ( std::vector< std::string > & code)
static

Copy-propagation peephole pass.

Folds sequences like mov reg, src ; op reg, rhs into op src, rhs when the intermediate register is not referenced again. The scan respects ret / done boundaries so that stores to global variables visible to the caller are never eliminated.

Definition at line 376 of file icode.cpp.

References isRegisterName(), parse2(), rtrim_comment(), and trim().

Referenced by peepholeOpt().

◆ foldAndTest()

void pascal::foldAndTest ( std::vector< std::string > & code)
static

Definition at line 253 of file icode.cpp.

References isLabelDef(), nextNonEmpty(), parse1(), and parse2().

Referenced by peepholeOpt().

◆ foldCmpTest()

void pascal::foldCmpTest ( std::vector< std::string > & code)
static

Definition at line 166 of file icode.cpp.

References invertJump(), isLabelDef(), nextNonEmpty(), parse1(), parse2(), parseJump(), rtrim_comment(), and trim().

Referenced by peepholeOpt().

◆ foldMovArithMov()

void pascal::foldMovArithMov ( std::vector< std::string > & code)
static

Definition at line 501 of file icode.cpp.

References isRegisterName(), parse2(), rtrim_comment(), and trim().

Referenced by peepholeOpt().

◆ foldOrTest()

void pascal::foldOrTest ( std::vector< std::string > & code)
static

Definition at line 306 of file icode.cpp.

References isLabelDef(), nextNonEmpty(), parse1(), and parse2().

Referenced by peepholeOpt().

◆ invertJump()

std::string pascal::invertJump ( const std::string & j)
static

Definition at line 108 of file icode.cpp.

Referenced by foldCmpTest().

◆ isLabelDef()

bool pascal::isLabelDef ( const std::string & line,
const std::string & label )
static

Definition at line 162 of file icode.cpp.

Referenced by foldAndTest(), foldCmpTest(), and foldOrTest().

◆ isRegisterName()

bool pascal::isRegisterName ( const std::string & s)
static

Forward declaration — checks whether a name is a hardware register.

Used by the peephole optimizer to distinguish register temporaries from global/local variable names when deciding whether a store is dead.

Definition at line 491 of file icode.cpp.

Referenced by copyPropagation(), foldMovArithMov(), and mxvmOpt().

◆ locate_sections()

void pascal::locate_sections ( const std::vector< std::string > & lines,
size_t & dataStart,
size_t & dataEnd,
size_t & codeStart,
size_t & codeEnd )
static

Definition at line 33 of file icode.cpp.

Referenced by mxvmOpt(), and sweep_unused_data().

◆ mxvmOpt()

std::string pascal::mxvmOpt ( const std::string & text)

Definition at line 589 of file icode.cpp.

References isRegisterName(), locate_sections(), peepholeOpt(), rtrim_comment(), sweep_unused_data(), and trim().

Referenced by compileFile().

◆ nextNonEmpty()

std::vector< std::pair< size_t, std::string > > pascal::nextNonEmpty ( const std::vector< std::string > & code,
size_t start,
size_t n )
static

Definition at line 97 of file icode.cpp.

References rtrim_comment(), and trim().

Referenced by foldAndTest(), foldCmpTest(), and foldOrTest().

◆ parse1()

bool pascal::parse1 ( const std::string & line,
const std::string & op,
std::string & a )
static

Definition at line 145 of file icode.cpp.

References trim().

Referenced by foldAndTest(), foldCmpTest(), and foldOrTest().

◆ parse2()

bool pascal::parse2 ( const std::string & line,
const std::string & op,
std::string & a,
std::string & b )
static

Definition at line 132 of file icode.cpp.

References trim().

Referenced by copyPropagation(), foldAndTest(), foldCmpTest(), foldMovArithMov(), and foldOrTest().

◆ parseJump()

bool pascal::parseJump ( const std::string & line,
std::string & jop,
std::string & label )
static

Definition at line 152 of file icode.cpp.

References trim().

Referenced by foldCmpTest().

◆ peepholeOpt()

void pascal::peepholeOpt ( std::vector< std::string > & code)
static

Definition at line 579 of file icode.cpp.

References copyPropagation(), foldAndTest(), foldCmpTest(), foldMovArithMov(), and foldOrTest().

Referenced by mxvmOpt().

◆ rtrim_comment()

std::string pascal::rtrim_comment ( const std::string & line)
inlinestatic

Definition at line 15 of file icode.cpp.

Referenced by copyPropagation(), foldCmpTest(), foldMovArithMov(), mxvmOpt(), and nextNonEmpty().

◆ sweep_unused_data()

void pascal::sweep_unused_data ( std::vector< std::string > & lines)
static

Definition at line 74 of file icode.cpp.

References collect_used(), and locate_sections().

Referenced by mxvmOpt().

◆ toLower()

◆ trim()

std::string pascal::trim ( const std::string & s)
inlinestatic

Variable Documentation

◆ fileFunctions

std::unordered_set<std::string> pascal::fileFunctions
static
Initial value:
= {
"assign", "reset", "rewrite", "append", "close", "eof", "eoln"}

Definition at line 985 of file icode_imp.cpp.

Referenced by pascal::FileFunctionHandler::canHandle().

◆ sdlFunctions

std::unordered_set<std::string> pascal::sdlFunctions
Initial value:
= {
"sdl_init", "sdl_quit", "sdl_create_window", "sdl_destroy_window", "sdl_set_window_title",
"sdl_set_window_position", "sdl_get_window_size", "sdl_set_window_fullscreen", "sdl_set_window_icon",
"sdl_create_renderer", "sdl_destroy_renderer", "sdl_set_draw_color", "sdl_clear", "sdl_present",
"sdl_get_renderer_output_size", "sdl_draw_point", "sdl_draw_line", "sdl_draw_rect", "sdl_fill_rect",
"sdl_poll_event", "sdl_get_event_type", "sdl_get_key_code", "sdl_get_mouse_x", "sdl_get_mouse_y",
"sdl_get_mouse_button", "sdl_get_mouse_buttons", "sdl_get_relative_mouse_x", "sdl_get_relative_mouse_y",
"sdl_get_relative_mouse_buttons", "sdl_create_rgb_surface", "sdl_free_surface", "sdl_blit_surface",
"sdl_get_mouse_state", "sdl_get_relative_mouse_state", "sdl_get_keyboard_state", "sdl_is_key_pressed",
"sdl_get_num_keys", "sdl_set_clipboard_text", "sdl_get_clipboard_text", "sdl_show_cursor",
"sdl_create_texture", "sdl_destroy_texture", "sdl_load_texture", "sdl_load_texture_color_key", "sdl_load_texture_color_key_rgb", "sdl_render_texture",
"sdl_update_texture", "sdl_lock_texture", "sdl_unlock_texture", "sdl_get_ticks", "sdl_delay",
"sdl_open_audio", "sdl_close_audio", "sdl_pause_audio", "sdl_load_wav", "sdl_free_wav",
"sdl_queue_audio", "sdl_get_queued_audio_size", "sdl_clear_queued_audio", "sdl_init_text",
"sdl_quit_text", "sdl_load_font", "sdl_draw_text", "sdl_create_render_target", "sdl_set_render_target",
"sdl_destroy_render_target", "sdl_present_scaled", "sdl_present_stretched"}

Definition at line 23 of file icode_imp.cpp.

Referenced by pascal::SDLFunctionHandler::canHandle().

◆ stdFunctions

std::unordered_set<std::string> pascal::stdFunctions
Initial value:
= {
"argc", "argv", "set_program_args", "free_program_args", "abs", "fabs",
"sqrt", "pow", "sin", "cos", "tan", "floor", "ceil", "rand", "srand",
"malloc", "calloc", "free", "toupper", "tolower", "isalpha", "isdigit",
"isspace", "atoi", "atof", "exit", "system", "memcpy", "memcmp",
"memmove", "memset", "exp", "exp2", "log", "log10", "log2", "fmod",
"atan2", "asin", "acos", "atan", "sinh", "cosh", "tanh", "hypot",
"round", "trunc", "float_to_int", "int_to_float", "halt",
"ord", "chr", "succ", "pred", "inc", "dec", "include", "exclude"}

Definition at line 40 of file icode_imp.cpp.

Referenced by pascal::StdFunctionHandler::canHandle().