Begin implementing human interface for Hyphae
Some checks failed
per-push tests / build (push) Failing after 39s
per-push tests / test-frontend (push) Has been skipped
per-push tests / timed-decomposer-parse (push) Has been skipped
per-push tests / test-utility (push) Has been skipped
per-push tests / test-backend (push) Has been skipped
Some checks failed
per-push tests / build (push) Failing after 39s
per-push tests / test-frontend (push) Has been skipped
per-push tests / timed-decomposer-parse (push) Has been skipped
per-push tests / test-utility (push) Has been skipped
per-push tests / test-backend (push) Has been skipped
This commit implements Display and FromStr for Datum, Operation, Operand, Instruction, and Program types. Additionally, tests are added for the new routines. This change was implemented in furtherance of a command line assembler and disassembler, as well as for the implementation of a debugger.
This commit is contained in:
parent
389bf6e9a0
commit
5582da5b41
7 changed files with 286 additions and 652 deletions
|
|
@ -105,13 +105,21 @@ fn main() {
|
|||
let mut isa_fromstr = "impl FromStr for Operation {\n".to_owned();
|
||||
isa_fromstr += " type Err = &'static str;\n";
|
||||
isa_fromstr += " fn from_str(v: &str) -> Result<Self, Self::Err> {\n";
|
||||
isa_fromstr += " let a = v.to_ascii_uppercase();\n";
|
||||
isa_fromstr += " let v = a.as_str();\n";
|
||||
isa_fromstr += " match v {\n";
|
||||
|
||||
let mut isa_from_str = "impl TryFrom<&str> for Operation {\n".to_owned();
|
||||
isa_from_str += " type Error = &'static str;\n";
|
||||
isa_from_str += " fn try_from(v: &str) -> Result<Self, Self::Error> {\n";
|
||||
isa_from_str += " let a = v.to_ascii_uppercase();\n";
|
||||
isa_from_str += " let v = a.as_str();\n";
|
||||
isa_from_str += " match v {\n";
|
||||
|
||||
let mut isa_into_str = "impl Display for Operation {\n".to_owned();
|
||||
isa_into_str += " fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), E> {\n";
|
||||
isa_into_str += " match self.0 {\n";
|
||||
|
||||
let mut isa_num_args = "impl Operation {\n".to_owned();
|
||||
isa_num_args += " pub fn num_args(&self) -> Result<u8, &'static str> {\n";
|
||||
isa_num_args += " match self.0 {\n";
|
||||
|
|
@ -133,6 +141,9 @@ fn main() {
|
|||
isa_fromstr += format!(" \"{}\" => Ok({}),\n",
|
||||
const_name, const_name).as_str();
|
||||
|
||||
isa_into_str += format!(" {} => write!(f, \"{}\"),\n",
|
||||
idx, const_name).as_str();
|
||||
|
||||
isa_num_args += format!(" {} => Ok({}),\n", idx, instr.args.len())
|
||||
.as_str();
|
||||
|
||||
|
|
@ -154,6 +165,11 @@ fn main() {
|
|||
isa_fromstr += " }\n";
|
||||
isa_fromstr += "}\n\n";
|
||||
|
||||
isa_into_str += " _ => panic!(\"illegal instruction\"),\n";
|
||||
isa_into_str += " }\n";
|
||||
isa_into_str += " }\n";
|
||||
isa_into_str += "}\n\n";
|
||||
|
||||
isa_num_args += " _ => Err(\"illegal instruction\"),\n";
|
||||
isa_num_args += " }\n";
|
||||
isa_num_args += " }\n";
|
||||
|
|
@ -163,9 +179,11 @@ fn main() {
|
|||
isa += isa_from_byte.as_str();
|
||||
isa += isa_from_str.as_str();
|
||||
isa += isa_fromstr.as_str();
|
||||
isa += isa_into_str.as_str();
|
||||
isa += isa_num_args.as_str();
|
||||
|
||||
write!(&mut output_file, "use core::str::FromStr;\n\n\n").unwrap();
|
||||
write!(&mut output_file, "use core::str::FromStr;\n").unwrap();
|
||||
write!(&mut output_file, "use alloc::fmt::{{Display, Formatter, Error as E}};\n\n\n").unwrap();
|
||||
write!(&mut output_file, "{}", isa).unwrap();
|
||||
write!(&mut output_file, "\n\npub const TOTAL_INSTRUCTIONS: usize = {};", peak)
|
||||
.unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue