1
0
This commit is contained in:
Jeff 2024-11-28 02:12:59 -05:00
parent dae5b7678c
commit b574ecc4cb
2 changed files with 9 additions and 8 deletions

View File

@ -194,13 +194,13 @@ impl<'src> Compiler<'src> {
let identifier = ConcreteValue::string(identifier); let identifier = ConcreteValue::string(identifier);
let identifier_index = self.chunk.push_or_get_constant(identifier); let identifier_index = self.chunk.push_or_get_constant(identifier);
let local_index = self.chunk.locals().len(); let local_index = self.chunk.locals().len() as u16;
self.chunk self.chunk
.locals_mut() .locals_mut()
.push(Local::new(identifier_index, r#type, is_mutable, scope)); .push(Local::new(identifier_index, r#type, is_mutable, scope));
(local_index as u16, identifier_index) (local_index, identifier_index)
} }
fn allow(&mut self, allowed: Token) -> Result<bool, CompileError> { fn allow(&mut self, allowed: Token) -> Result<bool, CompileError> {

View File

@ -50,8 +50,8 @@ use crate::{value::ConcreteValue, Chunk, Local};
const INSTRUCTION_HEADER: [&str; 4] = [ const INSTRUCTION_HEADER: [&str; 4] = [
"Instructions", "Instructions",
"------------", "------------",
" i POSITION OPERATION TYPE INFO ", " i POSITION OPERATION TYPE INFO ",
"--- ---------- ------------- ---------------- ----------------------------------", "--- ---------- ------------- -------------------------------- --------------------------------",
]; ];
const CONSTANT_HEADER: [&str; 4] = [ const CONSTANT_HEADER: [&str; 4] = [
@ -64,8 +64,8 @@ const CONSTANT_HEADER: [&str; 4] = [
const LOCAL_HEADER: [&str; 4] = [ const LOCAL_HEADER: [&str; 4] = [
"Locals", "Locals",
"------", "------",
" i SCOPE MUTABLE TYPE IDENTIFIER ", " i SCOPE MUTABLE TYPE IDENTIFIER ",
"--- ------- ------- ---------------- ----------------", "--- ------- ------- -------------------------------- ----------------",
]; ];
/// Builder that constructs a human-readable representation of a chunk. /// Builder that constructs a human-readable representation of a chunk.
@ -262,7 +262,7 @@ impl<'a> Disassembler<'a> {
let r#type = r#type.to_string(); let r#type = r#type.to_string();
let info = instruction.disassembly_info(); let info = instruction.disassembly_info();
let instruction_display = let instruction_display =
format!("{index:^3} {position:^10} {operation:13} {type:^16} {info:^34}"); format!("{index:^3} {position:^10} {operation:13} {type:^32} {info:^32}");
self.push_details(&instruction_display); self.push_details(&instruction_display);
} }
@ -290,8 +290,9 @@ impl<'a> Disassembler<'a> {
.map(|value| value.to_string()) .map(|value| value.to_string())
.unwrap_or_else(|| "unknown".to_string()); .unwrap_or_else(|| "unknown".to_string());
let type_display = r#type.to_string(); let type_display = r#type.to_string();
let scope = scope.to_string();
let local_display = format!( let local_display = format!(
"{index:^3} {scope:7} {is_mutable:^7} {type_display:^16} {identifier_display:^16}" "{index:^3} {scope:^7} {is_mutable:^7} {type_display:^32} {identifier_display:^16}"
); );
self.push_details(&local_display); self.push_details(&local_display);