factor/library/test/interpreter.factor

80 lines
1.6 KiB
Factor
Raw Normal View History

2005-09-28 20:09:10 -04:00
USING: errors interpreter io kernel lists math math-internals
namespaces prettyprint sequences test ;
IN: temporary
2004-11-09 22:22:25 -05:00
: done-cf? ( -- ? ) meta-cf get not ;
: done? ( -- ? ) done-cf? meta-r get length 0 = and ;
2005-03-10 17:57:22 -05:00
: interpret ( quot -- )
#! The quotation is called with each word as its executed.
2005-09-24 15:21:17 -04:00
done? [ drop ] [ [ next swap call ] keep interpret ] if ;
2005-03-10 17:57:22 -05:00
: run ( -- ) [ do ] interpret ;
2005-09-28 20:09:10 -04:00
: init-interpreter ( -- )
{ } clone meta-r set
{ } clone meta-d set
namestack meta-n set
catchstack meta-c set
meta-cf off
meta-executing off ;
2004-11-26 22:23:57 -05:00
: test-interpreter
2005-03-07 22:11:36 -05:00
init-interpreter meta-cf set run meta-d get ;
2004-11-26 22:23:57 -05:00
2004-11-09 22:22:25 -05:00
[ { 1 2 3 } ] [
2004-11-26 22:23:57 -05:00
[ 1 2 3 ] test-interpreter
2004-11-09 22:22:25 -05:00
] unit-test
[ { "Yo" 2 } ] [
2004-11-26 22:23:57 -05:00
[ 2 >r "Yo" r> ] test-interpreter
2004-11-09 22:22:25 -05:00
] unit-test
[ { 2 } ] [
2005-09-24 15:21:17 -04:00
[ t [ 2 ] [ "hi" ] if ] test-interpreter
2004-11-09 22:22:25 -05:00
] unit-test
[ { "hi" } ] [
2005-09-24 15:21:17 -04:00
[ f [ 2 ] [ "hi" ] if ] test-interpreter
2004-11-09 22:22:25 -05:00
] unit-test
[ { 4 } ] [
2004-11-26 22:23:57 -05:00
[ 2 2 fixnum+ ] test-interpreter
2004-11-09 22:22:25 -05:00
] unit-test
[ { "Hey" "there" } ] [
[ [[ "Hey" "there" ]] uncons ] test-interpreter
2004-11-09 22:22:25 -05:00
] unit-test
[ { t } ] [
2004-11-26 22:23:57 -05:00
[ "XYZ" "XYZ" = ] test-interpreter
2004-11-09 22:22:25 -05:00
] unit-test
[ { f } ] [
2004-11-26 22:23:57 -05:00
[ "XYZ" "XuZ" = ] test-interpreter
2004-11-09 22:22:25 -05:00
] unit-test
[ { #{ 1 1.5 }# { } #{ 1 1.5 }# { } } ] [
[ #{ 1 1.5 }# { } 2dup ] test-interpreter
2004-11-09 22:22:25 -05:00
] unit-test
[ { 4 } ] [
2004-11-26 22:23:57 -05:00
[ 2 2 + ] test-interpreter
2004-11-09 22:22:25 -05:00
] unit-test
2004-11-21 19:27:18 -05:00
2005-06-15 23:27:28 -04:00
[ { } ] [
[ 3 "x" set ] test-interpreter
] unit-test
2005-06-12 21:52:36 -04:00
[ { 3 } ] [
[ 3 "x" set "x" get ] test-interpreter
] unit-test
[ { "hi\n" } ] [
[ [ "hi" print ] string-out ] test-interpreter
2005-06-12 21:52:36 -04:00
] unit-test
2004-11-21 19:27:18 -05:00
[ { "4\n" } ] [
[ [ 2 2 + . ] string-out ] test-interpreter
2004-11-21 19:27:18 -05:00
] unit-test