Add is_truthy

This commit is contained in:
Andrew Morris
2022-05-02 16:03:03 +10:00
parent 93f338bbc4
commit b5f1cc7b78
6 changed files with 21 additions and 0 deletions

View File

@@ -51,4 +51,8 @@ impl VsValue for VsFunction {
return true;
}
fn is_truthy(&self) -> bool {
return true;
}
}

View File

@@ -35,4 +35,8 @@ impl VsValue for VsNumber {
fn push_frame(&self, vm: &mut VirtualMachine) -> bool {
return false;
}
fn is_truthy(&self) -> bool {
return self.value != 0_f64;
}
}

View File

@@ -93,4 +93,8 @@ impl VsValue for VsPointer {
fn push_frame(&self, vm: &mut VirtualMachine) -> bool {
return self.decode().push_frame(vm);
}
fn is_truthy(&self) -> bool {
return self.decode().is_truthy();
}
}

View File

@@ -39,4 +39,8 @@ impl VsValue for VsString {
fn push_frame(&self, vm: &mut VirtualMachine) -> bool {
return false;
}
fn is_truthy(&self) -> bool {
return self.value != "";
}
}

View File

@@ -33,4 +33,8 @@ impl VsValue for VsUndefined {
fn push_frame(&self, vm: &mut VirtualMachine) -> bool {
return false;
}
fn is_truthy(&self) -> bool {
return false;
}
}

View File

@@ -37,6 +37,7 @@ pub trait VsValue {
fn to_string(&self) -> String;
fn to_number(&self) -> f64;
fn is_primitive(&self) -> bool;
fn is_truthy(&self) -> bool;
fn push_frame(&self, vm: &mut VirtualMachine) -> bool;
}