Skip to content

Commit

Permalink
Added metadata field, compiles and runs but likely typing info is inc…
Browse files Browse the repository at this point in the history
…orrect
  • Loading branch information
davidchuyaya committed Jan 7, 2025
1 parent e5e6b75 commit 237ea2e
Show file tree
Hide file tree
Showing 10 changed files with 917 additions and 438 deletions.
26 changes: 15 additions & 11 deletions hydro_lang/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub struct FlowStateInner {

/// Counters for clock IDs.
pub(crate) next_clock_id: usize,

/// Counter for unique HydroNode IDs.
pub(crate) next_node_id: usize,
}

pub type FlowState = Rc<RefCell<FlowStateInner>>;
Expand All @@ -47,7 +50,7 @@ pub struct FlowBuilder<'a> {
nodes: RefCell<Vec<usize>>,
clusters: RefCell<Vec<usize>>,

next_node_id: RefCell<usize>,
next_location_id: RefCell<usize>,

/// Tracks whether this flow has been finalized; it is an error to
/// drop without finalizing.
Expand Down Expand Up @@ -86,10 +89,11 @@ impl<'a> FlowBuilder<'a> {
next_external_out: 0,
cycle_counts: HashMap::new(),
next_clock_id: 0,
next_node_id: 0,
})),
nodes: RefCell::new(vec![]),
clusters: RefCell::new(vec![]),
next_node_id: RefCell::new(0),
next_location_id: RefCell::new(0),
finalized: false,
_phantom: PhantomData,
}
Expand Down Expand Up @@ -126,9 +130,9 @@ impl<'a> FlowBuilder<'a> {
}

pub fn process<P>(&self) -> Process<'a, P> {
let mut next_node_id = self.next_node_id.borrow_mut();
let id = *next_node_id;
*next_node_id += 1;
let mut next_location_id = self.next_location_id.borrow_mut();
let id = *next_location_id;
*next_location_id += 1;

self.nodes.borrow_mut().push(id);

Expand All @@ -140,9 +144,9 @@ impl<'a> FlowBuilder<'a> {
}

pub fn external_process<P>(&self) -> ExternalProcess<'a, P> {
let mut next_node_id = self.next_node_id.borrow_mut();
let id = *next_node_id;
*next_node_id += 1;
let mut next_location_id = self.next_location_id.borrow_mut();
let id = *next_location_id;
*next_location_id += 1;

self.nodes.borrow_mut().push(id);

Expand All @@ -154,9 +158,9 @@ impl<'a> FlowBuilder<'a> {
}

pub fn cluster<C>(&self) -> Cluster<'a, C> {
let mut next_node_id = self.next_node_id.borrow_mut();
let id = *next_node_id;
*next_node_id += 1;
let mut next_location_id = self.next_location_id.borrow_mut();
let id = *next_location_id;
*next_location_id += 1;

self.clusters.borrow_mut().push(id);

Expand Down
Loading

0 comments on commit 237ea2e

Please sign in to comment.