fix 'extract word' putting stuff in the wrong place

cvs
Slava Pestov 2005-01-21 04:10:37 +00:00
parent 21ce71c4a4
commit 4154b4a2ac
11 changed files with 115 additions and 42 deletions

View File

@ -98,4 +98,12 @@
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>

View 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

View 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();

View File

@ -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();
} //}}}
}

View 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;
} //}}}
}

View File

@ -154,7 +154,8 @@ public class FactorPlugin extends EditPlugin
*/
public static void stopExternalInstance()
{
getFactorShell().closeStreams();
if(getFactorShell() != null)
getFactorShell().closeStreams();
if(external != null)
{

View 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

View 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:

View 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)
{

View 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 ;

View 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 [