refactor: 进一步拆分函数执行逻辑以简化主流程
This commit is contained in:
@@ -1 +1,21 @@
|
||||
// dispatch helper functions extracted from vm.rs
|
||||
use crate::coercion;
|
||||
use crate::vm::Vm;
|
||||
use oxide_types::value::JsValue;
|
||||
|
||||
impl Vm {
|
||||
#[inline(always)]
|
||||
pub(crate) fn dispatch_add(&mut self, rd: usize, a: usize, b: usize) {
|
||||
let lhs = self.regs[a];
|
||||
let rhs = self.regs[b];
|
||||
if lhs.is_string() || rhs.is_string() {
|
||||
let ls = coercion::to_string(self.kernel.string_forge().as_ref(), lhs);
|
||||
let rs = coercion::to_string(self.kernel.string_forge().as_ref(), rhs);
|
||||
let concat = format!("{ls}{rs}");
|
||||
self.regs[rd] = self.intern(&concat);
|
||||
} else {
|
||||
let ln = coercion::to_number(lhs, self.kernel.string_forge().as_ref());
|
||||
let rn = coercion::to_number(rhs, self.kernel.string_forge().as_ref());
|
||||
self.regs[rd] = JsValue::float(ln + rn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user