add machine stub and data structures, still got lifetime errors
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
[package]
|
||||
name = "rbfckr"
|
||||
version = "0.1.0"
|
||||
authors = ["id101010 <id101010@0x29a.ch>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[[bin]]
|
||||
doc = false
|
||||
name = "rbfckr"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
|
||||
1
src/lib.rs
Normal file
1
src/lib.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod machine;
|
||||
55
src/machine.rs
Normal file
55
src/machine.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
use std::io::{BufReader, BufWriter, Read, Write};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum InstructionType {
|
||||
Plus,
|
||||
Minus,
|
||||
Left,
|
||||
Right,
|
||||
PutChar,
|
||||
GetChar,
|
||||
JumpIfZero,
|
||||
JumpIfNotZero,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Instruction {
|
||||
pub ins_type: InstructionType,
|
||||
pub argument: usize,
|
||||
}
|
||||
|
||||
pub struct Machine {
|
||||
ip: usize,
|
||||
mp: usize,
|
||||
code: Vec<Instruction>,
|
||||
memory: [u32; 50000],
|
||||
input: &mut BufReader<Box<dyn Read>>,
|
||||
output: &mut BufWriter<Box<dyn Write>>,
|
||||
buf: [u8; 1],
|
||||
}
|
||||
|
||||
impl Machine {
|
||||
pub fn new(code: Vec<Instruction>, input: &mut BufReader<Box<dyn Read>>, output: &mut BufWriter<Box<dyn Write>>) -> Self {
|
||||
Machine {
|
||||
ip: 0,
|
||||
mp: 0,
|
||||
code,
|
||||
memory: [0, 50000],
|
||||
input,
|
||||
output,
|
||||
buf: [0;1],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn execute(&mut self){
|
||||
return;
|
||||
}
|
||||
|
||||
pub fn read_char(&mut self){
|
||||
return;
|
||||
}
|
||||
|
||||
pub fn put_char(&mut self){
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ use std::env;
|
||||
use std::fs;
|
||||
use std::io::{stdin, stdout, BufReader, Read};
|
||||
|
||||
use rbfckr::machine::Machine;
|
||||
|
||||
fn main() {
|
||||
let file_name = match env::args().nth(1){
|
||||
None => {
|
||||
|
||||
Reference in New Issue
Block a user