Adding stack over/underflow check.

This commit is contained in:
Brad Nelson
2022-07-31 21:53:13 -07:00
parent a32fce7334
commit 243087aee1
2 changed files with 7 additions and 2 deletions

View File

@ -93,9 +93,14 @@ create input-buffer input-limit allot
: tib-setup input-buffer 'tib ! ;
: refill tib-setup tib input-limit accept #tib ! 0 >in ! -1 ;
( Stack Guards )
sp0 'stack-cells @ 2 3 */ cells + constant sp-limit
: ?stack sp@ sp0 < if ." STACK UNDERFLOW " -1 throw then
sp-limit sp@ < if ." STACK OVERFLOW " -1 throw then ;
( REPL )
: prompt ." ok" cr ;
: evaluate-buffer begin >in @ #tib @ < while evaluate1 repeat ;
: evaluate-buffer begin >in @ #tib @ < while evaluate1 ?stack repeat ;
: evaluate ( a n -- ) 'tib @ >r #tib @ >r >in @ >r
#tib ! 'tib ! 0 >in ! evaluate-buffer
r> >in ! r> #tib ! r> 'tib ! ;

View File

@ -58,7 +58,7 @@ transfer{
evaluate-buffer aliteral value-bind
leaving( )leaving leaving leaving,
parse-quote digit $@ raw.s
tib-setup input-limit
tib-setup input-limit sp-limit ?stack
[SKIP] [SKIP]' raw-ok boot-prompt free.
$place zplace BUILTIN_MARK
}transfer