Skip to content

Commit

Permalink
VsFunctionMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Aug 13, 2023
1 parent b0fa02a commit 4c6b249
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
6 changes: 5 additions & 1 deletion valuescript_vm/src/bytecode_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::builtins::BUILTIN_VALS;
use crate::bytecode::Bytecode;
use crate::vs_class::VsClass;
use crate::vs_function::VsFunction;
use crate::vs_function_metadata::VsFunctionMetadata;
use crate::vs_object::VsObject;
use crate::vs_symbol::VsSymbol;
use crate::vs_value::ToVal;
Expand Down Expand Up @@ -292,7 +293,10 @@ impl BytecodeDecoder {

VsFunction {
bytecode: self.bytecode.clone(),
hash,
metadata: VsFunctionMetadata {
name: Rc::from(""),
hash,
},
is_generator,
register_count,
parameter_count,
Expand Down
1 change: 1 addition & 0 deletions valuescript_vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod virtual_machine;
pub mod vs_array;
pub mod vs_class;
mod vs_function;
mod vs_function_metadata;
pub mod vs_object;
mod vs_symbol;
pub mod vs_value;
Expand Down
4 changes: 2 additions & 2 deletions valuescript_vm/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub fn op_eq_impl(left: &Val, right: &Val) -> Result<bool, Val> {
}
}

left.hash == right.hash
left.metadata.hash == right.metadata.hash
}
_ => {
if left.is_truthy() != right.is_truthy() {
Expand Down Expand Up @@ -316,7 +316,7 @@ pub fn op_triple_eq_impl(left: &Val, right: &Val) -> Result<bool, Val> {
}
}

left.hash == right.hash
left.metadata.hash == right.metadata.hash
}
#[allow(clippy::vtable_address_comparisons)] // TODO: Is this ok?
(Val::Static(left), Val::Static(right)) => std::ptr::eq(&**left, &**right),
Expand Down
5 changes: 3 additions & 2 deletions valuescript_vm/src/vs_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::rc::Rc;

use crate::bytecode::Bytecode;
use crate::make_generator_frame::MakeGeneratorFrame;
use crate::vs_function_metadata::VsFunctionMetadata;
use crate::vs_value::ToVal;

use super::bytecode_decoder::BytecodeDecoder;
Expand All @@ -12,7 +13,7 @@ use super::vs_value::Val;
#[derive(Debug, Clone)]
pub struct VsFunction {
pub bytecode: Rc<Bytecode>,
pub hash: [u8; 32],
pub metadata: VsFunctionMetadata,
pub is_generator: bool,
pub register_count: usize,
pub parameter_count: usize,
Expand All @@ -30,7 +31,7 @@ impl VsFunction {

VsFunction {
bytecode: self.bytecode.clone(),
hash: self.hash,
metadata: self.metadata.clone(),
is_generator: self.is_generator,
register_count: self.register_count,
parameter_count: self.parameter_count,
Expand Down
7 changes: 7 additions & 0 deletions valuescript_vm/src/vs_function_metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::rc::Rc;

#[derive(Clone, Debug)]
pub struct VsFunctionMetadata {
pub name: Rc<str>,
pub hash: [u8; 32],
}

0 comments on commit 4c6b249

Please sign in to comment.