Merge branch 'main' into gui

This commit is contained in:
Jeff 2023-12-31 09:15:55 -05:00
commit f78070ca47
16 changed files with 34 additions and 34 deletions

View File

@ -103,7 +103,7 @@ impl AbstractTree for Assignment {
statement_type
};
context.set(variable_key, Value::Option(None), Some(variable_type))?;
context.set(variable_key, Value::none(), Some(variable_type))?;
Ok(Assignment {
identifier,
@ -143,7 +143,7 @@ impl AbstractTree for Assignment {
context.set(key.clone(), new_value, None)?;
}
Ok(Value::Option(None))
Ok(Value::none())
}
fn expected_type(&self, _context: &Map) -> Result<Type> {

View File

@ -52,7 +52,7 @@ impl AbstractTree for Block {
fn run(&self, source: &str, context: &Map) -> Result<Value> {
if self.is_async {
let statements = &self.statements;
let final_result = RwLock::new(Ok(Value::Option(None)));
let final_result = RwLock::new(Ok(Value::none()));
statements
.into_par_iter()
@ -74,7 +74,7 @@ impl AbstractTree for Block {
None
}
})
.unwrap_or(final_result.into_inner().unwrap())
.unwrap_or(final_result.into_inner()?)
} else {
let mut prev_result = None;
@ -86,7 +86,7 @@ impl AbstractTree for Block {
prev_result = Some(statement.run(source, context));
}
prev_result.unwrap_or(Ok(Value::Option(None)))
prev_result.unwrap_or(Ok(Value::none()))
}
}

View File

@ -71,7 +71,7 @@ impl AbstractTree for For {
}
}
Ok(Value::Option(None))
Ok(Value::none())
}
fn expected_type(&self, _context: &Map) -> Result<Type> {

View File

@ -76,7 +76,7 @@ impl AbstractTree for IfElse {
if let Some(block) = &self.else_block {
block.run(source, context)
} else {
Ok(Value::Option(None))
Ok(Value::none())
}
}
}

View File

@ -70,7 +70,7 @@ impl AbstractTree for IndexAssignment {
previous_value += value;
previous_value
} else {
Value::Option(None)
Value::none()
}
}
AssignmentOperator::MinusEqual => {
@ -80,7 +80,7 @@ impl AbstractTree for IndexAssignment {
previous_value -= value;
previous_value
} else {
Value::Option(None)
Value::none()
}
}
AssignmentOperator::Equal => value,
@ -88,7 +88,7 @@ impl AbstractTree for IndexAssignment {
index_context.set(index_key.clone(), new_value, None)?;
Ok(Value::Option(None))
Ok(Value::none())
}
fn expected_type(&self, _context: &Map) -> Result<Type> {

View File

@ -72,7 +72,7 @@ impl AbstractTree for Match {
if let Some(fallback) = &self.fallback {
fallback.run(source, context)
} else {
Ok(Value::Option(None))
Ok(Value::none())
}
}

View File

@ -59,7 +59,7 @@ impl AbstractTree for Root {
}
fn run(&self, source: &str, context: &Map) -> Result<Value> {
let mut value = Value::Option(None);
let mut value = Value::none();
for statement in &self.statements {
value = statement.run(source, context)?;

View File

@ -216,7 +216,7 @@ impl AbstractTree for Type {
}
fn run(&self, _source: &str, _context: &Map) -> Result<Value> {
Ok(Value::Option(None))
Ok(Value::none())
}
fn expected_type(&self, _context: &Map) -> Result<Type> {

View File

@ -57,7 +57,7 @@ impl AbstractTree for ValueNode {
{
function_context.set(
parameter_name.inner().clone(),
Value::Option(None),
Value::none(),
Some(parameter_type.clone()),
)?;
}

View File

@ -30,7 +30,7 @@ impl AbstractTree for While {
self.block.run(source, context)?;
}
Ok(Value::Option(None))
Ok(Value::none())
}
fn expected_type(&self, context: &Map) -> Result<Type> {

View File

@ -14,7 +14,7 @@ impl BuiltInFunction for Assert {
}
}
Ok(Value::Option(None))
Ok(Value::none())
}
fn r#type(&self) -> Type {
@ -39,7 +39,7 @@ impl BuiltInFunction for AssertEqual {
let right = arguments.get(1).unwrap();
if left == right {
Ok(Value::Option(None))
Ok(Value::none())
} else {
Err(Error::AssertEqualFailed {
expected: left.clone(),

View File

@ -65,7 +65,7 @@ impl BuiltInFunction for Write {
write(path, file_content)?;
Ok(Value::Option(None))
Ok(Value::none())
}
fn r#type(&self) -> Type {
@ -86,11 +86,11 @@ impl BuiltInFunction for Append {
fn run(&self, arguments: &[Value], _context: &Map) -> Result<Value> {
let file_content = arguments
.first()
.unwrap_or(&Value::Option(None))
.unwrap_or(&Value::none())
.as_string()?;
let path = arguments
.get(1)
.unwrap_or(&Value::Option(None))
.unwrap_or(&Value::none())
.as_string()?;
File::options()
@ -99,7 +99,7 @@ impl BuiltInFunction for Append {
.open(path)?
.write_all(file_content.as_bytes())?;
Ok(Value::Option(None))
Ok(Value::none())
}
fn r#type(&self) -> Type {

View File

@ -23,7 +23,7 @@ impl BuiltInFunction for InstallPackages {
command.spawn()?.wait()?;
Ok(Value::Option(None))
Ok(Value::none())
}
fn r#type(&self) -> Type {

View File

@ -58,7 +58,7 @@ impl Map {
pub fn unset_all(&self) -> Result<()> {
for (_key, (value, r#_type)) in self.variables.write()?.iter_mut() {
*value = Value::Option(None);
*value = Value::none();
}
Ok(())

View File

@ -88,7 +88,7 @@ impl Value {
}
pub fn none() -> Self {
Value::Option(None)
Value::none()
}
pub fn is_string(&self) -> bool {
@ -120,7 +120,7 @@ impl Value {
}
pub fn is_none(&self) -> bool {
matches!(self, Value::Option(None))
matches!(self, Value::none())
}
pub fn is_map(&self) -> bool {
@ -234,7 +234,7 @@ impl Value {
}
}
/// Returns `()`, or returns `Err` if `self` is not a `Value::Option(None)`.
/// Returns `()`, or returns `Err` if `self` is not a `Value::none()`.
pub fn as_none(&self) -> Result<()> {
match self {
Value::Option(option) => {
@ -255,7 +255,7 @@ impl Value {
impl Default for &Value {
fn default() -> Self {
&Value::Option(None)
&Value::none()
}
}
@ -546,7 +546,7 @@ impl From<Value> for Result<Value> {
impl From<()> for Value {
fn from(_: ()) -> Self {
Value::Option(None)
Value::none()
}
}
@ -769,7 +769,7 @@ impl<'de> Visitor<'de> for ValueVisitor {
where
E: serde::de::Error,
{
Ok(Value::Option(None))
Ok(Value::none())
}
fn visit_some<D>(self, deserializer: D) -> std::result::Result<Self::Value, D::Error>
@ -787,7 +787,7 @@ impl<'de> Visitor<'de> for ValueVisitor {
where
E: serde::de::Error,
{
Ok(Value::Option(None))
Ok(Value::none())
}
fn visit_newtype_struct<D>(self, deserializer: D) -> std::result::Result<Self::Value, D::Error>

View File

@ -81,13 +81,13 @@ mod for_loop {
fn modify_value_async() {
let result = interpret(
"
list = []
async for i in [1 2 3] { list += i }
length(list)
fn = (x <int>) <none> {}
fn(1)
",
);
assert_eq!(Ok(Value::Integer(3)), result);
assert_eq!(Ok(Value::none()), result);
}
}