refactor(tazjin/rlox): Introduce newtypes for various indices

Since this code is essentially a fairly plain translation from C, it
is a bit confusing to deal with the original untyped code. This is an
attempt to try and clean some of it up.

Change-Id: Icd21f531932e1a811c0d6dbf2e9acba61ca9c45d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3734
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
Vincent Ambo 2021-10-19 22:59:48 +02:00 committed by tazjin
parent e92a951f6c
commit 050a2b473c
4 changed files with 31 additions and 25 deletions

View file

@ -1,7 +1,13 @@
#[derive(Clone, Copy, Debug)]
pub struct ConstantIdx(pub usize);
#[derive(Clone, Copy, Debug)]
pub struct StackIdx(pub usize);
#[derive(Debug)]
pub enum OpCode {
/// Push a constant onto the stack.
OpConstant(usize),
OpConstant(ConstantIdx),
// Literal pushes
OpNil,
@ -31,9 +37,9 @@ pub enum OpCode {
OpPop,
// Variable management
OpDefineGlobal(usize),
OpGetGlobal(usize),
OpSetGlobal(usize),
OpGetLocal(usize),
OpSetLocal(usize),
OpDefineGlobal(ConstantIdx),
OpGetGlobal(ConstantIdx),
OpSetGlobal(ConstantIdx),
OpGetLocal(StackIdx),
OpSetLocal(StackIdx),
}