arithmetic shift no longer uses long long, plugin improvements
parent
f0322506b7
commit
541b6cd8d1
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
} //}}}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue