From 4e3a5b3d1a29a2fb66feb0c7a827784a15de4a88 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 27 Mar 2005 01:40:29 +0000 Subject: [PATCH] fix crossref and make-image --- doc/tools.tex | 12 +++--------- library/bootstrap/primitives.factor | 1 + library/compiler/compiler.factor | 12 ++++++++++-- library/syntax/see.factor | 2 +- library/test/gadgets.factor | 2 +- library/test/generic.factor | 4 ++-- library/test/image.factor | 2 +- library/test/redefine.factor | 11 +++++++++++ library/test/test.factor | 1 + library/words.factor | 2 +- 10 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 library/test/redefine.factor diff --git a/doc/tools.tex b/doc/tools.tex index 087883a34c..d82cf442cd 100644 --- a/doc/tools.tex +++ b/doc/tools.tex @@ -241,11 +241,8 @@ The \texttt{usages.} word finds all words that refer to a given word. This word \begin{alltt} \textbf{ok} \ttbs string-map usages. -\textbf{IN: gadgets -filter-nulls -IN: html -chars>entities -IN: url-encoding +\textbf{schars>entities +filter-null url-encode} \end{alltt} @@ -616,10 +613,7 @@ bootstrap: \textbf{bash\$} ./f boot.image.le32 -no-compile \end{alltt} -The compiler has some limitations you must be aware of. The most important one is that if you -redefine -a word that is called from a compiled word, the change will not take effect until the caller words are themselves recompiled. -The second limitation is that if an exception is thrown in compiled code, the return stack will be incomplete, since compiled words do not push themselves there. Finally, compiled code cannot be profiled, either. All of these limitations will be resolved in a future release. +The compiler has two limitations you must be aware of. First, if an exception is thrown in compiled code, the return stack will be incomplete, since compiled words do not push themselves there. Second, compiled code cannot be profiled. These limitations will be resolved in a future release. The compiler consists of multiple stages -- first, a dataflow graph is inferred, then various optimizations are done on this graph, then it is transformed into a linear representation, further optimizations are done, and finally, machine code is generated from the linear representation. To perform everything except for the machine code generation, use the \texttt{precompile} word. This will dump the optimized linear IR instead of generating code, which can be useful sometimes. diff --git a/library/bootstrap/primitives.factor b/library/bootstrap/primitives.factor index f7067597b8..e80320aada 100644 --- a/library/bootstrap/primitives.factor +++ b/library/bootstrap/primitives.factor @@ -18,6 +18,7 @@ classes vocabularies set classes set + crossref set vocabularies get [ reveal diff --git a/library/compiler/compiler.factor b/library/compiler/compiler.factor index 32e98a5991..6e494651f6 100644 --- a/library/compiler/compiler.factor +++ b/library/compiler/compiler.factor @@ -57,9 +57,17 @@ M: compound (compile) ( word -- ) ] ifte ; : decompile ( word -- ) - [ word-primitive ] keep set-word-primitive ; + dup compiled? [ + "Decompiling " write dup . flush + [ word-primitive ] keep set-word-primitive + ] [ + drop + ] ifte ; -M: compound (undefine) decompile ; +M: compound (undefine) + dup f "infer-effect" set-word-prop + dup f "no-effect" set-word-prop + decompile ; : recompile ( word -- ) dup decompile compile ; diff --git a/library/syntax/see.factor b/library/syntax/see.factor index 428022cf1b..9c290f297b 100644 --- a/library/syntax/see.factor +++ b/library/syntax/see.factor @@ -149,5 +149,5 @@ M: tuple-class class. M: word class. drop ; : see ( word -- ) - dup prettyprint-IN: dup definer. dup word. + dup prettyprint-IN: dup definer. dup stack-effect. terpri dup (see) class. ; diff --git a/library/test/gadgets.factor b/library/test/gadgets.factor index 676b4e794c..5a0504fde9 100644 --- a/library/test/gadgets.factor +++ b/library/test/gadgets.factor @@ -57,7 +57,7 @@ USING: gadgets kernel lists math namespaces test ; [ 20 ] [ 110 110 -100 -200 [ 20 30 rot move-shape ] keep shape-x ] unit-test [ 30 ] [ 110 110 -100 -200 [ 20 30 rot move-shape ] keep shape-y ] unit-test [ 10 ] [ 110 110 -100 -200 [ 400 400 rot resize-shape ] keep shape-x ] unit-test -[ 401 ] [ 110 110 -100 -200 [ 400 400 rot resize-shape ] keep shape-w ] unit-test +[ 400 ] [ 110 110 -100 -200 [ 400 400 rot resize-shape ] keep shape-w ] unit-test [ t ] [ [ diff --git a/library/test/generic.factor b/library/test/generic.factor index 1a13aa5d23..75f03fe77f 100644 --- a/library/test/generic.factor +++ b/library/test/generic.factor @@ -122,12 +122,12 @@ TUPLE: another-one ; [ << another-one f >> ] [ empty-method-test ] unit-test ! Test generic see and parsing -[ "IN: scratchpad\nSYMBOL: bah\nUNION: bah fixnum alien ;\n" ] +[ "IN: scratchpad\nSYMBOL: bah \nUNION: bah fixnum alien ;\n" ] [ [ \ bah see ] with-string ] unit-test [ t ] [ DEFER: not-fixnum - "IN: scratchpad\nSYMBOL: not-fixnum\nCOMPLEMENT: not-fixnum fixnum\n" + "IN: scratchpad\nSYMBOL: not-fixnum \nCOMPLEMENT: not-fixnum fixnum\n" dup eval [ \ not-fixnum see ] with-string = ] unit-test diff --git a/library/test/image.factor b/library/test/image.factor index 5b79372b0a..1a8c668201 100644 --- a/library/test/image.factor +++ b/library/test/image.factor @@ -28,7 +28,7 @@ USE: math [ boot-quot off - "/library/bootstrap/boot.factor" run-resource + "/library/bootstrap/boot-stage1.factor" run-resource ] with-image drop [ fixnum ] [ 4 class ] unit-test diff --git a/library/test/redefine.factor b/library/test/redefine.factor new file mode 100644 index 0000000000..5e3796b35a --- /dev/null +++ b/library/test/redefine.factor @@ -0,0 +1,11 @@ +IN: scratchpad +USING: compiler inference math ; + +USE: test + +: foo 1 2 ; +: bar foo foo ; compiled +: foo 1 2 3 ; + +[ 1 2 3 1 2 3 ] [ bar ] unit-test +[ [ [ ] [ fixnum fixnum fixnum ] ] ] [ [ foo ] infer ] unit-test diff --git a/library/test/test.factor b/library/test/test.factor index 6a50e32ddc..5b9510f7f6 100644 --- a/library/test/test.factor +++ b/library/test/test.factor @@ -93,6 +93,7 @@ prettyprint stdio strings words vectors unparser ; "line-editor" "gadgets" "memory" + "redefine" ] [ test ] each diff --git a/library/words.factor b/library/words.factor index d869c9ac60..7ce8ba00d8 100644 --- a/library/words.factor +++ b/library/words.factor @@ -89,7 +89,7 @@ GENERIC: (undefine) ( word -- ) M: word (undefine) drop ; : undefine ( word -- ) - usages [ (undefine) ] each ; + dup (undefine) usages [ (undefine) ] each ; ! The word primitive combined with the word def specify what the ! word does when invoked.