Explorar o código

command line args, and load fixes

jmelesky %!s(int64=4) %!d(string=hai) anos
pai
achega
df8092afa8
Modificáronse 2 ficheiros con 9 adicións e 5 borrados
  1. 5 0
      Cargo.toml
  2. 4 5
      src/main.rs

+ 5 - 0
Cargo.toml

@@ -8,3 +8,8 @@ edition = "2018"
 
 [dependencies]
 text_io = "0.1.8"
+
+
+[profile.release]
+debug = true
+

+ 4 - 5
src/main.rs

@@ -1,4 +1,5 @@
 use std::collections::HashMap;
+use std::env;
 use std::fmt;
 use std::fs;
 use text_io::read;
@@ -198,10 +199,7 @@ fn um_step(um: &mut UMState, op: UMOp) {
         },
         UMOp::Load(b, c) => {
             let new_arr = um.mem[um.arrmap[&um.regs[b as usize]]].clone();
-            let new_arr_add = um.mem.len() as u32;
-            um.mem.push(new_arr);
-            um.arrmap.remove(&0);
-            um.arrmap.insert(0,new_arr_add as usize);
+            um.mem[0] = new_arr;
             um.pc = um.regs[c as usize] as usize;
         },
         UMOp::Value(a, val) => {
@@ -224,6 +222,7 @@ fn um_run(masks: HashMap<&str, (u32,u32)>,
 }
 
 fn main() {
+    let args: Vec<String> = env::args().collect();
 
     let mut masks_map: HashMap<&str, (u32,u32)> = HashMap::new();
     masks_map.insert("op_mask",   (0b11110000000000000000000000000000, 28));
@@ -234,7 +233,7 @@ fn main() {
     masks_map.insert("val_mask",  (0b00000001111111111111111111111111,  0));
 
 
-    let codex8 = &fs::read("data/sandmark.umz").unwrap();
+    let codex8 = &fs::read(&args[1]).unwrap();
 
     let mut codex = vec![0u32; codex8.len() / 4];