From 4154b4a2acd8fc83d6973854fef7d4cad18289d1 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 21 Jan 2005 04:10:37 +0000 Subject: [PATCH] fix 'extract word' putting stuff in the wrong place --- actions.xml | 8 +++ examples/dejong.factor | 21 +++---- factor/FactorReader.java | 4 +- factor/jedit/CompileBufferProcessor.java | 70 ++++++++++++++++++++++++ factor/jedit/FactorBufferProcessor.java | 25 ++++----- factor/jedit/FactorPlugin.java | 3 +- factor/jedit/FactorPlugin.props | 8 ++- factor/jedit/FactorSideKickParser.java | 2 +- factor/jedit/InferBufferProcessor.java | 7 ++- library/sdl/sdl-ttf.factor | 6 +- library/tools/jedit.factor | 3 - 11 files changed, 115 insertions(+), 42 deletions(-) create mode 100644 factor/jedit/CompileBufferProcessor.java diff --git a/actions.xml b/actions.xml index 5f787210a1..b70bc9b67c 100644 --- a/actions.xml +++ b/actions.xml @@ -98,4 +98,12 @@ FactorPlugin.getExternalInstance()); + + + wm.showDockableWindow("console"); + CompileBufferProcessor.compileWordsInBuffer(view,buffer, + FactorPlugin.getExternalInstance(), + wm.getDockableWindow("console")); + + diff --git a/examples/dejong.factor b/examples/dejong.factor index ecb1967da9..6d3313e1c8 100644 --- a/examples/dejong.factor +++ b/examples/dejong.factor @@ -4,7 +4,7 @@ ! ! ./f boot.image.le32 ! -libraries:sdl:name=libSDL.so -! -libraries:sdl-gfx:name=libSDL_gfx. +! -libraries:sdl-gfx:name=libSDL_gfx.so ! ! (But all on one line) ! @@ -36,9 +36,6 @@ SYMBOL: d : next-x ( x y -- x ) a get * sin swap b get * cos - ; : next-y ( x y -- y ) swap c get * sin swap d get * cos - ; -: white ( -- rgb ) - HEX: ffffffff ; - : pixel ( #{ x y }# color -- ) >r >r surface get r> >rect r> pixelColor ; @@ -52,20 +49,20 @@ SYMBOL: d : draw-dejong ( x0 y0 iterations -- ) [ iterate-dejong 2dup scale-dejong rect> white pixel - ] times 2drop ; + ] times 2drop ; compiled : dejong ( -- ) ! Fiddle with these four values! - 1.4 a set - -2.3 b set - 2.4 c set + 1.0 a set + -1.3 b set + 0.8 c set -2.1 d set - 640 480 32 SDL_HWSURFACE [ - [ 0 0 100000 draw-dejong ] with-surface + 1024 768 0 SDL_HWSURFACE [ + [ 0 0 200000 [ draw-dejong ] time ] with-surface event-loop SDL_Quit - ] with-screen ; compiled + ] with-screen ; -[ dejong ] time +dejong diff --git a/factor/FactorReader.java b/factor/FactorReader.java index db5f6e31a5..88be4656d9 100644 --- a/factor/FactorReader.java +++ b/factor/FactorReader.java @@ -241,10 +241,7 @@ public class FactorReader FactorWord word; if(define) - { word = lookup.define(getIn(),name); - definedWords = new Cons(word,definedWords); - } else { word = searchVocabulary(getUse(),name); @@ -283,6 +280,7 @@ 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(); diff --git a/factor/jedit/CompileBufferProcessor.java b/factor/jedit/CompileBufferProcessor.java new file mode 100644 index 0000000000..36f5f3d0d0 --- /dev/null +++ b/factor/jedit/CompileBufferProcessor.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.jedit; + +import console.Output; +import factor.*; +import java.io.IOException; +import java.util.*; +import org.gjt.sp.jedit.*; +import org.gjt.sp.util.*; + +public class CompileBufferProcessor extends FactorBufferProcessor +{ + //{{{ compileWordsInBuffer() method + public static void compileWordsInBuffer(View view, + Buffer buffer, + ExternalFactor factor, + Output output) throws Exception + { + String results = new CompileBufferProcessor( + buffer,factor).getResults(); + output.print(null,results); + } //}}} + + //{{{ CompileBufferProcessor constructor + public CompileBufferProcessor(Buffer buffer, ExternalFactor factor) + throws Exception + { + super(buffer,factor); + } //}}} + + //{{{ processWord() method + /** + * @return Code to process the word. + */ + public String processWord(FactorWord word) + { + StringBuffer expression = new StringBuffer(); + expression.append(FactorPlugin.factorWord(word)); + expression.append(" try-compile"); + return expression.toString(); + } //}}} +} diff --git a/factor/jedit/FactorBufferProcessor.java b/factor/jedit/FactorBufferProcessor.java index 9c85a9f82e..9333c6e976 100644 --- a/factor/jedit/FactorBufferProcessor.java +++ b/factor/jedit/FactorBufferProcessor.java @@ -30,8 +30,6 @@ package factor.jedit; import factor.*; -import java.io.IOException; -import java.util.*; import org.gjt.sp.jedit.Buffer; /** @@ -40,13 +38,13 @@ import org.gjt.sp.jedit.Buffer; */ public abstract class FactorBufferProcessor { - private LinkedHashMap results; + private String results; //{{{ FactorBufferProcessor constructor public FactorBufferProcessor(Buffer buffer, ExternalFactor factor) throws Exception { - results = new LinkedHashMap(); + StringBuffer buf = new StringBuffer(); Cons words = (Cons)buffer.getProperty( FactorSideKickParser.WORDS_PROPERTY); @@ -55,10 +53,14 @@ public abstract class FactorBufferProcessor { FactorWord word = (FactorWord)words.car; String expr = processWord(word); - System.err.println(expr); - results.put(word,factor.eval(expr)); + buf.append("! "); + buf.append(expr); + buf.append('\n'); + buf.append(factor.eval(expr)); words = words.next(); } + + results = buf.toString(); } //}}} /** @@ -66,14 +68,9 @@ public abstract class FactorBufferProcessor */ public abstract String processWord(FactorWord word); - //{{{ insertResults() method - public void insertResults(Buffer buffer, int offset) - throws Exception + //{{{ getResults() method + public String getResults() { - StringBuffer result = new StringBuffer(); - Iterator iter = results.values().iterator(); - while(iter.hasNext()) - result.append(iter.next()); - buffer.insert(offset,result.toString().trim()); + return results; } //}}} } diff --git a/factor/jedit/FactorPlugin.java b/factor/jedit/FactorPlugin.java index 97f2a49185..67c4791adc 100644 --- a/factor/jedit/FactorPlugin.java +++ b/factor/jedit/FactorPlugin.java @@ -154,7 +154,8 @@ public class FactorPlugin extends EditPlugin */ public static void stopExternalInstance() { - getFactorShell().closeStreams(); + if(getFactorShell() != null) + getFactorShell().closeStreams(); if(external != null) { diff --git a/factor/jedit/FactorPlugin.props b/factor/jedit/FactorPlugin.props index 19aa62262c..f23e301970 100644 --- a/factor/jedit/FactorPlugin.props +++ b/factor/jedit/FactorPlugin.props @@ -30,10 +30,11 @@ plugin.factor.jedit.FactorPlugin.menu=factor-listener \ factor-extract-word \ - \ factor-infer-effect \ - factor-compile \ - - \ factor-infer-effects \ - \ + factor-compile \ + factor-compile-all \ + - \ factor-restart factor-listener.label=Listener @@ -47,8 +48,9 @@ factor-edit-dialog.label=Edit word... factor-usages.label=Word usages at caret factor-extract-word.label=Extract word... factor-infer-effect.label=Infer word at caret -factor-compile.label=Compile word at caret factor-infer-effects.label=Infer all words in buffer +factor-compile.label=Compile word at caret +factor-compile-all.label=Compile all words in buffer factor-restart.label=Restart Factor # SideKick stuff diff --git a/factor/jedit/FactorSideKickParser.java b/factor/jedit/FactorSideKickParser.java index 8afd403d1a..95d54fcfb6 100644 --- a/factor/jedit/FactorSideKickParser.java +++ b/factor/jedit/FactorSideKickParser.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: diff --git a/factor/jedit/InferBufferProcessor.java b/factor/jedit/InferBufferProcessor.java index cfc266fcec..f1042ae5ce 100644 --- a/factor/jedit/InferBufferProcessor.java +++ b/factor/jedit/InferBufferProcessor.java @@ -46,7 +46,11 @@ public class InferBufferProcessor extends FactorBufferProcessor public static void createInferUnitTests(View view, final Buffer buffer, final ExternalFactor factor) + throws Exception { + final String results = new InferBufferProcessor(buffer,factor) + .getResults(); + final Buffer newBuffer = jEdit.newFile(view); VFSManager.runInAWTThread(new Runnable() { @@ -55,8 +59,7 @@ public class InferBufferProcessor extends FactorBufferProcessor newBuffer.setMode("factor"); try { - new InferBufferProcessor(buffer,factor) - .insertResults(newBuffer,0); + newBuffer.insert(0,results); } catch(Exception e) { diff --git a/library/sdl/sdl-ttf.factor b/library/sdl/sdl-ttf.factor index 068317171b..3961b0b0d8 100644 --- a/library/sdl/sdl-ttf.factor +++ b/library/sdl/sdl-ttf.factor @@ -1,4 +1,4 @@ -! :folding=indent:collapseFolds=1:sidekick.parser=none: +! :folding=indent:collapseFolds=1: ! $Id$ ! @@ -78,8 +78,8 @@ USE: alien : TTF_FontFaceStyleName ( font -- n ) "char*" "sdl-ttf" "TTF_FontFaceStyleName" [ "void*" ] alien-invoke ; -: TTF_RenderText_Solid ( font text fg bg -- surface ) - "surface*" "sdl-ttf" "TTF_RenderText_Solid" [ "void*" "char*" "int" "int" ] alien-invoke ; +: TTF_RenderText_Solid ( font text fg -- surface ) + "surface*" "sdl-ttf" "TTF_RenderText_Solid" [ "void*" "char*" "int" ] alien-invoke ; : TTF_RenderGlyph_Shaded ( font text fg bg -- surface ) "surface*" "sdl-ttf" "TTF_RenderGlyph_Shaded" [ "void*" "ushort" "int" "int" ] alien-invoke ; diff --git a/library/tools/jedit.factor b/library/tools/jedit.factor index 2e5603075e..39ee372a61 100644 --- a/library/tools/jedit.factor +++ b/library/tools/jedit.factor @@ -83,9 +83,6 @@ USE: words "newPlainView" off ] extend make-jedit-request send-jedit-request ; -: resource-path ( -- path ) - global [ "resource-path" get ] bind [ "." ] unless* ; - : word-file ( path -- dir file ) dup [ "resource:/" ?str-head [