]> gitweb.factorcode.org Git - factor.git/commitdiff
fix 'extract word' putting stuff in the wrong place
authorSlava Pestov <slava@factorcode.org>
Fri, 21 Jan 2005 04:10:37 +0000 (04:10 +0000)
committerSlava Pestov <slava@factorcode.org>
Fri, 21 Jan 2005 04:10:37 +0000 (04:10 +0000)
actions.xml
examples/dejong.factor
factor/FactorReader.java
factor/jedit/CompileBufferProcessor.java [new file with mode: 0644]
factor/jedit/FactorBufferProcessor.java
factor/jedit/FactorPlugin.java
factor/jedit/FactorPlugin.props
factor/jedit/FactorSideKickParser.java
factor/jedit/InferBufferProcessor.java
library/sdl/sdl-ttf.factor
library/tools/jedit.factor

index 5f787210a127c251b16ba6a74f5c6520a6f0ea74..b70bc9b67c285924c6d69bdc132ac1738a206bfc 100644 (file)
                                FactorPlugin.getExternalInstance());
                </CODE>
        </ACTION>
+       <ACTION NAME="factor-compile-all">
+               <CODE>
+                       wm.showDockableWindow("console");
+                       CompileBufferProcessor.compileWordsInBuffer(view,buffer,
+                               FactorPlugin.getExternalInstance(),
+                               wm.getDockableWindow("console"));
+               </CODE>
+       </ACTION>
 </ACTIONS>
index ecb1967da9f653fd53459296717bf72052dd8f5d..6d3313e1c8b5de7dd20a5c519540c793d9056d7f 100644 (file)
@@ -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> event-loop
         SDL_Quit
-    ] with-screen ; compiled
+    ] with-screen ;
 
-[ dejong ] time
+dejong
index db5f6e31a570d9225c7bb960affae4a72349f45c..88be4656d9d2f90b8e876aefd6d2fa1bf62fad3f 100644 (file)
@@ -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 (file)
index 0000000..36f5f3d
--- /dev/null
@@ -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();
+       } //}}}
+}
index 9c85a9f82e48142c0c778f66290dab38ad3e2e4c..9333c6e976689316697448c98c2c9c76095df832 100644 (file)
@@ -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;
        } //}}}
 }
index 97f2a491857fbf3e2fd3ed572e4ff96717434fcc..67c4791adc3ada681af775c5d1d58709ce8ded5a 100644 (file)
@@ -154,7 +154,8 @@ public class FactorPlugin extends EditPlugin
         */
        public static void stopExternalInstance()
        {
-               getFactorShell().closeStreams();
+               if(getFactorShell() != null)
+                       getFactorShell().closeStreams();
 
                if(external != null)
                {
index 19aa62262c894d9d0a23d0ce7cc0d7dd61d14a92..f23e30197081d358e38dc9676a6260b746abcad6 100644 (file)
@@ -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
index 8afd403d1aa9d7241bd60754fbd58df85d7854a4..95d54fcfb6ed1a730c4c7b585a8f9847c5fa49e5 100644 (file)
@@ -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:
index cfc266fcecb9ee4e62a5c7b951eec0babbe4f17a..f1042ae5ce236301c7513960a986137e6b1c99c5 100644 (file)
@@ -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)
                                {
index 068317171ba4c2f5f30999ae32cfaf10615b3805..3961b0b0d84f84d6f16dc04d29b5e6d6aea1bf8a 100644 (file)
@@ -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 ;
index 2e5603075e7601f3db47d62f8a2be53573e2c995..39ee372a61a022e7437e6b22c0dc8f9f746c79dd 100644 (file)
@@ -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 [