Initial commit with types representing machine description
authorJacob Casper <dev@jacobcasper.com>
Mon, 15 Jan 2024 17:21:22 +0000 (11:21 -0600)
committerJacob Casper <dev@jacobcasper.com>
Mon, 15 Jan 2024 17:21:22 +0000 (11:21 -0600)
.gitignore [new file with mode: 0644]
Cargo.lock [new file with mode: 0644]
Cargo.toml [new file with mode: 0644]
src/main.rs [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..ea8c4bf
--- /dev/null
@@ -0,0 +1 @@
+/target
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644 (file)
index 0000000..9d1ca1d
--- /dev/null
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "mix"
+version = "0.1.0"
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644 (file)
index 0000000..0acd9e5
--- /dev/null
@@ -0,0 +1,8 @@
+[package]
+name = "mix"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/src/main.rs b/src/main.rs
new file mode 100644 (file)
index 0000000..12a5f53
--- /dev/null
@@ -0,0 +1,73 @@
+// > Each byte contains an unspecified amount of information but it must be capable of holding at
+// > least 64 distinct values.
+// > A computer word consists of five bytes and a sign. The sign portion has only two possible
+// values, + and -.
+// u8 is the smallest standard primitive, no bounds checking for now.
+#[derive(Debug, Default, Copy, Clone)]
+struct Word {
+    sign: bool,
+    bytes: [u8; 5],
+}
+
+impl Word {
+    fn new(sign: bool, bytes: [u8; 5]) -> Word {
+        Word { sign, bytes }
+    }
+}
+
+// There are nine registers in MIX.
+// We shall use a small letter "r", prefixed to the neame, to identify a MIX register.
+#[derive(Debug, Default)]
+struct Registers {
+    // Accumulator
+    rA: Word,
+    // Extension
+    rX: Word,
+    // Index registers: Should only hold 2 bytes together with a sign.
+    rI1: Word,
+    rI2: Word,
+    rI3: Word,
+    rI4: Word,
+    rI5: Word,
+    rI6: Word,
+    // Jump: holds two bytes; it behaves as if its sign is always +
+    rJ: Word,
+}
+
+// hacing three values: LESS, EQUAL, or GREATER
+#[derive(Debug, Default)]
+enum ComparisonIndicator {
+    Less,
+    #[default]
+    Equal,
+    Greater,
+}
+
+#[derive(Debug)]
+struct Machine {
+    registers: Registers,
+    // Besides its registers, MIX contains:
+    // an overflow toggle
+    overflow: bool,
+    // a comparison indicator
+    comp: ComparisonIndicator,
+    // memory: 4000 words of storage, each word with five bytes and a sign)
+    memory: [Word; 4000],
+    // and input-output devices
+    // TODO?
+}
+
+impl Machine {
+    fn default() -> Machine {
+        Machine {
+            registers: Registers::default(),
+            overflow: false,
+            comp: ComparisonIndicator::Equal,
+            memory: [Word::default(); 4000],
+        }
+    }
+}
+
+fn main() {
+    println!("{:?}", Machine::default());
+}