Skip to content

Commit

Permalink
WIP: status unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
AZWN committed Oct 7, 2024
1 parent 3ce08a3 commit 46ec3d1
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions scopegraphs/src/completeness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,18 @@ where
/// ```
#[macro_export]
macro_rules! add_scope {
($sg:ident[let $s:ident |-> $data:expr] with open labels: $($lbl:expr),*) => {
let $s: $crate::scopegraph::Scope;
{
// put initialized code in block
let sg = &$sg; // evaluate scope graph expression
let data = $data; // evaluate data expression

// create new scope
$s = sg.add_scope_with(data, [$($lbl),*]);

// return the scope, and the extension permissions
($(unsafe { $crate::completeness::ScopeExtPerm::init($s, $lbl, sg) }),*)
}
($sg:ident[let $s:ident |-> $data:expr] request open: $(- $lbl:expr => let $lbl_id:ident)*) => {
// put initialized code in block
let sg = &$sg; // evaluate scope graph expression
let data = $data; // evaluate data expression

// create new scope
let $s = sg.add_scope_with(data, [$($lbl),*]);

// return the scope, and the extension permissions
$(
let $lbl_id = unsafe { $crate::completeness::ScopeExtPerm::init($s, $lbl, sg) };
)*
};

($sg:expr, $data:expr, [ $($lbl:expr),* ]) => {
Expand Down Expand Up @@ -362,19 +361,35 @@ macro_rules! add_edge {

#[cfg(test)]
mod tests {
use crate::Label;
use std::fmt::Debug;

#[test]
pub fn test_new_add_macro() {
use crate::completeness::ExplicitClose;
#[derive(Label, Debug, PartialEq, Eq, Clone, Copy, Hash)]
enum Lbl {
L1,
L2,
}

pub mod scopegraphs {
pub use crate::*;
}

use crate::completeness::ImplicitClose;
use crate::ScopeGraph;

use crate::Storage;

let storage = Storage::new();
let scope_graph: ScopeGraph<(), (), ExplicitClose<()>> =
ScopeGraph::new(&storage, ExplicitClose::default());

let ext_unit = add_scope!(scope_graph[let s |-> ()] with open labels: ()).0;
let scope_graph: ScopeGraph<Lbl, (), ImplicitClose<Lbl>> =
ScopeGraph::new(&storage, ImplicitClose::default());

add_scope!(
scope_graph[let s |-> ()] request open:
- Lbl::L1 => let ext_l1
- Lbl::L2 => let ext_l2
);
println!("{:?}", s);
}
}

0 comments on commit 46ec3d1

Please sign in to comment.