]> gitweb.factorcode.org Git - factor.git/commitdiff
arithmetic shift no longer uses long long, plugin improvements
authorSlava Pestov <slava@factorcode.org>
Fri, 3 Sep 2004 20:54:58 +0000 (20:54 +0000)
committerSlava Pestov <slava@factorcode.org>
Fri, 3 Sep 2004 20:54:58 +0000 (20:54 +0000)
factor/jedit/FactorAsset.java
factor/jedit/FactorSideKickParser.java
factor/listener/FactorListener.java
library/test/httpd/httpd.factor
library/test/math/bignum.factor
library/test/math/bitops.factor
native/factor.h
native/fixnum.c

index d594b90979c86fa19a73b6394a23639f53d5022e..a5abc7047995914087c1ecaa806680e5531a506a 100644 (file)
@@ -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);
        }
 }
index fb0f78a9ea2a3eecd23a0091cf5c96b49ee26e6a..7f1ae03d5d63a91e5f13752b9a8feecda6839d76 100644 (file)
@@ -42,11 +42,19 @@ public class FactorSideKickParser extends SideKickParser
 {
        private WordPreview wordPreview;
 
+       /**
+        * When we parse a file, we store the <word,worddef> 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));
                        }
index 62685a8735c416571bb3fdda950e0e876c17bbea..773f2807ff3b6835f1c5b46dcafe85154546a974 100644 (file)
@@ -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);
                }
        } //}}}
 
index 5e1dc4189cdfefc91a6e7bd1a5673702d2b2f6d1..d933f0e79cc4ecd72297b84a41e095a6cfbab5a1 100644 (file)
@@ -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
index 28cf2fb1da2528bdcf7c3faf80437ee64294d74b..8e3258daea65e542a4f0685c5f50c3ad365d8284 100644 (file)
@@ -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
index 5f6faa82d44fd83d7265abc3bc9484fa43149658..a31c8a4159f794096655d15a060f1ed72adbd467 100644 (file)
@@ -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
index 02ce59703dae68b4d7789cf1af7e0c06c225cad8..0e638d9bcc0493498fd89028f7c34bed1186402a 100644 (file)
@@ -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))
index abef5af204a95ceec65e7483278e173ecbcf93bf..ca6a5c0323cd56efe780926e4f6fe8486ab5c268 100644 (file)
@@ -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(