mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Add stubs for ValTrait.next
This commit is contained in:
@@ -78,6 +78,10 @@ impl ValTrait for ArrayBuiltin {
|
||||
type_error!("Cannot assign to subscript of Array builtin")
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
LoadFunctionResult::NotAFunction
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\x1b[36m[Array]\x1b[39m")
|
||||
}
|
||||
|
||||
@@ -70,6 +70,10 @@ impl ValTrait for BooleanBuiltin {
|
||||
type_error!("Cannot assign to subscript of Boolean builtin")
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
LoadFunctionResult::NotAFunction
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\x1b[36m[Boolean]\x1b[39m")
|
||||
}
|
||||
|
||||
@@ -72,6 +72,10 @@ impl ValTrait for DebugBuiltin {
|
||||
type_error!("Cannot assign to subscript of Debug builtin")
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
LoadFunctionResult::NotAFunction
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\x1b[36m[Debug]\x1b[39m")
|
||||
}
|
||||
|
||||
@@ -75,6 +75,10 @@ impl ValTrait for ErrorBuiltin {
|
||||
type_error!("Cannot assign to subscript of Error builtin")
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
LoadFunctionResult::NotAFunction
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\x1b[36m[Error]\x1b[39m")
|
||||
}
|
||||
|
||||
@@ -117,6 +117,10 @@ impl ValTrait for MathBuiltin {
|
||||
type_error!("Cannot assign to subscript of Math builtin")
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
LoadFunctionResult::NotAFunction
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\x1b[36m[Math]\x1b[39m")
|
||||
}
|
||||
|
||||
@@ -86,6 +86,10 @@ impl ValTrait for NumberBuiltin {
|
||||
type_error!("Cannot assign to subscript of Number builtin")
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
LoadFunctionResult::NotAFunction
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\x1b[36m[Number]\x1b[39m")
|
||||
}
|
||||
|
||||
@@ -77,6 +77,10 @@ impl ValTrait for RangeErrorBuiltin {
|
||||
type_error!("Cannot assign to subscript of RangeError builtin")
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
LoadFunctionResult::NotAFunction
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\x1b[36m[RangeError]\x1b[39m")
|
||||
}
|
||||
|
||||
@@ -79,6 +79,10 @@ impl ValTrait for StringBuiltin {
|
||||
type_error!("Cannot assign to subscript of String builtin")
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
LoadFunctionResult::NotAFunction
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\x1b[36m[String]\x1b[39m")
|
||||
}
|
||||
|
||||
@@ -74,6 +74,10 @@ impl ValTrait for SymbolBuiltin {
|
||||
type_error!("Cannot assign to subscript of Symbol builtin")
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
LoadFunctionResult::NotAFunction
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\x1b[36m[Symbol]\x1b[39m")
|
||||
}
|
||||
|
||||
@@ -77,6 +77,10 @@ impl ValTrait for TypeErrorBuiltin {
|
||||
type_error!("Cannot assign to subscript of TypeError builtin")
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
LoadFunctionResult::NotAFunction
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\x1b[36m[TypeError]\x1b[39m")
|
||||
}
|
||||
|
||||
@@ -70,6 +70,10 @@ impl ValTrait for NativeFrameFunction {
|
||||
type_error!("Cannot assign to subscript of native function")
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
LoadFunctionResult::NotAFunction
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\x1b[36m[Function]\x1b[39m")
|
||||
}
|
||||
|
||||
@@ -91,6 +91,10 @@ impl ValTrait for NativeFunction {
|
||||
type_error!("Cannot assign to subscript of native function")
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
LoadFunctionResult::NotAFunction
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\x1b[36m[Function]\x1b[39m")
|
||||
}
|
||||
|
||||
@@ -141,6 +141,10 @@ impl ValTrait for ArrayPrototype {
|
||||
type_error!("Cannot assign to subscript of Array.prototype")
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
LoadFunctionResult::NotAFunction
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "\x1b[36m[Array Prototype]\x1b[39m")
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ impl VsPointer {
|
||||
pub fn new(bytecode: &Rc<Vec<u8>>, pos: usize) -> Val {
|
||||
return Val::Custom(Rc::new(VsPointer {
|
||||
bytecode: bytecode.clone(),
|
||||
pos: pos,
|
||||
pos,
|
||||
resolved: RefCell::new(None),
|
||||
}));
|
||||
}
|
||||
@@ -149,6 +149,10 @@ impl ValTrait for VsPointer {
|
||||
format_err!("TODO: Probably an exception, but might be possible")
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
self.resolve().next()
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
self.resolve().fmt(f)
|
||||
}
|
||||
|
||||
@@ -77,6 +77,8 @@ pub trait ValTrait {
|
||||
fn sub(&self, key: Val) -> Result<Val, Val>;
|
||||
fn submov(&mut self, key: Val, value: Val) -> Result<(), Val>;
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult;
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result;
|
||||
fn codify(&self) -> String;
|
||||
}
|
||||
@@ -362,6 +364,20 @@ impl ValTrait for Val {
|
||||
op_submov(self, key, value)
|
||||
}
|
||||
|
||||
fn next(&mut self) -> LoadFunctionResult {
|
||||
match self {
|
||||
// TODO: iterator
|
||||
_ => {
|
||||
let next_fn = op_sub(self.clone(), Val::String(Rc::new("next".into())));
|
||||
|
||||
match next_fn {
|
||||
Ok(next_fn) => next_fn.load_function(),
|
||||
Err(_) => LoadFunctionResult::NotAFunction,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(self, f)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user