refactor(tazjin/rlox): Represent VM values as enums

Introduces a new enum which represents the different types of possible
values, and modifies the rest of the existing code to wrap/unwrap
these enum variants correctly.

Notably in the vm module, a new macro has been introduced that makes
it possible to encode a type expectation and return a runtime error in
case of a type mismatch.

Change-Id: I325b5e31e395c62d8819ab2af6d398e1277333c0
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2570
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2021-02-28 14:37:35 +02:00 committed by tazjin
parent 6b990a7571
commit 127ef98486
6 changed files with 59 additions and 25 deletions

View file

@ -128,7 +128,7 @@ impl<T: Iterator<Item = Token>> Compiler<T> {
fn number(&mut self) -> LoxResult<()> {
if let TokenKind::Number(num) = self.previous().kind {
self.emit_constant(num);
self.emit_constant(Value::Number(num));
return Ok(());
}