refactor: extract core objects into a standalone package
Verify databases and deploy Aster VM / verify-and-deploy (push) Successful in 7m34s

This commit is contained in:
2026-10-19 13:33:24 +08:00
parent 78fc859825
commit f77b8370ea
40 changed files with 631 additions and 202 deletions
+12 -8
View File
@@ -1,11 +1,14 @@
use crate::code::jump_target;
use crate::frame::StackEntry;
use crate::instruction::{compare_operation, function_counts, invalid};
use crate::{
CompareOp, EndorCellObject, EndorCodeObject, EndorFrame, EndorFunctionObject,
EndorStringObject, ExecutionLimits, ExecutionLocation, ObjectRef, Opcode, Value, Vm, VmError,
EndorStringObject, ExecutionLimits, ExecutionLocation, Instruction, ObjectRef, Opcode, Value,
Vm, VmError,
};
fn invalid(offset: usize, reason: &'static str) -> VmError {
VmError::InvalidBytecode { offset, reason }
}
impl Vm {
/// Execute a code object in a globals dictionary. Like CPython's EvalCode
/// entry path, this constructs a temporary function and enters its frame.
@@ -315,7 +318,7 @@ impl Vm {
}
fn make_function(&mut self, frame: &EndorFrame, argument: u32) -> Result<ObjectRef, VmError> {
let (default_count, closure_count) = function_counts(argument);
let (default_count, closure_count) = Instruction::function_counts(argument);
let Value::Object(code) = Self::top_value(frame)? else {
return Err(VmError::ObjectKindMismatch("code"));
};
@@ -494,13 +497,13 @@ impl Vm {
}
}
Opcode::JumpForward | Opcode::JumpBackward => {
frame.instruction_offset = jump_target(decoded)?
frame.instruction_offset = decoded.jump_target()?
}
Opcode::PopJumpIfFalse | Opcode::PopJumpIfTrue => {
let truth = self.value_is_true(&Self::top_value(frame)?)?;
self.discard(frame, 1);
if truth == (opcode == Opcode::PopJumpIfTrue) {
frame.instruction_offset = jump_target(decoded)?;
frame.instruction_offset = decoded.jump_target()?;
}
}
Opcode::ToBool | Opcode::UnaryNot => {
@@ -520,7 +523,7 @@ impl Vm {
let result = self.compare_values(
&left,
&right,
compare_operation(decoded.instruction.argument).unwrap(),
Instruction::compare_operation(decoded.instruction.argument).unwrap(),
)?;
self.discard(frame, 2);
frame.stack.push(StackEntry::Value(Value::Bool(result)));
@@ -555,7 +558,8 @@ impl Vm {
}
Opcode::MakeFunction => {
let function = self.make_function(frame, decoded.instruction.argument)?;
let (defaults, closure) = function_counts(decoded.instruction.argument);
let (defaults, closure) =
Instruction::function_counts(decoded.instruction.argument);
self.discard(frame, defaults + closure + 1);
frame.stack.push(StackEntry::Value(Value::Object(function)));
}