VsFunctionMetadata

This commit is contained in:
Andrew Morris
2023-08-14 09:13:11 +10:00
parent b0fa02a7cf
commit 4c6b249c10
5 changed files with 18 additions and 5 deletions

View File

@@ -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;
@@ -292,7 +293,10 @@ impl BytecodeDecoder {
VsFunction {
bytecode: self.bytecode.clone(),
hash,
metadata: VsFunctionMetadata {
name: Rc::from(""),
hash,
},
is_generator,
register_count,
parameter_count,

View File

@@ -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;

View File

@@ -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() {
@@ -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),

View File

@@ -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;
@@ -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,
@@ -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,

View File

@@ -0,0 +1,7 @@
use std::rc::Rc;
#[derive(Clone, Debug)]
pub struct VsFunctionMetadata {
pub name: Rc<str>,
pub hash: [u8; 32],
}