diff options
| Commit | 1e75ec0d31f05fb8a87939db0415a63a8a021b18 (patch) | |
|---|---|---|
| Author | 2025-02-14 17:59:01 +0200 | |
| Committer | 2025-02-14 17:59:01 +0200 | |
| Files | 16528f9bdafcbbb9dc3072b626f485a5370068a4 /vm/src | |
| tonkobali-1e75ec0d31f05fb8a87939db0415a63a8a021b18.tar tonkobali-1e75ec0d31f05fb8a87939db0415a63a8a021b18.tar.gz tonkobali-1e75ec0d31f05fb8a87939db0415a63a8a021b18.zip | ||
| Parent | 1a6b9be6c585f7cfc3351b7554179123f7543174 (diff) | |
feat: Execute fib, add dec instruction, fix constants in memory creation
2 files changed, 15 insertions, 3 deletions
| -rw-r--r-- | vm/src/vm/memory.rs | 13 | ||||
| -rw-r--r-- | vm/src/vm/primitive.rs | 5 |
diff --git a/vm/src/vm/memory.rs b/vm/src/vm/memory.rs index 33a6de6..319b647 100644 --- a/vm/src/vm/memory.rs +++ b/vm/src/vm/memory.rs @@ -3,6 +3,8 @@ use std::{ ops::Index, }; +use super::primitive::spa; + pub(crate) type Word = i64; // Size of each memory block in words @@ -40,9 +42,13 @@ impl Memory { } fn new() -> Memory { - Memory { + let mut out = Memory { sparse_pages: HashMap::from([(0, Default::default())]), - } + }; + *out.get_mut(spa::Z) = 0; + *out.get_mut(spa::E) = 1; + *out.get_mut(spa::N) = -1; + out } pub(crate) fn new_from(mem: &Vec<Word>) -> Memory { @@ -50,6 +56,9 @@ impl Memory { for (i, chunk) in mem.chunks(PAGE_SIZE).enumerate() { memobj.sparse_pages.insert(i, Page::new(chunk)); } + *memobj.get_mut(spa::Z) = 0; + *memobj.get_mut(spa::E) = 1; + *memobj.get_mut(spa::N) = -1; memobj } diff --git a/vm/src/vm/primitive.rs b/vm/src/vm/primitive.rs index 43f217f..3e41bd0 100644 --- a/vm/src/vm/primitive.rs +++ b/vm/src/vm/primitive.rs @@ -2,7 +2,10 @@ use crate::vm::memory::{ Memory, Word }; // Special addrs pub mod spa { - pub(crate) const PROGRAM_COUNTER: usize = 2; + pub(crate) const Z: usize = 0; + pub(crate) const E: usize = 1; + pub(crate) const N: usize = 2; + pub(crate) const PROGRAM_COUNTER: usize = 3; } #[derive(Debug, PartialEq, Eq)] |
