]> gitweb.factorcode.org Git - factor.git/commitdiff
some compiler work
authorSlava Pestov <slava@factorcode.org>
Thu, 7 Oct 2004 01:04:01 +0000 (01:04 +0000)
committerSlava Pestov <slava@factorcode.org>
Thu, 7 Oct 2004 01:04:01 +0000 (01:04 +0000)
factor/jedit/FactorPlugin.props
factor/jedit/FactorWordRenderer.java
library/combinators.factor
library/compiler/compile-all.factor [new file with mode: 0644]
library/compiler/compiler.factor
library/compiler/generic.factor
library/compiler/interpret-only.factor
library/platform/native/boot-stage2.factor

index 7b04f0b103f994f61775541b3ac493d9f198c520..bbb1e4e05686a723c667a17a7b5a24e35172a72f 100644 (file)
@@ -48,6 +48,7 @@ factor.completion.defer=DEFER: <b>{0}</b>
 factor.completion.parsing=PARSING: <b>{0}</b>
 factor.completion.stack=: <b>{0}</b> {1}
 factor.completion.shuffle=~&lt;&lt; <b>{0}</b> {1} &gt;&gt;~
+factor.completion.symbol=SYMBOL: <b>{0}</b>
 
 factor.status.inserted-use=Inserted {0}
 factor.status.already-used=Already used {0}
index 900b0bffcd7708081feba7bb69b33b7b72c9fbd9..8df13a843b3cad608f1dd9152f1b53adf39d5ebb 100644 (file)
@@ -65,6 +65,10 @@ public class FactorWordRenderer extends DefaultListCellRenderer
                        }
                        stackEffect = buf.toString();
                }
+               else if(def instanceof FactorSymbolDefinition)
+               {
+                       prop = "factor.completion.symbol";
+               }
                else
                {
                        Cons d = def.toList(interp);
index abfbbba525edece838c43e02ad6dbe9f45dee81f..eb01315e8f1d611c7a736b7e3226b0b24f83639b 100644 (file)
@@ -156,7 +156,7 @@ USE: stack
     #!
     #! In order to compile, the quotation must consume one more
     #! value than it produces.
-    dupd [ drop ] ifte ; inline interpret-only
+    over [ call ] [ 2drop ] ifte ; inline interpret-only
 
 : while ( cond body -- )
     #! Evaluate cond. If it leaves t on the stack, evaluate
diff --git a/library/compiler/compile-all.factor b/library/compiler/compile-all.factor
new file mode 100644 (file)
index 0000000..3221415
--- /dev/null
@@ -0,0 +1,104 @@
+! :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.
+
+IN: compiler
+USE: combinators
+USE: lists
+USE: logic
+USE: stack
+USE: vectors
+USE: words
+
+! A set of words to determine a set of words :-) that can be
+! compiled.
+!
+! The heuristic is rather dumb; it errs on the side of safety
+! and assumes that any vector or list will potentually contain
+! words that will be compiled; so it will refuse to recognize
+! this as being compilable for instance:
+!
+! : foo { 1 2 3 call } vector-nth ;
+!
+! Even though the instance of 'call' is never compiled here.
+
+DEFER: can-compile?
+DEFER: can-compile-list?
+DEFER: can-compile-vector?
+
+: can-compile-reference? ( word -- ? )
+    #! We cannot compile a symbol, but we can compile a
+    #! reference to a symbol. Similarly, we can compile a
+    #! reference to a word with special compilation behavior,
+    #! but we cannot compile the word itself.
+    [
+        [ symbol? ] [ drop t ]
+        [ "interpret-only" word-property ] [ drop f ]
+        [ "compiling" word-property ] [ drop t ]
+        [ can-compile? ] [ drop t ]
+        [ drop t ] [ drop f ]
+    ] cond ;
+
+: can-compile-object? ( obj -- ? )
+    [
+        [ word? ] [ can-compile-reference? ]
+        [ list? ] [ can-compile-list? ]
+        [ vector? ] [ can-compile-vector? ]
+        [ drop t ] [ drop t ]
+    ] cond ;
+
+: can-compile-vector? ( quot -- ? )
+    [ can-compile-object? ] vector-all? ;
+
+: can-compile-list? ( quot -- ? )
+    [ can-compile-object? ] all? ;
+
+: (can-compile) ( word -- ? )
+    #! We can't actually compile a word itself that has
+    #! special compilation behavior.
+    [
+        [ "interpret-only" word-property ] [ drop f ]
+        [ "compiling" word-property ] [ drop f ]
+        [ compound? ] [ word-parameter can-compile-list? ]
+        [ compiled? ] [ drop t ]
+        [ drop t ] [ drop f ]
+    ] cond ;
+
+: can-compile? ( word -- ? )
+    #! We set it to true, then compute the actual flag, so that
+    #! mutually recursive words are processed without an
+    #! infinite loop.
+    dup "can-compile" word-property [
+        drop t
+    ] [
+        t over "can-compile" set-word-property
+        dup >r (can-compile) dup r>
+        "can-compile" set-word-property
+    ] ifte ;
+
+: compilable-words ( -- list )
+    #! Make a list of all words that can be compiled.
+    [, [ dup can-compile? [ , ] [ drop ] ifte ] each-word ,] ;
index d5aa74a57a10b006c039b492b8ef7230b384f470..bc06bb4e8d2e7ba5074c9db27bb1c9ee2b3a3a84 100644 (file)
@@ -99,7 +99,7 @@ SYMBOL: compile-words
     ] ifte ;
 
 : fixup-deferred-xt ( word where relative -- )
-    rot dup compiled? [
+    rot dup compiling? [
         compiled-xt swap - swap set-compiled-cell
     ] [
         "Not compiled: " swap word-name cat2 throw
@@ -112,7 +112,7 @@ SYMBOL: compile-words
     deferred-xts off ;
 
 : postpone-word ( word -- )
-    dup compiled? [ drop ] [ compile-words unique@ ] ifte ;
+    dup compiling? [ drop ] [ compile-words unique@ ] ifte ;
 
 ! During compilation, these two variables store pending
 ! literals. Literals are either consumed at compile-time by
index 893d1aca8a6b59eb7f96ef38f9a56b63d07913c9..3b7fc63740af92d4f3351b5dab5a08df4fd0bf2e 100644 (file)
@@ -53,7 +53,7 @@ USE: vectors
 : jump-table-entry ( word -- )
     #! Jump table entries are absolute addresses.
     dup postpone-word
-    compiled-offset 0 compile-cell 0 fixup-deferred-xt ;
+    compiled-offset 0 compile-cell 0 defer-xt ;
 
 : end-jump-table ( end-fixup -- )
     #! update the PUSH.
index 54c67d3bea0cd34141b5fbe2f8476eef983dacc1..9740cb5c3ace730f46ab2f1ee00b1109cc31c78b 100644 (file)
@@ -38,6 +38,7 @@ USE: words
     "Cannot compile " swap cat2 throw ;
 
 : word-interpret-only ( word -- )
+    t over "interpret-only" set-word-property
     dup word-name [ interpret-only-error ] cons
     swap
     "compiling" set-word-property ;
index e11f7f87e8c0ea6acb493a016e2d9174efad4f72..3478fa658f5762ee084cc103db9e82e2d9c59671 100644 (file)
@@ -142,6 +142,7 @@ USE: stdio
     "/library/compiler/ifte.factor"
     "/library/compiler/generic.factor"
     "/library/compiler/interpret-only.factor"
+    "/library/compiler/compile-all.factor"
     "/library/compiler/alien-types.factor"
     "/library/compiler/alien-macros.factor"
     "/library/compiler/alien.factor"