Tessera PVM
Tessera PVM is a Python implementation of the Tessera virtual machine, offering two execution modes: a straightforward interpreter and a more performant recompiler.
Project Structure
tsrkit_pvm/: The main package.core/: Abstract base classes and core PVM components.common/: Shared utilities and data structures.interpreter/: The interpreter-based PVM implementation.recompiler/: The recompiler-based PVM implementation.
tests/: The project's test suite, which includes PVM test cases and schemas.
Core Components
The fundamental building blocks of the PVM are defined in tsrkit_pvm/core/:
ipvm.py: Contains thePVMabstract base class.program_base.py: Defines the base class for PVM programs.memory.py: Provides the base class for memory management.
Implementations
- Interpreter: Located in
tsrkit_pvm/interpreter/, this implementation executes bytecode instruction by instruction. It is easier to debug and inspect. - Recompiler: Found in
tsrkit_pvm/recompiler/, this implementation recompiles PVM bytecode into native machine code for significantly faster execution.
Installation
Install the package using pip:
pip install .
Usage
The primary way to run a PVM program is to use the static execute method on either the Interpreter or Recompiler class.
Here is a corrected example of how to execute a PVM program with the interpreter:
from tsrkit_pvm.interpreter.pvm import Interpreter
from tsrkit_pvm.interpreter.program import Program
from tsrkit_pvm.interpreter.memory import INT_Memory
from tsrkit_pvm.common.status import ExecutionStatus
# Your PVM bytecode
bytecode = bytes([0, 0, 14, 40, 2, 200, 50, 1, 40, 2, 200, 67, 2, 51, 1, 40, 246, 165, 20])
# 1. Decode the bytecode into a Program object
# The `decode` method returns a single Program instance.
program = Program.decode(bytecode)
# 2. Initialize memory, registers, and gas
# INT_Memory takes a dictionary for initial memory, a list for input, and a list for output.
memory = INT_Memory({}, [], [])
registers = [0] * 13 # PVM has 13 registers
gas = 100_000
# 3. Execute the program
status, final_pc, remaining_gas, final_registers, final_memory = Interpreter.execute(
program=program,
program_counter=0,
gas=gas,
registers=registers,
memory=memory
)
# 4. Check the result
if status == ExecutionStatus.OUT_OF_GAS:
print("Execution finished: Out of gas.")
print(f"Gas consumed: {gas - remaining_gas}")
else:
print(f"Execution finished with status: {status}")
Testing
To run the comprehensive test suite and verify the functionality of both the interpreter and recompiler, use pytest:
poetry run pytest
Release files for tsrkit-pvm 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tsrkit_pvm-0.2.1.tar.gz | 1.9 MB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| tsrkit_pvm-0.2.1-cp312-cp312-musllinux_1_2_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux musl 1.2+ x86-64 | Details |
| tsrkit_pvm-0.2.1-cp312-cp312-musllinux_1_2_aarch64.whl | CPython 3.12 | CPython 3.12 | Linux musl 1.2+ ARM64 | Details |
| tsrkit_pvm-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.17+ x86-64 | Details |
| tsrkit_pvm-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.17+ ARM64 | Details |
| tsrkit_pvm-0.2.1-cp312-cp312-macosx_11_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 11.0+ ARM64 | Details |
| tsrkit_pvm-0.2.1-cp312-cp312-macosx_10_13_x86_64.whl | CPython 3.12 | CPython 3.12 | macOS 10.13+ x86-64 | Details |
Total release size: 32.0 MB
Release files / tsrkit_pvm-0.2.1.tar.gz
| Download URL | tsrkit_pvm-0.2.1.tar.gz |
|---|---|
| Size | 1.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f32acb702b3e18619aa234f8f427671260f867798da2f01cec1cd2c9f795880
|
|
BLAKE2b-256 checksum How to use checksums |
3a3625c5d3730a122b493cf58420e7f92c1d169babcfdd8d2011b27b43c5e220
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / tsrkit_pvm-0.2.1-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | tsrkit_pvm-0.2.1-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 6.2 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
6c1d73e335e65d19e7d1799e6a758ac857149a0385f893818999cf04814aefd3
|
|
BLAKE2b-256 checksum How to use checksums |
ad19eca4b4307c609329fbd428909c66ee19ad312cd87496ee7c4612a8d3d095
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / tsrkit_pvm-0.2.1-cp312-cp312-musllinux_1_2_aarch64.whl
| Download URL | tsrkit_pvm-0.2.1-cp312-cp312-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 6.1 MB |
| Tags | CPython 3.12 Linux musl 1.2+ ARM64 |
|
SHA-256 checksum How to use checksums |
5cd337fd2ee26709fc266aab825c1dc8bac89d56bbde653bb4817e9c2977fb16
|
|
BLAKE2b-256 checksum How to use checksums |
6a6e30175bab3edfe217ad1f5453b24dbeac53b39e45dfb125c2f9a1450c813d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / tsrkit_pvm-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | tsrkit_pvm-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 6.3 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
5baff8304fe04a689d440538a29d514b61cc3b31095eea4649d74e82c28888ee
|
|
BLAKE2b-256 checksum How to use checksums |
5c966e82b033edb8c313f26835e9f0786312819cd0401d1a6777123759b1cc38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / tsrkit_pvm-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | tsrkit_pvm-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 6.2 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
f215ee0ad790c997f4a4e42364866d7e92e0901746639b2573211295f40f707c
|
|
BLAKE2b-256 checksum How to use checksums |
9cdfd62e0ccf537956b1ffc5d916a084d8ea672ed079ec648c1ebbf769aa8ba9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / tsrkit_pvm-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | tsrkit_pvm-0.2.1-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.6 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
64b86e4df1d9bbe245036f1abfef6f2ee22be05ff79e3a07a5f0d1fc20e639dd
|
|
BLAKE2b-256 checksum How to use checksums |
b9eee8a7b812d325dbe354988091bde8201ebd751490bace38847454a5d0d797
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / tsrkit_pvm-0.2.1-cp312-cp312-macosx_10_13_x86_64.whl
| Download URL | tsrkit_pvm-0.2.1-cp312-cp312-macosx_10_13_x86_64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.12 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
6388de7f5d0bb1f42a308d5e8d108ffccb0c5dc6110d07f4f58a798356937976
|
|
BLAKE2b-256 checksum How to use checksums |
ffc162fb61454eb4ff2e60866409a51694b7ed2434270f5511e6445a6a94b7ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|