diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index b6659bb1fb..85f562ed45 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -3,18 +3,14 @@ - update plugin docs - word preview for remote words - faster completion - - [ [ dup call ] dup call ] infer hangs - 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 -- extract word inside M:, C:, and structure browsing for these -- fix completion invoke in middle of word - don't hardcode so many colors - ffi unicode strings: null char security hole - utf16 string boxing diff --git a/factor/DefaultVocabularyLookup.java b/factor/DefaultVocabularyLookup.java index a1e7c7f3bf..3ce94fccff 100644 --- a/factor/DefaultVocabularyLookup.java +++ b/factor/DefaultVocabularyLookup.java @@ -50,11 +50,11 @@ public class DefaultVocabularyLookup implements VocabularyLookup /* comments */ FactorWord lineComment = define("syntax","!"); - lineComment.parsing = new LineComment(lineComment,false); + lineComment.parsing = new LineComment(lineComment); FactorWord stackComment = define("syntax","("); stackComment.parsing = new StackComment(stackComment); FactorWord docComment = define("syntax","#!"); - docComment.parsing = new LineComment(docComment,true); + docComment.parsing = new LineComment(docComment); /* strings */ FactorWord str = define("syntax","\""); @@ -91,7 +91,6 @@ public class DefaultVocabularyLookup implements VocabularyLookup /* word defs */ FactorWord def = define("syntax",":"); def.parsing = new Def(def); - def.docComment = true; FactorWord ine = define("syntax",";"); ine.parsing = new Ine(ine); FactorWord symbol = define("syntax","SYMBOL:"); diff --git a/factor/FactorArtifact.java b/factor/FactorArtifact.java new file mode 100644 index 0000000000..6399028b1d --- /dev/null +++ b/factor/FactorArtifact.java @@ -0,0 +1,70 @@ +/* :folding=explicit:collapseFolds=1: */ + +/* + * $Id$ + * + * Copyright (C) 2005 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. + */ + +package factor; + +public abstract class FactorArtifact +{ + private String file; + private int line; + private int col; + + public String getFile() + { + return file; + } + + public void setFile(String file) + { + this.file = file; + } + + public int getLine() + { + return line; + } + + public void setLine(int line) + { + this.line = line; + } + + public int getColumn() + { + return col; + } + + public void setColumn(int column) + { + this.col = col; + } + + public abstract String getShortString(); + public abstract String getLongString(); +} diff --git a/factor/FactorReader.java b/factor/FactorReader.java index 49bb1453c2..20a6f8e49b 100644 --- a/factor/FactorReader.java +++ b/factor/FactorReader.java @@ -53,7 +53,7 @@ public class FactorReader private String in; private int base = 10; - private Cons definedWords; + private Cons artifacts; //{{{ getUnreadableString() method public static String getUnreadableString(String str) @@ -254,10 +254,16 @@ public class FactorReader return word; } //}}} - //{{{ getDefinedWords() method - public Cons getDefinedWords() + //{{{ getArtifacts() method + public Cons getArtifacts() { - return Cons.reverse(definedWords); + return Cons.reverse(artifacts); + } //}}} + + //{{{ addArtifact() method + public void addArtifact(FactorArtifact artifact) + { + artifacts = new Cons(artifact,artifacts); } //}}} //{{{ nextWord() method @@ -282,10 +288,10 @@ public class FactorReader FactorWord w = intern((String)next,define); if(define && w != null) { - definedWords = new Cons(w,definedWords); - w.line = line; - w.col = col; - w.file = scanner.getFileName(); + artifacts = new Cons(w,artifacts); + w.setFile(scanner.getFileName()); + w.setLine(line); + w.setColumn(col); w.stackEffect = null; w.documentation = null; } @@ -416,21 +422,6 @@ public class FactorReader getCurrentState().setStackComment(comment); } //}}} - //{{{ addDocComment() method - public void addDocComment(String comment) - { - getCurrentState().addDocComment(comment); - } //}}} - - //{{{ bar() method - /** - * Sets the current parser state's cdr to the given object. - */ - public void bar() throws FactorParseException - { - getCurrentState().bar(); - } //}}} - //{{{ error() method public void error(String msg) throws FactorParseException { @@ -444,35 +435,21 @@ public class FactorReader public FactorWord defining; public Cons first; public Cons last; - private boolean bar; - private boolean docComment; ParseState(FactorWord start, FactorWord defining) { - docComment = start.docComment; this.start = start; this.defining = defining; } void append(Object obj) throws FactorParseException { - docComment = false; - - if(bar) - { - if(last.cdr != null) - scanner.error("Only one token allowed after |"); - last.cdr = obj; - } + Cons next = new Cons(obj,null); + if(first == null) + first = next; else - { - Cons next = new Cons(obj,null); - if(first == null) - first = next; - else - last.cdr = next; - last = next; - } + last.cdr = next; + last = next; } void setStackComment(String comment) @@ -480,32 +457,5 @@ public class FactorReader if(defining != null && defining.stackEffect == null) defining.stackEffect = comment; } - - void addDocComment(String comment) - { - if(defining != null && (docComment || alwaysDocComments)) - { - if(defining.documentation == null) - defining.documentation = comment; - else - { - /* Its O(n^2). Big deal. */ - defining.documentation = defining.documentation - .concat(comment); - } - } - } - - void bar() throws FactorParseException - { - if(last.cdr != null) - { - // We already read [ a | b - // no more can be appended to this state. - scanner.error("Only one token allowed after |"); - } - - bar = true; - } } //}}} } diff --git a/factor/FactorWord.java b/factor/FactorWord.java index 2186683111..887eaaefdf 100644 --- a/factor/FactorWord.java +++ b/factor/FactorWord.java @@ -29,7 +29,9 @@ package factor; -public class FactorWord implements FactorExternalizable +import factor.jedit.FactorWordRenderer; + +public class FactorWord extends FactorArtifact implements FactorExternalizable { public String vocabulary; public String name; @@ -46,18 +48,6 @@ public class FactorWord implements FactorExternalizable */ private FactorWord definer; - /** - * Should the parser keep doc comments? - */ - public boolean docComment; - - /** - * For text editor integration. - */ - public String file; - public int line; - public int col; - //{{{ FactorWord constructor public FactorWord(String vocabulary, String name) { @@ -85,4 +75,16 @@ public class FactorWord implements FactorExternalizable { this.definer = definer; } //}}} + + //{{{ getShortString() method + public String getShortString() + { + return name; + } //}}} + + //{{{ getLongString() method + public String getLongString() + { + return FactorWordRenderer.getWordHTMLString(this,false); + } //}}} } diff --git a/factor/MethodArtifact.java b/factor/MethodArtifact.java new file mode 100644 index 0000000000..8a0066b56a --- /dev/null +++ b/factor/MethodArtifact.java @@ -0,0 +1,60 @@ +/* :folding=explicit:collapseFolds=1: */ + +/* + * $Id$ + * + * Copyright (C) 2005 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. + */ + +package factor; + +import factor.jedit.FactorWordRenderer; +import org.gjt.sp.jedit.jEdit; + +public class MethodArtifact extends FactorArtifact + implements FactorExternalizable +{ + private FactorWord type; + private FactorWord generic; + + //{{{ MethodArtifact constructor + public MethodArtifact(FactorWord type, FactorWord generic) + { + this.type = type; + this.generic = generic; + } //}}} + + //{{{ getShortString() method + public String getShortString() + { + return type.name + " " + generic.name; + } //}}} + + //{{{ getLongString() method + public String getLongString() + { + return jEdit.getProperty("factor.completion.method", + new String[] { type.name, generic.name }); + } //}}} +} diff --git a/factor/jedit/FactorAsset.java b/factor/jedit/FactorAsset.java index d426c9d441..115d431da8 100644 --- a/factor/jedit/FactorAsset.java +++ b/factor/jedit/FactorAsset.java @@ -29,7 +29,7 @@ package factor.jedit; -import factor.FactorWord; +import factor.*; import javax.swing.Icon; import javax.swing.text.Position; import org.gjt.sp.jedit.Buffer; @@ -37,12 +37,12 @@ import sidekick.*; public class FactorAsset extends Asset { - private FactorWord word; + private FactorArtifact artifact; - public FactorAsset(FactorWord word, Position start) + public FactorAsset(FactorArtifact artifact, Position start) { - super(word.name); - this.word = word; + super(artifact.getShortString()); + this.artifact = artifact; this.start = start; } @@ -53,11 +53,11 @@ public class FactorAsset extends Asset public String getShortString() { - return word.name; + return artifact.getShortString(); } public String getLongString() { - return FactorWordRenderer.getWordHTMLString(word,false); + return artifact.getLongString(); } } diff --git a/factor/jedit/FactorBufferProcessor.java b/factor/jedit/FactorBufferProcessor.java index 961586c208..348ab0fc8a 100644 --- a/factor/jedit/FactorBufferProcessor.java +++ b/factor/jedit/FactorBufferProcessor.java @@ -48,7 +48,7 @@ public abstract class FactorBufferProcessor StringBuffer buf = new StringBuffer(); Cons words = (Cons)buffer.getProperty( - FactorSideKickParser.WORDS_PROPERTY); + FactorSideKickParser.ARTIFACTS_PROPERTY); Cons wordCodeMap = null; while(words != null) { diff --git a/factor/jedit/FactorPlugin.java b/factor/jedit/FactorPlugin.java index c66ce9e4e2..2c309ed68b 100644 --- a/factor/jedit/FactorPlugin.java +++ b/factor/jedit/FactorPlugin.java @@ -3,7 +3,7 @@ /* * $Id$ * - * Copyright (C) 2004 Slava Pestov. + * Copyright (C) 2004, 2005 Slava Pestov. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -80,7 +80,7 @@ public class FactorPlugin extends EditPlugin Buffer buffer = jEdit.getFirstBuffer(); while(buffer != null) { - buffer.setProperty(FactorSideKickParser.WORDS_PROPERTY,null); + buffer.setProperty(FactorSideKickParser.ARTIFACTS_PROPERTY,null); buffer = buffer.getNext(); } } //}}} @@ -681,6 +681,7 @@ public class FactorPlugin extends EditPlugin buffer.indentLines(firstLine,lastLine); textArea.setSelectedText(newWord); + buffer.indentLine(textArea.getCaretLine(),true); } finally { diff --git a/factor/jedit/FactorPlugin.props b/factor/jedit/FactorPlugin.props index 19c7225f67..9b1cf9b0b0 100644 --- a/factor/jedit/FactorPlugin.props +++ b/factor/jedit/FactorPlugin.props @@ -60,6 +60,8 @@ mode.factor.sidekick.parser=factor factor.completion.in=IN: {0}\ factor.completion.def={0} {1} factor.completion.stack={0} ( {1}) +factor.completion.method=M: {0} {1} +factor.completion.constructor=C: {0} # Dialog boxes factor.status.inserted-use=Using {0} diff --git a/factor/jedit/FactorSideKickParser.java b/factor/jedit/FactorSideKickParser.java index 0b48708959..895cc5ee20 100644 --- a/factor/jedit/FactorSideKickParser.java +++ b/factor/jedit/FactorSideKickParser.java @@ -43,7 +43,7 @@ public class FactorSideKickParser extends SideKickParser /** * We store the file's parse tree in this property. */ - public static String WORDS_PROPERTY = "factor-parsed"; + public static String ARTIFACTS_PROPERTY = "factor-parsed"; private Map previewMap; @@ -98,7 +98,7 @@ public class FactorSideKickParser extends SideKickParser public SideKickParsedData parse(Buffer buffer, DefaultErrorSource errorSource) { - Object words = buffer.getProperty(WORDS_PROPERTY); + Object words = buffer.getProperty(ARTIFACTS_PROPERTY); if(words instanceof Cons) forgetWords((Cons)words); @@ -135,7 +135,7 @@ public class FactorSideKickParser extends SideKickParser d.in = r.getIn(); d.use = r.getUse(); - addWordDefNodes(d,r.getDefinedWords(),buffer); + addArtifactNodes(d,r.getArtifacts(),buffer); } catch(FactorParseException pe) { @@ -152,7 +152,7 @@ public class FactorSideKickParser extends SideKickParser } if(r != null) - buffer.setProperty(WORDS_PROPERTY,r.getDefinedWords()); + buffer.setProperty(ARTIFACTS_PROPERTY,r.getArtifacts()); return d; } //}}} @@ -171,21 +171,24 @@ public class FactorSideKickParser extends SideKickParser } } //}}} - //{{{ addWordDefNodes() method - private void addWordDefNodes(FactorParsedData d, Cons words, Buffer buffer) + //{{{ addArtifactNodes() method + private void addArtifactNodes(FactorParsedData d, Cons artifacts, Buffer buffer) { FactorAsset last = null; - while(words != null) + while(artifacts != null) { - FactorWord word = (FactorWord)words.car; + FactorArtifact artifact = (FactorArtifact)artifacts.car; - /* word lines are indexed from 1 */ - int startLine = Math.max(0,Math.min( + /* artifact lines are indexed from 1 */ + int startLine = artifact.getLine(); + startLine = Math.max(0,Math.min( buffer.getLineCount() - 1, - word.line - 1)); + startLine - 1)); int startLineLength = buffer.getLineLength(startLine); - int startCol = Math.min(word.col,startLineLength); + + int startCol = artifact.getColumn(); + startCol = Math.min(startCol,startLineLength); int start = buffer.getLineStartOffset(startLine) + startCol; @@ -193,10 +196,10 @@ public class FactorSideKickParser extends SideKickParser if(last != null) last.end = buffer.createPosition(Math.max(0,start - 1)); - last = new FactorAsset(word,buffer.createPosition(start)); + last = new FactorAsset(artifact,buffer.createPosition(start)); d.root.add(new DefaultMutableTreeNode(last)); - words = words.next(); + artifacts = artifacts.next(); } if(last != null) @@ -264,13 +267,13 @@ public class FactorSideKickParser extends SideKickParser String text = buffer.getText(lineStart,caret - lineStart); /* Don't complete in the middle of a word */ - int lineEnd = buffer.getLineEndOffset(caretLine) - 1; + /* int lineEnd = buffer.getLineEndOffset(caretLine) - 1; if(caret != lineEnd) { String end = buffer.getText(caret,lineEnd - caret); if(!isWhitespace(end.charAt(0))) return null; - } + } */ int wordStart = 0; for(int i = text.length() - 1; i >= 0; i--) diff --git a/factor/parser/BeginConstructor.java b/factor/parser/BeginConstructor.java index 17f9f1697c..a04d920d31 100644 --- a/factor/parser/BeginConstructor.java +++ b/factor/parser/BeginConstructor.java @@ -46,7 +46,7 @@ public class BeginConstructor extends FactorParsingDefinition return; reader.intern("<" + type + ">",true); - + reader.addArtifact(new ConstructorArtifact(type)); reader.pushExclusiveState(word,type); } } diff --git a/factor/parser/BeginMethod.java b/factor/parser/BeginMethod.java index 776fb44db0..29969768a8 100644 --- a/factor/parser/BeginMethod.java +++ b/factor/parser/BeginMethod.java @@ -41,14 +41,24 @@ public class BeginMethod extends FactorParsingDefinition public void eval(FactorReader reader) throws Exception { + // remember the position before the word name + FactorScanner scanner = reader.getScanner(); + int line = scanner.getLineNumber(); + int col = scanner.getColumnNumber(); + FactorWord type = reader.nextWord(false); if(type == null) return; - FactorWord newWord = reader.nextWord(false); - if(newWord == null) + FactorWord generic = reader.nextWord(false); + if(generic == null) return; - reader.pushExclusiveState(word,newWord); + MethodArtifact artifact = new MethodArtifact(type,generic); + artifact.setFile(scanner.getFileName()); + artifact.setLine(line); + artifact.setColumn(col); + reader.addArtifact(artifact); + reader.pushExclusiveState(word,generic); } } diff --git a/factor/parser/LineComment.java b/factor/parser/LineComment.java index edddc6c3dc..2b6822b805 100644 --- a/factor/parser/LineComment.java +++ b/factor/parser/LineComment.java @@ -34,23 +34,18 @@ import java.io.IOException; public class LineComment extends FactorParsingDefinition { - public boolean doc; - //{{{ LineComment constructor /** * A new definition. */ - public LineComment(FactorWord word, boolean doc) + public LineComment(FactorWord word) { super(word); - this.doc = doc; } //}}} public void eval(FactorReader reader) throws IOException, FactorParseException { String comment = reader.getScanner().readUntilEOL(); - if(doc) - reader.addDocComment(comment); } } diff --git a/library/generic/complement.factor b/library/generic/complement.factor index 67e144243b..2c56339f87 100644 --- a/library/generic/complement.factor +++ b/library/generic/complement.factor @@ -35,7 +35,7 @@ complement [ : complement-predicate ( complement -- list ) "predicate" word-property [ not ] append ; -: define-complement ( class predicate complement -- ) - [ complement-predicate define-compound ] keep - dupd "complement" set-word-property +: define-complement ( class complement -- ) + 2dup "complement" set-word-property + dupd complement-predicate "predicate" set-word-property complement define-class ; diff --git a/library/syntax/generic.factor b/library/syntax/generic.factor index a79466fe3e..741854840a 100644 --- a/library/syntax/generic.factor +++ b/library/syntax/generic.factor @@ -23,12 +23,10 @@ USING: syntax generic kernel lists namespaces parser words ; #! Syntax: BUILTIN: ; CREATE scan-word [ builtin-class ] [ ] ; parsing -: COMPLEMENT: ( -- class predicate definition ) +: COMPLEMENT: ( -- ) #! Followed by a class name, then a complemented class. CREATE dup intern-symbol - dup predicate-word - [ dupd unit "predicate" set-word-property ] keep scan-word define-complement ; parsing : UNION: ( -- class predicate definition ) diff --git a/library/tools/memory.factor b/library/tools/memory.factor index f7f5143f6c..8ebf1c6b2e 100644 --- a/library/tools/memory.factor +++ b/library/tools/memory.factor @@ -26,7 +26,7 @@ namespaces prettyprint stdio unparser vectors words ; swap dup slip (each-object) ] [ 2drop - ] ifte ; inline + ] ifte ; : each-object ( quot -- ) #! Applies the quotation to each object in the image. @@ -34,7 +34,7 @@ namespaces prettyprint stdio unparser vectors words ; begin-scan (each-object) ] [ end-scan rethrow - ] catch ; inline + ] catch ; : instances ( quot -- list ) #! Return a list of all object that return true when the