Phasor 3.1.1
Stack VM based Programming Language
Loading...
Searching...
No Matches
phasor.Deserializer.BytecodeDeserializer Class Reference

Public Member Functions

None __init__ (self)
Bytecode deserialize (self, bytes data)
Bytecode load_from_file (self, Path path)

Protected Member Functions

int _read_header (self)
None _read_constant_pool (self, Bytecode bytecode)
None _read_variable_mapping (self, Bytecode bytecode)
None _read_function_entries (self, Bytecode bytecode)
None _read_instructions (self, Bytecode bytecode)
Value _read_value (self)
None _require (self, int n)
int _read_uint8 (self)
int _read_uint16 (self)
int _read_uint32 (self)
int _read_int32 (self)
int _read_int64 (self)
float _read_double (self)
str _read_string (self)

Protected Attributes

bytes _data = b""
int _pos = 0

Detailed Description

Deserialises ``.phsb`` into :class:`~phasor.Bytecode.Bytecode`.

Definition at line 23 of file Deserializer.py.

Constructor & Destructor Documentation

◆ __init__()

None phasor.Deserializer.BytecodeDeserializer.__init__ ( self)
Initialise the deserializer with an empty data buffer and zero read position.

Definition at line 26 of file Deserializer.py.

Member Function Documentation

◆ _read_constant_pool()

None phasor.Deserializer.BytecodeDeserializer._read_constant_pool ( self,
Bytecode bytecode )
protected
Read the :data:`~phasor.Metadata.SEC_CONSTANTS` section and append entries to :attr:`bytecode.constants <phasor.Bytecode.Bytecode.constants>`.

Definition at line 103 of file Deserializer.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read_double()

float phasor.Deserializer.BytecodeDeserializer._read_double ( self)
protected
Read and return the next little-endian IEEE 754 double from the buffer.

Definition at line 218 of file Deserializer.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read_function_entries()

None phasor.Deserializer.BytecodeDeserializer._read_function_entries ( self,
Bytecode bytecode )
protected
Read the :data:`~phasor.Metadata.SEC_FUNCTIONS` section and populate :attr:`bytecode.function_entries <phasor.Bytecode.Bytecode.function_entries>`.

Definition at line 130 of file Deserializer.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read_header()

int phasor.Deserializer.BytecodeDeserializer._read_header ( self)
protected
Read and validate the 16-byte file header.

Returns:
    The CRC-32 checksum stored in the header, to be verified against
    the actual data after reading.

Raises:
    ValueError: If the magic number does not equal :data:`~phasor.Metadata.MAGIC`
        or the version does not equal :data:`~phasor.Metadata.VERSION`.

Definition at line 76 of file Deserializer.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read_instructions()

None phasor.Deserializer.BytecodeDeserializer._read_instructions ( self,
Bytecode bytecode )
protected
Read the :data:`~phasor.Metadata.SEC_INSTRUCTIONS` section and populate :attr:`bytecode.instructions <phasor.Bytecode.Bytecode.instructions>`.

Definition at line 144 of file Deserializer.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read_int32()

int phasor.Deserializer.BytecodeDeserializer._read_int32 ( self)
protected
Read and return the next little-endian signed 32-bit integer from the buffer.

Definition at line 204 of file Deserializer.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read_int64()

int phasor.Deserializer.BytecodeDeserializer._read_int64 ( self)
protected
Read and return the next little-endian signed 64-bit integer from the buffer.

Definition at line 211 of file Deserializer.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read_string()

str phasor.Deserializer.BytecodeDeserializer._read_string ( self)
protected
Read a length-prefixed UTF-8 string (uint16 length + bytes) and return it.

Definition at line 225 of file Deserializer.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read_uint16()

int phasor.Deserializer.BytecodeDeserializer._read_uint16 ( self)
protected
Read and return the next little-endian unsigned 16-bit integer from the buffer.

Definition at line 190 of file Deserializer.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read_uint32()

int phasor.Deserializer.BytecodeDeserializer._read_uint32 ( self)
protected
Read and return the next little-endian unsigned 32-bit integer from the buffer.

Definition at line 197 of file Deserializer.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read_uint8()

int phasor.Deserializer.BytecodeDeserializer._read_uint8 ( self)
protected
Read and return the next unsigned byte from the buffer.

Definition at line 183 of file Deserializer.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read_value()

Value phasor.Deserializer.BytecodeDeserializer._read_value ( self)
protected
Read a type-tagged value and return the corresponding :class:`~phasor.Value.Value`.

Definition at line 160 of file Deserializer.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _read_variable_mapping()

None phasor.Deserializer.BytecodeDeserializer._read_variable_mapping ( self,
Bytecode bytecode )
protected
Read the :data:`~phasor.Metadata.SEC_VARIABLES` section and populate :attr:`bytecode.variables <phasor.Bytecode.Bytecode.variables>` and :attr:`~phasor.Bytecode.Bytecode.next_var_index`.

Definition at line 115 of file Deserializer.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _require()

None phasor.Deserializer.BytecodeDeserializer._require ( self,
int n )
protected
Raise ``ValueError`` if fewer than *n* bytes remain in the buffer.

Definition at line 175 of file Deserializer.py.

Here is the caller graph for this function:

◆ deserialize()

Bytecode phasor.Deserializer.BytecodeDeserializer.deserialize ( self,
bytes data )
Parse a raw ``.phsb`` byte buffer into a :class:`~phasor.Bytecode.Bytecode` object.

Args:
    data: Raw bytes of a ``.phsb`` file.

Returns:
    A fully populated :class:`~phasor.Bytecode.Bytecode` instance.

Raises:
    ValueError: If the magic number, version, or CRC-32 checksum is invalid,
        or if any section tag is unexpected.

Definition at line 31 of file Deserializer.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_from_file()

Bytecode phasor.Deserializer.BytecodeDeserializer.load_from_file ( self,
Path path )
Read a ``.phsb`` file from disk and deserialise it.

Args:
    path: Path to the ``.phsb`` file to load.

Returns:
    A fully populated :class:`~phasor.Bytecode.Bytecode` instance.

Definition at line 64 of file Deserializer.py.

Here is the call graph for this function:

Member Data Documentation

◆ _data

phasor.Deserializer.BytecodeDeserializer._data = b""
protected

Definition at line 28 of file Deserializer.py.

◆ _pos

int phasor.Deserializer.BytecodeDeserializer._pos = 0
protected

Definition at line 29 of file Deserializer.py.


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