aboutsummaryrefslogtreecommitdiff
path: root/crates/sloth_vm/src/lib.rs
diff options
context:
space:
mode:
authorCody <cody@codyq.dev>2023-04-12 15:21:11 -0500
committerCody <cody@codyq.dev>2023-04-12 15:21:11 -0500
commit209328c5fa7d57805cb362e3a792232cb6e39ad0 (patch)
treefbfefadc3f14335fa47a14e58987b97b6fac58d9 /crates/sloth_vm/src/lib.rs
parent76082958904ada89ab721ac0f3e140f0e0a7abab (diff)
downloadsloth-209328c5fa7d57805cb362e3a792232cb6e39ad0.tar.gz
Hahaha
Diffstat (limited to 'crates/sloth_vm/src/lib.rs')
-rw-r--r--crates/sloth_vm/src/lib.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/crates/sloth_vm/src/lib.rs b/crates/sloth_vm/src/lib.rs
index be134d8..121ea6a 100644
--- a/crates/sloth_vm/src/lib.rs
+++ b/crates/sloth_vm/src/lib.rs
@@ -11,6 +11,8 @@ pub mod native;
pub mod value;
pub mod vm;
+use std::ops::{Index, IndexMut};
+
use value::{Object, ObjectType};
use crate::value::Primitive;
@@ -25,8 +27,8 @@ const STACK_SIZE: usize = 1024;
#[derive(Debug)]
pub struct Stack {
- top: usize,
stack: [Primitive; STACK_SIZE],
+ top: usize,
}
impl Default for Stack {
@@ -68,6 +70,25 @@ impl Stack {
pub fn peek(&self) -> Primitive {
self.stack[self.top - 1]
}
+
+ #[inline(always)]
+ pub fn peek_nth(&self, nth: usize) -> Primitive {
+ self.stack[self.top - 1 - nth]
+ }
+}
+
+impl Index<usize> for Stack {
+ type Output = Primitive;
+
+ fn index(&self, index: usize) -> &Self::Output {
+ &self.stack[index]
+ }
+}
+
+impl IndexMut<usize> for Stack {
+ fn index_mut(&mut self, index: usize) -> &mut Self::Output {
+ &mut self.stack[index]
+ }
}
pub struct ObjectMap {