|
| None | _write_constant_pool (self, List[Value] constants) |
| None | _write_variable_mapping (self, Dict[str, int] variables, int next_var_index) |
| None | _write_function_entries (self, Dict[str, int] function_entries) |
| None | _write_instructions (self, List[Instruction] instructions) |
| None | _write_value (self, Value value) |
| None | _write_uint8 (self, int v) |
| None | _write_uint16 (self, int v) |
| None | _write_uint32 (self, int v) |
| None | _write_int32 (self, int v) |
| None | _write_int64 (self, int v) |
| None | _write_double (self, float v) |
| None | _write_string (self, str s) |
|
| bytearray | _buf = bytearray() |
Converts a :class:`~phasor.Bytecode.Bytecode` object into its binary ``.phsb`` representation.
Definition at line 23 of file Serializer.py.
◆ __init__()
| None phasor.Serializer.BytecodeSerializer.__init__ |
( |
| self | ) |
|
Initialise the serializer with an empty write buffer.
Definition at line 26 of file Serializer.py.
◆ _write_constant_pool()
| None phasor.Serializer.BytecodeSerializer._write_constant_pool |
( |
| self, |
|
|
List[Value] | constants ) |
|
protected |
Write the :data:`~phasor.Metadata.SEC_CONSTANTS` section: count followed by each :class:`~phasor.Value.Value`.
Definition at line 73 of file Serializer.py.
◆ _write_double()
| None phasor.Serializer.BytecodeSerializer._write_double |
( |
| self, |
|
|
float | v ) |
|
protected |
Append a little-endian IEEE 754 double to the buffer.
Definition at line 154 of file Serializer.py.
◆ _write_function_entries()
| None phasor.Serializer.BytecodeSerializer._write_function_entries |
( |
| self, |
|
|
Dict[str, int] | function_entries ) |
|
protected |
Write the :data:`~phasor.Metadata.SEC_FUNCTIONS` section: count then each name→instruction-index entry point.
Definition at line 91 of file Serializer.py.
◆ _write_instructions()
| None phasor.Serializer.BytecodeSerializer._write_instructions |
( |
| self, |
|
|
List[Instruction] | instructions ) |
|
protected |
Write the :data:`~phasor.Metadata.SEC_INSTRUCTIONS` section: count then each :class:`~phasor.Instruction.Instruction` as ``uint8`` opcode + five ``int32`` operands.
Definition at line 99 of file Serializer.py.
◆ _write_int32()
| None phasor.Serializer.BytecodeSerializer._write_int32 |
( |
| self, |
|
|
int | v ) |
|
protected |
Append a little-endian signed 32-bit integer to the buffer.
Definition at line 146 of file Serializer.py.
◆ _write_int64()
| None phasor.Serializer.BytecodeSerializer._write_int64 |
( |
| self, |
|
|
int | v ) |
|
protected |
Append a little-endian signed 64-bit integer to the buffer.
Definition at line 150 of file Serializer.py.
◆ _write_string()
| None phasor.Serializer.BytecodeSerializer._write_string |
( |
| self, |
|
|
str | s ) |
|
protected |
Append a length-prefixed UTF-8 string (uint16 length + bytes) to the buffer.
Definition at line 158 of file Serializer.py.
◆ _write_uint16()
| None phasor.Serializer.BytecodeSerializer._write_uint16 |
( |
| self, |
|
|
int | v ) |
|
protected |
Append a little-endian unsigned 16-bit integer to the buffer.
Definition at line 138 of file Serializer.py.
◆ _write_uint32()
| None phasor.Serializer.BytecodeSerializer._write_uint32 |
( |
| self, |
|
|
int | v ) |
|
protected |
Append a little-endian unsigned 32-bit integer to the buffer.
Definition at line 142 of file Serializer.py.
◆ _write_uint8()
| None phasor.Serializer.BytecodeSerializer._write_uint8 |
( |
| self, |
|
|
int | v ) |
|
protected |
Append a single unsigned byte to the buffer.
Definition at line 134 of file Serializer.py.
◆ _write_value()
| None phasor.Serializer.BytecodeSerializer._write_value |
( |
| self, |
|
|
Value | value ) |
|
protected |
Write a :class:`~phasor.Value.Value` as a ``uint8`` type tag followed by its payload.
Raises:
NotImplementedError: If :attr:`value.type <phasor.Value.Value.type>` is not one of
Null, Bool, Int, Float, or String.
Definition at line 109 of file Serializer.py.
◆ _write_variable_mapping()
| None phasor.Serializer.BytecodeSerializer._write_variable_mapping |
( |
| self, |
|
|
Dict[str, int] | variables, |
|
|
int
| next_var_index ) |
|
protected |
Write the :data:`~phasor.Metadata.SEC_VARIABLES` section: count, :attr:`~phasor.Bytecode.Bytecode.next_var_index`, then each name→slot pair.
Definition at line 80 of file Serializer.py.
◆ save_to_file()
| None phasor.Serializer.BytecodeSerializer.save_to_file |
( |
| self, |
|
|
Bytecode | bytecode, |
|
|
Path | path ) |
Serialise *bytecode* and write the result to *path*.
Parent directories are created automatically if they do not exist.
Args:
bytecode: The :class:`~phasor.Bytecode.Bytecode` object to serialise.
path: Destination file path; typically ends with ``.phsb``.
Definition at line 60 of file Serializer.py.
◆ serialize()
| bytes phasor.Serializer.BytecodeSerializer.serialize |
( |
| self, |
|
|
Bytecode | bytecode ) |
Serialise *bytecode* to the ``.phsb`` wire format.
Writes a 16-byte header (magic, version, flags, CRC-32 checksum) followed
by the constants, variables, functions, and instructions sections in order.
Args:
bytecode: The :class:`~phasor.Bytecode.Bytecode` object to serialise.
Returns:
The complete ``.phsb`` binary as a :class:`bytes` object.
Definition at line 31 of file Serializer.py.
◆ _buf
| phasor.Serializer.BytecodeSerializer._buf = bytearray() |
|
protected |
The documentation for this class was generated from the following file: