]> gitweb.factorcode.org Git - factor.git/commitdiff
float parameters working on OS X
authorSlava Pestov <slava@factorcode.org>
Thu, 16 Jun 2005 03:27:28 +0000 (03:27 +0000)
committerSlava Pestov <slava@factorcode.org>
Thu, 16 Jun 2005 03:27:28 +0000 (03:27 +0000)
16 files changed:
TODO.FACTOR.txt
doc/handbook.tex
library/alien/compiler.factor
library/collections/strings-epilogue.factor
library/continuations.factor
library/generic/tuple.factor
library/httpd/html.factor
library/httpd/http-common.factor
library/inference/words.factor
library/syntax/unparser.factor
library/test/inference.factor
library/test/interpreter.factor
library/tools/interpreter.factor
library/tools/memory.factor
native/debug.c
native/float.c

index 1e861ded9a3185edd2be135321b8543b5ea8386c..5c84fbef9d8bed58c8009c167352ee45d757983b 100644 (file)
@@ -75,7 +75,7 @@
 + sequences\r
 \r
 - generic skip\r
-- dipping seq-2nmap, seq-2each\r
+- dipping 2nmap, 2each\r
 - array sort\r
 - 2map slow with lists\r
 - nappend: instead of using push, enlarge the sequence with set-length\r
index 76e6432a866c4c9a289b430abd540f6c6c450c59..dcbc6db0c538cc8a2d8d87d85600422bbd6fffed 100644 (file)
@@ -5344,7 +5344,7 @@ M: list prettyprint*
     ] check-recursion ;}
 \end{alltt}
 
-\chapter{Dealing with runtime errors}
+\chapter{Debugging and optimizing}
 
 \section{Looking at stacks}
 
@@ -5455,9 +5455,6 @@ You can undo the effect of \texttt{break} or \texttt{watch} by reloading the ori
 
 If you accidentally start an infinite loop, you can send the Factor runtime a \texttt{QUIT} signal. On Unix, this is done by pressing \texttt{Control-\bs} in the controlling terminal. This will cause the runtime to dump the data and return stacks in a semi-readable form. Note that this will help you find the root cause of the hang, but it will not let you interrupt the infinite loop.
 
-
-\chapter{Defensive coding}
-
 \section{Unit testing}
 
 Unit tests are very easy to write. They are usually placed in source files. A unit test can be executed with the \texttt{unit-test} word in the \texttt{test} vocabulary. This word takes a list and a quotation; the quotation is executed, and the resulting data stack is compared against the list. If they do not equal, the unit test has failed. Here is an example of a unit test:
@@ -5478,12 +5475,6 @@ To have a unit test assert that a piece of code does not execute successfully, b
 
 Unit testing is a good habit to get into. Sometimes, writing tests first, before any code, can speed the development process too; by running your unit test script, you can gauge progress.
 
-\chapter{Optimization}
-
-While both the Factor interpreter and compiler are relatively slow at this stage, there
-are still ways you can make your Factor code go faster. The key is to find bottlenecks,
-and optimize them.
-
 \section{Timing code}
 
 The \texttt{time} word reports the time taken to execute a quotation, in milliseconds. The portion of time spent in garbage collection is also shown:
@@ -5537,76 +5528,6 @@ word: 96960 bytes, 3030 instances
 tuple: 688 bytes, 22 instances}
 \end{alltt}
 
-\section{The profiler}
-
-Factor provides a statistical sampling profiler for narrowing down memory and processor bottlenecks.
-The profiler is only supported on Unix platforms. On FreeBSD 4.x, the Factor runtime must
-be compiled without the \texttt{-pthread} switch, since FreeBS 4.x userspace threading makes
-use of a signal that conflicts with the signal used for profiling.
-
-The \texttt{allot-profile} word executes a quotation with the memory profiler enabled, then prints a list of all words that allocated memory, along with the bytes allocated. Note that during particularly long executions, or executions where a lot of memory is allocated, these counters may overrun.
-
-\begin{alltt}
-\textbf{ok} [ "boot.image.le32" make-image ] allot-profile
-\emph{... many lines omitted ...}
-\textbf{[[ write-little-endian-32 673952 ]]
-[[ wait-to-read-line 788640 ]]
-[[ blocking-read-line 821264 ]]
-[[ vocabularies 822624 ]]
-[[ parse-resource 823376 ]]
-[[ next-line 1116440 ]]
-[[ vector-map 1326504 ]]
-[[ fixup-words 1326520 ]]
-[[ vector-each 1768640 ]]
-[[ (parse) 2434208 ]]
-[[ classes 2517920 ]]
-[[ when* 2939088 ]]
-[[ while 3614408 ]]
-[[ (parse-stream) 3634552 ]]
-[[ make-list 3862000 ]]
-[[ object 4143784 ]]
-[[ each 4712080 ]]
-[[ run-resource 5036904 ]]
-[[ (callcc) 5183400 ]]
-[[ catch 5188976 ]]
-[[ 2slip 8631736 ]]
-[[ end 202896600 ]]
-[[ make-image 208611888 ]]
-[[ with-scope 437823992 ]]}
-\end{alltt}
-
-The \texttt{call-profile} word executes a quotation with the CPU profiler enabled, then prints a list of all words that were found on the return stack, along with the number of times they were seen there. This gives a rough idea of what words are taking up the majority of execution time.
-
-\begin{alltt}
-\textbf{ok} [ "boot.image.le32" make-image ] call-profile
-\emph{... many lines omitted ...}
-\textbf{[[ stream-write 7 ]]
-[[ wait-to-write 7 ]]
-[[ vector-map 11 ]]
-[[ fixup-words 11 ]]
-[[ when* 12 ]]
-[[ write 16 ]]
-[[ write-word 17 ]]
-[[ parse-loop 22 ]]
-[[ make-list 24 ]]
-[[ (parse) 29 ]]
-[[ blocking-write 32 ]]
-[[ while 35 ]]
-[[ (parse-stream) 36 ]]
-[[ dispatch 47 ]]
-[[ run-resource 50 ]]
-[[ write-little-endian-32 76 ]]
-[[ (callcc) 173 ]]
-[[ catch 174 ]]
-[[ each 175 ]]
-[[ 2slip 199 ]]
-[[ end 747 ]]
-[[ make-image 785 ]]
-[[ with-scope 1848 ]]}
-\end{alltt}
-
-Normally, the memory and CPU profilers run every millisecond, and increment counters for all words on the return stack. The \texttt{only-top} variable can be switched on, in which case only the counter for the word at the top of the return stack is incremented. This gives a more localized picture of CPU and memory usage.
-
 \chapter{Stack effect inference}
 
 The stack effect inference tool checks correctness of code before it is run.
index 1d86aa8ca510bb3ea817fdbad2c3566fceb4b6dc..495d6c3624045a11427ef7f753011bac37daebd4 100644 (file)
@@ -91,10 +91,21 @@ C: alien-node make-node ;
     [ stack-space ] keep
     [ [ c-aligned - dup ] keep unbox-parameter ] map nip % ;
 
+: incr-param ( reg-class -- )
+    #! OS X is so ugly.
+    dup class [ 1 + ] change  dup float-regs? [
+        os "macosx" = [
+            int-regs [ swap float-regs-size 4 / + ] change
+        ] [
+            drop
+        ] ifte
+    ] [
+        drop
+    ] ifte ;
+
 : load-parameter ( n parameter -- node )
     c-type "reg-class" swap hash
-    [ class dup get dup 1 + rot set ] keep
-    %parameter ;
+    [ [ class get ] keep  incr-param ] keep  %parameter ;
 
 : load-parameters ( params -- )
     [
index 2e512181125af1c40e9bd45f71d74b74b770ab73..0b10a0322bb99a1db51c6bc7f2f0294749fe5ce1 100644 (file)
@@ -9,12 +9,14 @@ sequences strings ;
 
 : fill ( count char -- string ) <repeated> >string ;
 
-: pad ( string count char -- string )
-    >r over length - dup 0 <= [
-        r> 2drop
-    ] [
-        r> fill swap append
-    ] ifte ;
+: padding ( string count char -- string )
+    >r swap length - dup 0 <= [ r> 2drop "" ] [ r> fill ] ifte ;
+
+: pad-left ( string count char -- string )
+    pick >r padding r> append ;
+
+: pad-right ( string count char -- string )
+    pick >r padding r> swap append ;
 
 : ch>string ( ch -- str ) 1 <sbuf> [ push ] keep (sbuf>string) ;
 
index 4bbcba178f121b296a8b5fbc9d3ccac1f0ee2ea4..0d83b28b064103d9f72c9a3dd76d2f5640ddb553 100644 (file)
@@ -2,37 +2,30 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: kernel USING: errors lists namespaces sequences ;
 
-: reify ( quot -- )
-    >r datastack >pop> callstack >pop> namestack catchstack
-    r> call ;
+TUPLE: interp data call name catch ;
 
-: (callcc) cons cons cons cons swap call ;
+: interp ( -- interp )
+    datastack callstack >pop> >pop>
+    namestack catchstack <interp> ;
 
-: continue0 ( ds rs ns cs -- )
-    set-catchstack set-namestack
+: >interp< ( interp -- data call name catch )
+    [ interp-data ] keep
+    [ interp-call ] keep
+    [ interp-name ] keep
+    interp-catch ;
+
+: set-interp ( interp -- )
+    >interp< set-catchstack set-namestack
     >r set-datastack r> set-callstack ;
 
-: callcc0 ( code -- )
-    #! Calls the code with a special quotation at the top of the
-    #! stack. The quotation has stack effect:
-    #!
-    #! ( -- ... )
-    #!
-    #! When called, the quotation restores execution state to
-    #! the point after the callcc0 call.
-    [ [ continue0 ] (callcc) ] reify ;
+: continuation ( interp -- )
+    interp dup interp-call >pop> >pop> drop
+    dup interp-data >pop> drop ;
 
-: continue1 ( obj ds rs ns cs -- obj )
-    set-catchstack set-namestack
-    rot >r >r set-datastack r> r> swap set-callstack ;
+: callcc0 ( quot ++ | quot: cont -- | cont: ++ )
+    continuation
+    [ set-interp ] cons swap call ;
 
-: callcc1 ( code -- )
-    #! Calls the code with a special quotation at the top of the
-    #! stack. The quotation has stack effect:
-    #!
-    #! ( X -- ... )
-    #!
-    #! When called, the quotation restores execution state to
-    #! the point after the callcc1 call, and places X at the top
-    #! of the original datastack.
-    [ [ continue1 ] (callcc) ] reify ;
+: callcc1 ( quot ++ obj | quot: cont -- | cont: obj ++ obj )
+    continuation
+    [ [ interp-data push ] keep set-interp ] cons swap call ;
index d2767d2e7e5d9a9899c5d3d1bfb1f943c643b82a..91a8c13d7633d7cd69a480fce054f2554ae40e9e 100644 (file)
@@ -121,7 +121,7 @@ UNION: arrayed array tuple ;
     #! Turn a hash  table that maps values to quotations into a
     #! quotation that executes a quotation depending on the
     #! value on the stack.
-    dup hash-size 4 <= [
+    ( dup hash-size 4 <= ) t [
         hash>alist alist>quot
     ] [
         (hash>quot)
index 37b7c8ed87143535797d012fd058a5b79a9b4640..79ef06ab8f29918464187964fd8bdf6ec765fcc1 100644 (file)
@@ -23,7 +23,7 @@ stdio streams strings unparser http ;
     ] make-string ;
 
 : >hex-color ( triplet -- hex )
-    [ CHAR: # , [ >hex 2 CHAR: 0 pad % ] each ] make-string ;
+    [ CHAR: # , [ >hex 2 CHAR: 0 pad-left % ] each ] make-string ;
 
 : fg-css, ( color -- )
     "color: " , >hex-color , "; " , ;
index 0a87c80519fdc001789c03e1dfb8dc05acdd49a7..9702aedeb559ca92ffafd9628d96e6fa6de8fa00 100644 (file)
@@ -19,7 +19,7 @@ stdio streams strings unparser ;
             dup url-quotable? [
                 ,
             ] [
-                CHAR: % , >hex 2 CHAR: 0 pad %
+                CHAR: % , >hex 2 CHAR: 0 pad-left %
             ] ifte
         ] each
     ] make-string ;
index 9d2b32a2e58e61986b318ff6fb33b349b903909c..7197fb82a19e7d76915e19e88fe8225b978f0dfe 100644 (file)
@@ -76,7 +76,11 @@ M: object (apply-word) ( word -- )
     no-effect ;
 
 M: primitive (apply-word) ( word -- )
-    dup "infer-effect" word-prop consume/produce ;
+    dup "infer-effect" word-prop [
+        consume/produce
+    ] [
+        no-effect
+    ] ifte ;
 
 M: compound (apply-word) ( word -- )
     #! Infer a compound word's stack effect.
index 8ec6b10bb586ac7e7f64851e366250ce7a834465..cf78ef23e9dc677db3de510474d2941b6c007c5b 100644 (file)
@@ -80,7 +80,7 @@ M: complex unparse ( num -- str )
     ] assoc ;
 
 : ch>unicode-escape ( ch -- esc )
-    >hex 4 CHAR: 0 pad "\\u" swap append ;
+    >hex 4 CHAR: 0 pad-left "\\u" swap append ;
 
 : unparse-ch ( ch -- ch/str )
     dup quotable? [
index 2e7e96f82a049cd50467ece63b3c031f6fab0b1b..9aead67c17be6bb59f9b1f7e9a7ceb4ff240b816 100644 (file)
@@ -215,6 +215,8 @@ M: real iterate drop ;
 [ [[ 2 1 ]] ] [ [ remove ] infer old-effect ] unit-test
 [ [[ 1 1 ]] ] [ [ prune ] infer old-effect ] unit-test
 
+[ [ callstack ] infer ] unit-test-fails
+
 : no-base-case dup [ no-base-case ] [ no-base-case ] ifte ;
 
 [ [ no-base-case ] infer ] unit-test-fails
index c0e8ba49cd9674480a31b7d56bd8b7b5881fe8ea..8dc2ea0d54a4d81d2da89bf4c1e66a83e8eb6110 100644 (file)
@@ -64,6 +64,10 @@ USE: sequences
     [ 2 2 + ] test-interpreter
 ] unit-test
 
+[ { } ] [
+    [ 3 "x" set ] test-interpreter
+] unit-test
+
 [ { 3 } ] [
     [ 3 "x" set "x" get ] test-interpreter
 ] unit-test
index f61b01fba3aed2a57c56d521e0971b28d1e8e1f5..aa0e41b8c7156b1d1381511d4863aa5a928c3a41 100644 (file)
@@ -46,17 +46,19 @@ SYMBOL: meta-executing
 : next ( -- obj )
     meta-cf get [ meta-cf [ uncons ] change ] [ up next ] ifte ;
 
+: meta-interp ( -- interp )
+    meta-d get meta-r get meta-n get meta-c get <interp> ;
+
+: set-meta-interp ( interp -- )
+    >interp< meta-c set meta-n set meta-r set meta-d set ;
+
 : host-word ( word -- )
-    #! Swap in the meta-interpreter's stacks, execute the word,
-    #! swap in the old stacks. This is so messy.
-    push-d datastack push-d
-    meta-d get set-datastack
-    catchstack >r meta-c set-catchstack
-    namestack >r meta-n set-namestack
-    >r execute datastack r> tuck push
-    r> set-namestack
-    r> set-catchstack
-    set-datastack meta-d set ;
+    [
+        \ call push-r  interp [
+            interp over interp-data push
+            set-interp
+        ] cons cons push-r  meta-interp set-interp
+    ] call  set-meta-interp  pop-d 2drop ;
 
 : meta-call ( quot -- )
     #! Note we do tail call optimization here.
index 5a1d426eabe46ca3450da3034aeef31aa9a6774c..c13e4daa1bb93656821eeb50518cf14e27af70d6 100644 (file)
@@ -15,7 +15,7 @@ vectors words ;
 
 ! Printing an overview of heap usage.
 
-: kb. 1024 /i unparse 6 CHAR: \s pad  write " KB" write ;
+: kb. 1024 /i unparse 6 CHAR: \s pad-left  write " KB" write ;
 
 : (room.) ( free total -- )
     2dup swap - swap ( free used total )
index 4e4c8c811322948427d485e0ef79342035bfcb0f..bbe7acc92ce02fd9bb3f7b174347b4987015505a 100644 (file)
@@ -223,7 +223,6 @@ void factorbug(void)
        fcntl(1,F_SETFL,0);
 #endif
 
-       fprintf(stderr,"Factor low-level debugger\n");
        fprintf(stderr,"d <addr> <count> -- dump memory\n");
        fprintf(stderr,". <addr>         -- print object at <addr>\n");
        fprintf(stderr,"sz <addr>        -- print size of object at <addr>\n");
@@ -243,7 +242,7 @@ void factorbug(void)
        {
                char cmd[1024];
 
-               fprintf(stderr,"ldb ");
+               fprintf(stderr,"fep ");
                fflush(stdout);
 
                if(scanf("%s",cmd) <= 0)
index 432e4075bac2d3dd53dc363a5b443ce50ef434fc..071dec1b3135e7ff3072a59afc668d8262254fc6 100644 (file)
@@ -1,5 +1,13 @@
 #include "factor.h"
 
+void foobar(int x, int y, int z, int t)
+{
+       printf("%d\n",x);
+       printf("%d\n",y);
+       printf("%d\n",z);
+       printf("%d\n",t);
+}
+
 double to_float(CELL tagged)
 {
        F_RATIO* r;