bignum bitnot, bitop tests

cvs
Slava Pestov 2004-08-18 03:42:10 +00:00
parent c8cc64b031
commit 0c609f4a48
10 changed files with 80 additions and 52 deletions

View File

@ -1,5 +1,3 @@
- bitwise operations
- clone-hashtable
- sidekick: error source not removed - sidekick: error source not removed
- lineno/file for native - lineno/file for native
- jedit for native with socket communication - jedit for native with socket communication
@ -8,7 +6,6 @@
- maple-like: press enter at old commands to evaluate there - maple-like: press enter at old commands to evaluate there
- sending ^C on socket - sending ^C on socket
- read# - read#
- describe-word
- enforce bottom-up in native bootstrap - enforce bottom-up in native bootstrap
- standalone listener input style - standalone listener input style
- log-client: fix for native - log-client: fix for native
@ -32,8 +29,11 @@
+ listener/plugin: + listener/plugin:
- auto insert USE:
- why > 1 popup
- listener backspace overzealous - listener backspace overzealous
- lineno/file for shuffle defs - lineno/file for shuffle defs
- completion popups for shuffle defs
- balance needs USE: - balance needs USE:
- completion: enter no good - completion: enter no good
- completion: don't show automatically - completion: don't show automatically
@ -47,6 +47,7 @@
- postpone errors until actual read/write op - postpone errors until actual read/write op
- multitasking - multitasking
- parsing should be parsing - parsing should be parsing
- better error reporting
+ JVM compiler: + JVM compiler:

View File

@ -47,6 +47,11 @@ The Factor plugin adds a menu to jEdit's <b>Plugins</b> menu with the following
<li><b>Evaluate selection</b> evaluates the current selection.</li> <li><b>Evaluate selection</b> evaluates the current selection.</li>
<li><b>Apropos word at caret</b> performs an apropos search on the current selection, or the word at the caret if there is no selection. An "apropos search" lists all words in all vocabularies whose names contain a certain string. For example, you can use this to list all string words by searching for "str", or to find out which vocabulary contains the word "unparse" by searching for "unparse".</li> <li><b>Apropos word at caret</b> performs an apropos search on the current selection, or the word at the caret if there is no selection. An "apropos search" lists all words in all vocabularies whose names contain a certain string. For example, you can use this to list all string words by searching for "str", or to find out which vocabulary contains the word "unparse" by searching for "unparse".</li>
<li><b>See word at caret</b> shows the definition of the word at the caret in the listener dockable window.</li> <li><b>See word at caret</b> shows the definition of the word at the caret in the listener dockable window.</li>
<li><b>Edit word at caret</b> opens the source file containing the definition of the word at the caret.
For this to work with words defined in the standard library, you must set the "resource-path" variable in your <code>~/.factor-rc</code> to point to the location of the library sources:
<pre>"/home/slava/Factor/" "resource-path" set</pre>
</li>
<li><b>Word usages at caret</b> shows all usages of the word at the caret in the listener dockable window.</li> <li><b>Word usages at caret</b> shows all usages of the word at the caret in the listener dockable window.</li>
</ul> </ul>
@ -62,19 +67,5 @@ The Factor plugin uses the SideKick plugin to perform background parsing of Fact
</li> </li>
</ul> </ul>
<h2 class="fancy-heading">Jumping to a word definition</h2>
If you add the following line to your <code>~/.factor-rc</code>:
<pre>USE: jedit</pre>
You can then jump to a word definition using the <code>jedit</code> word in the Factor interpreter:
<pre>"numbers-game" jedit</pre>
For this to work with words defined in the standard library, you must set the "resource-path" variable in your <code>~/.factor-rc</code> to point to the location of the library sources:
<pre>"/home/slava/Factor/" "resource-path" set</pre>
</body> </body>
</html> </html>

View File

@ -0,0 +1,21 @@
IN: scratchpad
USE: arithmetic
USE: kernel
USE: stack
USE: test
[ -2 ] [ 1 bitnot ] unit-test
[ -2 ] [ 1 >bignum bitnot ] unit-test
[ -2 ] [ 1 >bignum bitnot ] unit-test
[ 0 ] [ 123 dup bitnot bitand ] unit-test
[ 0 ] [ 123 >bignum dup bitnot bitand ] unit-test
[ 0 ] [ 123 dup bitnot >bignum bitand ] unit-test
[ 0 ] [ 123 dup bitnot bitand >bignum ] unit-test
[ -1 ] [ 123 dup bitnot bitor ] unit-test
[ -1 ] [ 123 >bignum dup bitnot bitor ] unit-test
[ -1 ] [ 123 dup bitnot >bignum bitor ] unit-test
[ -1 ] [ 123 dup bitnot bitor >bignum ] unit-test
[ -1 ] [ 123 dup bitnot bitxor ] unit-test
[ -1 ] [ 123 >bignum dup bitnot bitxor ] unit-test
[ -1 ] [ 123 dup bitnot >bignum bitxor ] unit-test
[ -1 ] [ 123 dup bitnot bitxor >bignum ] unit-test

View File

@ -80,6 +80,7 @@ USE: unparser
"vectors" "vectors"
"unparser" "unparser"
"random" "random"
"math/bitops"
"math/rational" "math/rational"
"math/float" "math/float"
"math/complex" "math/complex"

View File

@ -151,3 +151,7 @@ BINARY_OP(greatereq)
BINARY_OP_INTEGER_ONLY(gcd) BINARY_OP_INTEGER_ONLY(gcd)
BINARY_OP_NUMBER_ONLY(gcd) BINARY_OP_NUMBER_ONLY(gcd)
BINARY_OP(gcd) BINARY_OP(gcd)
UNARY_OP_INTEGER_ONLY(not)
UNARY_OP_NUMBER_ONLY(not)
UNARY_OP(not)

View File

@ -157,7 +157,7 @@ CELL OP##_anytype(CELL x, CELL y) \
return F; \ return F; \
} }
#define UNARY_OP(OP,anytype,integerOnly) \ #define UNARY_OP(OP) \
CELL OP(CELL x) \ CELL OP(CELL x) \
{ \ { \
switch(type_of(x)) \ switch(type_of(x)) \
@ -165,39 +165,15 @@ CELL OP(CELL x) \
case FIXNUM_TYPE: \ case FIXNUM_TYPE: \
return OP##_fixnum(x); \ return OP##_fixnum(x); \
case RATIO_TYPE: \ case RATIO_TYPE: \
if(integerOnly) \ return OP##_ratio(x); \
{ \
type_error(INTEGER_TYPE,x); \
return F; \
} \
else \
return OP##_ratio(x); \
case COMPLEX_TYPE: \ case COMPLEX_TYPE: \
if(integerOnly) \ return OP##_complex(x); \
{ \
type_error(INTEGER_TYPE,x); \
return F; \
} \
else \
return OP##_complex(x); \
case BIGNUM_TYPE: \ case BIGNUM_TYPE: \
return OP##_bignum(x); \ return OP##_bignum(x); \
case FLOAT_TYPE: \ case FLOAT_TYPE: \
if(integerOnly) \ return OP##_float(x); \
{ \
type_error(INTEGER_TYPE,x); \
return F; \
} \
else \
return OP##_float(x); \
default: \ default: \
if(anytype) \ return OP##_anytype(x); \
return OP##_anytype(x); \
else \
{ \
type_error(NUMBER_TYPE,x); \
return F; \
} \
} \ } \
} \ } \
\ \
@ -206,6 +182,34 @@ void primitive_##OP(void) \
drepl(OP(dpeek())); \ drepl(OP(dpeek())); \
} }
#define UNARY_OP_INTEGER_ONLY(OP) \
\
CELL OP##_ratio(CELL x) \
{ \
type_error(INTEGER_TYPE,x); \
return F; \
} \
\
CELL OP##_complex(CELL x) \
{ \
type_error(INTEGER_TYPE,x); \
return F; \
} \
\
CELL OP##_float(CELL x) \
{ \
type_error(INTEGER_TYPE,x); \
return F; \
}
#define UNARY_OP_NUMBER_ONLY(OP) \
\
CELL OP##_anytype(CELL x) \
{ \
type_error(NUMBER_TYPE,x); \
return F; \
}
bool realp(CELL tagged); bool realp(CELL tagged);
bool numberp(CELL tagged); bool numberp(CELL tagged);
void primitive_numberp(void); void primitive_numberp(void);

View File

@ -198,3 +198,8 @@ CELL greatereq_bignum(CELL x, CELL y)
return tag_boolean(((BIGNUM*)UNTAG(x))->n return tag_boolean(((BIGNUM*)UNTAG(x))->n
>= ((BIGNUM*)UNTAG(y))->n); >= ((BIGNUM*)UNTAG(y))->n);
} }
CELL not_bignum(CELL x)
{
return tag_object(bignum(~((BIGNUM*)UNTAG(x))->n));
}

View File

@ -51,3 +51,4 @@ CELL less_bignum(CELL x, CELL y);
CELL lesseq_bignum(CELL x, CELL y); CELL lesseq_bignum(CELL x, CELL y);
CELL greater_bignum(CELL x, CELL y); CELL greater_bignum(CELL x, CELL y);
CELL greatereq_bignum(CELL x, CELL y); CELL greatereq_bignum(CELL x, CELL y);
CELL not_bignum(CELL x);

View File

@ -5,12 +5,6 @@ void primitive_fixnump(void)
drepl(tag_boolean(TAG(dpeek()) == FIXNUM_TYPE)); drepl(tag_boolean(TAG(dpeek()) == FIXNUM_TYPE));
} }
void primitive_not(void)
{
type_check(FIXNUM_TYPE,dpeek());
drepl(RETAG(UNTAG(~dpeek()),FIXNUM_TYPE));
}
FIXNUM to_fixnum(CELL tagged) FIXNUM to_fixnum(CELL tagged)
{ {
RATIO* r; RATIO* r;
@ -192,3 +186,8 @@ CELL greatereq_fixnum(CELL x, CELL y)
{ {
return tag_boolean((FIXNUM)x >= (FIXNUM)y); return tag_boolean((FIXNUM)x >= (FIXNUM)y);
} }
CELL not_fixnum(CELL n)
{
return RETAG(UNTAG(~n),FIXNUM_TYPE);
}

View File

@ -38,3 +38,4 @@ CELL less_fixnum(CELL x, CELL y);
CELL lesseq_fixnum(CELL x, CELL y); CELL lesseq_fixnum(CELL x, CELL y);
CELL greater_fixnum(CELL x, CELL y); CELL greater_fixnum(CELL x, CELL y);
CELL greatereq_fixnum(CELL x, CELL y); CELL greatereq_fixnum(CELL x, CELL y);
CELL not_fixnum(CELL n);