From 8e41735c79db74bf71efe0c6dddb16b78827864a Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 19 Apr 2020 21:47:00 -0700 Subject: [PATCH] format --- examples/simulator/src/lib.rs | 52 +++++++++++++++++------------------ src/interpreter.rs | 2 +- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/examples/simulator/src/lib.rs b/examples/simulator/src/lib.rs index 81cbcdd..cfef6ba 100644 --- a/examples/simulator/src/lib.rs +++ b/examples/simulator/src/lib.rs @@ -1,5 +1,5 @@ extern crate alloc; -use alloc::string::{String,ToString}; +use alloc::string::{String, ToString}; use alloc::vec::Vec; use watson::*; @@ -21,7 +21,6 @@ fn malloc(size: usize) -> *mut u8 { ptr } - #[no_mangle] fn load(ptr: *mut u8, len: usize) { log("starting interpreter"); @@ -37,13 +36,12 @@ fn load(ptr: *mut u8, len: usize) { Ok(executor) => { log("called main function"); s.execution = Some(executor); - }, + } Err(_) => { log("could not call main function"); } } - - }, + } Err(e) => { log(e); } @@ -51,15 +49,15 @@ fn load(ptr: *mut u8, len: usize) { } struct Simulator { - execution:Option>, - program_string:String, - interpreter_string:String, - } - + execution: Option>, + program_string: String, + interpreter_string: String, +} + impl Default for Simulator { fn default() -> Self { Simulator { - execution:None, + execution: None, program_string: "".to_string(), interpreter_string: "".to_string(), } @@ -67,13 +65,13 @@ impl Default for Simulator { } #[no_mangle] -fn get_program() -> *const u8 { +fn get_program() -> *const u8 { let s = globals::get::(); return s.program_string.as_ptr(); } #[no_mangle] -fn get_interpreter() -> *const u8 { +fn get_interpreter() -> *const u8 { let mut s = globals::get::(); s.interpreter_string = serde_json::to_string(&s.execution).unwrap(); s.interpreter_string.push_str("\0"); @@ -84,16 +82,16 @@ fn get_interpreter() -> *const u8 { fn next_instruction() { let mut s = globals::get::(); let execution_unit = match s.execution.as_mut().unwrap().next_unit() { - Ok(r)=>r, - Err(e)=>{ + Ok(r) => r, + Err(e) => { log(e); return; } - }; + }; let response = match execution_unit { // if an import is called, figure out what to do ExecutionUnit::CallImport(x) => { - let s = format!("import was called: {}",&x.name); + let s = format!("import was called: {}", &x.name); log(&s); ExecutionResponse::DoNothing } @@ -101,21 +99,21 @@ fn next_instruction() { ExecutionUnit::Complete(_) => { log("PROGRAM COMPLETE!"); return; - }, + } // handle other execution units with default behavior mut x @ _ => match x.evaluate() { - Ok(r)=>r, - Err(e)=>{ - log(e); - panic!(""); - } + Ok(r) => r, + Err(e) => { + log(e); + panic!(""); + } }, }; match s.execution.as_mut().unwrap().execute(response) { - Ok(r)=>r, - Err(e)=>{ + Ok(r) => r, + Err(e) => { log(e); return; } - } -} \ No newline at end of file + } +} diff --git a/src/interpreter.rs b/src/interpreter.rs index 7a7891c..1959b1a 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -1,6 +1,6 @@ use crate::core::*; -use alloc::sync::Arc; use alloc::string::{String, ToString}; +use alloc::sync::Arc; use alloc::vec::Vec; use core::cell::RefCell; use core::convert::TryInto;