PowerPC backend functional
parent
4d82ac0541
commit
22d5277c69
|
@ -68,3 +68,9 @@ I wrote down some issues I found while reading the devel-guide.pdf:
|
|||
- proper ordering for classes
|
||||
- make-vector and make-string should not need a reverse step
|
||||
- automatically recompiling defs
|
||||
|
||||
+ slow data structures:
|
||||
|
||||
- vector-map, string-map, vector-each, string-each, vector-project:
|
||||
consing
|
||||
- map, subset, project, append: not tail recursive
|
||||
|
|
|
@ -127,8 +127,14 @@ This is what is meant by the image being an \emph{infinite session}. When you sh
|
|||
|
||||
\subsection{Looking at objects}
|
||||
|
||||
Probably the most important debugging tool of them all is the \texttt{.} word. It prints the object at the top of the stack in a form that can be parsed by the Factor parser. A related word is \texttt{prettyprint}. It is identical to \texttt{.} except the output is more verbose; lists, vectors and hashtables are broken up into multiple lines and indented.
|
||||
|
||||
Most objects print in a parsable form, but not all. One exceptions to this rule is objects with external state, such as I/O ports or aliens (pointers to native structures). Also, objects with circular or very deeply nested structure will not print in a fully parsable form, since the prettyprinter has a limit on maximum nesting.
|
||||
|
||||
The prettyprinted form of a vector or list with many elements is not always readable. The \texttt{[.]} and \texttt{\{.\}} words output a list or a vector, respectively, with each element on its own line.
|
||||
|
||||
. prints an object in almost-readable form
|
||||
printing numbers in other bases, [.], {.}
|
||||
printing numbers in other bases
|
||||
we can inspect memory with instances references heap-stats
|
||||
|
||||
\section{Word tools}
|
||||
|
@ -308,12 +314,50 @@ In the future, the debugger will be linked with the walker, documented below. Ri
|
|||
|
||||
The walker lets you step through the execution of a qotation. When a colon definition is reached, you can either keep walking inside the definition, or execute it in one step. The stacks can be inspected at each stage.
|
||||
|
||||
There are two ways to use the walker. The first is to invoke it at the listener with an explicit quotation:
|
||||
There are two ways to use the walker. First of all, you can call the \texttt{walk} word explicitly, giving it a quotation:
|
||||
|
||||
\begin{alltt}
|
||||
\textbf{ok}
|
||||
walker
|
||||
annotations: watch and break
|
||||
\textbf{ok} [ [ 10 [ dup , ] repeat ] make-list ] walk
|
||||
\textbf{\&s \&r \&n \&c show stepper stacks.
|
||||
\&get ( var -- value ) inspects the stepper namestack.
|
||||
step -- single step over
|
||||
into -- single step into
|
||||
continue -- continue execution
|
||||
bye -- exit single-stepper
|
||||
[ [ 10 [ dup , ] repeat ] make-list ]
|
||||
walk}
|
||||
\end{alltt}
|
||||
|
||||
As you can see, the walker prints a brief help message, then the currently executing quotation. It changes the listener prompt from \texttt{ok} to \texttt{walk}, to remind you that there is a suspended continuation.
|
||||
|
||||
The first element of the quotation shown is the next object to be evaluated. If it is a literal, both \texttt{step} and \texttt{into} have the effect of pushing it on the walker data stack. If it is a colon definition, then \texttt{into} will recurse the walker into the colon definition; otherwise, the word executes in one step.
|
||||
|
||||
The \texttt{\&r} word shows the walker return stack, which is laid out just like the primary interpreter's return stack. In fact, a good way to understand how Factor's return stack works is to play with the walker.
|
||||
|
||||
Note that the walker does not automatically stop when the quotation originally given finishes executing; it just keeps on walking up the return stack, and even lets you step through the listener's code. You can invoke \texttt{continue} or \texttt{exit} to terminate the walker.
|
||||
|
||||
While the walker can be invoked explicitly using the \texttt{walk} word, sometimes it is more convenient to \emph{annotate} a word such that the walker is invoked automatically when the word is called. This can be done using the \texttt{break} word:
|
||||
|
||||
\begin{alltt}
|
||||
\textbf{ok} \ttbs layout* break
|
||||
\end{alltt}
|
||||
|
||||
Now, when some piece of code calls \texttt{layout*}, the walker will open, and you will be able to step through execution and see exactly what's going on. An important point to keep in mind is that when the walker is invoked in this manner, \texttt{exit} will not have the desired effect; execution will continue, but the data stack will be inconsistent, and an error will most likely be raised a short time later. Always use \texttt{continue} to resume execution after a break.
|
||||
|
||||
The walker is very handy, but sometimes you just want to see if a word is being called at all and when, and you don't care to single-step it. In that case, you can use the \texttt{watch} word:
|
||||
|
||||
\begin{alltt}
|
||||
\textbf{ok} \ttbs draw-shape break
|
||||
\end{alltt}
|
||||
|
||||
Now when \texttt{draw-shape} is called, a message will be printed to that effect.
|
||||
|
||||
You can undo the effect of \texttt{break} or \texttt{watch} by reloading the original source file containing the word definition in question:
|
||||
|
||||
\begin{alltt}
|
||||
\textbf{ok} \ttbs layout* reload
|
||||
\textbf{ok} \ttbs draw-shape reload
|
||||
\end{alltt}
|
||||
|
||||
\subsection{Dealing with hangs}
|
||||
|
||||
|
|
|
@ -92,13 +92,13 @@ SYMBOL: alien-parameters
|
|||
#! We should fail if the library does not exist, so that
|
||||
#! compilation does not keep trying to compile FFI words
|
||||
#! over and over again if the library is not loaded.
|
||||
! 2dup load-dll dlsym
|
||||
2dup load-dll dlsym drop
|
||||
cons #alien-invoke dataflow,
|
||||
[ set-alien-parameters ] keep
|
||||
set-alien-returns ;
|
||||
|
||||
: infer-alien ( -- )
|
||||
[ object object object object ] ensure-d
|
||||
[ string string string general-list ] ensure-d
|
||||
dataflow-drop, pop-d literal-value
|
||||
dataflow-drop, pop-d literal-value >r
|
||||
dataflow-drop, pop-d literal-value
|
||||
|
|
|
@ -65,10 +65,6 @@ DEFER: compile-jump-label ( label -- )
|
|||
compile-call
|
||||
] "generator" set-word-prop
|
||||
|
||||
#call-label [
|
||||
compile-call-label
|
||||
] "generator" set-word-prop
|
||||
|
||||
#jump-label [
|
||||
compile-jump-label
|
||||
] "generator" set-word-prop
|
||||
|
|
|
@ -51,6 +51,14 @@ words ;
|
|||
0 BL relative-24
|
||||
] ifte ;
|
||||
|
||||
#call-label [
|
||||
! Hack: length of instruction sequence that follows
|
||||
compiled-offset 20 + 18 LOAD32
|
||||
1 1 -16 STWU
|
||||
18 1 20 STW
|
||||
0 B relative-24
|
||||
] "generator" set-word-prop
|
||||
|
||||
: compile-jump-far ( n -- )
|
||||
19 LOAD
|
||||
19 MTCTR
|
||||
|
|
|
@ -16,6 +16,10 @@ math memory namespaces words ;
|
|||
: compile-call-label ( label -- ) 0 CALL relative ;
|
||||
: compile-jump-label ( label -- ) 0 JMP relative ;
|
||||
|
||||
#call-label [
|
||||
compile-call-label
|
||||
] "generator" set-word-prop
|
||||
|
||||
#jump [
|
||||
dup postpone-word compile-jump-label
|
||||
] "generator" set-word-prop
|
||||
|
|
|
@ -1,42 +1,7 @@
|
|||
! :folding=indent:collapseFolds=1:
|
||||
|
||||
! $Id$
|
||||
!
|
||||
! Copyright (C) 2004 Slava Pestov.
|
||||
!
|
||||
! Redistribution and use in source and binary forms, with or without
|
||||
! modification, are permitted provided that the following conditions are met:
|
||||
!
|
||||
! 1. Redistributions of source code must retain the above copyright notice,
|
||||
! this list of conditions and the following disclaimer.
|
||||
!
|
||||
! 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
! this list of conditions and the following disclaimer in the documentation
|
||||
! and/or other materials provided with the distribution.
|
||||
!
|
||||
! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
! Copyright (C) 2004, 2005 Slava Pestov.
|
||||
! See http://factor.sf.net/license.txt for BSD license.
|
||||
IN: parser
|
||||
USE: errors
|
||||
USE: kernel
|
||||
USE: lists
|
||||
USE: math
|
||||
USE: namespaces
|
||||
USE: stdio
|
||||
USE: streams
|
||||
USE: strings
|
||||
|
||||
! Stream parsing uses a number of variables:
|
||||
SYMBOL: file
|
||||
USING: kernel lists namespaces streams strings ;
|
||||
|
||||
: file-vocabs ( -- )
|
||||
"file-in" get "in" set
|
||||
|
|
|
@ -14,6 +14,8 @@ unparser ;
|
|||
! of vocabularies. If it is a parsing word, it is executed
|
||||
! immediately. Otherwise it is appended to the parse tree.
|
||||
|
||||
SYMBOL: file
|
||||
|
||||
: parsing? ( word -- ? )
|
||||
dup word? [ "parsing" word-prop ] [ drop f ] ifte ;
|
||||
|
||||
|
|
|
@ -11,12 +11,12 @@ USE: inference
|
|||
[ f ] [ "hello" 1024 <alien> = ] unit-test
|
||||
[ t ] [ 1024 <local-alien> local-alien? ] unit-test
|
||||
|
||||
: alien-inference-1
|
||||
"void" "foobar" "boo" [ "short" "short" ] alien-invoke ;
|
||||
|
||||
[ [[ 2 0 ]] ] [ [ alien-inference-1 ] infer old-effect ] unit-test
|
||||
|
||||
: alien-inference-2
|
||||
"int" "foobar" "boo" [ "short" "short" ] alien-invoke ;
|
||||
|
||||
[ [[ 2 1 ]] ] [ [ alien-inference-2 ] infer old-effect ] unit-test
|
||||
! : alien-inference-1
|
||||
! "void" "foobar" "boo" [ "short" "short" ] alien-invoke ;
|
||||
!
|
||||
! [ [[ 2 0 ]] ] [ [ alien-inference-1 ] infer old-effect ] unit-test
|
||||
!
|
||||
! : alien-inference-2
|
||||
! "int" "foobar" "boo" [ "short" "short" ] alien-invoke ;
|
||||
!
|
||||
! [ [[ 2 1 ]] ] [ [ alien-inference-2 ] infer old-effect ] unit-test
|
||||
|
|
|
@ -90,6 +90,9 @@ IN: vectors
|
|||
#! pushed onto the stack.
|
||||
>r vector>list r> each ; inline
|
||||
|
||||
: list>vector ( list -- vector )
|
||||
dup length <vector> swap [ over vector-push ] each ;
|
||||
|
||||
: vector-map ( vector code -- vector )
|
||||
#! Applies code to each element of the vector, return a new
|
||||
#! vector with the results. The code must have stack effect
|
||||
|
@ -105,9 +108,6 @@ IN: vectors
|
|||
[ rot vector-nappend ] keep
|
||||
[ swap vector-nappend ] keep ;
|
||||
|
||||
: list>vector ( list -- vector )
|
||||
dup length <vector> swap [ over vector-push ] each ;
|
||||
|
||||
: vector-project ( n quot -- vector )
|
||||
#! Execute the quotation n times, passing the loop counter
|
||||
#! the quotation as it ranges from 0..n-1. Collect results
|
||||
|
|
|
@ -24,9 +24,9 @@ MANGLE(flush_icache):
|
|||
srwi. r4,r4,5 /* note '.' suffix */
|
||||
beqlr /* if n_lines == 0, just return. */
|
||||
mtctr r4 /* flush cache lines */
|
||||
0: dcbf r0,r3 /* for each line... */
|
||||
0: dcbf 0,r3 /* for each line... */
|
||||
sync
|
||||
icbi r0,r3
|
||||
icbi 0,r3
|
||||
addi r3,r3,0x20
|
||||
bdnz 0b
|
||||
sync /* finish up */
|
||||
|
|
Loading…
Reference in New Issue