All pastes #124825 Raw Edit

Unnamed

public text v1 · immutable
·published 2006-08-10 07:38 UTC
rendered paste body
' | alias \
\ A quick implementation of tester.fs functionality.
\ neal@quartus.net August 2006, for rf 9.2.6
\ Version 0.1 fixed a small issue with what error displayed.
\ Version 0.2 has a working ?dup -- the one in the ANS rf code was broken.
\ Now {{ -> }} tests will succeed.

\ A few helpful definitions lifted from the rf ANS compatibility file:

loc:
  : sp@ dup [ $f089 2, ]  ;
  reset sp@ constant base
 :: base sp@ - 4 / 1- ;
;loc alias depth

macro
: else  $e9 1, here 0 , swap dup here swap - 4 - swap ! ;

macro : leave x: rdrop x: rdrop x: ;; ; forth

: abort rdrop reset ['] boot execute ;

\ A working ?dup
: ?dup dup 0 <> if dup then ;

\ A .s that only displays what's on the actual stack.

: (.s)  depth 0 swap < if >r (.s) r> dup . then ;
: .s  depth  ." <" # ." > " (.s) cr ;


\ tester.fs functionality:

variable actual-depth
create actual-results 20 cells allot

variable temp>in

: error  
  type
  type temp>in @ >in @ over - type cr abort
;

: {{  >in @ 3 - temp>in ! ;
: }}
  depth actual-depth @ = if
    depth ?dup if
      for
        actual-results r 1- cells + @
        <> if s" Incorrect result: " error  leave then
      next
    then
  else
    s" Wrong number of results: " error
  then ;

: ->
  depth dup actual-depth !
  ?dup if
    for actual-results r 1- cells + ! next
  then ;


\ Example tests:

{{ -> }} 
{{ 3 5 + -> 8 }}
{{ true not -> false }}