docs(objects): clarify numeric conversion and wordcode boundaries
This commit is contained in:
@@ -152,7 +152,7 @@ impl Instruction {
|
||||
pub const fn new(opcode: Opcode, argument: u32) -> Self {
|
||||
Self { opcode, argument }
|
||||
}
|
||||
/// 编译器发出无参数指令的便捷入口,把 argument 明确置零。
|
||||
/// 编译器发出无参数指令的便捷入口,把 argument 明确置零;此处不检查 opcode 是否真的无参数。
|
||||
pub const fn simple(opcode: Opcode) -> Self {
|
||||
Self::new(opcode, 0)
|
||||
}
|
||||
@@ -195,6 +195,7 @@ impl Instruction {
|
||||
|
||||
/// EndorCode::from_instructions 调用:小操作数直接编码,大操作数最多用三个前缀。
|
||||
/// 每单元两字节,前缀携带高位;不在这里重算跳转距离或校验常量/槽索引。
|
||||
/// 空输入可编码为空字节串,EndorCode 的后续解码才拒绝空代码,编码成功不等于可执行。
|
||||
pub fn encode_all(instructions: &[Self]) -> Result<Vec<u8>, VmError> {
|
||||
// 逐条追加;报错时局部缓冲丢弃,不向调用者返回部分编码。
|
||||
let mut bytes = Vec::new();
|
||||
@@ -222,6 +223,7 @@ impl Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
/// 解码器产出、代码校验器和 eval 消费的逻辑位置;公开字段本身不保证由验证过的代码产生。
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct DecodedInstruction {
|
||||
/// 逻辑指令起点(包括首个前缀),单位是双字节代码单元。
|
||||
|
||||
Reference in New Issue
Block a user