Commit b29082bd authored by Fletcher Haynes's avatar Fletcher Haynes
Browse files

Merge branch '0.0.18' into 'master'

0.0.18

See merge request !5
parents 3a7ecb14 904b671c
Loading
Loading
Loading
Loading
Loading
+92 −0
Original line number Diff line number Diff line
@@ -39,6 +39,16 @@ name = "cfg-if"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "chrono"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
 "num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "clap"
version = "2.32.0"
@@ -54,6 +64,14 @@ dependencies = [
 "yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "cloudabi"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "env_logger"
version = "0.5.13"
@@ -66,6 +84,20 @@ dependencies = [
 "termcolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
 "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "fuchsia-zircon-sys"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "humantime"
version = "1.1.1"
@@ -79,10 +111,12 @@ name = "iridium"
version = "0.0.17"
dependencies = [
 "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
 "log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
 "nom 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "uuid 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
@@ -122,11 +156,41 @@ dependencies = [
 "memchr 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "num-integer"
version = "0.1.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "num-traits"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "quick-error"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "rand"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
 "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
 "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "rand_core"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "redox_syscall"
version = "0.1.40"
@@ -199,6 +263,16 @@ dependencies = [
 "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "time"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
 "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
 "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "ucd-util"
version = "0.1.1"
@@ -214,6 +288,14 @@ name = "utf8-ranges"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "uuid"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "vec_map"
version = "0.8.1"
@@ -272,15 +354,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "90492c5858dd7d2e78691cfb89f90d273a2800fc11d98f60786e5d87e2f83781"
"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3"
"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878"
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0484fda3e7007f2a4a0d9c3a703ca38c71c54c55602ce4660c419fd32e188c9e"
"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7"
"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
"checksum log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cba860f648db8e6f269df990180c2217f333472b4a6e901e97446858487971e2"
"checksum memchr 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a3b4142ab8738a78c51896f704f83c11df047ff1bda9a92a661aa6361552d93d"
"checksum nom 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "898696750eb5c3ce5eb5afbfbe46e7f7c4e1936e19d3e97be4b7937da7b6d114"
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
"checksum num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "630de1ef5cc79d0cdd78b7e33b81f083cbfe90de0f4b2b2f07f905867c70e9fe"
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
"checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c"
"checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2"
"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum regex 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "67d0301b0c6804eca7e3c275119d0b01ff3b7ab9258a65709e608a66312a1025"
@@ -290,9 +380,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b"
"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d"
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
"checksum utf8-ranges 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd70f467df6810094968e2fce0ee1bd0e87157aceb026a8c083bcf5e25b9efe4"
"checksum uuid 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "39fc0def9b82e91083a03ce2f1e3d50aef224568d2044f6cafc98fbe2b866530"
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051"
"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd"
+2 −0
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@ clap = { version = "2.32", features = ["yaml"] }
log = "0.4"
env_logger = "0.5.13"
byteorder = "1"
uuid = { version = "0.7", features = ["v4"] }
chrono = "0.4"

[profile.dev]
opt-level = 0
+8 −1
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ extern crate clap;
extern crate log;
extern crate env_logger;
extern crate byteorder;
extern crate uuid;
extern crate chrono;

use clap::App;

@@ -34,7 +36,12 @@ fn main() {
            match program {
                Ok(p) => {
                    vm.add_bytes(p);
                    vm.run();
                    let events = vm.run();
                    println!("VM Events");
                    println!("--------------------------");
                    for event in &events {
                        println!("{:#?}", event);
                    };
                    std::process::exit(0);
                },
                Err(_e) => {
+9 −3
Original line number Diff line number Diff line
use std::thread;

use vm::VM;
use vm::{VM, VMEvent};

#[derive(Default)]
pub struct Scheduler {
@@ -17,9 +17,15 @@ impl Scheduler {
    }

    /// Takes a VM and runs it in a background thread
    pub fn get_thread(&mut self, mut vm: VM) -> thread::JoinHandle<u32> {
    pub fn get_thread(&mut self, mut vm: VM) -> thread::JoinHandle<Vec<VMEvent>> {
      thread::spawn(move || {
          vm.run()
          let events = vm.run();
          println!("VM Events");
          println!("--------------------------");
          for event in &events {
              println!("{:#?}", event);
          };
          events
      })
    }
}
+60 −14
Original line number Diff line number Diff line
use std;

use chrono::prelude::*;
use uuid::Uuid;

use instruction::Opcode;
use assembler::PIE_HEADER_PREFIX;
use scheduler::Scheduler;

#[derive(Clone, Debug)]
pub enum VMEventType {
    Start,
    GracefulStop{code: u32},
    Crash{code: u32}
}

#[derive(Clone, Debug)]
pub struct VMEvent {
    event: VMEventType,
    at: DateTime<Utc>,
    application_id: Uuid
}

pub const DEFAULT_HEAP_STARTING_SIZE: usize = 64;
/// Virtual machine struct that will execute bytecode
#[derive(Default, Clone)]
pub struct VM {
@@ -21,7 +38,11 @@ pub struct VM {
    /// Contains the result of the last comparison operation
    equal_flag: bool,
    /// Contains the read-only section data
    ro_data: Vec<u8>
    ro_data: Vec<u8>,
    /// Is a unique, randomly generated UUID for identifying this VM
    id: Uuid,
    /// Keeps a list of events for a particular VM
    events: Vec<VMEvent>
}

impl VM {
@@ -31,29 +52,54 @@ impl VM {
            registers: [0; 32],
            program: vec![],
            ro_data: vec![],
            heap: vec![],
            heap: vec![0; DEFAULT_HEAP_STARTING_SIZE],
            pc: 0,
            remainder: 0,
            equal_flag: false,

            id: Uuid::new_v4(),
            events: Vec::new()
        }
    }

    /// Wraps execution in a loop so it will continue to run until done or there is an error
    /// executing instructions.
    pub fn run(&mut self) -> u32 {
    pub fn run(&mut self) -> Vec<VMEvent> {
        self.events.push(
            VMEvent{
                event: VMEventType::Start,
                at: Utc::now(),
                application_id: self.id.clone()
            }
        );
        // TODO: Should setup custom errors here
        if !self.verify_header() {
            self.events.push(
                VMEvent{
                    event: VMEventType::Crash{
                        code: 1
                    },
                    at: Utc::now(),
                    application_id: self.id.clone()
                }
            );
            println!("Header was incorrect");
            return 1;
            return self.events.clone();
        }
        // If the header is valid, we need to change the PC to be at bit 65.
        self.pc = 64;
        let mut is_done = false;
        while !is_done {
        let mut is_done = None;
        while is_done.is_none() {
            is_done = self.execute_instruction();
        }
        0
        self.events.push(
            VMEvent{
                event: VMEventType::GracefulStop{
                    code: is_done.unwrap()},
                    at: Utc::now(),
                    application_id: self.id.clone()
            }
        );
        self.events.clone()
    }

    /// Executes one instruction. Meant to allow for more controlled execution of the VM
@@ -73,9 +119,9 @@ impl VM {

    /// Executes an instruction and returns a bool. Meant to be called by the various public run
    /// functions.
    fn execute_instruction(&mut self) -> bool {
    fn execute_instruction(&mut self) -> Option<u32> {
        if self.pc >= self.program.len() {
            return true;
            return Some(1);
        }
        match self.decode_opcode() {
            Opcode::LOAD => {
@@ -106,11 +152,11 @@ impl VM {
            }
            Opcode::HLT => {
                println!("HLT encountered");
                return true;
                return Some(0);
            }
            Opcode::IGL => {
                println!("Illegal instruction encountered");
                return true;
                return Some(1);
            }
            Opcode::JMP => {
                let target = self.registers[self.next_8_bits() as usize];
@@ -245,7 +291,7 @@ impl VM {
                };
            }
        };
        false
        None
    }

    /// Attempts to decode the byte the VM's program counter is pointing at into an opcode
@@ -506,7 +552,7 @@ mod tests {
        test_vm.registers[0] = 1024;
        test_vm.program = vec![17, 0, 0, 0];
        test_vm.run_once();
        assert_eq!(test_vm.heap.len(), 1024);
        assert_eq!(test_vm.heap.len(), 1024 + DEFAULT_HEAP_STARTING_SIZE);
    }

    #[test]