From 10ea9df31278aa22eeb5812e529b3586ef8022f0 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 14 Aug 2005 06:08:11 +0000 Subject: [PATCH] unit tests for identities, recrossref speedup --- doc/handbook.tex | 12 ++--- library/collections/tree-each.factor | 4 +- library/test/compiler/identities.factor | 59 +++++++++++++++++++++++++ library/test/test.factor | 1 + 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 library/test/compiler/identities.factor diff --git a/doc/handbook.tex b/doc/handbook.tex index 02891999fb..f6d2c08a08 100644 --- a/doc/handbook.tex +++ b/doc/handbook.tex @@ -189,8 +189,8 @@ This guide uses the standard mathematical notation to denote intervals. Notation&Meaning\\ \hline $(a,b)$&All numbers from $a$ to $b$, excluding $a$ and $b$\\ -$[a,b)$&All numbers from $a$ to $b$, including $a$ and excluding and $b$\\ -$(a,b]$&All numbers from $a$ to $b$, excluding $a$ and including and $b$\\ +$[a,b)$&All numbers from $a$ to $b$, including $a$ and excluding $b$\\ +$(a,b]$&All numbers from $a$ to $b$, excluding $a$ and including $b$\\ $[a,b]$&All numbers from $a$ to $b$, including $a$ and $b$ \end{tabular} @@ -233,7 +233,7 @@ parsing words. Tokens are appended to the parse tree, the top level of which is returned by the original parser invocation. Nested levels of the parse tree are created by parsing words. -Here is the parser algorithm in more detail -- some of the concepts therein will be defined shortly: +The parser iterates through the input text, checking each character in turn. Here is the parser algorithm in more detail -- some of the concepts therein will be defined shortly: \begin{itemize} \item If the current character is a double-quote (\texttt{"}), the \texttt{"} parsing word is executed, causing a string to be read. @@ -522,7 +522,7 @@ Escape code&Character\\ \texttt{\bs{}s}&Space\\ \texttt{\bs{}t}&Tab\\ \texttt{\bs{}n}&Newline\\ -\texttt{\bs{}t}&Carriage return\\ +\texttt{\bs{}r}&Carriage return\\ \texttt{\bs{}0}&Null byte (ASCII 0)\\ \texttt{\bs{}e}&Escape (ASCII 27)\\ \texttt{\bs{}"}&Double quote (\texttt{"})\\ @@ -1043,8 +1043,8 @@ There is one final conditional form that is used to implement the ``default valu } If the condition is \texttt{f}, the \texttt{false} quotation is called with the \texttt{default} value on the stack. Otherwise, the \texttt{true} quotation is called with the condition on the stack. The following two lines are equivalent: \begin{verbatim} -X [ Y ] [ Z ] ?ifte -X dup [ nip Y ] [ drop Z ] ifte +D X [ Y ] [ Z ] ?ifte +D X dup [ nip Y ] [ drop Z ] ifte \end{verbatim} \subsection{Boolean logic} diff --git a/library/collections/tree-each.factor b/library/collections/tree-each.factor index 11c8d57ba3..956128bb53 100644 --- a/library/collections/tree-each.factor +++ b/library/collections/tree-each.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2005 Slava Pestov. ! See http://factor.sf.net/license.txt for BSD license. IN: sequences -USING: generic kernel lists ; +USING: generic kernel lists strings ; G: tree-each ( obj quot -- | quot: elt -- ) [ over ] [ type ] ; inline @@ -13,5 +13,7 @@ M: object tree-each call ; M: sequence tree-each swap [ swap tree-each ] each-with ; +M: string tree-each call ; + M: cons tree-each ( cons quot -- ) >r uncons r> tuck >r >r tree-each r> r> tree-each ; diff --git a/library/test/compiler/identities.factor b/library/test/compiler/identities.factor new file mode 100644 index 0000000000..0f4a927dd2 --- /dev/null +++ b/library/test/compiler/identities.factor @@ -0,0 +1,59 @@ +IN: temporary +USING: compiler kernel math test ; + +[ 5 ] [ 5 [ 0 + ] compile-1 ] unit-test +[ 5 ] [ 5 [ 0 swap + ] compile-1 ] unit-test + +[ 5 ] [ 5 [ 0 - ] compile-1 ] unit-test +[ -5 ] [ 5 [ 0 swap - ] compile-1 ] unit-test +[ 0 ] [ 5 [ dup - ] compile-1 ] unit-test + +[ 5 ] [ 5 [ 1 * ] compile-1 ] unit-test +[ 5 ] [ 5 [ 1 swap * ] compile-1 ] unit-test +[ 0 ] [ 5 [ 0 * ] compile-1 ] unit-test +[ 0 ] [ 5 [ 0 swap * ] compile-1 ] unit-test +[ -5 ] [ 5 [ -1 * ] compile-1 ] unit-test +[ -5 ] [ 5 [ -1 swap * ] compile-1 ] unit-test + +[ 5 ] [ 5 [ 1 / ] compile-1 ] unit-test +[ 1/5 ] [ 5 [ 1 swap / ] compile-1 ] unit-test +[ -5 ] [ 5 [ -1 / ] compile-1 ] unit-test + +[ 0 ] [ 5 [ 1 mod ] compile-1 ] unit-test +[ 0 ] [ 5 [ 1 rem ] compile-1 ] unit-test + +[ 5 ] [ 5 [ 1 ^ ] compile-1 ] unit-test +[ 25 ] [ 5 [ 2 ^ ] compile-1 ] unit-test +[ 1/5 ] [ 5 [ -1 ^ ] compile-1 ] unit-test +[ 1/25 ] [ 5 [ -2 ^ ] compile-1 ] unit-test +[ 1 ] [ 5 [ 1 swap ^ ] compile-1 ] unit-test + +[ 5 ] [ 5 [ -1 bitand ] compile-1 ] unit-test +[ 0 ] [ 5 [ 0 bitand ] compile-1 ] unit-test +[ 5 ] [ 5 [ -1 swap bitand ] compile-1 ] unit-test +[ 0 ] [ 5 [ 0 swap bitand ] compile-1 ] unit-test +[ 5 ] [ 5 [ dup bitand ] compile-1 ] unit-test + +[ 5 ] [ 5 [ 0 bitor ] compile-1 ] unit-test +[ -1 ] [ 5 [ -1 bitor ] compile-1 ] unit-test +[ 5 ] [ 5 [ 0 swap bitor ] compile-1 ] unit-test +[ -1 ] [ 5 [ -1 swap bitor ] compile-1 ] unit-test +[ 5 ] [ 5 [ dup bitor ] compile-1 ] unit-test + +[ 5 ] [ 5 [ 0 bitxor ] compile-1 ] unit-test +[ 5 ] [ 5 [ 0 swap bitxor ] compile-1 ] unit-test +[ -6 ] [ 5 [ -1 bitxor ] compile-1 ] unit-test +[ -6 ] [ 5 [ -1 swap bitxor ] compile-1 ] unit-test +[ 0 ] [ 5 [ dup bitxor ] compile-1 ] unit-test + +[ 0 ] [ 5 [ 0 swap shift ] compile-1 ] unit-test +[ 5 ] [ 5 [ 0 shift ] compile-1 ] unit-test + +[ f ] [ 5 [ dup < ] compile-1 ] unit-test +[ t ] [ 5 [ dup <= ] compile-1 ] unit-test +[ f ] [ 5 [ dup > ] compile-1 ] unit-test +[ t ] [ 5 [ dup >= ] compile-1 ] unit-test + +[ t ] [ 5 [ dup eq? ] compile-1 ] unit-test +[ t ] [ 5 [ dup = ] compile-1 ] unit-test +[ t ] [ 5 [ dup number= ] compile-1 ] unit-test diff --git a/library/test/test.factor b/library/test/test.factor index 4c0b083189..e54e71b3c2 100644 --- a/library/test/test.factor +++ b/library/test/test.factor @@ -110,6 +110,7 @@ SYMBOL: failures "compiler/stack" "compiler/ifte" "compiler/generic" "compiler/bail-out" "compiler/linearizer" "compiler/intrinsics" + "compiler/identities" ] run-tests ; : all-tests tests compiler-tests benchmarks ;