Add stubs for ValTrait.next

This commit is contained in:
Andrew Morris
2023-05-25 15:19:33 +10:00
parent a20f71a440
commit 35c9699f2b
15 changed files with 73 additions and 1 deletions

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -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")
}

View File

@@ -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)
}

View File

@@ -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)
}