[rlox] Use fewer files

This commit is contained in:
ctsk
2023-03-29 20:07:31 +02:00
parent ff67071f5b
commit d6e6b1d3ab
3 changed files with 9 additions and 14 deletions

36
rlox/src/vm.rs Normal file
View File

@@ -0,0 +1,36 @@
use std::fmt;
#[repr(u8)]
#[derive(Debug)]
pub enum Op {
Return
}
pub struct Chunk {
code: Vec<Op>,
name: String
}
impl Chunk {
pub fn new(name: String) -> Chunk {
Chunk {
code: Vec::new(),
name
}
}
pub fn add(&mut self, op: Op) {
self.code.push(op)
}
}
impl fmt::Debug for Chunk {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
writeln!(f, "-*-*- {} -*-*-", self.name)?;
for (idx, op) in self.code.iter().enumerate() {
write!(f, "{:04} {:?}", idx, op)?;
}
return Ok(());
}
}