From 28a8fb462fa88da300c6cf016ed3c70c402b8dba Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sun, 7 Mar 2021 06:32:15 -0700 Subject: add a good-enough-for-now system actor type --- src/actor.rs | 29 +++++++++++++++++++++++++++++ src/main.rs | 4 ++++ src/number.rs | 20 ++++++++++++++++++++ src/system.rs | 31 +++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 src/actor.rs create mode 100644 src/number.rs create mode 100644 src/system.rs 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 + }, + AnyNumber, + NumberInRange { + min: Option, + max: Option, + }, + List { + contents: Box, + }, +} + +#[derive(Clone)] +pub struct Slot { + pub name: String, + pub r#type: Type, +} + +pub trait Actorful { + fn inputs() -> Vec; + fn outputs() -> Vec; +} 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, +} + +impl Actorful for System { + fn inputs() -> Vec { + 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 { + 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) }}] + } +} -- cgit v1.2.3