summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Cully <bjc@spork.org>2025-08-25 08:25:29 -0400
committerBrian Cully <bjc@spork.org>2025-08-25 08:25:29 -0400
commitee78cb6f7f8243217098bd420ea1482d5db254f2 (patch)
tree2575519e7545075b4c71531676151e5c6c93e964 /src
parent8879df0983737b42eee1df26004b861599dd88d6 (diff)
downloadautomathon-ee78cb6f7f8243217098bd420ea1482d5db254f2.tar.gz
automathon-ee78cb6f7f8243217098bd420ea1482d5db254f2.zip
use ‘DataStackType’ instead of hard-coding i32
i want to try isize
Diffstat (limited to 'src')
-rw-r--r--src/forth/compiler.rs4
-rw-r--r--src/forth/vm.rs6
-rwxr-xr-xsrc/lib.rs2
3 files changed, 7 insertions, 5 deletions
diff --git a/src/forth/compiler.rs b/src/forth/compiler.rs
index 17f0113..97e94a9 100644
--- a/src/forth/compiler.rs
+++ b/src/forth/compiler.rs
@@ -1,4 +1,4 @@
-use super::vm::{ByteCode, OpCode, WordList};
+use super::vm::{ByteCode, DataStackType, OpCode, WordList};
use std::collections::HashMap;
use std::iter::{Enumerate, Iterator};
@@ -116,7 +116,7 @@ impl<'a> Compiler<'a> {
pub fn compile(&mut self) -> CompileResult<()> {
while let Some((word, start, end)) = self.next_word() {
let anno = Annotation { loc: (start, end) };
- if let Ok(i) = word.parse::<i32>() {
+ if let Ok(i) = word.parse::<DataStackType>() {
self.bc_push(OpCode::Num(i), anno);
} else if let Some(i) = self.wordalog.0.get(word) {
self.bc_push(OpCode::Call(*i), anno);
diff --git a/src/forth/vm.rs b/src/forth/vm.rs
index fe034a6..8cec0d2 100644
--- a/src/forth/vm.rs
+++ b/src/forth/vm.rs
@@ -2,9 +2,11 @@ use log::debug;
use std::ops::Index;
+pub type DataStackType = i32;
+
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum OpCode {
- Num(i32),
+ Num(DataStackType),
Str(usize, usize),
Call(usize),
TCall(usize), // tail call, really just ‘jmp’, but named to indicate desired usage.
@@ -85,7 +87,7 @@ impl Default for InstructionPointer {
}
#[derive(Debug)]
-pub struct DataStack(pub Vec<i32>);
+pub struct DataStack(pub Vec<DataStackType>);
#[derive(Debug)]
pub struct CallStack(pub Vec<InstructionPointer>);
diff --git a/src/lib.rs b/src/lib.rs
index 487a5ce..e9060f0 100755
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -144,7 +144,7 @@ impl ExportedVM {
vm.run().map_err(|err| format!("runtime error: {err:?}"))
}
- pub fn stack(&self) -> Vec<i32> {
+ pub fn stack(&self) -> Vec<forth::vm::DataStackType> {
let Some(vm) = &self.vm else {
return vec![]
};