From d937593337d4f3a03fcf689b46c977d70a2171ee Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Sun, 24 Jul 2016 19:28:52 +1200 Subject: [PATCH] Added stack overflow exceptions. --- src/forth.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/forth.jl b/src/forth.jl index 3d5fbd5..5c09b49 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -48,13 +48,26 @@ function ensurePSDepth(depth::Int64) end end +function ensurePSCapacity(toAdd::Int64) + if reg.PSP + toAdd >= PSP0 + size_PS + error("Parameter stack overflow.") + end +end + function ensureRSDepth(depth::Int64) if reg.RSP - RSP0 < depth error("Return stack underflow.") end end +function ensureRSCapacity(toAdd::Int64) + if reg.RSP + toAdd >= RSP0 + size_RS + error("Return stack overflow.") + end +end + function pushRS(val::Int64) + ensureRSCapacity(1) mem[reg.RSP+=1] = val end @@ -67,6 +80,8 @@ function popRS() end function pushPS(val::Int64) + ensurePSCapacity(1) + mem[reg.PSP += 1] = val end -- 2.20.1