Skip to content

Commit

Permalink
feat: add a hello world program to main
Browse files Browse the repository at this point in the history
  • Loading branch information
heypoom committed Oct 5, 2023
1 parent 0f78fbd commit 53d95ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
fn main() {}
use opcodes_to_algorithms::{Execute, Instruction as I, Load, Machine, WithStringManager};

fn main() {
let mut m = Machine::new();
m.handlers.print.push(Box::new(|s| print!("{}", s)));

let welcome_ptr = m.mem.string().add_str("hello, world!");
m.mem.load_code(vec![I::Push(welcome_ptr), I::Print]);
m.run();
}
12 changes: 0 additions & 12 deletions tests/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,4 @@ mod tests {
m.run();
assert_eq!(m.mem.read_stack(5), [104, 101, 108, 108, 111]);
}

/// TODO: manipulate the stack to reverse the string.
#[test]
fn reverse_string() {
let mut m = M::new();

let mut ms = m.mem.string();
let s_addr = ms.add_str("poom");
m.mem.load_code(vec![I::LoadString(s_addr)]);
m.tick();
assert_eq!(m.mem.read_stack(4), [112, 111, 111, 109]);
}
}

0 comments on commit 53d95ca

Please sign in to comment.