From 541b6cd8d1e70d745b4fda3918c8de1fb3a1c4d3 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 3 Sep 2004 20:54:58 +0000 Subject: [PATCH] arithmetic shift no longer uses long long, plugin improvements --- factor/jedit/FactorAsset.java | 13 ++++++++---- factor/jedit/FactorSideKickParser.java | 11 +++++++++- factor/listener/FactorListener.java | 7 +++---- library/test/httpd/httpd.factor | 2 +- library/test/math/bignum.factor | 7 ------- library/test/math/bitops.factor | 28 ++++++++++++++++++++++++++ native/factor.h | 2 ++ native/fixnum.c | 21 +++++++++++++------ 8 files changed, 68 insertions(+), 23 deletions(-) diff --git a/factor/jedit/FactorAsset.java b/factor/jedit/FactorAsset.java index d594b90979..a5abc70479 100644 --- a/factor/jedit/FactorAsset.java +++ b/factor/jedit/FactorAsset.java @@ -29,6 +29,7 @@ package factor.jedit; +import factor.FactorWord; import javax.swing.Icon; import javax.swing.text.Position; import org.gjt.sp.jedit.Buffer; @@ -36,10 +37,13 @@ import sidekick.*; public class FactorAsset extends Asset { - public FactorAsset(String name, Position start) + private FactorWord word; + + public FactorAsset(FactorWord word, Position start) { - super(name); + super(word.name); this.start = start; + this.word = word; } public Icon getIcon() @@ -49,11 +53,12 @@ public class FactorAsset extends Asset public String getShortString() { - return name; + return word.name; } public String getLongString() { - return name; + return FactorWordRenderer.getWordHTMLString( + FactorPlugin.getInterpreter(),word,false); } } diff --git a/factor/jedit/FactorSideKickParser.java b/factor/jedit/FactorSideKickParser.java index fb0f78a9ea..7f1ae03d5d 100644 --- a/factor/jedit/FactorSideKickParser.java +++ b/factor/jedit/FactorSideKickParser.java @@ -42,11 +42,19 @@ public class FactorSideKickParser extends SideKickParser { private WordPreview wordPreview; + /** + * When we parse a file, we store the pairs in this + * map, so that completion popups show the latest stack effects, + * and not whatever they were the last time the source was run-file'd. + */ + private Map worddefs; + //{{{ FactorSideKickParser constructor public FactorSideKickParser() { super("factor"); wordPreview = new WordPreview(); + worddefs = new HashMap(); } //}}} //{{{ activate() method @@ -151,6 +159,7 @@ public class FactorSideKickParser extends SideKickParser parsed.car; FactorWord word = def.word; + worddefs.put(word,def); /* word lines are indexed from 1 */ int startLine = Math.min( @@ -167,7 +176,7 @@ public class FactorSideKickParser extends SideKickParser if(last != null) last.end = buffer.createPosition(start - 1); - last = new FactorAsset(word.name, + last = new FactorAsset(word, buffer.createPosition(start)); d.root.add(new DefaultMutableTreeNode(last)); } diff --git a/factor/listener/FactorListener.java b/factor/listener/FactorListener.java index 62685a8735..773f2807ff 100644 --- a/factor/listener/FactorListener.java +++ b/factor/listener/FactorListener.java @@ -310,7 +310,6 @@ public class FactorListener extends JTextPane } int caret = getCaretPosition(); - int limit; if(caret == cmdStart) { getToolkit().beep(); @@ -328,12 +327,12 @@ public class FactorListener extends JTextPane } } //}}} - //{{{ BackspaceAction class - class BackspaceAction extends AbstractAction + //{{{ HomeAction class + class HomeAction extends AbstractAction { public void actionPerformed(ActionEvent evt) { - setCaretPosition(limit); + setCaretPosition(cmdStart); } } //}}} diff --git a/library/test/httpd/httpd.factor b/library/test/httpd/httpd.factor index 5e1dc4189c..d933f0e79c 100644 --- a/library/test/httpd/httpd.factor +++ b/library/test/httpd/httpd.factor @@ -11,7 +11,7 @@ USE: strings USE: stack USE: lists -[ "HTTP/1.0 200 OK\nContent-Length: 12\nContent-Type: text/html\n" ] +[ "HTTP/1.0 200 OK\nContent-Length: 12\nContent-Type: text/html\n\n" ] [ [ "text/html" 12 file-response ] with-string ] unit-test diff --git a/library/test/math/bignum.factor b/library/test/math/bignum.factor index 28cf2fb1da..8e3258daea 100644 --- a/library/test/math/bignum.factor +++ b/library/test/math/bignum.factor @@ -10,13 +10,6 @@ USE: unparser [ 134217728 dup + dup + dup + dup + dup + dup + unparse ] unit-test -[ 256 ] [ 65536 -8 shift ] unit-test -[ 256 ] [ 65536 >bignum -8 shift ] unit-test -[ 256 ] [ 65536 -8 >bignum shift ] unit-test -[ 256 ] [ 65536 >bignum -8 >bignum shift ] unit-test -[ 4294967296 ] [ 1 16 shift 16 shift ] unit-test -[ 4294967296 ] [ 1 32 shift ] unit-test -[ 1267650600228229401496703205376 ] [ 1 100 shift ] unit-test [ 268435456 ] [ -268435456 >fixnum -1 / ] unit-test [ 268435456 ] [ -268435456 >fixnum -1 /i ] unit-test [ 268435456 0 ] [ -268435456 >fixnum -1 /mod ] unit-test diff --git a/library/test/math/bitops.factor b/library/test/math/bitops.factor index 5f6faa82d4..a31c8a4159 100644 --- a/library/test/math/bitops.factor +++ b/library/test/math/bitops.factor @@ -3,6 +3,8 @@ USE: kernel USE: math USE: stack USE: test +USE: logic +USE: lists [ -2 ] [ 1 bitnot ] unit-test [ -2 ] [ 1 >bignum bitnot ] unit-test @@ -20,3 +22,29 @@ USE: test [ -1 ] [ 123 dup bitnot >bignum bitxor ] unit-test [ -1 ] [ 123 dup bitnot bitxor >bignum ] unit-test [ 4 ] [ 4 7 bitand ] unit-test + +[ 256 ] [ 65536 -8 shift ] unit-test +[ 256 ] [ 65536 >bignum -8 shift ] unit-test +[ 256 ] [ 65536 -8 >bignum shift ] unit-test +[ 256 ] [ 65536 >bignum -8 >bignum shift ] unit-test +[ 4294967296 ] [ 1 16 shift 16 shift ] unit-test +[ 4294967296 ] [ 1 32 shift ] unit-test +[ 1267650600228229401496703205376 ] [ 1 100 shift ] unit-test + +[ t ] [ 1 27 shift fixnum? ] unit-test + +[ t ] [ + t + [ 27 28 29 30 31 32 59 60 61 62 63 64 ] + [ + 1 over shift swap 1 >bignum swap shift = and + ] each +] unit-test + +[ t ] [ + t + [ 27 28 29 30 31 32 59 60 61 62 63 64 ] + [ + -1 over shift swap -1 >bignum swap shift = and + ] each +] unit-test diff --git a/native/factor.h b/native/factor.h index 02ce59703d..0e638d9bcc 100644 --- a/native/factor.h +++ b/native/factor.h @@ -29,6 +29,8 @@ typedef unsigned long int CELL; #define CELLS ((signed)sizeof(CELL)) +#define WORD_SIZE (CELLS*8) + /* must always be 16 bits */ typedef unsigned short CHAR; #define CHARS ((signed)sizeof(CHAR)) diff --git a/native/fixnum.c b/native/fixnum.c index abef5af204..ca6a5c0323 100644 --- a/native/fixnum.c +++ b/native/fixnum.c @@ -149,16 +149,25 @@ CELL xor_fixnum(FIXNUM x, FIXNUM y) return tag_fixnum(x ^ y); } +/* + * Note the hairy overflow check. + * If we're shifting right by n bits, we won't overflow as long as none of the + * high WORD_SIZE-TAG_BITS-n bits are set. + */ CELL shift_fixnum(FIXNUM x, FIXNUM y) { - if(y > -CELLS * 8 && y < CELLS * 8) + if(y < 0) + return tag_fixnum(x >> -y); + else if(y == 0) + return tag_fixnum(x); + else if(y < WORD_SIZE - TAG_BITS) { - long long result = (y < 0 - ? (long long)x >> -y - : (long long)x << y); + FIXNUM mask = (1 << (WORD_SIZE - 1 - TAG_BITS - y)); + if(x > 0) + mask = -mask; - if(result >= FIXNUM_MIN && result <= FIXNUM_MAX) - return tag_fixnum(result); + if((x & mask) == 0) + return tag_fixnum(x << y); } return tag_object(s48_bignum_arithmetic_shift(