CC = gcc
-CFLAGS = -g -Wall
+CFLAGS = -Os -mpentiumpro -g -Wall
LIBS = -lm
STRIP = strip
- plugin should not exit jEdit on fatal errors\r
- IN: format base: work with all types of numbers\r
- wordpreview: don't show for string literals and comments\r
-- eliminate usage of long long\r
+- NPE in activate()/deactivate()\r
+- NPE in ErrorHighlight\r
- 64 bit support\r
- alist -vs- assoc terminology\r
- clean up listener's action popups\r
\r
+ listener/plugin:\r
\r
+- don't use jEdit's word finding API\r
- some way to not have previous definitions from a source file\r
clutter the namespace\r
- use inferior.factor for everything not just listener\r
\r
+ misc:\r
\r
+- telnetd: init-history\r
+- str-reverse primitive\r
- some way to run httpd from command line\r
- don't rehash strings on every startup\r
- 'cascading' styles\r
</ACTION>
<ACTION NAME="factor-edit-dialog">
<CODE>
- new EditWordDialog(view,FactorPlugin.getInterpreter());
+ new EditWordDialog(view,FactorPlugin
+ .getSideKickParser());
</CODE>
</ACTION>
<ACTION NAME="factor-usages">
private Timer timer;
//{{{ EditWordDialog constructor
- public EditWordDialog(View view, FactorInterpreter interp)
+ public EditWordDialog(View view, FactorSideKickParser parser)
{
- super(view,interp,jEdit.getProperty("factor.edit-word.title"));
+ super(view,parser,jEdit.getProperty("factor.edit-word.title"));
Box top = new Box(BoxLayout.X_AXIS);
top.add(new JLabel(jEdit.getProperty(
package factor.jedit;
import factor.FactorWord;
+import factor.FactorWordDefinition;
import javax.swing.Icon;
import javax.swing.text.Position;
import org.gjt.sp.jedit.Buffer;
public class FactorAsset extends Asset
{
private FactorWord word;
+ private FactorWordDefinition def;
- public FactorAsset(FactorWord word, Position start)
+ public FactorAsset(FactorWord word, FactorWordDefinition def,
+ Position start)
{
super(word.name);
this.start = start;
this.word = word;
+ this.def = def;
}
public Icon getIcon()
public String getLongString()
{
return FactorWordRenderer.getWordHTMLString(
- FactorPlugin.getInterpreter(),word,false);
+ FactorPlugin.getInterpreter(),word,def,false);
}
}
public ListCellRenderer getRenderer()
{
- return new FactorWordRenderer(
- FactorPlugin.getInterpreter(),
- false);
+ return new FactorWordRenderer(data.parser,false);
}
}
public class FactorParsedData extends SideKickParsedData
{
- public FactorInterpreter interp;
+ public FactorSideKickParser parser;
public String in;
public Cons use;
- FactorParsedData(FactorInterpreter interp, String fileName)
+ FactorParsedData(FactorSideKickParser parser, String fileName)
{
super(fileName);
- this.interp = interp;
+ this.parser = parser;
}
}
return interp;
} //}}}
+ //{{{ getSideKickParser() method
+ public static FactorSideKickParser getSideKickParser()
+ {
+ return (FactorSideKickParser)ServiceManager.getService(
+ "sidekick.SideKickParser","factor");
+ } //}}}
+
//{{{ eval() method
public static void eval(View view, String cmd)
{
else if(words.length == 1)
insertUse(view,words[0].vocabulary);
else
- new InsertUseDialog(view,getInterpreter(),words);
+ new InsertUseDialog(view,getSideKickParser(),words);
} //}}}
//{{{ insertUse() method
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)
+ if(text.startsWith("IN:") || text.startsWith("USE:"))
+ {
+ lastUseOffset = buffer.getLineEndOffset(i) - 1;
+ }
+ else if(text.startsWith("!") || text.length() == 0)
{
- lastUseOffset = buffer.getLineStartOffset(i);
+ if(i == 0)
+ lastUseOffset = 0;
+ else
+ lastUseOffset = buffer.getLineEndOffset(i-1) - 1;
}
else
break;
}
- String decl = "USE: " + vocab + "\n";
+ String decl = "USE: " + vocab;
+ if(lastUseOffset != 0)
+ decl = "\n" + decl;
buffer.insert(lastUseOffset,decl);
showStatus(view,"inserted-use",decl);
} //}}}
public class FactorSideKickParser extends SideKickParser
{
+ private FactorInterpreter interp;
private WordPreview wordPreview;
/**
public FactorSideKickParser()
{
super("factor");
- wordPreview = new WordPreview();
+ interp = FactorPlugin.getInterpreter();
+ wordPreview = new WordPreview(this);
worddefs = new HashMap();
} //}}}
+ //{{{ getInterpreter() method
+ public FactorInterpreter getInterpreter()
+ {
+ return interp;
+ } //}}}
+
+ //{{{ getWordDefinition() method
+ /**
+ * Check for a word definition from a parsed source file. If one is
+ * found, return it, otherwise return interpreter's definition.
+ */
+ public FactorWordDefinition getWordDefinition(FactorWord word)
+ {
+ FactorWordDefinition def = (FactorWordDefinition)
+ worddefs.get(word);
+ if(def != null)
+ return def;
+ else
+ return word.def;
+ } //}}}
+
//{{{ activate() method
/**
* This method is called when a buffer using this parser is selected
public SideKickParsedData parse(Buffer buffer,
DefaultErrorSource errorSource)
{
- FactorInterpreter interp = FactorPlugin.getInterpreter();
FactorParsedData d = new FactorParsedData(
- interp,buffer.getPath());
+ this,buffer.getPath());
String text;
if(last != null)
last.end = buffer.createPosition(start - 1);
- last = new FactorAsset(word,
+ last = new FactorAsset(word,def,
buffer.createPosition(start));
d.root.add(new DefaultMutableTreeNode(last));
}
{
//{{{ getWordHTMLString() method
public static String getWordHTMLString(FactorInterpreter interp,
- FactorWord word, boolean showIn)
+ FactorWord word, FactorWordDefinition def, boolean showIn)
{
String prop = "factor.completion.plain";
String stackEffect = null;
- if(word.def == null)
+ if(def == null)
{
if(word.parsing != null)
prop = "factor.completion.parsing";
else
prop = "factor.completion.defer";
}
- else if(word.def instanceof FactorShuffleDefinition)
+ else if(def instanceof FactorShuffleDefinition)
{
prop = "factor.completion.shuffle";
StringBuffer buf = new StringBuffer();
- Cons def = word.def.toList(interp);
- while(def != null)
+ Cons d = def.toList(interp);
+ while(d != null)
{
if(buf.length() != 0)
buf.append(' ');
- buf.append(def.car);
- def = def.next();
+ buf.append(d.car);
+ d = d.next();
}
stackEffect = buf.toString();
}
else
{
- Cons def = word.def.toList(interp);
- if(def != null && def.car instanceof FactorDocComment)
+ Cons d = def.toList(interp);
+ if(d != null && d.car instanceof FactorDocComment)
{
FactorDocComment comment = (FactorDocComment)
- def.car;
+ d.car;
if(comment.isStackComment())
{
prop = "factor.completion.stack";
});
} //}}}
- private FactorInterpreter interp;
+ private FactorSideKickParser parser;
private boolean showIn;
//{{{ FactorWordRenderer constructor
- public FactorWordRenderer(FactorInterpreter interp, boolean showIn)
+ public FactorWordRenderer(FactorSideKickParser parser, boolean showIn)
{
- this.interp = interp;
+ this.parser = parser;
this.showIn = showIn;
} //}}}
if(!(value instanceof FactorWord))
return this;
- setText(getWordHTMLString(interp,(FactorWord)value,showIn));
+ FactorWord word = (FactorWord)value;
+ setText(getWordHTMLString(parser.getInterpreter(),
+ word,
+ parser.getWordDefinition(word),
+ showIn));
return this;
} //}}}
public class InsertUseDialog extends WordListDialog
{
//{{{ InsertUseDialog constructor
- public InsertUseDialog(View view, FactorInterpreter interp,
+ public InsertUseDialog(View view, FactorSideKickParser parser,
FactorWord[] words)
{
- super(view,interp,jEdit.getProperty("factor.insert-use.title"));
+ super(view,parser,jEdit.getProperty("factor.insert-use.title"));
getContentPane().add(BorderLayout.NORTH,new JLabel(
jEdit.getProperty("factor.insert-use.caption",
protected JButton ok, cancel;
//{{{ WordListDialog constructor
- public WordListDialog(View view, FactorInterpreter interp, String title)
+ public WordListDialog(View view, FactorSideKickParser parser,
+ String title)
{
super(view,title,true);
content.add(BorderLayout.CENTER,new JScrollPane(
list = new JList()));
- list.setCellRenderer(new FactorWordRenderer(interp,true));
+ list.setCellRenderer(new FactorWordRenderer(parser,true));
content.add(BorderLayout.SOUTH,createButtonPanel());
} //}}}
public class WordPreview implements CaretListener
{
+ private FactorSideKickParser parser;
+
+ //{{{ WordPreview constructor
+ public WordPreview(FactorSideKickParser parser)
+ {
+ this.parser = parser;
+ } //}}}
+
+ //{{{ caretUpdate() method
public void caretUpdate(CaretEvent e)
{
showPreview((JEditTextArea)e.getSource());
- }
+ } //}}}
+ //{{{ showPreview() method
private void showPreview(JEditTextArea textArea)
{
View view = textArea.getView();
if(data instanceof FactorParsedData)
{
FactorParsedData fdata = (FactorParsedData)data;
- FactorWord w = fdata.interp
- .searchVocabulary(fdata.use,word);
+ FactorInterpreter interp = fdata.parser
+ .getInterpreter();
+ FactorWord w = interp.searchVocabulary(fdata.use,word);
if(w != null)
{
view.getStatus().setMessageAndClear(
FactorWordRenderer.getWordHTMLString(
- fdata.interp,w,true));
+ interp,w,fdata.parser.getWordDefinition(w),true));
}
}
- }
+ } //}}}
}
swap write-image ;
: make-images ( -- )
- "big-endian" off "boot.image.le" make-image
- "big-endian" on "boot.image.be" make-image
- "boot.image.le and boot.image.be have been generated." print
- ;
+ "64-bits" off
+ "big-endian" off "boot.image.le32" make-image
+ "big-endian" on "boot.image.be32" make-image
+ "64-bits" on
+ "big-endian" off "boot.image.le64" make-image
+ "big-endian" on "boot.image.be64" make-image ;
"size" "href" "class" "border" "rows" "cols"
"id" "onclick" "style" "valign" "accesskey"
"src" "language" "colspan" "onchange" "rel"
- "width" "src"
+ "width"
] [ define-attribute-word ] each
: image "image" get ;
: emit ( cell -- ) image vector-push ;
-: lo/hi64 ( long -- hi lo )
- dup
- -32 shift
- HEX: ffffffff bitand
- swap
- HEX: ffffffff bitand ;
-
-: emit64 ( bignum -- )
- lo/hi64 "big-endian" get [ swap ] when emit emit ;
-
: fixup ( value offset -- ) image set-vector-nth ;
( Object memory )
: image-magic HEX: 0f0e0d0c ;
: image-version 0 ;
-: cell ( we're compiling for a 32-bit system ) 4 ;
+: cell "64-bits" get 8 4 ? ;
+: char "64-bits" get 4 2 ? ;
: tag-mask BIN: 111 ;
: tag-bits 3 ;
: 'fixnum ( n -- tagged ) fixnum-tag immediate ;
-( Floats )
-
-: 'float ( f -- tagged )
- object-tag here-as >r
- float-type >header emit
- 0 emit ( alignment -- FIXME 64-bit arch )
- float>bits emit64 r> ;
-
( Bignums )
: 'bignum ( bignum -- tagged )
( Strings )
-: pack ( n n -- )
- "big-endian" get [ swap ] when 16 shift bitor emit ;
+: pad-string ( n str -- )
+ tuck str-length - CHAR: \0 fill cat2 ;
-: pack-at ( n str -- )
- 2dup str-nth rot succ rot str-nth pack ;
+: emit-string ( str -- )
+ "big-endian" get [ str-reverse ] unless
+ 0 swap [ swap 16 shift + ] str-each emit ;
-: (pack-string) ( n str -- )
- 2dup str-length >= [
- 2drop
- ] [
- 2dup str-length pred = [
- 2dup str-nth 0 pack
- ] [
- 2dup pack-at
- ] ifte >r 2 + r> (pack-string)
- ] ifte ;
+: (pack-string) ( n list -- )
+ #! Emit bytes for a string, with n characters per word.
+ [
+ 2dup str-length < [ dupd pad-string ] when
+ emit-string
+ ] each drop ;
-: pack-string ( str -- ) 0 swap (pack-string) ;
+: pack-string ( string -- )
+ char tuck swap split-n (pack-string) ;
: string, ( string -- )
object-tag here-as swap
[
[ fixnum? ] [ 'fixnum ]
[ bignum? ] [ 'bignum ]
- [ float? ] [ 'float ]
[ ratio? ] [ 'ratio ]
[ complex? ] [ 'complex ]
[ word? ] [ 'word ]
( Image output )
: write-word ( word -- )
- "big-endian" get [
- write-big-endian-32
+ "64-bits" get [
+ "big-endian" get [
+ write-big-endian-64
+ ] [
+ write-little-endian-64
+ ] ifte
] [
- write-little-endian-32
+ "big-endian" get [
+ write-big-endian-32
+ ] [
+ write-little-endian-32
+ ] ifte
] ifte ;
: write-image ( image file -- )
: odd? 2 mod 1 = ;
: even? 2 mod 0 = ;
-: i #{ 0 1 } ; inline
-: -i #{ 0 -1 } ; inline
-: inf 1.0 0.0 / ; inline
-: -inf -1.0 0.0 / ; inline
-: e 2.7182818284590452354 ; inline
-: pi 3.14159265358979323846 ; inline
-: pi/2 1.5707963267948966 ; inline
-
: f>0 ( obj -- obj )
#! If f at the top of the stack, turn it into 0.
f 0 replace ;
: neg 0 swap - ; inline
: recip 1 swap / ; inline
-
-: deg2rad pi * 180 / ;
-
-: rad2deg 180 * pi / ;
! Hyperbolic functions:
! cosh sech sinh cosech tanh coth
+: deg2rad pi * 180 / ;
+: rad2deg 180 * pi / ;
+
: cos ( z -- cos )
>rect 2dup
fcosh swap fcos * -rot
!!! Math library.
"/library/platform/jvm/real-math.factor" run-resource ! real-math
+"/library/math/constants.factor" run-resource ! math
"/library/math/math.factor" run-resource ! math
"/library/math/pow.factor" run-resource ! math
"/library/math/trig-hyp.factor" run-resource ! math
"/library/debugger.factor"
"/library/platform/native/init.factor"
+ "/library/math/constants.factor"
"/library/math/math.factor"
"/library/platform/native/math.factor"
"/library/math/pow.factor"
#! Split the string at each occurrence of split, and push a
#! list of the pieces.
[, 0 -rot (split) ,] ;
+
+: split-n-advance substring , >r tuck + swap r> ;
+: split-n-finish nip dup str-length swap substring , ;
+
+: (split-n) ( start n str -- )
+ 3dup >r dupd + r> 2dup str-length < [
+ split-n-advance (split-n)
+ ] [
+ split-n-finish 3drop
+ ] ifte ;
+
+: split-n ( n str -- list )
+ #! Split a string into n-character chunks.
+ [, 0 -rot (split-n) ,] ;
+
+: str-reverse ( str -- str )
+ str>sbuf dup sbuf-reverse sbuf>str ;
read1 8 shift bitor
read1 bitor ;
+: byte7 ( num -- byte ) -56 shift HEX: ff bitand ;
+: byte6 ( num -- byte ) -48 shift HEX: ff bitand ;
+: byte5 ( num -- byte ) -40 shift HEX: ff bitand ;
+: byte4 ( num -- byte ) -32 shift HEX: ff bitand ;
: byte3 ( num -- byte ) -24 shift HEX: ff bitand ;
: byte2 ( num -- byte ) -16 shift HEX: ff bitand ;
: byte1 ( num -- byte ) -8 shift HEX: ff bitand ;
: byte0 ( num -- byte ) HEX: ff bitand ;
+: write-little-endian-64 ( word -- )
+ dup byte0 >char write
+ dup byte1 >char write
+ dup byte2 >char write
+ dup byte3 >char write
+ dup byte4 >char write
+ dup byte5 >char write
+ dup byte6 >char write
+ byte7 >char write ;
+
+: write-big-endian-64 ( word -- )
+ dup byte7 >char write
+ dup byte6 >char write
+ dup byte5 >char write
+ dup byte4 >char write
+ dup byte3 >char write
+ dup byte2 >char write
+ dup byte1 >char write
+ byte0 >char write ;
+
: write-little-endian-32 ( word -- )
dup byte0 >char write
dup byte1 >char write
[ t ] [ "abc" "abd" str-compare 0 < ] unit-test
[ t ] [ "z" "abd" str-compare 0 > ] unit-test
-[ "fedcba" ] [ "abcdef" str>sbuf dup sbuf-reverse sbuf>str ] unit-test
-[ "edcba" ] [ "abcde" str>sbuf dup sbuf-reverse sbuf>str ] unit-test
+[ "fedcba" ] [ "abcdef" str-reverse ] unit-test
+[ "edcba" ] [ "abcde" str-reverse ] unit-test
native? [
[ t ] [ "Foo" str>sbuf "Foo" str>sbuf = ] unit-test
] when
[ f ] [ [ 0 10 "hello" substring ] [ not ] catch ] unit-test
+
+[ [ "hell" "o wo" "rld" ] ] [ 4 "hello world" split-n ] unit-test
void general_error(CELL error, CELL tagged)
{
- CELL c = cons(error,tag_cons(cons(tagged,F)));
+ CELL c = cons(error,cons(tagged,F));
if(userenv[BREAK_ENV] == 0)
{
/* Crash at startup */
void type_error(CELL type, CELL tagged)
{
- CELL c = cons(tag_fixnum(type),tag_cons(cons(tagged,F)));
+ CELL c = cons(tag_fixnum(type),cons(tagged,F));
general_error(ERROR_TYPE,c);
}
*/
CELL multiply_fixnum(FIXNUM x, FIXNUM y)
{
+ FIXNUM prod;
+
if(x == 0 || y == 0)
return tag_fixnum(0);
- else
- {
- FIXNUM prod = x * y;
- if(prod / x == y)
- return tag_integer(prod);
- }
+
+ prod = x * y;
+ /* if this is not equal, we have overflow */
+ if(prod / x == y)
+ return tag_integer(prod);
return tag_object(
s48_bignum_multiply(
typedef struct {
CELL header;
-/* FIXME */
-#ifndef FACTOR_64
- CELL alignment;
-#endif
double n;
} FLOAT;