add machine stub and data structures, still got lifetime errors

This commit is contained in:
2021-09-20 00:38:44 +02:00
parent ab174af8af
commit adf039057d
4 changed files with 63 additions and 1 deletions

View File

@@ -1,8 +1,12 @@
[package] [package]
name = "rbfckr" name = "rbfckr"
version = "0.1.0" version = "0.1.0"
authors = ["id101010 <id101010@0x29a.ch>"]
edition = "2018" 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] [dependencies]

1
src/lib.rs Normal file
View File

@@ -0,0 +1 @@
pub mod machine;

55
src/machine.rs Normal file
View 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;
}
}

View File

@@ -2,6 +2,8 @@ use std::env;
use std::fs; use std::fs;
use std::io::{stdin, stdout, BufReader, Read}; use std::io::{stdin, stdout, BufReader, Read};
use rbfckr::machine::Machine;
fn main() { fn main() {
let file_name = match env::args().nth(1){ let file_name = match env::args().nth(1){
None => { None => {