translate to english!

This commit is contained in:
Nilton Constantino
2026-01-19 07:28:14 +00:00
parent 38ec13b248
commit 0f3105d622
49 changed files with 2488 additions and 2488 deletions
@@ -2,25 +2,25 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u16)]
pub enum OpCode {
// 6.1 Controle de Execução
// 6.1 Execution Control
Nop = 0x00,
Halt = 0x01,
Jmp = 0x02,
JmpIfFalse = 0x03,
// 6.2 Pilha
// 6.2 Stack
PushConst = 0x10,
Pop = 0x11,
Dup = 0x12,
Swap = 0x13,
// 6.3 Aritmética
// 6.3 Arithmetic
Add = 0x20,
Sub = 0x21,
Mul = 0x22,
Div = 0x23,
// 6.4 Comparação e Lógica
// 6.4 Comparison and Logic
Eq = 0x30,
Neq = 0x31,
Lt = 0x32,
@@ -29,13 +29,13 @@ pub enum OpCode {
Or = 0x35,
Not = 0x36,
// 6.5 Variáveis
// 6.5 Variables
GetGlobal = 0x40,
SetGlobal = 0x41,
GetLocal = 0x42,
SetLocal = 0x43,
// 6.6 Funções
// 6.6 Functions
Call = 0x50,
Ret = 0x51,
PushScope = 0x52,
@@ -46,7 +46,7 @@ pub enum OpCode {
LoadRef = 0x61,
StoreRef = 0x62,
// 6.8 Periféricos e Sistema
// 6.8 Peripherals and System
Syscall = 0x70,
FrameSync = 0x80,
}
@@ -126,7 +126,7 @@ impl OpCode {
OpCode::Alloc => 10,
OpCode::LoadRef => 3,
OpCode::StoreRef => 3,
OpCode::Syscall => 1, // Variável, mas vamos usar 1 como base ou definir via ID
OpCode::Syscall => 1, // Variable, but we'll use 1 as base or define via ID
OpCode::FrameSync => 1,
}
}
@@ -7,7 +7,7 @@ pub enum Value {
Float(f64),
Boolean(bool),
String(String),
Ref(usize), // Referência ao heap
Ref(usize), // Heap reference
Null,
}
@@ -27,7 +27,7 @@ pub struct VirtualMachine {
pub call_stack: Vec<CallFrame>,
pub globals: Vec<Value>,
pub program: Program,
pub heap: Vec<Value>, // Simplificado para demo, futuramente RAM/Heap real
pub heap: Vec<Value>, // Simplified for demo, future real RAM/Heap
pub cycles: u64,
pub halted: bool,
pub breakpoints: std::collections::HashSet<usize>,
@@ -56,12 +56,12 @@ impl VirtualMachine {
self.program = Program::new(program_bytes, vec![]);
}
} else {
// Por enquanto, tratamos os bytes como a ROM diretamente.
// For now, we treat the bytes as the ROM directly.
self.program = Program::new(program_bytes, vec![]);
}
// Se o entrypoint for numérico, podemos tentar usá-lo como PC inicial.
// Se não, por enquanto ignoramos ou começamos do 0.
// If the entrypoint is numeric, we can try to use it as the initial PC.
// If not, for now we ignore it or start from 0.
if let Ok(addr) = entrypoint.parse::<usize>() {
self.pc = addr;
} else {
@@ -173,7 +173,7 @@ impl VirtualMachine {
let pc_before = self.pc;
let cycles_before = self.cycles;
// Fast-path: FRAME_SYNC encerra o frame lógico
// Fast-path: FRAME_SYNC ends the logical frame
let opcode_val = self.peek_u16()?;
let opcode = OpCode::try_from(opcode_val)?;
if opcode == OpCode::FrameSync {
@@ -187,7 +187,7 @@ impl VirtualMachine {
self.step(native, hw)?;
steps_executed += 1;
// garante progresso real
// ensures real progress
if self.pc == pc_before && self.cycles == cycles_before && !self.halted {
return Err(format!("VM stuck at PC 0x{:08X}", self.pc));
}