diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 85f562ed45..f2f4284449 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -7,10 +7,8 @@ - type inference fails with some assembler words; displaced, register and other predicates need to inherit from list not cons, and need stronger branch partial eval -- print warning on null class - optimize away dispatch - code gc -- #jump-f #jump-f-label - don't hardcode so many colors - ffi unicode strings: null char security hole - utf16 string boxing @@ -19,6 +17,7 @@ + compiler/ffi: +- #jump-f #jump-f-label - declarations - value type structs - out parameters diff --git a/examples/mandel.factor b/examples/mandel.factor index 5ee2fcaf6f..b3084b0c99 100644 --- a/examples/mandel.factor +++ b/examples/mandel.factor @@ -89,10 +89,10 @@ SYMBOL: center ] with-pixels ; compiled : mandel ( -- ) - 640 480 0 SDL_HWSURFACE [ + 1280 1024 0 SDL_HWSURFACE [ [ - 0.8 zoom-fact set - -0.65 center set + 3.7 zoom-fact set + -0.45 center set 100 nb-iter set init-mandel [ render ] time diff --git a/factor/DefaultVocabularyLookup.java b/factor/DefaultVocabularyLookup.java index 3ce94fccff..697e38f15e 100644 --- a/factor/DefaultVocabularyLookup.java +++ b/factor/DefaultVocabularyLookup.java @@ -193,7 +193,7 @@ public class DefaultVocabularyLookup implements VocabularyLookup { // save to same workspace as vocabulary, // or no workspace if vocabulary is builtins - FactorWord word = new FactorWord(vocabulary,name); + FactorWord word = new FactorWord(this,vocabulary,name); v.put(name,word); return word; } diff --git a/factor/ExternalFactor.java b/factor/ExternalFactor.java index 4d825452d1..20bbd1b25d 100644 --- a/factor/ExternalFactor.java +++ b/factor/ExternalFactor.java @@ -201,7 +201,7 @@ public class ExternalFactor extends DefaultVocabularyLookup String name = (String)info.next().car; FactorWord w = super.searchVocabulary(new Cons(vocabulary,null),name); if(w == null) - w = new FactorWord(vocabulary,name); + w = new FactorWord(this,vocabulary,name); w.stackEffect = (String)info.next().next().car; return w; } //}}} diff --git a/factor/FactorArtifact.java b/factor/FactorArtifact.java index 6399028b1d..7df18faaa0 100644 --- a/factor/FactorArtifact.java +++ b/factor/FactorArtifact.java @@ -67,4 +67,6 @@ public abstract class FactorArtifact public abstract String getShortString(); public abstract String getLongString(); + + public void forget() {} } diff --git a/factor/FactorReader.java b/factor/FactorReader.java index 20a6f8e49b..b9db8fa98b 100644 --- a/factor/FactorReader.java +++ b/factor/FactorReader.java @@ -46,7 +46,7 @@ public class FactorReader /** * Top level of parse tree. */ - private FactorWord toplevel = new FactorWord(null,"#"); + private FactorWord toplevel = new FactorWord(null,null,"#"); private boolean alwaysDocComments; private Cons use; diff --git a/factor/FactorWord.java b/factor/FactorWord.java index 887eaaefdf..e247fd85bf 100644 --- a/factor/FactorWord.java +++ b/factor/FactorWord.java @@ -43,14 +43,18 @@ public class FactorWord extends FactorArtifact implements FactorExternalizable */ public FactorParsingDefinition parsing; + private VocabularyLookup lookup; + /** * For browsing, the parsing word that was used to define this word. */ private FactorWord definer; //{{{ FactorWord constructor - public FactorWord(String vocabulary, String name) + public FactorWord(VocabularyLookup lookup, + String vocabulary, String name) { + this.lookup = lookup; this.vocabulary = vocabulary; this.name = name; } //}}} @@ -65,7 +69,7 @@ public class FactorWord extends FactorArtifact implements FactorExternalizable public FactorWord getDefiner() { if(definer == null) - return new FactorWord(null,"DEFER:"); + return new FactorWord(lookup,null,"DEFER:"); else return definer; } //}}} @@ -87,4 +91,15 @@ public class FactorWord extends FactorArtifact implements FactorExternalizable { return FactorWordRenderer.getWordHTMLString(this,false); } //}}} + + //{{{ forget() method + public void forget() + { + /* Not allowed to forget parsing words, since that confuses our + parser */ + if(parsing != null) + return; + + lookup.forget(this); + } //}}} } diff --git a/factor/jedit/FactorSideKickParser.java b/factor/jedit/FactorSideKickParser.java index 895cc5ee20..0a9f4e8833 100644 --- a/factor/jedit/FactorSideKickParser.java +++ b/factor/jedit/FactorSideKickParser.java @@ -98,9 +98,9 @@ public class FactorSideKickParser extends SideKickParser public SideKickParsedData parse(Buffer buffer, DefaultErrorSource errorSource) { - Object words = buffer.getProperty(ARTIFACTS_PROPERTY); - if(words instanceof Cons) - forgetWords((Cons)words); + Object artifacts = buffer.getProperty(ARTIFACTS_PROPERTY); + if(artifacts instanceof Cons) + forgetArtifacts((Cons)artifacts); FactorParsedData d = new FactorParsedData( this,buffer.getPath()); @@ -157,17 +157,13 @@ public class FactorSideKickParser extends SideKickParser return d; } //}}} - //{{{ forgetWords() method - private void forgetWords(Cons words) + //{{{ forgetArtifacts() method + private void forgetArtifacts(Cons artifacts) { - while(words != null) + while(artifacts != null) { - FactorWord word = (FactorWord)words.car; - // We're not allowed to forget parsing words. - if(word.parsing != null) - return; - FactorPlugin.getExternalInstance().forget(word); - words = words.next(); + ((FactorArtifact)artifacts.car).forget(); + artifacts = artifacts.next(); } } //}}} diff --git a/library/assoc.factor b/library/assoc.factor index 713b8be1d7..81cef39def 100644 --- a/library/assoc.factor +++ b/library/assoc.factor @@ -11,14 +11,21 @@ IN: lists USING: kernel ; dup list? [ [ cons? ] all? ] [ drop f ] ifte ; : assoc* ( key alist -- [[ key value ]] ) - #! Looks up the key in an alist. Push the key/value pair. - #! Most of the time you want to use assoc not assoc*. + #! Look up a key/value pair. [ car = ] some-with? dup [ car ] when ; : assoc ( key alist -- value ) - #! Looks up the key in an alist. + #! Look up a value. assoc* dup [ cdr ] when ; +: assq* ( key alist -- [[ key value ]] ) + #! Looks up a key/value pair using identity comparison. + [ car eq? ] some-with? dup [ car ] when ; + +: assq ( key alist -- value ) + #! Looks up a key/value pair using identity comparison. + assq* dup [ cdr ] when ; + : remove-assoc ( key alist -- alist ) #! Remove all key/value pairs with this key. [ car = not ] subset-with ; diff --git a/library/bootstrap/boot-stage2.factor b/library/bootstrap/boot-stage2.factor index c5b793c6ea..bdfcf30a45 100644 --- a/library/bootstrap/boot-stage2.factor +++ b/library/bootstrap/boot-stage2.factor @@ -94,6 +94,7 @@ IN: alien : add-library 3drop ; "/library/tools/profiler.factor" "/library/tools/interpreter.factor" + "/library/inference/conditions.factor" "/library/inference/dataflow.factor" "/library/inference/inference.factor" "/library/inference/branches.factor" diff --git a/library/compiler/generator.factor b/library/compiler/generator.factor index 699826f3da..df2cac619b 100644 --- a/library/compiler/generator.factor +++ b/library/compiler/generator.factor @@ -1,41 +1,8 @@ -! :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: compiler -USE: assembler -USE: inference -USE: errors -USE: kernel -USE: lists -USE: math -USE: namespaces -USE: strings -USE: words -USE: vectors +USING: assembler inference errors kernel lists math namespaces +strings words vectors ; ! To support saving compiled code to disk, generator words ! append relocation instructions to this vector. diff --git a/library/compiler/linearizer.factor b/library/compiler/linearizer.factor index b1bf1574cc..e5b51acee4 100644 --- a/library/compiler/linearizer.factor +++ b/library/compiler/linearizer.factor @@ -1,41 +1,8 @@ -! :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: compiler -USE: inference -USE: kernel -USE: lists -USE: math -USE: namespaces -USE: words -USE: strings -USE: errors -USE: prettyprint -USE: kernel-internals +USING: inference kernel lists math namespaces words strings +errors prettyprint kernel-internals ; ! The linear IR is close to assembly language. It also resembles ! Forth code in some sense. It exists so that pattern matching @@ -49,6 +16,9 @@ SYMBOL: #push-indirect SYMBOL: #replace-immediate SYMBOL: #replace-indirect SYMBOL: #jump-t ( branch if top of stack is true ) +SYMBOL: #jump-t-label ( branch if top of stack is true ) +SYMBOL: #jump-f ( branch if top of stack is false ) +SYMBOL: #jump-f-label ( branch if top of stack is false ) SYMBOL: #jump ( tail-call ) SYMBOL: #jump-label ( tail-call ) SYMBOL: #return-to ( push addr on C stack ) @@ -133,7 +103,7 @@ SYMBOL: #end-dispatch #! The parameter is a list of two lists, each one a dataflow #! IR. 2unlist