This commit is contained in:
Andrew Morris
2023-08-14 17:35:24 +10:00
parent 5abd1c472e
commit 3ffafda8d2
12 changed files with 293 additions and 137 deletions

View File

@@ -1,6 +1,7 @@
use std::rc::Rc;
use crate::bytecode::Bytecode;
use crate::builtins::internal_error_builtin::ToInternalError;
use crate::bytecode::{Bytecode, DecoderMaker};
use crate::make_generator_frame::MakeGeneratorFrame;
use crate::vs_value::ToVal;
@@ -12,7 +13,7 @@ use super::vs_value::Val;
#[derive(Debug, Clone)]
pub struct VsFunction {
pub bytecode: Rc<Bytecode>,
pub metadata: Val,
pub metadata_pos: Option<usize>,
pub is_generator: bool,
pub register_count: usize,
pub parameter_count: usize,
@@ -30,7 +31,7 @@ impl VsFunction {
VsFunction {
bytecode: self.bytecode.clone(),
metadata: self.metadata.clone(),
metadata_pos: self.metadata_pos,
is_generator: self.is_generator,
register_count: self.register_count,
parameter_count: self.parameter_count,
@@ -39,6 +40,13 @@ impl VsFunction {
}
}
pub fn content_hash(&self) -> Result<[u8; 32], Val> {
match self.metadata_pos {
Some(p) => self.bytecode.decoder(p).decode_content_hash(),
None => Err("Can't get content_hash without metadata_pos".to_internal_error()),
}
}
pub fn make_bytecode_frame(&self) -> BytecodeStackFrame {
let mut registers: Vec<Val> = Vec::with_capacity(self.register_count - 1);