17 lines
594 B
Rust
17 lines
594 B
Rust
use crate::compiler::{CompileCtx, Compiler};
|
|
use crate::ir::inst::Inst;
|
|
use crate::ir::operand::Operand;
|
|
use oxide_bytecode::opcode::OpCode;
|
|
use oxide_parser::Statement;
|
|
|
|
impl Compiler {
|
|
pub(crate) fn emit_throw_statement(&self, stmt: &Statement, ctx: &mut CompileCtx) -> Result<Option<u8>, String> {
|
|
let Statement::ThrowStatement(ts) = stmt else {
|
|
return Ok(None);
|
|
};
|
|
let exc_reg = self.emit_expression(&ts.argument, ctx)?;
|
|
ctx.inst(Inst::new(OpCode::THROW, Operand::Reg(exc_reg as u32), Operand::None, Operand::None));
|
|
Ok(None)
|
|
}
|
|
}
|