diff --git a/mers/Cargo.toml b/mers/Cargo.toml index b84ed04..6a2f8e8 100644 --- a/mers/Cargo.toml +++ b/mers/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/Dummi26/mers" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -mers_lib = "0.7.0" -# mers_lib = { path = "../mers_lib" } +# mers_lib = "0.7.0" +mers_lib = { path = "../mers_lib" } clap = { version = "4.3.19", features = ["derive"] } colored = "2.1.0" diff --git a/mers_lib/examples/00_parse_compile_check_run.rs b/mers_lib/examples/00_parse_compile_check_run.rs index 46c8e39..7a55dd0 100644 --- a/mers_lib/examples/00_parse_compile_check_run.rs +++ b/mers_lib/examples/00_parse_compile_check_run.rs @@ -3,7 +3,8 @@ use std::sync::Arc; use mers_lib::{ data::{Data, MersType, Type}, errors::CheckError, - prelude_compile::{parse, CompInfo, Config, Source}, + prelude_compile::{parse, Config, Source}, + program::parsed::CompInfo, }; fn main() { diff --git a/mers_lib/examples/01_user_scripts.rs b/mers_lib/examples/01_user_scripts.rs index a920dde..5735bc6 100644 --- a/mers_lib/examples/01_user_scripts.rs +++ b/mers_lib/examples/01_user_scripts.rs @@ -3,7 +3,8 @@ use std::sync::Arc; use mers_lib::{ data::{self, Data, Type}, errors::CheckError, - prelude_compile::{parse, CompInfo, Config, Source}, + prelude_compile::{parse, Config, Source}, + program::parsed::CompInfo, }; fn main() -> Result<(), CheckError> { diff --git a/mers_lib/examples/02_own_variable.rs b/mers_lib/examples/02_own_variable.rs index 3e78434..b7eb9bc 100644 --- a/mers_lib/examples/02_own_variable.rs +++ b/mers_lib/examples/02_own_variable.rs @@ -3,7 +3,8 @@ use std::sync::Arc; use mers_lib::{ data::{self, Data, MersType, Type}, errors::CheckError, - prelude_compile::{parse, CompInfo, Config, Source}, + prelude_compile::{parse, Config, Source}, + program::parsed::CompInfo, }; fn main() { diff --git a/mers_lib/src/data/int.rs b/mers_lib/src/data/int.rs index 3f1b62a..1163873 100755 --- a/mers_lib/src/data/int.rs +++ b/mers_lib/src/data/int.rs @@ -2,7 +2,7 @@ use std::{any::Any, fmt::Display, sync::Arc}; use super::{MersData, MersType, Type}; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub struct Int(pub isize); impl MersData for Int { diff --git a/mers_lib/src/data/mod.rs b/mers_lib/src/data/mod.rs index 1b5ae1e..c804eb0 100755 --- a/mers_lib/src/data/mod.rs +++ b/mers_lib/src/data/mod.rs @@ -5,6 +5,7 @@ use std::{ }; pub mod bool; +pub mod byte; pub mod float; pub mod function; pub mod int; diff --git a/mers_lib/src/lib.rs b/mers_lib/src/lib.rs index 5cf29a6..f717bb9 100755 --- a/mers_lib/src/lib.rs +++ b/mers_lib/src/lib.rs @@ -44,7 +44,7 @@ fn test_examples() { let (mut i1, _, mut i3) = prelude_compile::Config::new().bundle_std().infos(); prelude_compile::parse(&mut src.clone(), &std::sync::Arc::new(src)) .unwrap() - .compile(&mut i1, prelude_compile::CompInfo::default()) + .compile(&mut i1, program::parsed::CompInfo::default()) .unwrap() .check(&mut i3, None) .unwrap(); diff --git a/mers_lib/src/parsing/statements.rs b/mers_lib/src/parsing/statements.rs index 5ead923..3dc9be9 100755 --- a/mers_lib/src/parsing/statements.rs +++ b/mers_lib/src/parsing/statements.rs @@ -519,6 +519,15 @@ pub fn parse_no_chain( data: Data::new(crate::data::int::Int(n)), }) } + } else if let Some(b) = o + .ends_with('b') + .then(|| o[0..o.len() - 1].parse().ok()) + .flatten() + { + Box::new(program::parsed::value::Value { + pos_in_src: (pos_in_src, src.get_pos(), srca).into(), + data: Data::new(crate::data::byte::Byte(b)), + }) } else { if let Some('&') = o.chars().next() { Box::new(program::parsed::variable::Variable { diff --git a/mers_lib/src/program/configs/mod.rs b/mers_lib/src/program/configs/mod.rs index 08c0453..d91334b 100755 --- a/mers_lib/src/program/configs/mod.rs +++ b/mers_lib/src/program/configs/mod.rs @@ -74,6 +74,7 @@ impl Config { }; } init_d!(data::bool::BoolT); + init_d!(data::byte::ByteT); init_d!(data::int::IntT); init_d!(data::float::FloatT); init_d!(data::string::StringT); diff --git a/mers_lib/src/program/configs/with_command_running.rs b/mers_lib/src/program/configs/with_command_running.rs index 257a4f9..5bacf4b 100755 --- a/mers_lib/src/program/configs/with_command_running.rs +++ b/mers_lib/src/program/configs/with_command_running.rs @@ -186,10 +186,10 @@ impl Config { info: Arc::new(program::run::Info::neverused()), info_check: Arc::new(Mutex::new( CheckInfo::neverused())), out: Arc::new(|a, _i| { - if a.types.iter().all(|a| a.as_any().downcast_ref::().is_some_and(|t| t.0.len() == 2 && t.0[0].is_included_in(&ChildProcessT) && t.0[1].iterable().is_some_and(|i| i.is_included_in(&data::int::IntT)))) { + if a.types.iter().all(|a| a.as_any().downcast_ref::().is_some_and(|t| t.0.len() == 2 && t.0[0].is_included_in(&ChildProcessT) && t.0[1].iterable().is_some_and(|i| i.is_included_in(&data::byte::ByteT)))) { Ok(Type::new(data::bool::BoolT)) } else { - return Err(format!("childproc_write_bytes called on non-`(ChildProcess, Iter)` type {a}").into()); + return Err(format!("childproc_write_bytes called on non-`(ChildProcess, Iter)` type {a}").into()); } }), run: Arc::new(|a, _i| { @@ -199,7 +199,7 @@ impl Config { let bytes = tuple.0[1].get(); let child = child.as_any().downcast_ref::().unwrap(); let mut child = child.0.lock().unwrap(); - let buf = bytes.iterable().unwrap().map(|v| v.get().as_any().downcast_ref::().unwrap().0.max(0).min(255) as u8).collect::>(); + let buf = bytes.iterable().unwrap().map(|v| v.get().as_any().downcast_ref::().unwrap().0).collect::>(); if child.1.as_mut().is_some_and(|v| v.write_all(&buf).is_ok() && v.flush().is_ok()) { Data::new(data::bool::Bool(true)) } else { @@ -246,7 +246,7 @@ impl Config { out: Arc::new(|a, _i| { if a.is_included_in(&ChildProcessT) { Ok(Type::newm(vec![ - Arc::new(data::tuple::TupleT(vec![Type::new(data::int::IntT)])), + Arc::new(data::tuple::TupleT(vec![Type::new(data::byte::ByteT)])), Arc::new(data::tuple::TupleT(vec![])), ])) } else { @@ -259,7 +259,7 @@ impl Config { let mut child = child.0.lock().unwrap(); let mut buf = [0]; if child.2.read_exact(&mut buf).is_ok() { - Data::one_tuple(Data::new(data::int::Int(buf[0] as _))) + Data::one_tuple(Data::new(data::byte::Byte(buf[0]))) } else { Data::empty_tuple() } @@ -275,7 +275,7 @@ impl Config { out: Arc::new(|a, _i| { if a.is_included_in(&ChildProcessT) { Ok(Type::newm(vec![ - Arc::new(data::tuple::TupleT(vec![Type::new(data::int::IntT)])), + Arc::new(data::tuple::TupleT(vec![Type::new(data::byte::ByteT)])), Arc::new(data::tuple::TupleT(vec![])), ])) } else { @@ -288,7 +288,7 @@ impl Config { let mut child = child.0.lock().unwrap(); let mut buf = [0]; if child.3.read_exact(&mut buf).is_ok() { - Data::one_tuple(Data::new(data::int::Int(buf[0] as _))) + Data::one_tuple(Data::new(data::byte::Byte(buf[0]))) } else { Data::empty_tuple() }