ft: initial work in interpreter

This commit is contained in:
2025-06-03 21:31:28 +09:00
parent 5ee80c9364
commit ac69d75273
8 changed files with 344 additions and 51 deletions

View File

@@ -8,12 +8,12 @@ use crate::operands::{Byte, Word};
#[allow(non_camel_case_types)]
pub type c_long = i32; // we use a a.out with 32 byte
#[derive(Debug)]
#[derive(Debug, Clone)]
/// Internal representation of the a.out binary format.
pub struct Aout {
pub header: Header,
pub text: Vec<Byte>,
pub data: Vec<Word>,
pub data: Vec<Byte>,
}
impl fmt::Display for Aout {
@@ -48,20 +48,16 @@ impl Aout {
let text_section = &buf[text_start..text_end];
let data_section = &buf[data_start..data_end];
let data_words: Vec<Word> = data_section
.chunks_exact(2)
.map(|chunk| u16::from_le_bytes(chunk.try_into().unwrap()))
.collect();
Aout {
header: hdr,
text: Vec::from(text_section),
data: Vec::from(data_words),
data: Vec::from(data_section),
}
}
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Header {
pub magic: [c_uchar; 2], // magic number
pub flags: c_uchar, // flags, see below