commit 81167dcccd000cd0ff297a9f42464c0fbf43b215 parent ac66cfcbb4072f2f4b4f2c282e8b29bcf554bd8d Author: Christian Ermann <christianermann@gmail.com> Date: Thu, 7 Nov 2024 22:30:14 -0800 Add test harness Diffstat:
| M | forth.f | | | 48 | ++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 48 insertions(+), 0 deletions(-)
diff --git a/forth.f b/forth.f @@ -89,3 +89,51 @@ then ; immediate : depth sp@ sp0 swap - ; + +variable depth-start +variable depth-actual +create stack-actual 32 cells allot + +: cr 10 emit ; +: space 32 emit ; + +: error type space source type cr ; + +: reset-stack + begin + depth depth-start @ - + while + drop + repeat ; + +: t{ depth depth-start ! ; + +: -> + depth depth-actual ! + begin + depth depth-start @ - + dup + while + 1 cells - + stack-actual + ! + repeat + drop ; + +: }t + depth depth-actual @ <> if + " stack depths not equal:" error + reset-stack exit + then + begin + depth depth-start @ - + dup + while + 1 cells - + stack-actual + @ <> if + " stack elements not equal:" error + reset-stack exit + then + repeat + drop ; + +t{ 1 1 + -> 2 }t