Phasor 3.3.0
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, manipulating, and executing 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
32Compile and run via the libphasorrt library::
33
34 from phasor import new_state, free_state, evaluate_phs, compile_phs, run
35
36 evaluate_phs('print("hello");')
37
38 vm = new_state()
39 evaluate_phs('var x = 42;, state=vm)
40 evaluate_phs('print(x);', state=vm)
41 free_state(vm)
42
43 bytecode = compile_phs('print("hello");')
44 run(bytecode)
45
46 evaluate_phs_file("scripts/hello.phs", state=vm)
47 run_file("scripts/hello.phsb")
48"""
49
50from .Bytecode import Bytecode
51from .Deserializer import BytecodeDeserializer
52from .Instruction import Instruction
53from .Metadata import MAGIC, VERSION
54from .Native import extract_phsb_bytes
55from .OpCode import OpCode
56from .Runtime import (
57 new_state,
58 free_state,
59 reset_state,
60 compile_phs,
61 compile_phs_file,
62 compile_pul,
63 compile_pul_file,
64 run,
65 run_file,
66 evaluate_phs,
67 evaluate_phs_file,
68 evaluate_pul,
69 evaluate_pul_file,
70)
71from .Serializer import BytecodeSerializer
72from .Value import Value, ValueType
73
74__all__ = [
75 "Bytecode",
76 "BytecodeDeserializer",
77 "BytecodeSerializer",
78 "Instruction",
79 "OpCode",
80 "Value",
81 "ValueType",
82 "extract_phsb_bytes",
83 "MAGIC",
84 "VERSION",
85 "new_state",
86 "free_state",
87 "reset_state",
88 "compile_phs",
89 "compile_phs_file",
90 "compile_pul",
91 "compile_pul_file",
92 "run",
93 "run_file",
94 "evaluate_phs",
95 "evaluate_phs_file",
96 "evaluate_pul",
97 "evaluate_pul_file",
98]