package factor.jedit;
+import factor.FactorWord;
import javax.swing.Icon;
import javax.swing.text.Position;
import org.gjt.sp.jedit.Buffer;
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()
public String getShortString()
{
- return name;
+ return word.name;
}
public String getLongString()
{
- return name;
+ return FactorWordRenderer.getWordHTMLString(
+ FactorPlugin.getInterpreter(),word,false);
}
}
{
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
parsed.car;
FactorWord word = def.word;
+ worddefs.put(word,def);
/* word lines are indexed from 1 */
int startLine = Math.min(
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));
}
}
int caret = getCaretPosition();
- int limit;
if(caret == cmdStart)
{
getToolkit().beep();
}
} //}}}
- //{{{ BackspaceAction class
- class BackspaceAction extends AbstractAction
+ //{{{ HomeAction class
+ class HomeAction extends AbstractAction
{
public void actionPerformed(ActionEvent evt)
{
- setCaretPosition(limit);
+ setCaretPosition(cmdStart);
}
} //}}}
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
[ 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
USE: math
USE: stack
USE: test
+USE: logic
+USE: lists
[ -2 ] [ 1 bitnot ] unit-test
[ -2 ] [ 1 >bignum bitnot ] unit-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
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))
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(