diff options
author | Vincent Ambo <mail@tazj.in> | 2021-10-19T20·59+0200 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2021-10-20T12·50+0000 |
commit | 050a2b473c48b87994e56ade381afbfc2bca4de3 (patch) | |
tree | 97dd9dc0c36418cf967befd9ba672c93b095c561 /users/tazjin/rlox/src/bytecode/opcode.rs | |
parent | e92a951f6cd14b5e207e5a1b04ea93cf97ba92d0 (diff) |
refactor(tazjin/rlox): Introduce newtypes for various indices r/2980
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>
Diffstat (limited to 'users/tazjin/rlox/src/bytecode/opcode.rs')
-rw-r--r-- | users/tazjin/rlox/src/bytecode/opcode.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/users/tazjin/rlox/src/bytecode/opcode.rs b/users/tazjin/rlox/src/bytecode/opcode.rs index 143a79f41916..d2a264242496 100644 --- a/users/tazjin/rlox/src/bytecode/opcode.rs +++ b/users/tazjin/rlox/src/bytecode/opcode.rs @@ -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), } |