mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
IterationResult, remove as_object_data
This commit is contained in:
@@ -5,7 +5,6 @@ use num_bigint::BigInt;
|
||||
use crate::{
|
||||
vs_array::VsArray,
|
||||
vs_class::VsClass,
|
||||
vs_object::VsObject,
|
||||
vs_value::{Val, VsType},
|
||||
LoadFunctionResult, ValTrait,
|
||||
};
|
||||
@@ -59,10 +58,6 @@ where
|
||||
None
|
||||
}
|
||||
|
||||
fn as_object_data(&self) -> Option<Rc<VsObject>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn as_class_data(&self) -> Option<Rc<VsClass>> {
|
||||
Self::bo_as_class_data()
|
||||
}
|
||||
|
||||
91
valuescript_vm/src/iteration/iteration_result.rs
Normal file
91
valuescript_vm/src/iteration/iteration_result.rs
Normal file
@@ -0,0 +1,91 @@
|
||||
use std::{fmt, rc::Rc};
|
||||
|
||||
use num_bigint::BigInt;
|
||||
|
||||
use crate::{
|
||||
builtins::type_error_builtin::ToTypeError,
|
||||
vs_array::VsArray,
|
||||
vs_class::VsClass,
|
||||
vs_value::{ToVal, Val, VsType},
|
||||
LoadFunctionResult, ValTrait,
|
||||
};
|
||||
|
||||
struct IterationResult {
|
||||
pub value: Val,
|
||||
pub done: bool,
|
||||
}
|
||||
|
||||
impl ValTrait for IterationResult {
|
||||
fn typeof_(&self) -> VsType {
|
||||
VsType::Object
|
||||
}
|
||||
|
||||
fn to_number(&self) -> f64 {
|
||||
core::f64::NAN
|
||||
}
|
||||
|
||||
fn to_index(&self) -> Option<usize> {
|
||||
None
|
||||
}
|
||||
|
||||
fn is_primitive(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn is_truthy(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn is_nullish(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn bind(&self, _params: Vec<Val>) -> Option<Val> {
|
||||
None
|
||||
}
|
||||
|
||||
fn as_bigint_data(&self) -> Option<BigInt> {
|
||||
None
|
||||
}
|
||||
|
||||
fn as_array_data(&self) -> Option<Rc<VsArray>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn as_class_data(&self) -> Option<Rc<VsClass>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn load_function(&self) -> LoadFunctionResult {
|
||||
LoadFunctionResult::NotAFunction
|
||||
}
|
||||
|
||||
fn sub(&self, key: Val) -> Result<Val, Val> {
|
||||
Ok(match key.to_string().as_str() {
|
||||
"value" => self.value.clone(),
|
||||
"done" => self.done.to_val(),
|
||||
_ => Val::Undefined,
|
||||
})
|
||||
}
|
||||
|
||||
fn submov(&mut self, _key: Val, _value: Val) -> Result<(), Val> {
|
||||
Err("Cannot assign to iteration result".to_type_error())
|
||||
}
|
||||
|
||||
fn pretty_fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self.done {
|
||||
false => write!(f, "Iteration({})", self.value.pretty()),
|
||||
true => write!(f, "IterationDone({})", self.value.pretty()),
|
||||
}
|
||||
}
|
||||
|
||||
fn codify(&self) -> String {
|
||||
format!("{{ value: {}, done: {} }}", self.value.codify(), self.done)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for IterationResult {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str("[object Object]")
|
||||
}
|
||||
}
|
||||
1
valuescript_vm/src/iteration/mod.rs
Normal file
1
valuescript_vm/src/iteration/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
mod iteration_result;
|
||||
@@ -6,6 +6,7 @@ mod bytecode_decoder;
|
||||
mod bytecode_stack_frame;
|
||||
mod first_stack_frame;
|
||||
mod helpers;
|
||||
mod iteration;
|
||||
mod native_frame_function;
|
||||
mod native_function;
|
||||
mod number_methods;
|
||||
|
||||
@@ -8,7 +8,6 @@ use crate::builtins::type_error_builtin::ToTypeError;
|
||||
use crate::stack_frame::StackFrame;
|
||||
use crate::vs_array::VsArray;
|
||||
use crate::vs_class::VsClass;
|
||||
use crate::vs_object::VsObject;
|
||||
use crate::vs_value::{LoadFunctionResult, Val, ValTrait, VsType};
|
||||
|
||||
pub struct NativeFrameFunction {
|
||||
@@ -45,9 +44,6 @@ impl ValTrait for NativeFrameFunction {
|
||||
fn as_array_data(&self) -> Option<Rc<VsArray>> {
|
||||
None
|
||||
}
|
||||
fn as_object_data(&self) -> Option<Rc<VsObject>> {
|
||||
None
|
||||
}
|
||||
fn as_class_data(&self) -> Option<Rc<VsClass>> {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ use crate::builtins::error_builtin::ToError;
|
||||
use crate::builtins::type_error_builtin::ToTypeError;
|
||||
use crate::vs_array::VsArray;
|
||||
use crate::vs_class::VsClass;
|
||||
use crate::vs_object::VsObject;
|
||||
use crate::vs_value::{LoadFunctionResult, Val, ValTrait, VsType};
|
||||
|
||||
pub struct ThisWrapper<'a> {
|
||||
@@ -73,9 +72,6 @@ impl ValTrait for NativeFunction {
|
||||
fn as_array_data(&self) -> Option<Rc<VsArray>> {
|
||||
None
|
||||
}
|
||||
fn as_object_data(&self) -> Option<Rc<VsObject>> {
|
||||
None
|
||||
}
|
||||
fn as_class_data(&self) -> Option<Rc<VsClass>> {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -89,9 +89,6 @@ impl ValTrait for ArrayPrototype {
|
||||
fn as_array_data(&self) -> Option<Rc<VsArray>> {
|
||||
None
|
||||
}
|
||||
fn as_object_data(&self) -> Option<Rc<VsObject>> {
|
||||
None
|
||||
}
|
||||
fn as_class_data(&self) -> Option<Rc<VsClass>> {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -66,7 +66,6 @@ pub trait ValTrait: fmt::Display {
|
||||
|
||||
fn as_bigint_data(&self) -> Option<BigInt>;
|
||||
fn as_array_data(&self) -> Option<Rc<VsArray>>;
|
||||
fn as_object_data(&self) -> Option<Rc<VsObject>>;
|
||||
fn as_class_data(&self) -> Option<Rc<VsClass>>;
|
||||
|
||||
fn load_function(&self) -> LoadFunctionResult;
|
||||
@@ -272,17 +271,6 @@ impl ValTrait for Val {
|
||||
};
|
||||
}
|
||||
|
||||
fn as_object_data(&self) -> Option<Rc<VsObject>> {
|
||||
use Val::*;
|
||||
|
||||
return match self {
|
||||
Object(obj) => Some(obj.clone()),
|
||||
Custom(val) => val.as_object_data(),
|
||||
|
||||
_ => None,
|
||||
};
|
||||
}
|
||||
|
||||
fn as_class_data(&self) -> Option<Rc<VsClass>> {
|
||||
use Val::*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user