Files
OxideJS-New/crates/oxide_emit/src/expr/this.rs
T
2026-08-05 21:46:47 +08:00

17 lines
625 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! `this` 表达式 emit:`emit_this_expression` 解析当前函数的 this 寄存器。
use crate::{CompileCtx, Emitter};
use oxide_ir::inst::Inst;
use oxide_ir::operand::Operand;
use oxide_bytecode::opcode::OpCode;
impl Emitter {
pub(crate) fn emit_this_expression(&self, ctx: &mut CompileCtx) -> Result<u8, String> {
let r = ctx.alloc_reg();
let src = ctx.static_block_this_reg.unwrap_or(254);
let src_op = if src == 254 { Operand::This } else { Operand::Reg(src as u32) };
ctx.inst(Inst::new(OpCode::LOAD_VAR, Operand::Reg(r as u32), src_op, Operand::None));
Ok(r)
}
}