upgrade the variable system

This commit is contained in:
afonya2 2025-06-03 17:08:32 +02:00
parent 431b04cf2a
commit a8e174af7f
Signed by: afonya
GPG key ID: EBB9C4CAFAAFB2DC
3 changed files with 131 additions and 83 deletions

View file

@ -45,7 +45,7 @@ struct DecompiledFile {
struct DecompiledFunction {
name: String,
body: Vec<DecompiledOperation>,
var_ids: HashMap<String, u32>,
variables: Vec<Variable>,
strings: HashMap<u32, String>,
functions: HashMap<u32, u32>
}
@ -63,9 +63,17 @@ pub struct Register {
pointer: usize
}
#[derive(Debug, Clone)]
struct Variable {
name: String,
id: u32,
start: usize,
end: usize
}
pub struct Machine {
pub memory: Vec<VMMemory>,
pub files: Vec<DecompiledFile>,
files: Vec<DecompiledFile>,
pub stack: Vec<VMMemory>,
pub registers: Vec<Register>,
pub pc: usize,
@ -362,7 +370,7 @@ impl Machine {
offset += func_name_len;
let var_id_len = read_be_num(&data[offset..offset + 4]);
offset += 4;
let mut var_ids: HashMap<String, u32> = HashMap::new();
let mut variables: Vec<Variable> = vec![];
for _ in 0..var_id_len {
let name_len = read_be_num(&data[offset..offset + 4]);
offset += 4;
@ -370,7 +378,11 @@ impl Machine {
offset += name_len;
let var_id = read_be_num(&data[offset..offset + 3]) as u32;
offset += 3;
var_ids.insert(name, var_id);
let start = read_be_num(&data[offset..offset + 4]);
offset += 4;
let end = read_be_num(&data[offset..offset + 4]);
offset += 4;
variables.push(Variable { name: name, id: var_id, start: start, end: end });
}
let mut strings: HashMap<u32, String> = HashMap::new();
let string_count = read_be_num(&data[offset..offset + 4]);
@ -413,7 +425,7 @@ impl Machine {
});
}
let mut file_functions: Vec<DecompiledFunction> = Vec::new();
file_functions.push(DecompiledFunction { name: func_name, body: body, var_ids: var_ids, strings: strings, functions: functions });
file_functions.push(DecompiledFunction { name: func_name, body: body, variables: variables, strings: strings, functions: functions });
self.files.push(DecompiledFile {
name: filename,
functions: file_functions