Skip to content

Commit

Permalink
as_any for StackFrameTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Jul 19, 2024
1 parent 29c028e commit 9c6280c
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::any::Any;
use std::rc::Rc;

use crate::builtins::type_error_builtin::ToTypeError;
Expand Down Expand Up @@ -155,4 +156,12 @@ impl StackFrameTrait for ArrayMappingFrame {
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())
}

fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
9 changes: 9 additions & 0 deletions valuescript_vm/src/array_higher_functions/array_reduce.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::any::Any;
use std::rc::Rc;

use crate::builtins::type_error_builtin::ToTypeError;
Expand Down Expand Up @@ -120,4 +121,12 @@ impl StackFrameTrait for ReduceFrame {
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())
}

fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::any::Any;
use std::rc::Rc;

use crate::builtins::type_error_builtin::ToTypeError;
Expand Down Expand Up @@ -133,4 +134,12 @@ impl StackFrameTrait for ReduceRightFrame {
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())
}

fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
9 changes: 9 additions & 0 deletions valuescript_vm/src/array_higher_functions/array_sort.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::any::Any;
use std::rc::Rc;

use crate::builtins::type_error_builtin::ToTypeError;
Expand Down Expand Up @@ -314,4 +315,12 @@ impl StackFrameTrait for SortFrame {
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())
}

fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
9 changes: 9 additions & 0 deletions valuescript_vm/src/bytecode_stack_frame.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::any::Any;
use std::mem::take;

use valuescript_common::InstructionByte;
Expand Down Expand Up @@ -732,4 +733,12 @@ impl StackFrameTrait for BytecodeStackFrame {
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())
}

fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
10 changes: 9 additions & 1 deletion valuescript_vm/src/cat_stack_frame.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{mem::take, rc::Rc};
use std::{any::Any, mem::take, rc::Rc};

use crate::{
builtins::{internal_error_builtin::ToInternalError, type_error_builtin::ToTypeError},
Expand Down Expand Up @@ -154,4 +154,12 @@ impl StackFrameTrait for CatStackFrame {
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())
}

fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
10 changes: 10 additions & 0 deletions valuescript_vm/src/first_stack_frame.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::any::Any;

use crate::stack_frame::StackFrame;

use super::stack_frame::{CallResult, FrameStepResult, StackFrameTrait};
Expand Down Expand Up @@ -58,4 +60,12 @@ impl StackFrameTrait for FirstStackFrame {
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())
}

fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
17 changes: 17 additions & 0 deletions valuescript_vm/src/generator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
any::Any,
fmt,
mem::{swap, take},
rc::Rc,
Expand Down Expand Up @@ -241,6 +242,14 @@ impl StackFrameTrait for GeneratorFrame {
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())
}

fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}

#[derive(Clone, Default)]
Expand Down Expand Up @@ -356,4 +365,12 @@ impl StackFrameTrait for YieldStarFrame {
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())
}

fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
10 changes: 9 additions & 1 deletion valuescript_vm/src/make_generator_frame.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::mem::take;
use std::{any::Any, mem::take};

use crate::{
bytecode_stack_frame::BytecodeStackFrame,
Expand Down Expand Up @@ -61,4 +61,12 @@ impl StackFrameTrait for MakeGeneratorFrame {
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())
}

fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
12 changes: 11 additions & 1 deletion valuescript_vm/src/stack_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub enum FrameStepOk {

pub type FrameStepResult = Result<FrameStepOk, Val>;

pub trait StackFrameTrait: Any {
pub trait StackFrameTrait {
fn write_this(&mut self, const_: bool, this: Val) -> Result<(), Val>;
fn write_param(&mut self, param: Val);
fn step(&mut self) -> FrameStepResult;
Expand All @@ -29,6 +29,8 @@ pub trait StackFrameTrait: Any {
fn can_catch_exception(&self, exception: &Val) -> bool;
fn catch_exception(&mut self, exception: &mut Val);
fn clone_to_stack_frame(&self) -> StackFrame;
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
}

impl Clone for StackFrame {
Expand Down Expand Up @@ -75,4 +77,12 @@ impl StackFrameTrait for VoidStackFrame {
fn clone_to_stack_frame(&self) -> StackFrame {
Box::new(self.clone())
}

fn as_any(&self) -> &dyn Any {
self
}

fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}

0 comments on commit 9c6280c

Please sign in to comment.