1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::ast;
use crate::compiler::{Compiler, Needs};
use crate::error::CompileResult;
use crate::traits::Compile;
use runestick::Inst;

/// Compile a literal boolean such as `true`.
impl Compile<(&ast::LitBool, Needs)> for Compiler<'_, '_> {
    fn compile(&mut self, (lit_bool, needs): (&ast::LitBool, Needs)) -> CompileResult<()> {
        let span = lit_bool.span();
        log::trace!("LitBool => {:?}", self.source.source(span)?);

        // If the value is not needed, no need to encode it.
        if !needs.value() {
            return Ok(());
        }

        self.asm.push(
            Inst::Bool {
                value: lit_bool.value,
            },
            span,
        );

        Ok(())
    }
}