vitorenesduarte / pluscal-rs

Let's write some PlusCal in Rust!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pluscal-rs

Let's write some PlusCal in Rust!

The What

use pluscal::prelude::*;

fn main() {
    let mut module = Module::new("transfer");
    module.extends("Naturals");
    module.extends("TLC");

    let alice = module.natural("alice").value(10);
    let bob = module.natural("bob").value(10);
    let money = module.natural("money").in_range(1, 20);

    let transfer = module.label("Transfer");
    transfer
        .if_(alice.ge(&money))
        .then(|ctx| {
            let a = ctx.label("A");
            a.exec(alice.set(alice.minus(&money)));

            let b = ctx.label("B");
            b.exec(bob.set(bob.plus(&money)));
        })
        .end_if();
    let c = module.label("C");
    c.assert(alice.geq(&ZERO));

    println!("{}", module);
}

The above Rust code outputs (example from the Learn TLA+ website):

---- MODULE transfer ----
EXTENDS Naturals, TLC

(* --algorithm transfer

variables
    alice = 10,
    bob = 10,
    money \in 1..20;

begin
Transfer:
    if alice >= money then
        A:
            alice := alice - money;
        B:
            bob := bob + money;
    end if;
C:
    assert alice >= 0


end algorithm *)
====

The Why

I'm afraid I don't have a good answer. I can at least blame this PLTalk with Jean Yang, Hongyi Hu and Hillel Wayne on Practical Formal Methods.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Let's write some PlusCal in Rust!

License:Apache License 2.0


Languages

Language:Rust 100.0%