|
|
@ -59,15 +59,13 @@ impl<'a> From<&'a str> for Value {
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub struct Signal {
|
|
|
|
pub struct Signal {
|
|
|
|
direction: Direction,
|
|
|
|
direction: Direction,
|
|
|
|
position: (usize, usize),
|
|
|
|
|
|
|
|
stack: Vec<Value>,
|
|
|
|
stack: Vec<Value>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Signal {
|
|
|
|
impl Signal {
|
|
|
|
pub fn empty(position: (usize, usize), direction: Direction) -> Self {
|
|
|
|
pub fn empty(direction: Direction) -> Self {
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
direction,
|
|
|
|
direction,
|
|
|
|
position,
|
|
|
|
|
|
|
|
stack: Vec::new(),
|
|
|
|
stack: Vec::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -115,14 +113,6 @@ impl Signal {
|
|
|
|
self.direction
|
|
|
|
self.direction
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn position(&self) -> (usize, usize) {
|
|
|
|
|
|
|
|
self.position
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn set_position(&mut self, position: (usize, usize)) {
|
|
|
|
|
|
|
|
self.position = position;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Pushes a value onto the stack of the signal.
|
|
|
|
/// Pushes a value onto the stack of the signal.
|
|
|
|
/// Signals are pushed on top of the stack and can be [`pop`ped](Signal::pop) in reverse order.
|
|
|
|
/// Signals are pushed on top of the stack and can be [`pop`ped](Signal::pop) in reverse order.
|
|
|
|
///
|
|
|
|
///
|
|
|
@ -130,7 +120,7 @@ impl Signal {
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
/// # use stackline::prelude::*;
|
|
|
|
/// # use stackline::prelude::*;
|
|
|
|
/// let mut signal = Signal::empty((0, 0), Direction::Down);
|
|
|
|
/// let mut signal = Signal::empty(Direction::Down);
|
|
|
|
/// assert_eq!(signal.len(), 0);
|
|
|
|
/// assert_eq!(signal.len(), 0);
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// signal.push(Value::Number(1.0));
|
|
|
|
/// signal.push(Value::Number(1.0));
|
|
|
@ -150,7 +140,7 @@ impl Signal {
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
/// # use stackline::prelude::*;
|
|
|
|
/// # use stackline::prelude::*;
|
|
|
|
/// let mut signal = Signal::empty((0, 0), Direction::Down);
|
|
|
|
/// let mut signal = Signal::empty(Direction::Down);
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// signal.push(Value::Number(1.0));
|
|
|
|
/// signal.push(Value::Number(1.0));
|
|
|
|
/// signal.push(Value::Number(2.0));
|
|
|
|
/// signal.push(Value::Number(2.0));
|
|
|
@ -170,7 +160,7 @@ impl Signal {
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
/// # use stackline::prelude::*;
|
|
|
|
/// # use stackline::prelude::*;
|
|
|
|
/// let signal = stackline::signal!((0, 0), Direction::Down, [1.0, -1.5]);
|
|
|
|
/// let signal = stackline::signal!(Direction::Down, [1.0, -1.5]);
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// assert_eq!(signal.len(), 2);
|
|
|
|
/// assert_eq!(signal.len(), 2);
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
@ -204,18 +194,18 @@ impl Signal {
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
/// # use stackline::prelude::*;
|
|
|
|
/// # use stackline::prelude::*;
|
|
|
|
/// // Creates an empty signal at (1, 2)
|
|
|
|
/// // Creates an empty signal at (1, 2)
|
|
|
|
/// let signal = stackline::signal!((1, 2));
|
|
|
|
/// let signal = stackline::signal!();
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// // Creates an empty signal going right at (2, 2)
|
|
|
|
/// // Creates an empty signal going right at (2, 2)
|
|
|
|
/// let signal = stackline::signal!((2, 2), Direction::Right);
|
|
|
|
/// let signal = stackline::signal!(Direction::Right);
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// // Creates a signal with the values 10 and 12 on its stack
|
|
|
|
/// // Creates a signal with the values 10 and 12 on its stack
|
|
|
|
/// let signal = stackline::signal!((0, 0), [10, 12]);
|
|
|
|
/// let signal = stackline::signal!([10, 12]);
|
|
|
|
/// ```
|
|
|
|
/// ```
|
|
|
|
#[macro_export]
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! signal {
|
|
|
|
macro_rules! signal {
|
|
|
|
( $pos:expr, $dir:expr, [ $( $x:expr ),* ] ) => {{
|
|
|
|
( $dir:expr, [ $( $x:expr ),* ] ) => {{
|
|
|
|
let mut res = Signal::empty($pos, $dir);
|
|
|
|
let mut res = Signal::empty($dir);
|
|
|
|
|
|
|
|
|
|
|
|
$({
|
|
|
|
$({
|
|
|
|
res.push(Value::from($x));
|
|
|
|
res.push(Value::from($x));
|
|
|
@ -224,8 +214,8 @@ macro_rules! signal {
|
|
|
|
res
|
|
|
|
res
|
|
|
|
}};
|
|
|
|
}};
|
|
|
|
|
|
|
|
|
|
|
|
( $pos:expr, [ $( $x:expr ),* ] ) => {{
|
|
|
|
( [ $( $x:expr ),* ] ) => {{
|
|
|
|
let mut res = Signal::empty($pos, Direction::default());
|
|
|
|
let mut res = Signal::empty(Direction::default());
|
|
|
|
|
|
|
|
|
|
|
|
$({
|
|
|
|
$({
|
|
|
|
res.push(Value::from($x));
|
|
|
|
res.push(Value::from($x));
|
|
|
@ -234,14 +224,14 @@ macro_rules! signal {
|
|
|
|
res
|
|
|
|
res
|
|
|
|
}};
|
|
|
|
}};
|
|
|
|
|
|
|
|
|
|
|
|
( $pos:expr, $dir:expr) => {{
|
|
|
|
( $dir:expr ) => {{
|
|
|
|
let mut res = Signal::empty($pos, $dir);
|
|
|
|
let mut res = Signal::empty($dir);
|
|
|
|
|
|
|
|
|
|
|
|
res
|
|
|
|
res
|
|
|
|
}};
|
|
|
|
}};
|
|
|
|
|
|
|
|
|
|
|
|
( $pos:expr) => {{
|
|
|
|
() => {{
|
|
|
|
let mut res = Signal::empty($pos, Direction::default());
|
|
|
|
let mut res = Signal::empty(Direction::default());
|
|
|
|
|
|
|
|
|
|
|
|
res
|
|
|
|
res
|
|
|
|
}};
|
|
|
|
}};
|
|
|
|