Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e9a70c7
Update dependencies in Cargo.lock and add Cargo.lock to .gitignore
shawhanken Dec 18, 2025
68da611
Merge branch 'main' of https://github.com/yusufyian/RustPython
shawhanken Dec 18, 2025
1bf2bdf
Update dependencies in Cargo.lock and add Cargo.lock to .gitignore
shawhanken Dec 19, 2025
1726b36
Add additional reference files to .gitignore
shawhanken Dec 19, 2025
fd57302
Update .gitignore to exclude additional files and improve dependency …
shawhanken Dec 19, 2025
ecfabb8
Merge branch 'RustPython:main' into main
yusufyian Dec 19, 2025
bc9b80a
Merge branch 'main' of https://github.com/yusufyian/RustPython
shawhanken Dec 19, 2025
1a1c97a
Add checkpoint functionality to VirtualMachine
shawhanken Dec 19, 2025
3997507
Add checkpoint request handling and update checkpoint functionality
shawhanken Dec 19, 2025
551d025
Enhance demo script with additional print statements for debugging
shawhanken Dec 19, 2025
665790f
Update demo user and enhance README with testing instructions
shawhanken Dec 24, 2025
c2edc6b
Update .gitignore to include demo files
shawhanken Dec 24, 2025
4dc6120
Update .gitignore and demo script for type checking
shawhanken Dec 25, 2025
9ac5e54
Rename RustPython binary to "pvm" in Cargo.toml and update demo.py fo…
yusufyian Dec 26, 2025
8ea2822
Rename RustPython binary to 'pvm' in Cargo.toml and update demo.py fo…
yusufyian Dec 26, 2025
66dc584
Update README and test script to reflect binary name change from 'rus…
yusufyian Dec 29, 2025
6c26391
Refactor demo.py for improved clarity and structure in checkpointing …
yusufyian Dec 29, 2025
a1c1891
Update demo.py and README for financial trading scenario simulation
yusufyian Dec 29, 2025
f41b080
Enhance demo.py with additional trading scenario features and update …
yusufyian Dec 29, 2025
5f547a5
Implement PVM host and runtime modules with initial configurations
yusufyian Dec 29, 2025
3ed0799
Update various files for improved functionality and clarity
yusufyian Dec 29, 2025
9704677
Enhance VM functionality and code clarity
yusufyian Dec 29, 2025
965b201
Enhance demo script and update .gitignore
yusufyian Dec 30, 2025
9f354c2
Update .gitignore to include all reference files and remove specific …
yusufyian Dec 30, 2025
b50f1f3
Remove obsolete reference files for PVM integration and continuation …
yusufyian Dec 30, 2025
f8fc889
Remove obsolete demo files for checkpoint/resume functionality
yusufyian Dec 30, 2025
26ac488
Remove obsolete binary snapshot file for demo functionality
yusufyian Dec 30, 2025
b2ba6ea
Remove obsolete test script for checkpoint/resume functionality
yusufyian Dec 30, 2025
2dfed2d
Refactor comments in state_store.py for clarity and consistency
yusufyian Dec 30, 2025
d8aabdd
Enhance checkpoint functionality and update .gitignore
yusufyian Dec 30, 2025
6d54427
Update source location handling in compiler-source
yusufyian Dec 30, 2025
a1a7ec6
Refactor checkpoint and snapshot handling for improved functionality
yusufyian Dec 30, 2025
3620c13
Update version formatting in version.rs to reflect PVM 0.0.2 integration
yusufyian Dec 31, 2025
fe31a3d
Add PVM versioning support and update build script
yusufyian Dec 31, 2025
8eaf89f
Implement multi-frame checkpoint support and enhance stack management
yusufyian Dec 31, 2025
5544761
Enhance checkpoint functionality and update demo scripts
yusufyian Dec 31, 2025
13117d6
Add support for enumerate, zip, map, and filter in snapshot handling
yusufyian Dec 31, 2025
63c44b5
Enhance checkpoint and block stack management in VM
yusufyian Dec 31, 2025
c6806af
Add support for ListIterator and RangeIterator in snapshot handling
yusufyian Jan 3, 2026
9844d0d
Add comprehensive demo snapshot to .gitignore
yusufyian Jan 3, 2026
a07fed6
Remove Cargo.lock file to prevent unnecessary tracking of dependencies
yusufyian Jan 5, 2026
06e9e6a
Add error handling and execution options in PVM runtime
yusufyian Jan 5, 2026
072c0cc
Add determinism support and enhance error handling in PVM runtime
yusufyian Jan 8, 2026
5e01466
Enhance PVM runtime with import tracing and version updates
yusufyian Jan 8, 2026
b9dc39d
Add new business scenario demos to README
yusufyian Jan 8, 2026
d5afdde
Fix formatting issue in escrow_marketplace_demo.py by adding a newlin…
yusufyian Jan 12, 2026
9f3c462
Enhance PVM runtime with continuation support and new features
yusufyian Jan 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Enhance PVM runtime with continuation support and new features
- Added support for continuation modes (FSM and checkpoint) in the PVM runtime, allowing for more flexible execution control.
- Introduced new methods for sending messages, scheduling timers, and canceling timers in the `FsHost` struct.
- Updated `HostContext` to include additional fields for actor address, message ID, and nonce.
- Enhanced the `ExecutionOptions` struct to accommodate continuation options and updated related functions for better configurability.
- Refactored demo scripts to showcase new continuation features and provide clearer usage instructions.
- Improved error handling and state management during checkpoint operations, ensuring robust execution flow.
  • Loading branch information
yusufyian committed Jan 18, 2026
commit 9f3c462d667722ee0895dec6d9c04e98c965d296
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ examples/breakpoint_resume_demo/demo.rpsnap
examples/breakpoint_resume_demo/actor_complex_demo.rpsnap
examples/breakpoint_resume_demo/comprehensive_demo.rpsnap
tmp/

.DS_Store
21 changes: 20 additions & 1 deletion Lib/pvm_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
from . import pvm_random
from . import pvm_sys
from . import pvm_time
from . import runtime
from . import continuation
from . import runner
from . import actor
from . import verify
from . import types

__all__ = ["pvm_random", "pvm_sys", "pvm_time"]
capture = continuation.capture

__all__ = [
"pvm_random",
"pvm_sys",
"pvm_time",
"runtime",
"continuation",
"runner",
"actor",
"verify",
"types",
"capture",
]
28 changes: 28 additions & 0 deletions Lib/pvm_sdk/actor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from . import runtime


def continuation(*_args, **_kwargs):
def decorator(func):
return func
return decorator


class ActorRef:
def __init__(self, address):
self.address = address

def async_call(self, method, *args, **kwargs):
if runtime.mode() != "checkpoint":
raise RuntimeError("actor async is only supported in checkpoint mode without FSM")
return _ActorAwaitable(self.address, method, *args, **kwargs)


class _ActorAwaitable:
def __init__(self, address, method, *args, **kwargs):
self.address = address
self.method = method
self.args = args
self.kwargs = kwargs

def __await__(self):
raise RuntimeError("actor await not implemented")
158 changes: 158 additions & 0 deletions Lib/pvm_sdk/continuation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import hashlib
import json

import pvm_host


def _encode_value(value):
if isinstance(value, bytes):
return {"__bytes__": value.hex()}
if isinstance(value, bytearray):
return {"__bytes__": bytes(value).hex()}
if isinstance(value, dict):
return {str(k): _encode_value(v) for k, v in value.items()}
if isinstance(value, list):
return [_encode_value(v) for v in value]
if value is None or isinstance(value, (bool, int, str)):
return value
raise TypeError("unsupported capture value type")


def _decode_value(value):
if isinstance(value, dict) and "__bytes__" in value:
return bytes.fromhex(value["__bytes__"])
if isinstance(value, dict):
return {k: _decode_value(v) for k, v in value.items()}
if isinstance(value, list):
return [_decode_value(v) for v in value]
return value


def _encode_json(value):
try:
return json.dumps(
value,
sort_keys=True,
separators=(",", ":"),
ensure_ascii=True,
).encode("ascii")
except AttributeError as exc:
if "check_circular" not in str(exc):
raise
try:
import importlib
import json as _json
importlib.reload(_json)
return _json.dumps(
value,
sort_keys=True,
separators=(",", ":"),
ensure_ascii=True,
).encode("ascii")
except Exception:
raise exc


def _decode_json(data):
try:
return json.loads(data.decode("utf-8"))
except TypeError as exc:
if "Pattern" not in str(exc):
raise
try:
import importlib
import re as _re
import json as _json
importlib.reload(_re)
importlib.reload(_json)
return _json.loads(data.decode("utf-8"))
except Exception:
raise exc


class Capture:
def __init__(self):
object.__setattr__(self, "_data", {})

def __getattr__(self, name):
data = object.__getattribute__(self, "_data")
if name in data:
return data[name]
raise AttributeError(name)

def __setattr__(self, name, value):
data = object.__getattribute__(self, "_data")
data[name] = value

def to_dict(self):
return dict(self._data)

@classmethod
def from_dict(cls, value):
inst = cls()
for k, v in value.items():
inst._data[k] = v
return inst


def capture():
return Capture()


def new_cid(self_obj, name):
ctx = pvm_host.context()
seed = b""
tx_hash = ctx.get("tx_hash")
if isinstance(tx_hash, (bytes, bytearray)):
seed += bytes(tx_hash)
sender = ctx.get("sender")
if isinstance(sender, (bytes, bytearray)):
seed += bytes(sender)
seed += str(name).encode("utf-8")
return hashlib.sha256(seed).digest()


def _cont_key(cid):
return b"__continuation:" + cid


def save_cont(cid, state, ctx, handler, timeout_blocks=0, guard_unchanged=None):
if isinstance(ctx, Capture):
ctx_dict = ctx.to_dict()
else:
ctx_dict = dict(ctx)
guard_value = guard_unchanged
if isinstance(guard_value, Capture):
guard_value = guard_value.to_dict()
payload = {
"state": int(state),
"ctx": _encode_value(ctx_dict),
"handler": str(handler),
"timeout_blocks": int(timeout_blocks),
"guard_unchanged": _encode_value(guard_value),
}
pvm_host.set_state(_cont_key(cid), _encode_json(payload))


def load_cont(cid):
raw = pvm_host.get_state(_cont_key(cid))
if raw is None:
raise RuntimeError("continuation state missing")
data = _decode_json(raw)
ctx = _decode_value(data.get("ctx") or {})
data["ctx"] = Capture.from_dict(ctx)
if "guard_unchanged" in data:
data["guard_unchanged"] = _decode_value(data["guard_unchanged"])
return data


def delete_cont(cid):
pvm_host.delete_state(_cont_key(cid))


def encode_payload(value):
return _encode_json(_encode_value(value))


def decode_payload(data):
return _decode_value(_decode_json(data))
82 changes: 82 additions & 0 deletions Lib/pvm_sdk/runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import pvm_host
from . import continuation as _continuation
from . import runtime

try:
import rustpython_checkpoint as _checkpoint
except Exception:
_checkpoint = None


RUNNER_ADDRESS = b"__runner__"


def continuation(*_args, **_kwargs):
def decorator(func):
return func
return decorator


def _send_job(job_type, cid, reply_handler, *args, **kwargs):
payload = {
"kind": "runner_job",
"job_type": job_type,
"payload": {
"args": list(args),
"kwargs": kwargs,
},
"cid": cid,
"reply_handler": reply_handler,
}
pvm_host.send_message(RUNNER_ADDRESS, _continuation.encode_payload(payload))


def _result_key(cid):
return b"__runner_result:" + cid


def _try_get_result(cid):
raw = pvm_host.get_state(_result_key(cid))
if raw is None:
return None
pvm_host.delete_state(_result_key(cid))
return _continuation.decode_payload(raw)


class _RunnerAwaitable:
def __init__(self, job_type, *args, **kwargs):
self.job_type = job_type
self.args = args
self.kwargs = kwargs
self.cid = _continuation.new_cid(None, job_type)

def __await__(self):
if runtime.mode() != "checkpoint":
raise RuntimeError("runner await is only supported in checkpoint mode without FSM")
if False:
yield None
try_get_result = _try_get_result
send_job = _send_job
checkpoint = _checkpoint
while True:
result = try_get_result(self.cid)
if result is not None:
return result
send_job(self.job_type, self.cid, "", *self.args, **self.kwargs)
if checkpoint is None:
raise RuntimeError("checkpoint support missing")
checkpoint.checkpoint_bytes()


def _request_checkpoint():
if _checkpoint is None:
raise RuntimeError("checkpoint support missing")
_checkpoint.checkpoint_bytes()


def llm(*args, **kwargs):
return _RunnerAwaitable("llm", *args, **kwargs)


def http(*args, **kwargs):
return _RunnerAwaitable("http", *args, **kwargs)
6 changes: 6 additions & 0 deletions Lib/pvm_sdk/runtime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pvm_host


def mode():
cfg = pvm_host.runtime_config()
return cfg.get("continuation_mode", "fsm")
3 changes: 3 additions & 0 deletions Lib/pvm_sdk/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class SoftFloat(str):
def __new__(cls, value):
return str.__new__(cls, str(value))
45 changes: 45 additions & 0 deletions Lib/pvm_sdk/verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class VerifyBuilder:
def __init__(self):
self._data = {
"mode": "none",
"runners": 1,
"threshold": 1,
"checks": [],
}

def mode(self, value):
self._data["mode"] = value
return self

def runners(self, value):
self._data["runners"] = int(value)
return self

def threshold(self, value):
self._data["threshold"] = int(value)
return self

def check(self, value):
self._data["checks"].append(value)
return self

def build(self):
return dict(self._data)


class Verify:
@staticmethod
def builder():
return VerifyBuilder()

@staticmethod
def json_schema_valid(schema):
return {"kind": "json_schema_valid", "schema": schema}

@staticmethod
def structured_match(fields):
return {"kind": "structured_match", "fields": list(fields)}

@staticmethod
def majority_vote(field):
return {"kind": "majority_vote", "field": field}
2 changes: 1 addition & 1 deletion crates/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rustpython-compiler-core = { workspace = true }
rustpython-literal = {workspace = true }
rustpython-wtf8 = { workspace = true }
ruff_python_ast = { workspace = true }
ruff_python_parser = { workspace = true }
ruff_text_size = { workspace = true }

ahash = { workspace = true }
Expand All @@ -28,7 +29,6 @@ memchr = { workspace = true }
unicode_names2 = { workspace = true }

[dev-dependencies]
ruff_python_parser = { workspace = true }
insta = { workspace = true }

[lints]
Expand Down
Loading
Loading