cas-compiler 0.2.0

Bytecode compiler for CalcScript programs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use cas_compute::numerical::value::Value;
use cas_error::Error;
use cas_parser::parser::ast::loop_expr::Break;
use crate::{Compile, Compiler, InstructionKind};

impl Compile for Break {
    fn compile(&self, compiler: &mut Compiler) -> Result<(), Error> {
        if let Some(value) = &self.value {
            value.compile(compiler)?;
        } else {
            compiler.add_instr(InstructionKind::LoadConst(Value::Unit));
        }

        let loop_end = compiler.state.loop_end.unwrap();
        compiler.add_instr(InstructionKind::Jump(loop_end));
        Ok(())
    }
}