cas_compiler/expr/
index.rs

1use cas_error::Error;
2use cas_parser::parser::ast::index::Index;
3use crate::{Compile, Compiler, InstructionKind};
4
5impl Compile for Index {
6    fn compile(&self, compiler: &mut Compiler) -> Result<(), Error> {
7        // load the (hopefully) list value onto the stack
8        self.target.compile(compiler)?;
9
10        // load the index value onto the stack
11        self.index.compile(compiler)?;
12
13        // load the value at the index onto the stack
14        compiler.add_instr_with_spans(
15            InstructionKind::LoadIndexed,
16            vec![self.target.span(), self.index.span()],
17        );
18        Ok(())
19    }
20}