mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 14:13:52 +01:00
added clone() to dereference by cloning
This commit is contained in:
parent
9741fa64cc
commit
dd017ffea4
@ -24,6 +24,7 @@ pub enum BuiltinFunction {
|
|||||||
AssumeNoEnum, // assume enum(*)/t is t.
|
AssumeNoEnum, // assume enum(*)/t is t.
|
||||||
NoEnum,
|
NoEnum,
|
||||||
Matches,
|
Matches,
|
||||||
|
Clone,
|
||||||
// print
|
// print
|
||||||
Print,
|
Print,
|
||||||
Println,
|
Println,
|
||||||
@ -93,6 +94,7 @@ impl BuiltinFunction {
|
|||||||
"assume_no_enum" => Self::AssumeNoEnum,
|
"assume_no_enum" => Self::AssumeNoEnum,
|
||||||
"noenum" => Self::NoEnum,
|
"noenum" => Self::NoEnum,
|
||||||
"matches" => Self::Matches,
|
"matches" => Self::Matches,
|
||||||
|
"clone" => Self::Clone,
|
||||||
"print" => Self::Print,
|
"print" => Self::Print,
|
||||||
"println" => Self::Println,
|
"println" => Self::Println,
|
||||||
"debug" => Self::Debug,
|
"debug" => Self::Debug,
|
||||||
@ -214,6 +216,7 @@ impl BuiltinFunction {
|
|||||||
}
|
}
|
||||||
Self::NoEnum => input.len() == 1,
|
Self::NoEnum => input.len() == 1,
|
||||||
Self::Matches => input.len() == 1,
|
Self::Matches => input.len() == 1,
|
||||||
|
Self::Clone => input.len() == 1 && matches!(input[0].is_reference(), Some(true)),
|
||||||
Self::Print | Self::Println => {
|
Self::Print | Self::Println => {
|
||||||
if input.len() == 1 {
|
if input.len() == 1 {
|
||||||
input[0].fits_in(&VSingleType::String.to()).is_empty()
|
input[0].fits_in(&VSingleType::String.to()).is_empty()
|
||||||
@ -502,6 +505,9 @@ impl BuiltinFunction {
|
|||||||
}
|
}
|
||||||
Self::NoEnum => input[0].clone().noenum(),
|
Self::NoEnum => input[0].clone().noenum(),
|
||||||
Self::Matches => input[0].matches().1,
|
Self::Matches => input[0].matches().1,
|
||||||
|
Self::Clone => input[0]
|
||||||
|
.dereference()
|
||||||
|
.expect("type is a reference, so it can be dereferenced"),
|
||||||
// []
|
// []
|
||||||
Self::Print | Self::Println | Self::Debug | Self::Sleep => VType {
|
Self::Print | Self::Println | Self::Debug | Self::Sleep => VType {
|
||||||
types: vec![VSingleType::Tuple(vec![])],
|
types: vec![VSingleType::Tuple(vec![])],
|
||||||
@ -750,6 +756,13 @@ impl BuiltinFunction {
|
|||||||
Some(v) => VDataEnum::Tuple(vec![v]).to(),
|
Some(v) => VDataEnum::Tuple(vec![v]).to(),
|
||||||
None => VDataEnum::Tuple(vec![]).to(),
|
None => VDataEnum::Tuple(vec![]).to(),
|
||||||
},
|
},
|
||||||
|
Self::Clone => {
|
||||||
|
if let VDataEnum::Reference(r) = args[0].run(vars, info).data {
|
||||||
|
r.lock().unwrap().clone()
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
BuiltinFunction::Print => {
|
BuiltinFunction::Print => {
|
||||||
if let VDataEnum::String(arg) = args[0].run(vars, info).data {
|
if let VDataEnum::String(arg) = args[0].run(vars, info).data {
|
||||||
print!("{}", arg);
|
print!("{}", arg);
|
||||||
|
@ -52,7 +52,7 @@ impl VType {
|
|||||||
}
|
}
|
||||||
Some(out)
|
Some(out)
|
||||||
}
|
}
|
||||||
// returns Some(true) or Some(false) if all types are references or not references. If it is mixed or types is empty, returns None.
|
/// returns Some(true) or Some(false) if all types are references or not references. If it is mixed or types is empty, returns None.
|
||||||
pub fn is_reference(&self) -> Option<bool> {
|
pub fn is_reference(&self) -> Option<bool> {
|
||||||
let mut noref = false;
|
let mut noref = false;
|
||||||
let mut reference = false;
|
let mut reference = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user