From: Tim Vaughan Date: Sun, 24 Jul 2016 07:28:52 +0000 (+1200) Subject: Added stack overflow exceptions. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=forth.jl.git;a=commitdiff_plain;h=d937593337d4f3a03fcf689b46c977d70a2171ee Added stack overflow exceptions. --- 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