0a09356f82
grfn pointed out in cl/6069 that naming them like this makes it clear that things are being added to the end of the state. Change-Id: I6a23215c4fef713869a3c85b0dde1ebbda7637e9 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6179 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
26 lines
611 B
Rust
26 lines
611 B
Rust
use crate::opcode::{CodeIdx, ConstantIdx, OpCode};
|
|
use crate::value::Value;
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct Chunk {
|
|
pub code: Vec<OpCode>,
|
|
constants: Vec<Value>,
|
|
}
|
|
|
|
impl Chunk {
|
|
pub fn push_op(&mut self, data: OpCode) -> CodeIdx {
|
|
let idx = self.code.len();
|
|
self.code.push(data);
|
|
CodeIdx(idx)
|
|
}
|
|
|
|
pub fn push_constant(&mut self, data: Value) -> ConstantIdx {
|
|
let idx = self.constants.len();
|
|
self.constants.push(data);
|
|
ConstantIdx(idx)
|
|
}
|
|
|
|
pub fn constant(&self, idx: ConstantIdx) -> &Value {
|
|
&self.constants[idx.0]
|
|
}
|
|
}
|