Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Bytecode.H File Reference

Reusable bytecode format and lowering from Compiler_IR_Model.H. More...

#include <cctype>
#include <cstdlib>
#include <limits>
#include <sstream>
#include <string>
#include <utility>
#include <Compiler_IR_Model.H>
#include <ah-arena.H>
#include <ah-errors.H>
#include <tpl_dynArray.H>
Include dependency graph for Bytecode.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Aleph::Compiler_Bytecode_Constant
 One constant stored in a function-level constant pool. More...
 
struct  Aleph::Compiler_Bytecode_Instruction
 One lowered bytecode instruction. More...
 
struct  Aleph::Compiler_Bytecode_Block_Info
 Debug metadata that maps original IR basic blocks to bytecode PCs. More...
 
struct  Aleph::Compiler_Bytecode_Function
 Bytecode for one lowered function or top-level body. More...
 
struct  Aleph::Compiler_Bytecode_Module
 Bytecode module sharing global slot layout with the source IR module. More...
 
class  Aleph::Compiler_Bytecode_Context
 Arena-backed ownership context for bytecode functions and modules. More...
 
struct  Aleph::Compiler_Bytecode_Context::Owned_Object
 
struct  Aleph::Compiler_Bytecode_Validation_Report
 Structural validation report for one bytecode function or module. More...
 
class  Aleph::Compiler_Bytecode_Lowering
 Lowers explicit IR into register-based bytecode. More...
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 
namespace  Aleph::Compiler_Bytecode_Detail
 

Typedefs

using Aleph::Compiler_Bytecode_Register_Id = size_t
 
using Aleph::Compiler_Bytecode_Constant_Id = size_t
 
using Aleph::Compiler_Bytecode_Function_Id = size_t
 
using Aleph::Compiler_Bytecode_Block_Id = size_t
 
using Aleph::Compiler_Bytecode_PC = size_t
 

Enumerations

enum class  Aleph::Compiler_Bytecode_Constant_Kind {
  Aleph::Unit , Aleph::Boolean , Aleph::Integer , Aleph::String ,
  Aleph::Character , Aleph::Raw_Text
}
 Constant kinds supported by the bytecode constant pool. More...
 
enum class  Aleph::Compiler_Bytecode_Opcode {
  Aleph::Load_Constant , Aleph::Load_Local , Aleph::Store_Local , Aleph::Load_Global ,
  Aleph::Store_Global , Aleph::Load_Function , Aleph::Unary , Aleph::Binary ,
  Aleph::Call , Aleph::Jump , Aleph::Branch , Aleph::Return ,
  Aleph::Halt , Aleph::Trap
}
 VM opcodes supported by the bytecode MVP. More...
 

Functions

constexpr size_t Aleph::compiler_bytecode_invalid_id () noexcept
 Returns the sentinel invalid bytecode id.
 
const char * Aleph::compiler_bytecode_constant_kind_name (const Compiler_Bytecode_Constant_Kind kind) noexcept
 Stable debug name for one constant kind.
 
const char * Aleph::compiler_bytecode_opcode_name (const Compiler_Bytecode_Opcode opcode) noexcept
 Stable debug name for one bytecode opcode.
 
std::string Aleph::Compiler_Bytecode_Detail::register_name (const Compiler_Bytecode_Register_Id id)
 
std::string Aleph::Compiler_Bytecode_Detail::constant_name (const Compiler_Bytecode_Constant_Id id)
 
std::string Aleph::Compiler_Bytecode_Detail::block_name (const Compiler_Bytecode_Block_Id id)
 
std::string Aleph::Compiler_Bytecode_Detail::local_slot_name (const Compiler_IR_Local_Slot_Id id)
 
std::string Aleph::Compiler_Bytecode_Detail::global_slot_name (const Compiler_IR_Global_Slot_Id id)
 
std::string Aleph::Compiler_Bytecode_Detail::function_name (const Compiler_Bytecode_Function_Id id)
 
const char * Aleph::Compiler_Bytecode_Detail::token_name (const Compiler_Operator_Kind kind) noexcept
 
void Aleph::Compiler_Bytecode_Detail::append_indented_text (std::ostream &out, const std::string &text, const size_t indent)
 
bool Aleph::Compiler_Bytecode_Detail::parse_integer (const std::string &text, long long &value) noexcept
 
std::string Aleph::Compiler_Bytecode_Detail::decode_escape_string (const std::string &raw)
 
char Aleph::Compiler_Bytecode_Detail::decode_escape_char (const std::string &raw)
 
Compiler_Bytecode_Constant Aleph::Compiler_Bytecode_Detail::classify_constant (const Compiler_IR_Instruction &inst)
 
bool Aleph::Compiler_Bytecode_Detail::same_constant (const Compiler_Bytecode_Constant &lhs, const Compiler_Bytecode_Constant &rhs) noexcept
 
Compiler_Bytecode_Constant_Id Aleph::Compiler_Bytecode_Detail::intern_constant (DynArray< Compiler_Bytecode_Constant > &pool, const Compiler_Bytecode_Constant &constant)
 
bool Aleph::Compiler_Bytecode_Detail::contains_pc (const DynArray< Compiler_Bytecode_Block_Info > &blocks, const Compiler_Bytecode_PC pc) noexcept
 
std::string Aleph::Compiler_Bytecode_Detail::constant_to_string (const Compiler_Bytecode_Constant &constant)
 
Compiler_Bytecode_Validation_Report Aleph::validate_bytecode_function (const Compiler_Bytecode_Function &function, const Compiler_Bytecode_Module *module=nullptr)
 Validates one lowered bytecode function structurally.
 
Compiler_Bytecode_Validation_Report Aleph::validate_bytecode_module (const Compiler_Bytecode_Module &module)
 Validates all bytecode functions in one module.
 
std::string Aleph::compiler_dump_bytecode_function (const Compiler_Bytecode_Function *function, const Compiler_Bytecode_Module *module=nullptr, const Compiler_Type_Context *types=nullptr)
 Dumps one lowered bytecode function deterministically.
 
std::string Aleph::compiler_dump_bytecode_module (const Compiler_Bytecode_Module *module, const Compiler_Type_Context *types=nullptr)
 Dumps all lowered bytecode in one module deterministically.
 

Detailed Description

Reusable bytecode format and lowering from Compiler_IR_Model.H.

This header defines the first VM-oriented intermediate format in the compiler platform. Compared with Compiler_IR_Model.H, the bytecode layer is deliberately closer to execution:

  • instructions are described by opcodes instead of IR node kinds
  • constants live in a per-function constant pool
  • branch and jump targets are patched to concrete program counters
  • IR values become virtual registers addressed by numeric ids
  • local/global slots remain explicit, which keeps the MVP simple and clear

The current MVP is intentionally register-based instead of stack-based. That keeps lowering from IR direct and deterministic while still providing a compact, VM-friendly format for the future Bytecode_Interpreter.H.

The current header includes:

  • constant-pool and opcode definitions
  • bytecode functions and modules
  • lowering from explicit IR to bytecode
  • structural validation
  • deterministic textual dumps

Definition in file Bytecode.H.