Phasor 3.1.1
Stack VM based Programming Language
Loading...
Searching...
No Matches
__init__.py
Go to the documentation of this file.
1"""
2phasor
3======
4Python module for reading, writing, and manipulating Phasor VM bytecode.
5
6-----------
7Load a ``.phsb`` file::
8
9 from phasor import Bytecode
10 bc = Bytecode.load("program.phsb")
11 print(bc.disassemble())
12
13Round-trip a bytecode object::
14
15 bc.save("copy.phsb")
16 bc2 = Bytecode.from_bytes(bc.to_bytes())
17
18Extract bytecode from a compiled native binary (requires ``lief``)::
19
20 bc = Bytecode.from_native_binary("program")
21
22Build bytecode programmatically::
23
24 from phasor import Bytecode, Value, OpCode
25
26 bc = Bytecode()
27 ci = bc.add_constant(Value.from_int(42))
28 bc.emit(OpCode.PUSH_CONST, ci)
29 bc.emit(OpCode.HALT)
30 bc.save("hello.phsb")
31"""
32
33from .Bytecode import Bytecode
34from .Deserializer import BytecodeDeserializer
35from .Instruction import Instruction
36from .Metadata import MAGIC, VERSION
37from .Native import extract_phsb_bytes
38from .OpCode import OpCode
39from .Serializer import BytecodeSerializer
40from .Value import Value, ValueType
41
42__all__ = [
43 "Bytecode",
44 "BytecodeDeserializer",
45 "BytecodeSerializer",
46 "Instruction",
47 "OpCode",
48 "Value",
49 "ValueType",
50 "extract_phsb_bytes",
51 "MAGIC",
52 "VERSION",
53]