forth-tests.txt (2837 bytes)
1 \ forth-tests.txt -- layer 3 tests: kernel words over the serial console (host.lisp ktest). 2 \ Each line: INPUT ==> what the kernel prints after the echo, before " ok." (trimmed). 3 \ Lines without ==> must just answer ok. Runs on a freshly booted kernel, before lisp.fs. 4 1 2 + . ==> 3 5 7 3 - . ==> 4 6 6 7 * . ==> 42 7 17 5 / . 17 5 mod . ==> 3 2 8 -17 5 / . -17 5 mod . ==> -3 -2 9 17 5 /mod . . ==> 3 2 10 -7 abs . 5 negate . ==> 7 -5 11 1 2 swap . . ==> 1 2 12 1 2 over . . . ==> 1 2 1 13 1 2 3 rot . . . ==> 1 3 2 14 1 2 3 -rot . . . ==> 2 1 3 15 1 2 nip . 1 2 tuck . . . ==> 2 2 1 2 16 1 2 3 2 pick . . . . ==> 1 3 2 1 17 0 ?dup . 5 ?dup . . ==> 0 5 5 18 1 2 2dup . . . . ==> 2 1 2 1 19 1 2 3 2drop . ==> 1 20 depth . 1 2 depth . 2drop ==> 0 2 21 3 4 = . 4 4 = . 3 4 <> . ==> 0 -1 -1 22 -1 0 < . 1 0 > . -1 0 u< . ==> -1 -1 0 23 3 3 <= . 2 3 >= . ==> -1 0 24 0 0= . 5 0<> . -5 0< . ==> -1 -1 -1 25 3 5 min . 3 5 max . ==> 3 5 26 1 4 lshift . 256 4 rshift . -16 2 arshift . ==> 16 16 -4 27 12 10 and . 12 10 or . 12 10 xor . 12 4 bic . ==> 8 14 6 8 28 0 invert . 5 1+ . 5 1- . 5 2* . -6 2/ . ==> -1 6 4 10 -3 29 3 cells . 4 cell+ . ==> 12 8 30 100000 100000 m* . . ==> 2 1410065408 31 hex ff . decimal $ff . #10 . %101 . ==> FF 255 10 5 32 10 base ! -42 . ==> -42 33 5 u. -1 u. ==> 5 4294967295 34 65 emit 66 emit ==> AB 35 : sq dup * ; 7 sq . ==> 49 36 : fact dup 2 < if drop 1 else dup 1- recurse * then ; 10 fact . ==> 3628800 37 : cnt 0 swap 0 do 1+ loop ; 1000 cnt . ==> 1000 38 : evens 10 0 do i . 2 +loop ; evens ==> 0 2 4 6 8 39 : nest 3 0 do 2 0 do j . i . loop loop ; nest ==> 0 0 0 1 1 0 1 1 2 0 2 1 40 : none 0 0 ?do 99 . loop ; none ==> 41 : lv 10 0 do i 3 = if leave then i . loop ; lv ==> 0 1 2 42 : bw begin dup . 1- dup 0= until drop ; 3 bw ==> 3 2 1 43 : wr begin dup 0> while dup . 1- repeat drop ; 3 wr ==> 3 2 1 44 : hi ." hello" ; hi ==> hello 45 : sl s" abc" type ; sl ==> abc 46 : ch [char] A emit ; ch ==> A 47 : li [ 6 7 * ] literal . ; li ==> 42 48 42 constant answer answer . ==> 42 49 7 variable v v @ . 5 v +! v @ . ==> 7 12 50 16 buffer: buf buf 16 65 fill buf 3 type ==> AAA 51 create? ==> create? not found. 52 s" abc" s" abc" compare . s" abc" s" abd" compare . ==> -1 0 53 pad? ==> pad? not found. 54 1 2 3 sp@ 8 + sp! . ==> 1 55 ' sq 3 swap execute . ==> 9 56 : im 42 ; immediate : use im ; . ==> 42 57 1 2 >r . r> . ==> 1 2 58 5 >r r@ . rdrop ==> 5 59 1 2 \ comment 3 60 . . ==> 2 1 61 1 ( comment ) 2 + . ==> 3 62 256 here ! here @ . here c@ . ==> 256 0 63 -1 here ! 5 here c! here @ . ==> -251 64 here 4 + here 2 move ==> 65 undefined-word ==> undefined-word not found. 66 drop ==> Stack underflow 67 1 2x+ ==> 2x+ not found. 68 3 s>f 4 s>f f+ f>s . ==> 7 69 7 s>f 2 s>f f- f>s . 7 s>f 2 s>f f* f>s . ==> 5 14 70 1 s>f 3 s>f f/ hex u. decimal ==> 3EAAAAAB 71 -7 s>f f>s . 7 s>f 2 s>f f/ f>s . ==> -7 3 72 16 s>f fsqrt f>s . ==> 4 73 1 s>f 2 s>f f< . 2 s>f 1 s>f f< . 2 s>f 2 s>f f= . ==> -1 0 -1 74 : sq2 1 ; : sq2 2 ; sq2 . ==> Redefine sq2. 2 75 ' drop emit-hook ! 65 emit 0 emit-hook ! 66 emit ==> B