Remove instruction prints

master
Raymon Zutekouw 3 years ago
parent aff0ed0034
commit 303da9ff9e
No known key found for this signature in database
GPG Key ID: 1E9BCC39EDD1DD53
  1. 23
      src/main.rs

@ -69,7 +69,6 @@ fn to_bf(rule: Rule, operand: &str, state: &mut State, out: &mut Builder) {
match rule { match rule {
Rule::var => { Rule::var => {
let variable_name = operand; let variable_name = operand;
println!("Creation of variable '{}'", variable_name);
if let Some(_v) = state.variables.insert( if let Some(_v) = state.variables.insert(
String::from(variable_name), String::from(variable_name),
MemCell::allocate(state.alloc_cnt), MemCell::allocate(state.alloc_cnt),
@ -80,14 +79,12 @@ fn to_bf(rule: Rule, operand: &str, state: &mut State, out: &mut Builder) {
} }
Rule::delvar => { Rule::delvar => {
let variable_name = operand; let variable_name = operand;
println!("Deletion of variable '{}'", variable_name);
if let None = state.variables.remove(&String::from(variable_name)) { if let None = state.variables.remove(&String::from(variable_name)) {
panic!("Variable '{}' did not exists", variable_name); panic!("Variable '{}' did not exists", variable_name);
} }
} }
Rule::point => { Rule::point => {
let variable_name = operand; let variable_name = operand;
println!("Pointing to variable '{}'", variable_name);
let address = state let address = state
.variables .variables
.get(variable_name) .get(variable_name)
@ -99,7 +96,6 @@ fn to_bf(rule: Rule, operand: &str, state: &mut State, out: &mut Builder) {
Rule::pointa => { Rule::pointa => {
let address = operand; let address = operand;
let address_parsed = parse_constant(address).unwrap(); let address_parsed = parse_constant(address).unwrap();
println!("Pointing to address '{}'", address);
if address_parsed < state.mem_pointer { if address_parsed < state.mem_pointer {
out.append("<".repeat((state.mem_pointer - address_parsed) as usize)) out.append("<".repeat((state.mem_pointer - address_parsed) as usize))
} else if address_parsed > state.mem_pointer { } else if address_parsed > state.mem_pointer {
@ -109,7 +105,6 @@ fn to_bf(rule: Rule, operand: &str, state: &mut State, out: &mut Builder) {
} }
Rule::pointm => { Rule::pointm => {
let variable_name = operand; let variable_name = operand;
println!("Pointing back to marker variable {}", variable_name);
let address = state let address = state
.variables .variables
.get(variable_name) .get(variable_name)
@ -122,15 +117,10 @@ fn to_bf(rule: Rule, operand: &str, state: &mut State, out: &mut Builder) {
Rule::add => { Rule::add => {
let constant = operand; let constant = operand;
let constant_parsed = parse_constant(constant).unwrap(); let constant_parsed = parse_constant(constant).unwrap();
println!(
"Addition of '{}', decimal value is {}",
constant, constant_parsed
);
out.append("+".repeat(constant_parsed as usize)); out.append("+".repeat(constant_parsed as usize));
} }
Rule::addv => { Rule::addv => {
let variable_name = operand; let variable_name = operand;
println!("Addition to variable '{}'", variable_name);
let source_address = state.mem_pointer.to_string(); let source_address = state.mem_pointer.to_string();
out.append("["); out.append("[");
to_bf(Rule::sub, "1", state, out); to_bf(Rule::sub, "1", state, out);
@ -142,15 +132,10 @@ fn to_bf(rule: Rule, operand: &str, state: &mut State, out: &mut Builder) {
Rule::sub => { Rule::sub => {
let constant = operand; let constant = operand;
let constant_parsed = parse_constant(constant).unwrap(); let constant_parsed = parse_constant(constant).unwrap();
println!(
"Subtraction of '{}', decimal value is {}",
constant, constant_parsed
);
out.append("-".repeat(constant_parsed as usize)); out.append("-".repeat(constant_parsed as usize));
} }
Rule::subv => { Rule::subv => {
let variable_name = operand; let variable_name = operand;
println!("Subtraction from variable '{}'", variable_name);
let source_address = state.mem_pointer.to_string(); let source_address = state.mem_pointer.to_string();
out.append("["); out.append("[");
to_bf(Rule::sub, "1", state, out); to_bf(Rule::sub, "1", state, out);
@ -161,7 +146,6 @@ fn to_bf(rule: Rule, operand: &str, state: &mut State, out: &mut Builder) {
} }
Rule::copy => { Rule::copy => {
let variable_name = operand; let variable_name = operand;
println!("Copy to variable '{}'", variable_name);
let source_address = state.mem_pointer.to_string(); let source_address = state.mem_pointer.to_string();
to_bf(Rule::var, "__temp", state, out); to_bf(Rule::var, "__temp", state, out);
out.append("["); out.append("[");
@ -182,27 +166,21 @@ fn to_bf(rule: Rule, operand: &str, state: &mut State, out: &mut Builder) {
to_bf(Rule::delvar, "__temp", state, out); to_bf(Rule::delvar, "__temp", state, out);
} }
Rule::setz => { Rule::setz => {
println!("Set current variable to zero");
out.append("[-]"); out.append("[-]");
} }
Rule::getchr => { Rule::getchr => {
println!("Reading char from user input into current variable");
out.append(","); out.append(",");
} }
Rule::print => { Rule::print => {
println!("Printing current variable");
out.append("."); out.append(".");
} }
Rule::loopBlockStart => { Rule::loopBlockStart => {
println!("Start of loopBlock");
out.append("["); out.append("[");
} }
Rule::loopBlockEnd => { Rule::loopBlockEnd => {
println!("End of loopBlock");
out.append("]"); out.append("]");
} }
Rule::EOI => { Rule::EOI => {
println!("End of Input");
out.append("\n"); out.append("\n");
} }
_ => unreachable!(), _ => unreachable!(),
@ -214,7 +192,6 @@ fn instruct(statement: Pair<Rule>, state: &mut State, out: &mut Builder) {
Rule::include => { Rule::include => {
let file_path_raw = extract_operand(statement); let file_path_raw = extract_operand(statement);
let file_path = &file_path_raw[1..file_path_raw.len() - 1]; let file_path = &file_path_raw[1..file_path_raw.len() - 1];
println!("Including {} into this src file", file_path);
let content = std::fs::read_to_string(&file_path) let content = std::fs::read_to_string(&file_path)
.with_context(|| format!("could not read source file {:?}", file_path)) .with_context(|| format!("could not read source file {:?}", file_path))
.unwrap(); .unwrap();

Loading…
Cancel
Save