mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Move backpointer check into BytecodeDecoder
This commit is contained in:
@@ -71,9 +71,14 @@ impl BytecodeDecoder {
|
||||
let from_pos = self.pos;
|
||||
let pos = self.decode_pos();
|
||||
|
||||
if pos < from_pos {
|
||||
if self.clone_at(pos).decode_type() != BytecodeType::Function {
|
||||
std::panic!("Invalid: non-function pointer that points backwards");
|
||||
}
|
||||
}
|
||||
|
||||
return vs_value::VsPointer::new(
|
||||
&self.data,
|
||||
from_pos,
|
||||
pos,
|
||||
);
|
||||
},
|
||||
@@ -123,4 +128,8 @@ impl BytecodeDecoder {
|
||||
// size of the bytecode
|
||||
return self.decode_byte() as usize;
|
||||
}
|
||||
|
||||
pub fn clone_at(&self, pos: usize) -> BytecodeDecoder {
|
||||
return BytecodeDecoder { data: self.data.clone(), pos: pos };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,21 +69,7 @@ pub struct VsPointer {
|
||||
}
|
||||
|
||||
impl VsPointer {
|
||||
pub fn new(bytecode: &Rc<Vec<u8>>, from_pos: usize, pos: usize) -> Val {
|
||||
if pos < from_pos {
|
||||
let mut bd = BytecodeDecoder {
|
||||
data: bytecode.clone(),
|
||||
pos: pos,
|
||||
};
|
||||
|
||||
let byte = bd.decode_byte();
|
||||
|
||||
if byte != BytecodeType::Function as u8 {
|
||||
// Prevent circular objects
|
||||
std::panic!("Invalid: non-function pointer that points backwards");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(bytecode: &Rc<Vec<u8>>, pos: usize) -> Val {
|
||||
return Rc::new(VsPointer {
|
||||
bytecode: bytecode.clone(),
|
||||
pos: pos,
|
||||
|
||||
Reference in New Issue
Block a user