diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..993c31d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +target +**/*.rs.bk diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..7ac2b71 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "ambient-ast" +version = "0.1.0" + diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..3cdd286 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +members = [ + "ambient-ast" +] \ No newline at end of file diff --git a/README.md b/README.md index 92d0a47..1c41586 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ -# ambient-engine -Ambient engine +# Ambient Engine + +The Ambient Engine is the implementation of the orchestrator on top +of the Typed Ambient Calculus with Resources. diff --git a/ambient-ast/Cargo.toml b/ambient-ast/Cargo.toml new file mode 100644 index 0000000..7f3d22c --- /dev/null +++ b/ambient-ast/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "ambient-ast" +version = "0.1.0" +authors = ["Alessio Coltellacci ", "Didier Plaindoux "] +edition = "2018" + +[dependencies] + diff --git a/ambient-ast/README.md b/ambient-ast/README.md new file mode 100644 index 0000000..408f7fa --- /dev/null +++ b/ambient-ast/README.md @@ -0,0 +1,32 @@ +# Ambient AST + +This crate provides intermediate Abstract Syntax Tree (AST) for the compilation process. +These definitions came from the +[Cardellis' Paper](http://lucacardelli.name/Papers/MobileAmbients.A4.pdf). + +## Capabilities + +``` +M ::= -- Capability + x -- variable + n -- name + in M -- enter + out M -- exit + open M -- open + ε -- empty + M.M′ -- path +``` + +## Processes + +``` +P,Q ::= + (νn)P -- restriction + 0 -- inactivity + P|Q -- composition + !P -- replication + M[P] -- ambient + M.P -- capability action + (x).P -- input action + -- async output action +``` diff --git a/ambient-ast/src/ast/capabilities.rs b/ambient-ast/src/ast/capabilities.rs new file mode 100644 index 0000000..9241ae4 --- /dev/null +++ b/ambient-ast/src/ast/capabilities.rs @@ -0,0 +1,158 @@ +//! This is the documentation to capabilities module + +/// The `Capability` type. See [Cardellis' Paper](http://lucacardelli.name/Papers/MobileAmbients.A4.pdf) page 20. +/// +/// ```text +/// M ::= -- Capability +/// x -- variable +/// n -- name +/// in M -- enter +/// out M -- exit +/// open M -- open +/// ε -- empty +/// M.M′ -- path +/// ``` +/// +pub trait Capability {} + +/// `Variable` capability for dynamic purposes +#[derive(Debug)] +pub struct Variable + where + S: Into, +{ + pub value: S, +} + +/// `Name` for action target or ambient namespace definition +#[derive(Debug)] +pub struct Name + where + S: Into, +{ + pub value: S, +} + +/// `In` enter a sibling named ambient +#[derive(Debug)] +pub struct In { + pub capability: M, +} + +/// `Out` exit a parent named ambient +#[derive(Debug)] +pub struct Out + where + M: Capability, +{ + pub capability: M, +} + +/// `Open` dissolve a sibling named abient +#[derive(Debug)] +pub struct Open + where + M: Capability, +{ + pub capability: M, +} + +/// `Path` composition of two sequential capabilities. The left one should be done before. +#[derive(Debug)] +pub struct Path + where + N: Capability, + M: Capability, +{ + pub capability_l: N, + pub capability_r: M, +} + +/// `Empty` capability meaning nothing to be done +pub struct Empty; + +// Kind of Capability + +impl Capability for Variable where S: Into {} + +impl Capability for Name where S: Into {} + +impl Capability for In where M: Capability {} + +impl Capability for Out where M: Capability {} + +impl Capability for Open where M: Capability {} + +impl Capability for Path + where + N: Capability, + M: Capability, +{} + +impl Capability for Empty {} + +// Factories + +impl Variable + where + S: Into, +{ + pub fn new(value: S) -> Self { + Self { value } + } +} + +impl Name + where + S: Into, +{ + pub fn new(value: S) -> Self { + Self { value } + } +} + +impl In + where + M: Capability, +{ + pub fn new(capability: M) -> Self { + Self { capability } + } +} + +impl Out + where + M: Capability, +{ + pub fn new(capability: M) -> Self { + Self { capability } + } +} + +impl Open + where + M: Capability, +{ + pub fn new(capability: M) -> Self { + Self { capability } + } +} + +impl Path + where + N: Capability, + M: Capability, +{ + pub fn new(capability_l: N, capability_r: M) -> Self { + Self { + capability_l, + capability_r, + } + } +} + +impl Empty { + pub fn new() -> Self { + Self + } +} diff --git a/ambient-ast/src/ast/mod.rs b/ambient-ast/src/ast/mod.rs new file mode 100644 index 0000000..6249573 --- /dev/null +++ b/ambient-ast/src/ast/mod.rs @@ -0,0 +1,2 @@ +pub mod capabilities; +pub mod processes; diff --git a/ambient-ast/src/ast/processes.rs b/ambient-ast/src/ast/processes.rs new file mode 100644 index 0000000..7e4889d --- /dev/null +++ b/ambient-ast/src/ast/processes.rs @@ -0,0 +1,224 @@ +//! This is the documentation to processes module + +use crate::ast::capabilities::*; + +/// The `Process` type. See [Cardellis' Paper](http://lucacardelli.name/Papers/MobileAmbients.A4.pdf) page 20. +/// +/// ```text +/// P,Q ::= +/// (νn)P -- restriction +/// 0 -- inactivity +/// P|Q -- composition +/// !P -- replication +/// M[P] -- ambient +/// M.P -- capability action +/// (x).P -- input action +/// -- async output action +///``` +/// +pub trait Process {} + +/// `Restriction` defines a process with a private name +#[derive(Debug)] +pub struct Restriction +where + S: Into, + P: Process, +{ + pub name: S, + pub process: P, +} + +/// `Inactivity` defines a process doing nothing +#[derive(Debug)] +pub struct Inactivity; + +/// `Composition` defines a two processes running in parallel +#[derive(Debug)] +pub struct Composition +where + P: Process, + Q: Process, +{ + pub process_l: P, + pub process_r: Q, +} + +/// `Replication` defines a perpetual process where `!P` is isomorphic to `P | !P` +#[derive(Debug)] +pub struct Replication

+where + P: Process, +{ + pub process: P, +} + +/// `Ambient` defines a named bounded space containing processes +#[derive(Debug)] +pub struct Ambient +where + M: Capability, + P: Process, +{ + pub capability: M, + pub process: P, +} + +/// `Action` attach a capability to a given process defining an action to be done +#[derive(Debug)] +pub struct Action +where + M: Capability, + P: Process, +{ + pub capability: M, + pub process: P, +} + +/// `Input` defines the function able to capture a message. +#[derive(Debug)] +pub struct Input +where + X: Into, + P: Process, +{ + pub variable: X, + pub process: P, +} + +/// `Output` defines the message able to be captured by an `Input` +#[derive(Debug)] +pub struct Output +where + M: Capability, +{ + pub message: M, +} + +// Kind of process + +impl Process for Restriction +where + N: Into, + P: Process, +{ +} + +impl Process for Inactivity {} + +impl Process for Composition +where + P: Process, + Q: Process, +{ +} + +impl

Process for Replication

where P: Process {} + +impl Process for Ambient +where + M: Capability, + P: Process, +{ +} + +impl Process for Action +where + M: Capability, + P: Process, +{ +} + +impl Process for Input +where + X: Into, + P: Process, +{ +} + +impl Process for Output where M: Capability {} + +// Factories + +impl Restriction +where + S: Into, + P: Process, +{ + pub fn new(name: S, process: P) -> Self { + Self { name, process } + } +} + +impl Inactivity { + pub fn new() -> Self { + Inactivity + } +} + +impl Composition +where + P: Process, + Q: Process, +{ + pub fn new(process_l: P, process_r: Q) -> Self { + Self { + process_l, + process_r, + } + } +} + +impl

Replication

+where + P: Process, +{ + pub fn new(process: P) -> Self { + Self { process } + } +} + +impl Ambient +where + M: Capability, + P: Process, +{ + pub fn new(capability: M, process: P) -> Self { + Self { + capability, + process, + } + } +} + +impl Action +where + M: Capability, + P: Process, +{ + pub fn new(capability: M, process: P) -> Self { + Self { + capability, + process, + } + } +} + +impl Input +where + X: Into, + P: Process, +{ + pub fn new(variable: X, process: P) -> Self { + Self { variable, process } + } +} + +impl Output +where + M: Capability, +{ + pub fn new(message: M) -> Self { + Self { message } + } +} diff --git a/ambient-ast/src/lib.rs b/ambient-ast/src/lib.rs new file mode 100644 index 0000000..851c0bc --- /dev/null +++ b/ambient-ast/src/lib.rs @@ -0,0 +1 @@ +pub mod ast;