Phasor 3.3.0
Stack VM based Programming Language
Loading...
Searching...
No Matches
phasor Namespace Reference

Namespaces

namespace  Bytecode
namespace  Deserializer
namespace  Instruction
namespace  Native
namespace  OpCode
namespace  Runtime
namespace  Serializer
namespace  Value

Variables

list __all__

Detailed Description

phasor
======
Python module for reading, writing, manipulating, and executing Phasor VM bytecode.

-----------
Load a ``.phsb`` file::

    from phasor import Bytecode
    bc = Bytecode.load("program.phsb")
    print(bc.disassemble())

Round-trip a bytecode object::

    bc.save("copy.phsb")
    bc2 = Bytecode.from_bytes(bc.to_bytes())

Extract bytecode from a compiled native binary (requires ``lief``)::

    bc = Bytecode.from_native_binary("program")

Build bytecode programmatically::

    from phasor import Bytecode, Value, OpCode

    bc = Bytecode()
    ci = bc.add_constant(Value.from_int(42))
    bc.emit(OpCode.PUSH_CONST, ci)
    bc.emit(OpCode.HALT)
    bc.save("hello.phsb")

Compile and run via the libphasorrt library::

    from phasor import new_state, free_state, evaluate_phs, compile_phs, run

    evaluate_phs('print("hello");')

    vm = new_state()
    evaluate_phs('var x = 42;, state=vm)
    evaluate_phs('print(x);',   state=vm)
    free_state(vm)

    bytecode = compile_phs('print("hello");')
    run(bytecode)

    evaluate_phs_file("scripts/hello.phs", state=vm)
    run_file("scripts/hello.phsb")

Variable Documentation

◆ __all__

list phasor.__all__
private
Initial value:
1= [
2 "Bytecode",
3 "BytecodeDeserializer",
4 "BytecodeSerializer",
5 "Instruction",
6 "OpCode",
7 "Value",
8 "ValueType",
9 "extract_phsb_bytes",
10 "MAGIC",
11 "VERSION",
12 "new_state",
13 "free_state",
14 "reset_state",
15 "compile_phs",
16 "compile_phs_file",
17 "compile_pul",
18 "compile_pul_file",
19 "run",
20 "run_file",
21 "evaluate_phs",
22 "evaluate_phs_file",
23 "evaluate_pul",
24 "evaluate_pul_file",
25]

Definition at line 74 of file __init__.py.