refactor(tazjin/rlox): Return index after adding operations

Change-Id: I100eb9b55ace37e5c7c878d3c224b567ee8d1e36
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3738
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
Vincent Ambo 2021-10-20 15:57:49 +02:00 committed by tazjin
parent 4ea7fc392a
commit d57e43e161
3 changed files with 18 additions and 15 deletions

View file

@ -1,6 +1,6 @@
use std::ops::Index;
use super::opcode::{ConstantIdx, OpCode};
use super::opcode::{CodeIdx, ConstantIdx, OpCode};
use super::value;
// In the book, this type is a hand-rolled dynamic array
@ -25,11 +25,11 @@ struct Span {
}
impl Chunk {
pub fn add_op(&mut self, data: OpCode, line: usize) -> usize {
pub fn add_op(&mut self, data: OpCode, line: usize) -> CodeIdx {
let idx = self.code.len();
self.code.push(data);
self.add_line(line);
idx
CodeIdx(idx)
}
pub fn add_constant(&mut self, data: value::Value) -> usize {