diff options
-rw-r--r-- | src/actor.rs | 29 | ||||
-rw-r--r-- | src/main.rs | 4 | ||||
-rw-r--r-- | src/number.rs | 20 | ||||
-rw-r--r-- | src/system.rs | 31 |
4 files changed, 84 insertions, 0 deletions
diff --git a/src/actor.rs b/src/actor.rs new file mode 100644 index 0000000..3b03fa6 --- /dev/null +++ b/src/actor.rs @@ -0,0 +1,29 @@ +use crate::number::Number; + +#[derive(Clone)] +pub enum Type { + String, + Record { + name: String, + fields: Vec<Slot> + }, + AnyNumber, + NumberInRange { + min: Option<Number>, + max: Option<Number>, + }, + List { + contents: Box<Type>, + }, +} + +#[derive(Clone)] +pub struct Slot { + pub name: String, + pub r#type: Type, +} + +pub trait Actorful { + fn inputs() -> Vec<Slot>; + fn outputs() -> Vec<Slot>; +} diff --git a/src/main.rs b/src/main.rs index 424f3fc..0f87d5b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,10 @@ use std::time::Duration; use minifb::{Key, Window, WindowOptions}; +mod actor; +mod number; +mod system; + const WIDTH: usize = 1600; const HEIGHT: usize = 900; diff --git a/src/number.rs b/src/number.rs new file mode 100644 index 0000000..a71399c --- /dev/null +++ b/src/number.rs @@ -0,0 +1,20 @@ +#[derive(Clone)] +pub struct Number { + pub integer_part: String, + pub fractional_part: String, +} + +macro_rules! int_conv { + ($($t:ty),*) => {$( + impl From<$t> for Number { + fn from(x: $t) -> Number { + Number { + integer_part: x.to_string(), + fractional_part: "".to_string(), + } + } + } + )*}; +} + +int_conv!(u8, u16, u32, u64, usize, i8, i16, i32, i64, isize); diff --git a/src/system.rs b/src/system.rs new file mode 100644 index 0000000..7df8af8 --- /dev/null +++ b/src/system.rs @@ -0,0 +1,31 @@ +use crate::actor::{Actorful, Slot, Type}; +use crate::number::Number; + +pub struct System { + pub screen_buffer: Vec<u32>, +} + +impl Actorful for System { + fn inputs() -> Vec<Slot> { + let nonnegative_int = Type::NumberInRange { + min: Some(Number::from(0)), + max: None, + }; + let screen_position_type = Type::Record { + name: "Screen Position".to_string(), + fields: vec![ + Slot { name: "X".to_string(), r#type: nonnegative_int.clone() }, + Slot { name: "Y".to_string(), r#type: nonnegative_int }, + ], + }; + vec![Slot { name: "mouse_position".to_string(), r#type: screen_position_type }] + } + + fn outputs() -> Vec<Slot> { + let u24 = Type::NumberInRange { + min: Some(Number::from(0)), + max: Some(Number::from(1 << 24 - 1)), + }; + vec![Slot { name: "screen_buffer".to_string(), r#type: Type::List { contents: Box::new(u24) }}] + } +} |