Crates.io | p2sh |
lib.rs | p2sh |
version | 0.4.2 |
source | src |
created_at | 2024-11-05 17:02:57.284133 |
updated_at | 2024-11-06 16:02:34.209227 |
description | The p2sh Programming language interpreter |
homepage | |
repository | https://github.com/binoyjayan/p2sh |
max_upload_size | |
id | 1436825 |
size | 841,080 |
🦀 🦀 🦀 Interpreter for the p2sh programming language 🦀 🦀 🦀
p2sh
is a scripting language designed for packet processing. The Documentation can be found here.
This project served as a means for me to learn Rust; therefore, some parts of the code might not adhere strictly to Rust idioms. A p2sh script can be edited using the kilo editor which is tailored to recognize its syntax.
The p2sh interpreter is compiled using a Rust compiler v1.65.0. Any version later than that should work. Please visit the Rust website for installation.
It has decent test coverage for all the modules, including tests for the scanner, parser, opcode definitions, compiler, virtual machine, and built-ins.
cargo test
cargo run --release examples/formatting/formatted-output.p2
cargo run --release examples/algorithms/fibonacci-recursive.p2
cargo run --release examples/algorithms/fibonacci-iterative.p2
Run an interactive REPL loop to execute program statements on the terminal one at a time and see the output immediately.
cargo run --release
>> 1 + 2
3
Build release with default options
cargo build --release
This will create a release binary in the './target/release' directory.
The option helps building source with source code disassembly enabled.
Build with the option:
cargo build --release --features 'debug_print_code'
Run the REPL:
cargo run --release --features 'debug_print_code'
...
>> 1 + 2
--------- Instructions [len: 8 ] -------------------
0000 OpConstant 0
0003 OpConstant 1
0006 OpAdd
0007 OpPop
------------------------------------------------------
----------- Constants [len: 2 ] --------------------
[0] 1
[1] 2
------------------------------------------------------
3
Run an example:
cargo run --release --features 'debug_print_code' examples/algorithms/fibonacci-recursive.p2
This option helps build the release for tracing program execution and examining the state of the stack.
cargo build --release --features 'debug_trace_execution'
The p2sh intepreter can be installed by copying the binary to a directory
that is in your path such as /usr/local/bin
. Once installed, it can be
executed by running it like so
p2sh script.p2 <args>
A p2sh script may also be executed using a shebang. The first line of a p2sh script must be a line that looks like this:
#!/usr/bin/env p2sh
Then, the script may be run as:
./script.p2 <args>
OR
/path/to/script.p2 <args>