\r
- inferior hangs\r
- plugin should not exit jEdit on fatal errors\r
-- auto insert USE:\r
- balance needs USE:\r
- fedit broken with listener\r
- maple-like: press enter at old commands to evaluate there\r
</ACTION>
<ACTION NAME="factor-balance">
<CODE>
- if(textArea.selectedText == null)
+ if(textArea.selectionCount == 0)
textArea.toolkit.beep();
else
{
}
</CODE>
</ACTION>
+ <ACTION NAME="factor-insert-use">
+ <CODE>
+ if(textArea.selectionCount == 0)
+ textArea.selectWord();
+ factor.jedit.FactorPlugin.insertUseDialog(view,
+ textArea.selectedText);
+ </CODE>
+ </ACTION>
</ACTIONS>
* Cloning constructor.
*/
public FactorNamespace(Map words, Object obj)
- throws Exception
{
this.words = new TreeMap();
} //}}}
//{{{ isDefined() method
- public synchronized boolean isDefined(String name) throws Exception
+ public synchronized boolean isDefined(String name)
{
Object o = words.get(name);
if(o instanceof VarBinding)
} //}}}
//{{{ getVariable() method
- public synchronized Object getVariable(String name) throws Exception
+ public synchronized Object getVariable(String name)
{
Object o = words.get(name);
if(o instanceof VarBinding)
//{{{ setVariable() method
public synchronized void setVariable(String name, Object value)
- throws Exception
{
if(name == null)
throw new NullPointerException();
if(!constraint.isAssignableFrom(
value.getClass()))
{
- throw new FactorRuntimeException(
+ throw new RuntimeException(
"Can only store "
+ constraint
+ " in " + this);
/**
* Returns a list of variable values.
*/
- public synchronized Cons toValueList() throws Exception
+ public synchronized Cons toValueList()
{
initAllFields();
/**
* Returns a list of pairs of variable names, and their values.
*/
- public synchronized Cons toVarValueList() throws Exception
+ public synchronized Cons toVarValueList()
{
initAllFields();
this.instance = instance;
}
- public Object get() throws Exception
+ public Object get()
{
- return FactorJava.convertFromJavaType(
- field.get(instance));
+ try
+ {
+ return FactorJava.convertFromJavaType(
+ field.get(instance));
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException(e);
+ }
}
- public void set(Object value) throws Exception
+ public void set(Object value)
{
- field.set(instance,FactorJava.convertToJavaType(
- value,field.getType()));
+ try
+ {
+ field.set(instance,FactorJava.convertToJavaType(
+ value,field.getType()));
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException(e);
+ }
}
} //}}}
public ListCellRenderer getRenderer()
{
- return new FactorWordRenderer(FactorPlugin.getInterpreter());
+ return new FactorWordRenderer(
+ FactorPlugin.getInterpreter(),
+ false);
}
}
package factor.jedit;
import factor.listener.FactorListenerPanel;
-import factor.FactorInterpreter;
+import factor.*;
import java.io.InputStreamReader;
+import java.util.ArrayList;
import org.gjt.sp.jedit.gui.*;
+import org.gjt.sp.jedit.textarea.*;
import org.gjt.sp.jedit.*;
+import sidekick.*;
public class FactorPlugin extends EditPlugin
{
wm.getDockableWindow(DOCKABLE_NAME);
panel.getListener().eval(cmd);
} //}}}
+
+ //{{{ getWordAtCaret() method
+ public static String getWordAtCaret(JEditTextArea textArea)
+ {
+ if(textArea.getSelectionCount() != 0)
+ return textArea.getSelectedText();
+
+ String line = textArea.getLineText(textArea.getCaretLine());
+ if(line.length() == 0)
+ return null;
+
+ int caret = textArea.getCaretPosition()
+ - textArea.getLineStartOffset(
+ textArea.getCaretLine());
+ String noWordSep = textArea.getBuffer().getStringProperty(
+ "noWordSep");
+ int wordStart = TextUtilities.findWordStart(line,caret,
+ noWordSep);
+ int wordEnd = TextUtilities.findWordEnd(line,caret,
+ noWordSep);
+ return line.substring(wordStart,wordEnd);
+ } //}}}
+
+ //{{{ showStatus() method
+ public static void showStatus(View view, String msg, String arg)
+ {
+ view.getStatus().setMessage(
+ jEdit.getProperty("factor.status." + msg,
+ new String[] { arg }));
+ } //}}}
+
+ //{{{ isUsed() method
+ private static boolean isUsed(View view, String vocab)
+ {
+ SideKickParsedData data = SideKickParsedData
+ .getParsedData(view);
+ if(data instanceof FactorParsedData)
+ {
+ FactorParsedData fdata = (FactorParsedData)data;
+ Cons use = fdata.use;
+ return Cons.contains(use,vocab);
+ }
+ else
+ return false;
+ } //}}}
+
+ //{{{ findAllWordsNamed() method
+ private static FactorWord[] findAllWordsNamed(View view, String word)
+ {
+ ArrayList words = new ArrayList();
+ Cons vocabs = getInterpreter().vocabularies.toValueList();
+ while(vocabs != null)
+ {
+ FactorNamespace vocab = (FactorNamespace)vocabs.car;
+ FactorWord w = (FactorWord)vocab.getVariable(word);
+ if(w != null)
+ words.add(w);
+ vocabs = vocabs.next();
+ }
+ return (FactorWord[])words.toArray(
+ new FactorWord[words.size()]);
+ } //}}}
+
+ //{{{ insertUseDialog() method
+ public static void insertUseDialog(View view, String word)
+ {
+ FactorWord[] words = findAllWordsNamed(view,word);
+ if(words.length == 0)
+ view.getToolkit().beep();
+ else if(words.length == 1)
+ insertUse(view,words[0].vocabulary);
+ else
+ new InsertUseDialog(view,words);
+ } //}}}
+
+ //{{{ insertUse() method
+ public static void insertUse(View view, String vocab)
+ {
+ if(isUsed(view,vocab))
+ {
+ showStatus(view,"already-used",vocab);
+ return;
+ }
+
+ Buffer buffer = view.getBuffer();
+ int lastUseOffset = 0;
+
+ for(int i = 0; i < buffer.getLineCount(); i++)
+ {
+ String text = buffer.getLineText(i).trim();
+ if(text.startsWith("IN:") || text.startsWith("USE:")
+ || text.startsWith("!")
+ || text.length() == 0)
+ {
+ lastUseOffset = buffer.getLineStartOffset(i);
+ }
+ else
+ break;
+ }
+
+ String decl = "USE: " + vocab + "\n";
+ buffer.insert(lastUseOffset,decl);
+ showStatus(view,"inserted-use",decl);
+ } //}}]
}
plugin.factor.jedit.FactorPlugin.activate=defer
plugin.factor.jedit.FactorPlugin.name=Factor
-plugin.factor.jedit.FactorPlugin.version=0.64
+plugin.factor.jedit.FactorPlugin.version=0.65
plugin.factor.jedit.FactorPlugin.author=Slava Pestov
plugin.factor.jedit.FactorPlugin.docs=/doc/plugin.html
- \
factor-run-file \
factor-eval-selection \
+ - \
factor-apropos \
+ factor-insert-use \
+ - \
factor-edit \
factor-see \
factor-usages \
+ - \
factor-balance
factor.label=Factor Listener
factor-run-file.label=Run current file
factor-eval-selection.label=Evaluate selection
factor-apropos.label=Apropos at caret
+factor-insert-use.label=Use word at caret
factor-see.label=See word at caret
factor-edit.label=Edit word at caret
factor-usages.label=Word usages at caret
sidekick.parser.factor.label=Factor
mode.factor.sidekick.parser=factor
-factor.completion.plain=<html>: <b>{0}</b>
-factor.completion.defer=<html>DEFER: <b>{0}</b>
-factor.completion.parsing=<html>PARSING: <b>{0}</b>
-factor.completion.stack=<html>: <b>{0}</b> {1}
-factor.completion.shuffle=<html>~<< <b>{0}</b> {1} >>~
+factor.completion.in=<font color="#eeeeee">IN: {0}</font>
+factor.completion.plain=: <b>{0}</b>
+factor.completion.defer=DEFER: <b>{0}</b>
+factor.completion.parsing=PARSING: <b>{0}</b>
+factor.completion.stack=: <b>{0}</b> {1}
+factor.completion.shuffle=~<< <b>{0}</b> {1} >>~
+
+factor.status.inserted-use=Inserted {0}
+factor.status.already-used=Already used {0}
+
+factor.insert-use.title=Insert USE: Declaration
+factor.insert-use.caption=There are multiple words named "{0}". Select the one to use:
return d;
} //}}}
-
+
//{{{ addWordDefNodes() method
private void addWordDefNodes(SideKickParsedData d, Cons parsed,
Buffer buffer)
return (ReadTable.DEFAULT_READTABLE.getCharacterType(ch)
== ReadTable.WHITESPACE);
} //}}}
-
+
//{{{ canCompleteAnywhere() method
/**
* Returns if completion popups should be shown after any period of
public class FactorWordRenderer extends DefaultListCellRenderer
{
- private FactorInterpreter interp;
-
- public FactorWordRenderer(FactorInterpreter interp)
- {
- this.interp = interp;
- }
-
- public Component getListCellRendererComponent(
- JList list,
- Object value,
- int index,
- boolean isSelected,
- boolean cellHasFocus)
+ //{{{ getWordHTMLString() method
+ public static String getWordHTMLString(FactorInterpreter interp,
+ FactorWord word, boolean showIn)
{
- super.getListCellRendererComponent(list,value,index,
- isSelected,cellHasFocus);
-
String prop = "factor.completion.plain";
String stackEffect = null;
- if(!(value instanceof FactorWord))
- return this;
-
- FactorWord word = (FactorWord)value;
if(word.def == null)
{
if(word.parsing != null)
}
}
- setText(jEdit.getProperty(prop,
- new String[] {
+ String in;
+ if(showIn)
+ {
+ in = jEdit.getProperty("factor.completion.in",
+ new Object[] {
+ MiscUtilities.charsToEntities(word.vocabulary)
+ });
+ }
+ else
+ in = "";
+
+ return "<html>" + in + jEdit.getProperty(prop,
+ new Object[] {
MiscUtilities.charsToEntities(word.name),
stackEffect == null
? null :
MiscUtilities.charsToEntities(stackEffect)
- }));
+ });
+ } //}}}
+
+ private FactorInterpreter interp;
+ private boolean showIn;
+
+ //{{{ FactorWordRenderer constructor
+ public FactorWordRenderer(FactorInterpreter interp, boolean showIn)
+ {
+ this.interp = interp;
+ this.showIn = showIn;
+ } //}}}
+
+ //{{{ getListCellRendererComponent() method
+ public Component getListCellRendererComponent(
+ JList list,
+ Object value,
+ int index,
+ boolean isSelected,
+ boolean cellHasFocus)
+ {
+ super.getListCellRendererComponent(list,value,index,
+ isSelected,cellHasFocus);
+
+ if(!(value instanceof FactorWord))
+ return this;
+
+ setText(getWordHTMLString(interp,(FactorWord)value,showIn));
return this;
- }
+ } //}}}
}
--- /dev/null
+/* :folding=explicit: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.
+ */
+
+package factor.jedit;
+
+import factor.FactorWord;
+import javax.swing.border.*;
+import javax.swing.*;
+import java.awt.event.*;
+import java.awt.*;
+import org.gjt.sp.jedit.gui.EnhancedDialog;
+import org.gjt.sp.jedit.*;
+
+public class InsertUseDialog extends EnhancedDialog
+{
+ private View view;
+ private JList list;
+ private JButton ok, cancel;
+
+ //{{{ InsertUseDialog constructor
+ public InsertUseDialog(View view, FactorWord[] words)
+ {
+ super(view,jEdit.getProperty("factor.insert-use.title"),true);
+
+ this.view = view;
+
+ JPanel content = new JPanel(new BorderLayout());
+ content.setBorder(new EmptyBorder(12,12,12,12));
+ setContentPane(content);
+
+ content.add(BorderLayout.NORTH,new JLabel(
+ jEdit.getProperty("factor.insert-use.caption",
+ new String[] { words[0].name })));
+
+ content.add(BorderLayout.CENTER,new JScrollPane(
+ list = new JList(words)));
+ list.setCellRenderer(new FactorWordRenderer(
+ FactorPlugin.getInterpreter(),true));
+ list.setSelectedIndex(0);
+
+ content.add(BorderLayout.SOUTH,createButtonPanel());
+
+ setLocationRelativeTo(view);
+ pack();
+ setVisible(true);
+ } //}}}
+
+ //{{{ createButtonPanel() method
+ private Box createButtonPanel()
+ {
+ Box buttons = new Box(BoxLayout.X_AXIS);
+ buttons.add(Box.createGlue());
+ buttons.add(ok = new JButton(jEdit.getProperty(
+ "common.ok")));
+ getRootPane().setDefaultButton(ok);
+ ok.addActionListener(new ActionHandler());
+ buttons.add(Box.createHorizontalStrut(12));
+ buttons.add(cancel = new JButton(jEdit.getProperty(
+ "common.cancel")));
+ cancel.addActionListener(new ActionHandler());
+ buttons.add(Box.createGlue());
+
+ return buttons;
+ } //}}}
+
+ //{{{ ok() method
+ public void ok()
+ {
+ FactorWord w = (FactorWord)list.getSelectedValue();
+ FactorPlugin.insertUse(view,w.vocabulary);
+ dispose();
+ } //}}}
+
+ //{{{ cancel() method
+ public void cancel()
+ {
+ dispose();
+ } //}}}
+
+ //{{{ ActionHandler class
+ class ActionHandler implements ActionListener
+ {
+ public void actionPerformed(ActionEvent evt)
+ {
+ if(evt.getSource() == ok)
+ ok();
+ else if(evt.getSource() == cancel)
+ cancel();
+ }
+ } //}}}
+}
+import factor.jedit.*;
+
factorEval(view,str)
{
- factor.jedit.FactorPlugin.eval(view,str);
+ FactorPlugin.eval(view,str);
}
/* Build a Factor expression for pushing the selected word on the stack */
data = sidekick.SideKickParsedData.getParsedData(view);
if(data instanceof factor.jedit.FactorParsedData)
{
- if(textArea.selectionCount == 0)
- textArea.selectWord();
+ word = FactorPlugin.getWordAtCaret(textArea);
+ if(word == null)
+ return null;
return "\""
- + factor.FactorReader.charsToEscapes(textArea.selectedText)
+ + factor.FactorReader.charsToEscapes(word)
+ "\" " + factor.FactorReader.unparseObject(data.use)
+ " search";
}
: post-request ( url -- )
[ "post" swap serve-responder ] with-request ;
+: head-request ( url -- )
+ [ "head" swap serve-responder ] with-request ;
+
: handle-request ( arg cmd -- )
[
[ "GET" = ] [ drop get-request ]
[ "POST" = ] [ drop post-request ]
+ [ "HEAD" = ] [ drop head-request ]
[ drop t ] [ 2drop bad-request ]
] cond ;
[
drop "POST method not implemented" httpd-error
] "post" set
+ ( url -- )
+ [
+ drop "HEAD method not implemented" httpd-error
+ ] "head" set
] extend ;
: get-responder ( name -- responder )
return;
}
- if(in_zone(active,pointer))
+ if(in_zone(&active,pointer))
critical_error("copy_object given newspace ptr",pointer);
header = get(UNTAG(pointer));
gc_in_progress = true;
flip_zones();
- scan = active->here = active->base;
+ scan = active.here = active.base;
collect_roots();
collect_io_tasks();
- while(scan < active->here)
+ while(scan < active.here)
{
gc_debug("scan loop",scan);
collect_next();
size = h.size / CELLS;
- if(size != fread((void*)active->base,sizeof(CELL),size,file))
+ if(size != fread((void*)active.base,sizeof(CELL),size,file))
fatal_error("Wrong image length",h.size);
- active->here = active->base + h.size;
+ active.here = active.base + h.size;
fclose(file);
fprintf(stderr," relocating...");
h.magic = IMAGE_MAGIC;
h.version = IMAGE_VERSION;
- h.relocation_base = active->base;
+ h.relocation_base = active.base;
h.boot = userenv[BOOT_ENV];
- h.size = (active->here - active->base);
+ h.size = (active.here - active.base);
h.global = userenv[GLOBAL_ENV];
fwrite(&h,sizeof(HEADER),1,file);
- fwrite((void*)active->base,h.size,1,file);
+ fwrite((void*)active.base,h.size,1,file);
fclose(file);
return array + pagesize;
}
-ZONE* zalloc(CELL size)
+void init_zone(ZONE* z, CELL size)
{
- ZONE* z = (ZONE*)malloc(sizeof(ZONE));
- if(z == 0)
- fatal_error("Cannot allocate zone header",size);
z->base = z->here = align8((CELL)malloc(size));
if(z->base == 0)
fatal_error("Cannot allocate zone",size);
z->limit = z->base + size;
z->alarm = z->base + (size * 3) / 4;
z->base = align8(z->base);
- return z;
}
void init_arena(CELL size)
{
- z1 = zalloc(size);
- z2 = zalloc(size);
- active = z1;
+ init_zone(&active,size);
+ init_zone(&prior,size);
allot_profiling = false;
gc_in_progress = false;
}
void check_memory(void)
{
- if(active->here > active->alarm)
+ if(active.here > active.alarm)
{
- if(active->here > active->limit)
+ if(active.here > active.limit)
{
fprintf(stderr,"Out of memory\n");
- fprintf(stderr,"active->base = %ld\n",active->base);
- fprintf(stderr,"active->here = %ld\n",active->here);
- fprintf(stderr,"active->limit = %ld\n",active->limit);
+ fprintf(stderr,"active.base = %ld\n",active.base);
+ fprintf(stderr,"active.here = %ld\n",active.here);
+ fprintf(stderr,"active.limit = %ld\n",active.limit);
fflush(stderr);
exit(1);
}
void flip_zones()
{
- if(active == z1)
- {
- prior = z1;
- active = z2;
- }
- else
- {
- prior = z2;
- active = z1;
- }
+ ZONE z = prior;
+ active = prior;
+ prior = z;
}
bool in_zone(ZONE* z, CELL pointer)
void primitive_room(void)
{
/* push: free total */
- dpush(tag_integer(active->limit - active->here));
- dpush(tag_integer(active->limit - active->base));
+ dpush(tag_integer(active.limit - active.here));
+ dpush(tag_integer(active.limit - active.base));
}
void primitive_allot_profiling(void)
CELL limit;
} ZONE;
-ZONE* z1;
-ZONE* z2;
-ZONE* active; /* either z1 or z2 */
-ZONE* prior; /* if active==z1, z2; if active==z2, z1 */
+ZONE active;
+ZONE prior;
bool allot_profiling;
void* alloc_guarded(CELL size);
-ZONE* zalloc(CELL size);
+void init_zone(ZONE* zone, CELL size);
void init_arena(CELL size);
void flip_zones();
INLINE void* allot(CELL a)
{
- CELL h = active->here;
- active->here += align8(a);
+ CELL h = active.here;
+ active.here += align8(a);
#ifdef FACTOR_PROFILER
if(allot_profiling)
allot_profile_step(align8(a));
void fixup(CELL* cell)
{
if(TAG(*cell) != FIXNUM_TYPE)
- *cell += (active->base - relocation_base);
+ *cell += (active.base - relocation_base);
}
void relocate_object()
fixup(&userenv[BOOT_ENV]);
fixup(&userenv[GLOBAL_ENV]);
- relocating = active->base;
+ relocating = active.base;
/* The first two objects in the image must always be F, T */
init_object(&F,F_TYPE);
for(;;)
{
- if(relocating >= active->here)
+ if(relocating >= active.here)
break;
relocate_next();
INLINE STRING* fixup_untagged_string(STRING* str)
{
- return (STRING*)((CELL)str + (active->base - relocation_base));
+ return (STRING*)((CELL)str + (active.base - relocation_base));
}
INLINE STRING* copy_untagged_string(STRING* str)
void fixup_vector(VECTOR* vector)
{
vector->array = (ARRAY*)((CELL)vector->array
- + (active->base - relocation_base));
+ + (active.base - relocation_base));
}
void collect_vector(VECTOR* vector)