Skip to content
Open
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
target
**/*.rs.bk
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[workspace]

members = [
"ambient-ast"
]
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions ambient-ast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "ambient-ast"
version = "0.1.0"
authors = ["Alessio Coltellacci <lightplay8@gmail.com>", "Didier Plaindoux <d.plaindoux@free.fr>"]
edition = "2018"

[dependencies]

32 changes: 32 additions & 0 deletions ambient-ast/README.md
Original file line number Diff line number Diff line change
@@ -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
<M> -- async output action
```
158 changes: 158 additions & 0 deletions ambient-ast/src/ast/capabilities.rs
Original file line number Diff line number Diff line change
@@ -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<S>
where
S: Into<String>,
{
pub value: S,
}

/// `Name` for action target or ambient namespace definition
#[derive(Debug)]
pub struct Name<S>
where
S: Into<String>,
{
pub value: S,
}

/// `In` enter a sibling named ambient
#[derive(Debug)]
pub struct In<M: Capability> {
pub capability: M,
}

/// `Out` exit a parent named ambient
#[derive(Debug)]
pub struct Out<M>
where
M: Capability,
{
pub capability: M,
}

/// `Open` dissolve a sibling named abient
#[derive(Debug)]
pub struct Open<M>
where
M: Capability,
{
pub capability: M,
}

/// `Path` composition of two sequential capabilities. The left one should be done before.
#[derive(Debug)]
pub struct Path<N, M>
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<S> Capability for Variable<S> where S: Into<String> {}

impl<S> Capability for Name<S> where S: Into<String> {}

impl<M> Capability for In<M> where M: Capability {}

impl<M> Capability for Out<M> where M: Capability {}

impl<M> Capability for Open<M> where M: Capability {}

impl<N, M> Capability for Path<N, M>
where
N: Capability,
M: Capability,
{}

impl Capability for Empty {}

// Factories

impl<S> Variable<S>
where
S: Into<String>,
{
pub fn new(value: S) -> Self {
Self { value }
}
}

impl<S> Name<S>
where
S: Into<String>,
{
pub fn new(value: S) -> Self {
Self { value }
}
}

impl<M> In<M>
where
M: Capability,
{
pub fn new(capability: M) -> Self {
Self { capability }
}
}

impl<M> Out<M>
where
M: Capability,
{
pub fn new(capability: M) -> Self {
Self { capability }
}
}

impl<M> Open<M>
where
M: Capability,
{
pub fn new(capability: M) -> Self {
Self { capability }
}
}

impl<N, M> Path<N, M>
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
}
}
2 changes: 2 additions & 0 deletions ambient-ast/src/ast/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod capabilities;
pub mod processes;
Loading