p2sh

Crates.iop2sh
lib.rsp2sh
version0.4.3
sourcesrc
created_at2024-11-05 17:02:57.284133
updated_at2024-11-13 02:50:48.338545
descriptionThe p2sh Programming language interpreter
homepage
repositoryhttps://github.com/binoyjayan/p2sh
max_upload_size
id1436825
size842,039
Binoy (binoyjayan)

documentation

https://docs.rs/p2sh

README

p2sh

Rust

🦀 🦀 🦀 Interpreter for the p2sh programming language 🦀 🦀 🦀

Introduction

p2sh is a scripting language designed for packet processing. The Documentation can be found here. A p2sh script can be edited using the kilo editor which is tailored to recognize its syntax.

Dependencies

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.

Build and test

Run tests

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

Run examples

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 the REPL

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

Create a release build

Build release with default options

cargo build --release

This will create a release binary in the './target/release' directory.

Additional build options

debug_print_code

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

debug_trace_execution

This option helps build the release for tracing program execution and examining the state of the stack.

cargo build --release --features  'debug_trace_execution'

Installation

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>

shebang

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>

More Information

  • Examples may be found in the examples directory
  • Documentation can be found here
Commit count: 278

cargo fmt