Now with Atomicity
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::sync::Mutex;
|
use std::sync::{Mutex, Arc};
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use Result;
|
use Result;
|
||||||
use block::Block;
|
use block::Block;
|
||||||
@@ -32,7 +31,7 @@ pub struct Machine {
|
|||||||
pub heap: Heap,
|
pub heap: Heap,
|
||||||
|
|
||||||
pub stream_in: Box<Read + Send + Sync>,
|
pub stream_in: Box<Read + Send + Sync>,
|
||||||
pub stream_out: Rc<Mutex<Write + Send + Sync>>,
|
pub stream_out: Arc<Mutex<Write + Send + Sync>>,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +44,7 @@ impl Machine {
|
|||||||
block,
|
block,
|
||||||
frame: vec![Frame::new(ANTI_BS_SIZE)],
|
frame: vec![Frame::new(ANTI_BS_SIZE)],
|
||||||
stream_in: Box::new(::std::io::stdin()),
|
stream_in: Box::new(::std::io::stdin()),
|
||||||
stream_out: Rc::new(Mutex::new(::std::io::stdout())),
|
stream_out: Arc::new(Mutex::new(::std::io::stdout())),
|
||||||
|
|
||||||
#[cfg(feature = "bonus:network")]
|
#[cfg(feature = "bonus:network")]
|
||||||
net: NetStack::new(),
|
net: NetStack::new(),
|
||||||
@@ -152,7 +151,7 @@ impl Machine {
|
|||||||
self.stream_in = instream;
|
self.stream_in = instream;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_output(&mut self, outstream: Rc<Mutex<Write + Send + Sync>>) {
|
pub fn set_output(&mut self, outstream: Arc<Mutex<Write + Send + Sync>>) {
|
||||||
self.stream_out = outstream;
|
self.stream_out = outstream;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
extern crate rustijvm;
|
extern crate rustijvm;
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::sync::{Arc, Mutex};
|
||||||
use std::sync::Mutex;
|
|
||||||
use std::io::{Cursor, Seek, SeekFrom, Read};
|
use std::io::{Cursor, Seek, SeekFrom, Read};
|
||||||
|
|
||||||
fn steps(machine: &mut rustijvm::Machine, num: usize) {
|
fn steps(machine: &mut rustijvm::Machine, num: usize) {
|
||||||
@@ -12,7 +11,7 @@ fn steps(machine: &mut rustijvm::Machine, num: usize) {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn advanced1() {
|
fn advanced1() {
|
||||||
let output: Rc<Mutex<Cursor<Vec<u8>>>> = Rc::new(Mutex::new(Cursor::new(Vec::new())));
|
let output: Arc<Mutex<Cursor<Vec<u8>>>> = Arc::new(Mutex::new(Cursor::new(Vec::new())));
|
||||||
let input = Box::new("A".as_bytes());
|
let input = Box::new("A".as_bytes());
|
||||||
let mut machine = rustijvm::Machine::new_from_file("files/task5/all_regular.ijvm").unwrap();
|
let mut machine = rustijvm::Machine::new_from_file("files/task5/all_regular.ijvm").unwrap();
|
||||||
machine.set_input(input);
|
machine.set_input(input);
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
extern crate rustijvm;
|
extern crate rustijvm;
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::sync::{Arc, Mutex};
|
||||||
use std::sync::Mutex;
|
|
||||||
use std::io::{Cursor, Seek, SeekFrom, Read};
|
use std::io::{Cursor, Seek, SeekFrom, Read};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn advanced4_tanenbaum() {
|
fn advanced4_tanenbaum() {
|
||||||
let rc = Rc::new(Mutex::new(Cursor::new(Vec::new())));
|
let rc = Arc::new(Mutex::new(Cursor::new(Vec::new())));
|
||||||
let mut machine = rustijvm::Machine::new_from_file("files/advanced/Tanenbaum.ijvm").unwrap();
|
let mut machine = rustijvm::Machine::new_from_file("files/advanced/Tanenbaum.ijvm").unwrap();
|
||||||
machine.set_output(rc.clone());
|
machine.set_output(rc.clone());
|
||||||
machine.run().unwrap();
|
machine.run().unwrap();
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
extern crate rustijvm;
|
extern crate rustijvm;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::rc::Rc;
|
use std::sync::{Arc, Mutex};
|
||||||
use std::sync::Mutex;
|
|
||||||
use std::io::{Cursor, Seek, SeekFrom, Read};
|
use std::io::{Cursor, Seek, SeekFrom, Read};
|
||||||
|
|
||||||
fn run_bfi(file: &str) -> String {
|
fn run_bfi(file: &str) -> String {
|
||||||
let file = File::open(file).expect("Missing bf file");
|
let file = File::open(file).expect("Missing bf file");
|
||||||
let rc = Rc::new(Mutex::new(Cursor::new(Vec::new())));
|
let rc = Arc::new(Mutex::new(Cursor::new(Vec::new())));
|
||||||
let mut machine = rustijvm::Machine::new_from_file("files/bonus/bfi.ijvm").unwrap();
|
let mut machine = rustijvm::Machine::new_from_file("files/bonus/bfi.ijvm").unwrap();
|
||||||
machine.set_output(rc.clone());
|
machine.set_output(rc.clone());
|
||||||
machine.set_input(Box::new(file));
|
machine.set_input(Box::new(file));
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
extern crate rustijvm;
|
extern crate rustijvm;
|
||||||
|
|
||||||
use std::io::{Cursor, Read, Seek, SeekFrom};
|
use std::io::{Cursor, Read, Seek, SeekFrom};
|
||||||
use std::rc::Rc;
|
use std::sync::{Arc, Mutex};
|
||||||
use std::sync::Mutex;
|
|
||||||
|
|
||||||
fn steps(machine: &mut rustijvm::Machine, num: usize) {
|
fn steps(machine: &mut rustijvm::Machine, num: usize) {
|
||||||
for _ in 0..num {
|
for _ in 0..num {
|
||||||
@@ -84,7 +83,7 @@ fn task4_complex_load() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn task4_iteration_load() {
|
fn task4_iteration_load() {
|
||||||
let rc = Rc::new(Mutex::new(Cursor::new(Vec::new())));
|
let rc = Arc::new(Mutex::new(Cursor::new(Vec::new())));
|
||||||
|
|
||||||
let mut machine = rustijvm::Machine::new_from_file("files/task4/LoadTest4.ijvm").unwrap();
|
let mut machine = rustijvm::Machine::new_from_file("files/task4/LoadTest4.ijvm").unwrap();
|
||||||
machine.set_output(rc.clone());
|
machine.set_output(rc.clone());
|
||||||
|
|||||||
Reference in New Issue
Block a user