fix type and arithmetic-type intrinsics
parent
124ee9ef16
commit
a77efca4c1
|
@ -137,6 +137,7 @@ words ;
|
||||||
in-1
|
in-1
|
||||||
0 %arithmetic-type ,
|
0 %arithmetic-type ,
|
||||||
0 %tag-fixnum ,
|
0 %tag-fixnum ,
|
||||||
|
1 %inc-d ,
|
||||||
out-1
|
out-1
|
||||||
] "linearizer" set-word-prop
|
] "linearizer" set-word-prop
|
||||||
|
|
||||||
|
|
|
@ -135,12 +135,10 @@ VOP: %type
|
||||||
: %type ( vreg ) <vreg> dest-vop <%type> ;
|
: %type ( vreg ) <vreg> dest-vop <%type> ;
|
||||||
|
|
||||||
VOP: %arithmetic-type
|
VOP: %arithmetic-type
|
||||||
: %arithmetic-type empty-vop <%arithmetic-type> ;
|
: %arithmetic-type <vreg> dest-vop <%arithmetic-type> ;
|
||||||
|
|
||||||
VOP: %tag-fixnum
|
VOP: %tag-fixnum
|
||||||
: %tag-fixnum <vreg> dest-vop <%tag-fixnum> ;
|
: %tag-fixnum <vreg> dest-vop <%tag-fixnum> ;
|
||||||
|
|
||||||
: check-dest ( vop reg -- )
|
: check-dest ( vop reg -- )
|
||||||
swap vop-dest v>operand = [
|
swap vop-dest = [ "invalid VOP destination" throw ] unless ;
|
||||||
"invalid VOP destination" throw
|
|
||||||
] unless ;
|
|
||||||
|
|
|
@ -125,7 +125,7 @@ M: %type generate-node ( vop -- )
|
||||||
M: %arithmetic-type generate-node ( vop -- )
|
M: %arithmetic-type generate-node ( vop -- )
|
||||||
#! This one works directly with the stack. It outputs an
|
#! This one works directly with the stack. It outputs an
|
||||||
#! UNBOXED value in vop-dest.
|
#! UNBOXED value in vop-dest.
|
||||||
EAX check-dest
|
0 <vreg> check-dest
|
||||||
<label> "end" set
|
<label> "end" set
|
||||||
! Load top two stack values
|
! Load top two stack values
|
||||||
EAX [ ESI -4 ] MOV
|
EAX [ ESI -4 ] MOV
|
||||||
|
@ -138,5 +138,5 @@ M: %arithmetic-type generate-node ( vop -- )
|
||||||
"end" get JE
|
"end" get JE
|
||||||
! No, they are not equal. Call a runtime function to
|
! No, they are not equal. Call a runtime function to
|
||||||
! coerce the integers to a higher type.
|
! coerce the integers to a higher type.
|
||||||
"arithmetic_type" compile-c-call
|
"arithmetic_type" f compile-c-call
|
||||||
"end" get save-xt ;
|
"end" get save-xt ;
|
||||||
|
|
|
@ -122,3 +122,11 @@ math-internals test words ;
|
||||||
[ 268435456 ] [ -268435456 >fixnum -1 [ fixnum/i ] compile-1 ] unit-test
|
[ 268435456 ] [ -268435456 >fixnum -1 [ fixnum/i ] compile-1 ] unit-test
|
||||||
|
|
||||||
[ 3 1 ] [ 10 3 [ fixnum/mod ] compile-1 ] unit-test
|
[ 3 1 ] [ 10 3 [ fixnum/mod ] compile-1 ] unit-test
|
||||||
|
|
||||||
|
[ t ] [ 3 type 3 [ type ] compile-1 eq? ] unit-test
|
||||||
|
[ t ] [ 3 >bignum type 3 >bignum [ type ] compile-1 eq? ] unit-test
|
||||||
|
[ t ] [ "hey" type "hey" [ type ] compile-1 eq? ] unit-test
|
||||||
|
[ t ] [ f type f [ type ] compile-1 eq? ] unit-test
|
||||||
|
|
||||||
|
[ 1 1 0 ] [ 1 1 [ arithmetic-type ] compile-1 ] unit-test
|
||||||
|
[ 1.0 1.0 5 ] [ 1.0 1 [ arithmetic-type ] compile-1 ] unit-test
|
||||||
|
|
|
@ -4,8 +4,14 @@ IN: test
|
||||||
USING: errors kernel lists math memory namespaces parser
|
USING: errors kernel lists math memory namespaces parser
|
||||||
prettyprint sequences stdio strings unparser vectors words ;
|
prettyprint sequences stdio strings unparser vectors words ;
|
||||||
|
|
||||||
: assert ( t -- )
|
TUPLE: assert expect got ;
|
||||||
[ "Assertion failed!" throw ] unless ;
|
M: assert error.
|
||||||
|
"Assertion failed" print
|
||||||
|
"Expected: " write dup assert-expect .
|
||||||
|
"Got: " write assert-got . ;
|
||||||
|
|
||||||
|
: assert= ( a b -- )
|
||||||
|
2dup = [ <assert> throw ] unless ;
|
||||||
|
|
||||||
: print-test ( input output -- )
|
: print-test ( input output -- )
|
||||||
"--> " write 2list . flush ;
|
"--> " write 2list . flush ;
|
||||||
|
@ -25,7 +31,7 @@ prettyprint sequences stdio strings unparser vectors words ;
|
||||||
[
|
[
|
||||||
2dup print-test
|
2dup print-test
|
||||||
swap >r >r clear r> call
|
swap >r >r clear r> call
|
||||||
datastack >list r> = assert
|
datastack >list r> assert=
|
||||||
] keep-datastack 2drop
|
] keep-datastack 2drop
|
||||||
] time ;
|
] time ;
|
||||||
|
|
||||||
|
@ -34,9 +40,7 @@ prettyprint sequences stdio strings unparser vectors words ;
|
||||||
[ [ not ] catch ] cons [ f ] swap unit-test ;
|
[ [ not ] catch ] cons [ f ] swap unit-test ;
|
||||||
|
|
||||||
: assert-depth ( quot -- )
|
: assert-depth ( quot -- )
|
||||||
depth slip depth = [
|
depth slip depth assert= ;
|
||||||
"Unequal before/after depth" throw
|
|
||||||
] unless ;
|
|
||||||
|
|
||||||
SYMBOL: failures
|
SYMBOL: failures
|
||||||
|
|
||||||
|
|
|
@ -66,5 +66,5 @@ F_FIXNUM arithmetic_type(void)
|
||||||
|
|
||||||
void primitive_arithmetic_type(void)
|
void primitive_arithmetic_type(void)
|
||||||
{
|
{
|
||||||
dpush(arithmetic_type());
|
dpush(tag_fixnum(arithmetic_type()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue