mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 05:43:53 +01:00
add Byte to replace Int when appropriate
This commit is contained in:
parent
a1c585a30d
commit
45a46f32a5
@ -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"
|
||||
|
@ -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() {
|
||||
|
@ -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> {
|
||||
|
@ -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() {
|
||||
|
@ -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 {
|
||||
|
@ -5,6 +5,7 @@ use std::{
|
||||
};
|
||||
|
||||
pub mod bool;
|
||||
pub mod byte;
|
||||
pub mod float;
|
||||
pub mod function;
|
||||
pub mod int;
|
||||
|
@ -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();
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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::<data::tuple::TupleT>().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::<data::tuple::TupleT>().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<Int>)` type {a}").into());
|
||||
return Err(format!("childproc_write_bytes called on non-`(ChildProcess, Iter<Byte>)` 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::<ChildProcess>().unwrap();
|
||||
let mut child = child.0.lock().unwrap();
|
||||
let buf = bytes.iterable().unwrap().map(|v| v.get().as_any().downcast_ref::<data::int::Int>().unwrap().0.max(0).min(255) as u8).collect::<Vec<_>>();
|
||||
let buf = bytes.iterable().unwrap().map(|v| v.get().as_any().downcast_ref::<data::byte::Byte>().unwrap().0).collect::<Vec<_>>();
|
||||
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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user