The Lambda Lab
/
projects
/
forth.jl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
bd6a460
)
Added stack overflow exceptions.
author
Tim Vaughan
<tgvaughan@gmail.com>
Sun, 24 Jul 2016 07:28:52 +0000
(19:28 +1200)
committer
Tim Vaughan
<tgvaughan@gmail.com>
Sun, 24 Jul 2016 07:28:52 +0000
(19:28 +1200)
src/forth.jl
patch
|
blob
|
history
diff --git
a/src/forth.jl
b/src/forth.jl
index
3d5fbd5
..
5c09b49
100644
(file)
--- a/
src/forth.jl
+++ b/
src/forth.jl
@@
-48,13
+48,26
@@
function ensurePSDepth(depth::Int64)
end
end
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 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)
function pushRS(val::Int64)
+ ensureRSCapacity(1)
mem[reg.RSP+=1] = val
end
mem[reg.RSP+=1] = val
end
@@
-67,6
+80,8
@@
function popRS()
end
function pushPS(val::Int64)
end
function pushPS(val::Int64)
+ ensurePSCapacity(1)
+
mem[reg.PSP += 1] = val
end
mem[reg.PSP += 1] = val
end