From 47ffa8071152bcafb4b6ff87a3142bf12dbce12b Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 28 Feb 2021 15:15:46 +0200 Subject: feat(tazjin/rlox): Support trivial literals in bytecode compiler Adds support for true, false & nil. These each come with a new separate opcode and are pushed directly on the stack. Change-Id: I405b5b09496dcf99d514d3411c083e0834377167 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2571 Reviewed-by: tazjin Tested-by: BuildkiteCI --- users/tazjin/rlox/src/bytecode/vm.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'users/tazjin/rlox/src/bytecode/vm.rs') diff --git a/users/tazjin/rlox/src/bytecode/vm.rs b/users/tazjin/rlox/src/bytecode/vm.rs index ee3abbd6cc18..74c3e338fce4 100644 --- a/users/tazjin/rlox/src/bytecode/vm.rs +++ b/users/tazjin/rlox/src/bytecode/vm.rs @@ -72,6 +72,10 @@ impl VM { self.push(c); } + OpCode::OpNil => self.push(Value::Nil), + OpCode::OpTrue => self.push(Value::Bool(true)), + OpCode::OpFalse => self.push(Value::Bool(false)), + OpCode::OpNegate => { let v = self.pop(); with_type!( -- cgit 1.4.1