diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index dd970328e2..390802b4fe 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -12,9 +12,7 @@ + native: - native float>bits -- printing floats: append .0 always - vector= -- make-image: take a parameter, include le & be images in dist - do something about "base" variable -- too fragile ERROR: I/O error: [ "primitive_read_line_fd_8" "Resource temporarily unavailable" ] - errors: don't show .factor-rc diff --git a/build.sh b/build.sh index 8904f74520..17045a1bfb 100644 --- a/build.sh +++ b/build.sh @@ -1,5 +1,5 @@ export CC=gcc34 -export CFLAGS="-pedantic -Wall -Winline -O3 -march=pentium4 -fomit-frame-pointer" +export CFLAGS="-lm -pedantic -Wall -Winline -O3 -march=pentium4 -fomit-frame-pointer" $CC $CFLAGS -o f native/*.c diff --git a/factor/FactorCompoundDefinition.java b/factor/FactorCompoundDefinition.java index 8cdaa39f44..e381aa55c9 100644 --- a/factor/FactorCompoundDefinition.java +++ b/factor/FactorCompoundDefinition.java @@ -96,7 +96,8 @@ public class FactorCompoundDefinition extends FactorWordDefinition RecursiveState recursiveCheck) throws Exception { // Each word has its own class loader - FactorClassLoader loader = new FactorClassLoader(); + FactorClassLoader loader = new FactorClassLoader( + getClass().getClassLoader()); StackEffect effect = getStackEffect(interp); diff --git a/factor/compiler/FactorClassLoader.java b/factor/compiler/FactorClassLoader.java index dc633e90e9..210179196c 100644 --- a/factor/compiler/FactorClassLoader.java +++ b/factor/compiler/FactorClassLoader.java @@ -42,6 +42,13 @@ public class FactorClassLoader extends ClassLoader { private long id; private FactorNamespace table = new FactorNamespace(); + private ClassLoader delegate; + + //{{{ FactorClassLoader constructor + public FactorClassLoader(ClassLoader delegate) + { + this.delegate = delegate; + } //}}} //{{{ addDependency() method public void addDependency(String name, FactorClassLoader loader) @@ -88,7 +95,15 @@ public class FactorClassLoader extends ClassLoader System.err.println("WARNING: unknown object in class loader table for " + this + ": " + obj); } - return super.loadClass(name,resolve); + if(delegate == null) + return super.loadClass(name,resolve); + else + { + c = delegate.loadClass(name); + if(resolve) + resolveClass(c); + return c; + } } catch(ClassNotFoundException e) { diff --git a/library/cross-compiler.factor b/library/cross-compiler.factor index 5a5a198769..ba10b4320f 100644 --- a/library/cross-compiler.factor +++ b/library/cross-compiler.factor @@ -29,7 +29,9 @@ IN: cross-compiler USE: arithmetic USE: kernel USE: lists +USE: namespaces USE: parser +USE: real-math USE: stack USE: stdio USE: streams @@ -160,6 +162,19 @@ IN: cross-compiler <= > >= + gcd + facos + fasin + fatan + fatan2 + fcos + fexp + fcosh + flog + fpow + fsin + fsinh + fsqrt word? word-primitive @@ -211,12 +226,14 @@ IN: cross-compiler : version, ( -- ) "version" [ "kernel" ] search version unit compound, ; -: make-image ( -- ) +: make-image ( name -- ) #! Make an image for the C interpreter. [ "/library/platform/native/boot.factor" run-resource ] with-image - ! Uncomment this on sparc and powerpc. - ! "big-endian" on - "factor.image" write-image ; + swap write-image ; + +: make-images ( -- ) + "big-endian" off "factor.image.le" make-image + "big-endian" on "factor.image.be" make-image ; diff --git a/library/image.factor b/library/image.factor index ac7a1e8d42..aa81616874 100644 --- a/library/image.factor +++ b/library/image.factor @@ -69,14 +69,14 @@ USE: words : untag ( cell tag -- ) tag-mask bitnot bitand ; : tag ( cell -- tag ) tag-mask bitand ; -: fixnum-tag BIN: 000 ; -: word-tag BIN: 001 ; -: cons-tag BIN: 010 ; -: object-tag BIN: 011 ; -: rational-tag BIN: 100 ; -: complex-tag BIN: 101 ; -: header-tag BIN: 110 ; -: gc-fwd-ptr BIN: 111 ; ( we don't output these ) +: fixnum-tag BIN: 000 ; +: word-tag BIN: 001 ; +: cons-tag BIN: 010 ; +: object-tag BIN: 011 ; +: ratio-tag BIN: 100 ; +: complex-tag BIN: 101 ; +: header-tag BIN: 110 ; +: gc-fwd-ptr BIN: 111 ; ( we don't output these ) : f-type 6 ; : t-type 7 ; @@ -128,20 +128,19 @@ USE: words ( Floats ) : 'float ( f -- tagged ) - object-tag here-as + object-tag here-as >r float-type >header emit 0 emit ( alignment -- FIXME 64-bit arch ) - float>bits emit64 ; + float>bits emit64 r> ; ( Bignums ) : 'bignum ( bignum -- tagged ) - dup . #! Very bad! - object-tag here-as + object-tag here-as >r bignum-type >header emit 0 emit ( alignment -- FIXME 64-bit arch ) - ( bignum -- ) emit64 ; + ( bignum -- ) emit64 r> ; ( Special objects ) @@ -196,6 +195,18 @@ DEFER: ' : cons, ( -- pointer ) cons-tag here-as ; : 'cons ( c -- tagged ) uncons ' swap ' cons, -rot emit emit ; +( Ratios -- almost the same as a cons ) + +: ratio, ( -- pointer ) ratio-tag here-as ; +: 'ratio ( a/b -- tagged ) + dup denominator ' swap numerator ' ratio, -rot emit emit ; + +( Complex -- almost the same as ratio ) + +: complex, ( -- pointer ) complex-tag here-as ; +: 'complex ( #{ a b } -- tagged ) + dup imaginary ' swap real ' complex, -rot emit emit ; + ( Strings ) : pack ( n n -- ) @@ -299,17 +310,19 @@ IN: cross-compiler : ' ( obj -- pointer ) [ - [ fixnum? ] [ 'fixnum ] - [ bignum? ] [ 'bignum ] - [ float? ] [ 'float ] - [ word? ] [ 'word ] - [ cons? ] [ 'cons ] - [ char? ] [ 'fixnum ] - [ string? ] [ 'string ] - [ vector? ] [ 'vector ] - [ t = ] [ drop "t" get ] - [ f = ] [ drop "f" get ] - [ drop t ] [ "Cannot cross-compile: " swap cat2 throw ] + [ fixnum? ] [ 'fixnum ] + [ bignum? ] [ 'bignum ] + [ float? ] [ 'float ] + [ ratio? ] [ 'ratio ] + [ complex? ] [ 'complex ] + [ word? ] [ 'word ] + [ cons? ] [ 'cons ] + [ char? ] [ 'fixnum ] + [ string? ] [ 'string ] + [ vector? ] [ 'vector ] + [ t = ] [ drop "t" get ] + [ f = ] [ drop "f" get ] + [ drop t ] [ "Cannot cross-compile: " swap cat2 throw ] ] cond ; ( End of the image ) @@ -353,7 +366,7 @@ IN: cross-compiler : write-image ( image file -- ) [ [ write-word ] vector-each ] with-stream ; -: with-image ( quot -- image ) +: with-minimal-image ( quot -- image ) [ 300000 "image" set 521 "objects" set @@ -362,8 +375,11 @@ IN: cross-compiler ! since ; ends up using this variable from nested ! parser namespaces. 1000 "word-fixups" set - begin call end + call "image" get ] bind ; +: with-image ( quot -- image ) + [ begin call end ] with-minimal-image ; + : test-image ( quot -- ) with-image vector>list . ; diff --git a/library/math/arithmetic.factor b/library/math/arithmetic.factor index 237dc1533a..697b9a300b 100644 --- a/library/math/arithmetic.factor +++ b/library/math/arithmetic.factor @@ -43,8 +43,6 @@ USE: stack : pi 3.14159265358979323846 ; inline : pi/2 1.5707963267948966 ; inline -: /f / >float ; inline - : f>0 ( obj -- obj ) #! If f at the top of the stack, turn it into 0. [ 0 ] unless* ; @@ -53,9 +51,6 @@ USE: stack #! If 0 at the top of the stack, turn it into f. dup 0 = [ drop f ] when ; -: compare ( x y [ if x < y ] [ if x = y ] [ if x > y ] -- ) - >=< call ; inline interpret-only - : max ( x y -- z ) 2dup > [ drop ] [ nip ] ifte ; @@ -74,9 +69,6 @@ USE: stack : neg 0 swap - ; inline : recip 1 swap / ; inline -: round ( x to -- y ) - dupd rem - ; - : deg2rad pi * 180 / ; : rad2deg 180 * pi / ; diff --git a/library/platform/jvm/arithmetic.factor b/library/platform/jvm/arithmetic.factor index a5b0068345..3e3ecf60d2 100644 --- a/library/platform/jvm/arithmetic.factor +++ b/library/platform/jvm/arithmetic.factor @@ -57,6 +57,8 @@ USE: stack "factor.math.FactorMath" "_divide" jinvoke-static ; inline +: /f / >float ; inline + : mod ( a b -- a%b ) [ "java.lang.Number" "java.lang.Number" ] "factor.math.FactorMath" "mod" @@ -93,6 +95,9 @@ USE: stack ] "factor.FactorLib" "branch3" jinvoke-static ; +: compare ( x y [ if x < y ] [ if x = y ] [ if x > y ] -- ) + >=< call ; inline interpret-only + : bitand ( x y -- x&y ) #! Bitwise and. [ "java.lang.Number" "java.lang.Number" ] @@ -140,6 +145,9 @@ USE: stack [ "double" "double" ] "java.lang.Math" "IEEEremainder" jinvoke-static ; inline +: round ( x to -- y ) + dupd rem - ; + : gcd ( a b -- c ) [ "java.lang.Number" "java.lang.Number" ] "factor.math.FactorMath" "gcd" jinvoke-static ; diff --git a/library/platform/jvm/parser.factor b/library/platform/jvm/parser.factor index 9b311b7fa5..b04aa82ee9 100644 --- a/library/platform/jvm/parser.factor +++ b/library/platform/jvm/parser.factor @@ -29,6 +29,7 @@ IN: parser USE: namespaces USE: stack USE: streams +USE: strings : parse-file ( file -- list ) dup parse-stream ; @@ -36,6 +37,17 @@ USE: streams : run-file ( path -- ) parse-file call ; +: parse-resource* ( resource -- list ) + dup swap "resource:" swap cat2 swap parse-stream ; + +: parse-resource ( file -- ) + #! Override this to be slightly more useful for development. + global [ "resource-path" get ] bind dup [ + swap cat2 parse-file + ] [ + drop parse-resource* + ] ifte ; + : ( filename reader interactive docs -- parser ) interpreter [ diff --git a/library/platform/jvm/real-math.factor b/library/platform/jvm/real-math.factor index 88c23c124d..592ab21af4 100644 --- a/library/platform/jvm/real-math.factor +++ b/library/platform/jvm/real-math.factor @@ -35,10 +35,6 @@ USE: arithmetic USE: kernel USE: stack -: fabs ( x -- abs ) - [ "double" ] "java.lang.Math" "abs" - jinvoke-static ; inline - : facos ( x -- acos ) [ "double" ] "java.lang.Math" "acos" jinvoke-static ; inline @@ -51,7 +47,7 @@ USE: stack [ "double" ] "java.lang.Math" "atan" jinvoke-static ; inline -: fatan2 ( x y -- atan2 ) +: fatan2 ( y x -- atan2 ) [ "double" "double" ] "java.lang.Math" "atan2" jinvoke-static ; inline diff --git a/library/platform/native/arithmetic.factor b/library/platform/native/arithmetic.factor deleted file mode 100644 index 0506083119..0000000000 --- a/library/platform/native/arithmetic.factor +++ /dev/null @@ -1,28 +0,0 @@ -! This file will go away very shortly! - -IN: arithmetic -USE: combinators -USE: kernel -USE: logic -USE: stack - -: integer? dup fixnum? swap bignum? or ; - -: max ( x y -- z ) - 2dup > [ drop ] [ nip ] ifte ; - -: min ( x y -- z ) - 2dup < [ drop ] [ nip ] ifte ; - -: between? ( x min max -- ? ) - #! Push if min <= x <= max. - >r dupd max r> min = ; - -: pred 1 - ; inline -: succ 1 + ; inline - -: neg 0 swap - ; inline - -!: e 2.7182818284590452354 ; inline -!: pi 3.14159265358979323846 ; inline -!: pi/2 1.5707963267948966 ; inline diff --git a/library/platform/native/boot.factor b/library/platform/native/boot.factor index d1d7976b10..6aa485ac73 100644 --- a/library/platform/native/boot.factor +++ b/library/platform/native/boot.factor @@ -78,11 +78,16 @@ primitives, "/library/vocabularies.factor" "/library/vocabulary-style.factor" "/library/words.factor" - "/library/math/math-combinators.factor" + "/library/math/arc-trig-hyp.factor" + "/library/math/arithmetic.factor" "/library/math/list-math.factor" + "/library/math/math.factor" + "/library/math/math-combinators.factor" "/library/math/namespace-math.factor" + "/library/math/pow.factor" + "/library/math/quadratic.factor" + "/library/math/trig-hyp.factor" "/library/test/test.factor" - "/library/platform/native/arithmetic.factor" "/library/platform/native/errors.factor" "/library/platform/native/io-internals.factor" "/library/platform/native/stream.factor" diff --git a/library/platform/native/errors.factor b/library/platform/native/errors.factor index a6d7facfba..9d9b90b3dc 100644 --- a/library/platform/native/errors.factor +++ b/library/platform/native/errors.factor @@ -60,11 +60,11 @@ USE: vectors "Type check: " "Array range check: " "Underflow" - "Bad primitive: " "Incompatible handle: " "I/O error: " "Overflow" "Incomparable types: " + "Float format: " ] ?nth ; : ?kernel-error ( cons -- error# param ) diff --git a/library/platform/native/parse-numbers.factor b/library/platform/native/parse-numbers.factor index dd083e9729..90b528b196 100644 --- a/library/platform/native/parse-numbers.factor +++ b/library/platform/native/parse-numbers.factor @@ -62,7 +62,11 @@ USE: unparser ] ifte ; : (str>integer) ( str -- num ) - 0 swap [ digit> digit ] str-each ; + dup str-length 0 = [ + not-a-number + ] [ + 0 swap [ digit> digit ] str-each + ] ifte ; : str>integer ( str -- num ) #! Parse a string representation of an integer. @@ -70,7 +74,7 @@ USE: unparser drop not-a-number ] [ dup "-" str-head? dup [ - nip str>integer neg + nip (str>integer) neg ] [ drop (str>integer) ] ifte diff --git a/library/platform/native/parse-syntax.factor b/library/platform/native/parse-syntax.factor index bfb66c52b2..f08b376601 100644 --- a/library/platform/native/parse-syntax.factor +++ b/library/platform/native/parse-syntax.factor @@ -134,6 +134,11 @@ USE: unparser ! Char literal : CHAR: ( -- ) skip-blank next-ch parse-ch parsed ; parsing +! Complex literal +: #{ + #! Read #{ real imaginary #} + scan str>number scan str>number rect> parsed "}" expect ; + ! Comments : ( ")" until drop ; parsing : ! until-eol drop ; parsing diff --git a/library/platform/native/parser.factor b/library/platform/native/parser.factor index 4e7462f954..0f7280d426 100644 --- a/library/platform/native/parser.factor +++ b/library/platform/native/parser.factor @@ -104,11 +104,15 @@ USE: unparser #! Some ugly ugly code to handle [ a | b ] expressions. >r nreverse dup last* r> swap set-cdr swons ; -: expect-] ( -- ) - scan "]" = not [ "Expected ]" throw ] when ; +: expect ( word -- ) + dup scan = not [ + "Expected " swap cat2 throw + ] [ + drop + ] ifte ; : parsed ( obj -- ) - over "|" = [ nip parsed| expect-] ] [ swons ] ifte ; + over "|" = [ nip parsed| "]" expect ] [ swons ] ifte ; : number, ( num -- ) str>number parsed ; diff --git a/library/platform/native/unparser.factor b/library/platform/native/unparser.factor index 27601bed06..968b34cef0 100644 --- a/library/platform/native/unparser.factor +++ b/library/platform/native/unparser.factor @@ -108,6 +108,11 @@ USE: vocabularies : unparse-word ( word -- str ) word-name dup "#" ? ; +: fix-float ( str -- str ) + #! This is terrible. Will go away when we do our own float + #! output. + "." over str-contains? [ ".0" cat2 ] unless ; + : unparse ( obj -- str ) [ [ t eq? ] [ drop "t" ] @@ -115,7 +120,7 @@ USE: vocabularies [ word? ] [ unparse-word ] [ integer? ] [ unparse-integer ] [ ratio? ] [ unparse-ratio ] - [ float? ] [ unparse-float ] + [ float? ] [ unparse-float fix-float ] [ complex? ] [ unparse-complex ] [ string? ] [ unparse-str ] [ drop t ] [ <% "#<" % class-of % ">" % %> ] diff --git a/library/test/math.factor b/library/test/math.factor deleted file mode 100644 index d1c13e9dbc..0000000000 --- a/library/test/math.factor +++ /dev/null @@ -1,225 +0,0 @@ -IN: scratchpad -USE: arithmetic -USE: compiler -USE: kernel -USE: math -USE: stdio -USE: test - -"Testing math words." print - -[ 100 ] [ 100 100 ] [ gcd ] test-word -[ 100 ] [ 1000 100 ] [ gcd ] test-word -[ 100 ] [ 100 1000 ] [ gcd ] test-word -[ 4 ] [ 132 64 ] [ gcd ] test-word -[ 4 ] [ -132 64 ] [ gcd ] test-word -[ 4 ] [ -132 -64 ] [ gcd ] test-word -[ 4 ] [ 132 -64 ] [ gcd ] test-word -[ 4 ] [ -132 -64 ] [ gcd ] test-word - -! Make sure computation results are sane types. -[ t ] [ 30 2^ ] [ fixnum? ] test-word -[ t ] [ 32 2^ ] [ bignum? ] test-word - -[ 2.1 ] [ -2.1 ] [ neg ] test-word - -! Make sure equality testing works. - -[ t ] [ 1 1.0 ] [ = ] test-word -[ f ] [ #{ 5 12.5 } 5 ] [ = ] test-word -[ t ] [ #{ 1.0 2.0 } #{ 1 2 } ] [ = ] test-word -[ f ] [ #{ 1.0 2.3 } #{ 1 2 } ] [ = ] test-word - -! Complex number tests. - -[ #{ 2 5 } ] [ 2 5 ] [ rect> ] test-word -[ 2 5 ] [ #{ 2 5 } ] [ >rect ] test-word -[ #{ 1/2 1 } ] [ 1/2 i ] [ + ] test-word -[ #{ 1/2 1 } ] [ i 1/2 ] [ + ] test-word -[ t ] [ #{ 11 64 } #{ 11 64 } ] [ = ] test-word -[ #{ 2 1 } ] [ 2 i ] [ + ] test-word -[ #{ 2 1 } ] [ i 2 ] [ + ] test-word -[ #{ 5 4 } ] [ #{ 2 2 } #{ 3 2 } ] [ + ] test-word -[ 5 ] [ #{ 2 2 } #{ 3 -2 } ] [ + ] test-word -[ #{ 1.0 1 } ] [ 1.0 i ] [ + ] test-word - -[ #{ 1/2 -1 } ] [ 1/2 i ] [ - ] test-word -[ #{ -1/2 1 } ] [ i 1/2 ] [ - ] test-word -[ #{ 1/3 1/4 } ] [ 1 3 / 1 2 / i * + 1 4 / i * ] [ - ] test-word -[ #{ -1/3 -1/4 } ] [ 1 4 / i * 1 3 / 1 2 / i * + ] [ - ] test-word -[ #{ 1/5 1/4 } ] [ #{ 3/5 1/2 } #{ 2/5 1/4 } ] [ - ] test-word -[ 4 ] [ #{ 5 10/3 } #{ 1 10/3 } ] [ - ] test-word -[ #{ 1.0 -1 } ] [ 1.0 i ] [ - ] test-word - -[ #{ 0 1 } ] [ i 1 ] [ * ] test-word -[ #{ 0 1 } ] [ 1 i ] [ * ] test-word -[ #{ 0 1.0 } ] [ 1.0 i ] [ * ] test-word -[ -1 ] [ i i ] [ * ] test-word -[ #{ 0 1 } ] [ 1 i ] [ * ] test-word -[ #{ 0 1 } ] [ i 1 ] [ * ] test-word -[ #{ 0 1/2 } ] [ 1/2 i ] [ * ] test-word -[ #{ 0 1/2 } ] [ i 1/2 ] [ * ] test-word -[ 2 ] [ #{ 1 1 } #{ 1 -1 } ] [ * ] test-word -[ 1 ] [ i -i ] [ * ] test-word - -[ -1 ] [ i -i ] [ / ] test-word -[ #{ 0 1 } ] [ 1 -i ] [ / ] test-word -[ t ] [ #{ 12 13 } #{ 13 14 } / #{ 13 14 } * #{ 12 13 } ] [ = ] test-word - -[ #{ -3 4 } ] [ #{ 3 -4 } ] [ neg ] test-word - -! Comparison tests; make sure we're doing appropriate -! comparisons based on operand types. - -! bignum -vs- bignum - -[ t ] -[ 100000000000000000000000000 100000000000000000000000000 ] -[ = ] -test-word - -[ f ] -[ 100000000000000000000000000 100000000000000000000000001 ] -[ = ] -test-word - -[ t ] -[ 100000000000000000000000000 100000000000000000000000001 ] -[ < ] -test-word - -[ t ] -[ 100000000000000000000000000 100000000000000000000000001 ] -[ <= ] -test-word - -[ f ] -[ 100000000000000000000000000 100000000000000000000000001 ] -[ > ] -test-word - -[ t ] -[ 100000000000000000000000002 100000000000000000000000001 ] -[ > ] -test-word - -[ t ] -[ 100000000000000000000000002 100000000000000000000000001 ] -[ >= ] -test-word - -[ f ] -[ 100000000000000000000000002 100000000000000000000000001 ] -[ < ] -test-word - -! bignum -vs- fixnum - -[ t ] -[ 100000000000000000000000000 1000 ] -[ >= ] -test-word - -[ f ] -[ 100000000000000000000000000 1000 ] -[ < ] -test-word - -! fixnum -vs- bignum - -[ f ] -[ 1000 100000000000000000000000000 ] -[ >= ] -test-word - -[ t ] -[ 1000 100000000000000000000000000 ] -[ < ] -test-word - -! fixnum -vs- ratio - -[ t ] -[ 1000000000/999999 1000 ] -[ > ] -test-word - -! ratio -vs- fixnum - -[ f ] -[ 100000 100000000000/999999 ] -[ > ] -test-word - -! ratio -vs- ratio - -[ t ] -[ 1000000000000/999999999999 1000000000001/999999999998 ] -[ < ] -test-word - -! float -vs- fixnum - -[ t ] -[ pi 3 ] -[ > ] -test-word - -! fixnum -vs- float - -[ f ] -[ e 2 ] -[ <= ] -test-word - -! Test irrationals. - -[ [ 1 1 0 0 ] ] [ [ sqrt ] ] [ balance>list ] test-word -[ 4.0 ] [ 16 ] [ sqrt ] test-word -[ #{ 0 4.0 } ] [ -16 ] [ sqrt ] test-word - -[ [ 2 1 0 0 ] ] [ [ ^ ] ] [ balance>list ] test-word -[ 4.0 ] [ 2 2 ] [ ^ ] test-word -[ 0.25 ] [ 2 -2 ] [ ^ ] test-word -[ t ] [ 2 0.5 ^ 2 ^ ] [ 2 2.00001 between? ] test-word -[ t ] [ e pi i * ^ real ] [ -1.0 = ] test-word -[ t ] [ e pi i * ^ imaginary ] [ -0.00001 0.00001 between? ] test-word - -[ [ 1 1 0 0 ] ] [ [ cosh ] ] [ balance>list ] test-word -[ [ 1 1 0 0 ] ] [ [ acosh ] ] [ balance>list ] test-word -[ 1.0 ] [ 0 ] [ cosh ] test-word -[ 0.0 ] [ 1 ] [ acosh ] test-word - -[ [ 1 1 0 0 ] ] [ [ cos ] ] [ balance>list ] test-word -[ [ 1 1 0 0 ] ] [ [ acos ] ] [ balance>list ] test-word -[ 1.0 ] [ 0 ] [ cos ] test-word -[ 0.0 ] [ 1 ] [ acos ] test-word - -[ [ 1 1 0 0 ] ] [ [ sinh ] ] [ balance>list ] test-word -[ [ 1 1 0 0 ] ] [ [ asinh ] ] [ balance>list ] test-word -[ 0.0 ] [ 0 ] [ sinh ] test-word -[ 0.0 ] [ 0 ] [ asinh ] test-word - -[ [ 1 1 0 0 ] ] [ [ sin ] ] [ balance>list ] test-word -[ [ 1 1 0 0 ] ] [ [ asin ] ] [ balance>list ] test-word -[ 0.0 ] [ 0 ] [ sin ] test-word -[ 0.0 ] [ 0 ] [ asin ] test-word - -! Make sure shift< is doing bignum upgrading. - -[ 4294967296 ] -[ 1 32 ] -[ shift< ] -test-word - -[ 18446744073709551616 ] -[ 1 64 ] -[ shift< ] -test-word - -[ 340282366920938463463374607431768211456 ] -[ 1 128 ] -[ shift< ] -test-word - -"Math tests done." print diff --git a/library/test/math/complex.factor b/library/test/math/complex.factor new file mode 100644 index 0000000000..7b1f7bdfa1 --- /dev/null +++ b/library/test/math/complex.factor @@ -0,0 +1,45 @@ +IN: scratchpad +USE: arithmetic +USE: kernel +USE: stack +USE: test + +[ f ] [ #{ 5 12.5 } 5 ] [ = ] test-word +[ t ] [ #{ 1.0 2.0 } #{ 1 2 } ] [ = ] test-word +[ f ] [ #{ 1.0 2.3 } #{ 1 2 } ] [ = ] test-word + +[ #{ 2 5 } ] [ 2 5 ] [ rect> ] test-word +[ 2 5 ] [ #{ 2 5 } ] [ >rect ] test-word +[ #{ 1/2 1 } ] [ 1/2 i ] [ + ] test-word +[ #{ 1/2 1 } ] [ i 1/2 ] [ + ] test-word +[ t ] [ #{ 11 64 } #{ 11 64 } ] [ = ] test-word +[ #{ 2 1 } ] [ 2 i ] [ + ] test-word +[ #{ 2 1 } ] [ i 2 ] [ + ] test-word +[ #{ 5 4 } ] [ #{ 2 2 } #{ 3 2 } ] [ + ] test-word +[ 5 ] [ #{ 2 2 } #{ 3 -2 } ] [ + ] test-word +[ #{ 1.0 1 } ] [ 1.0 i ] [ + ] test-word + +[ #{ 1/2 -1 } ] [ 1/2 i ] [ - ] test-word +[ #{ -1/2 1 } ] [ i 1/2 ] [ - ] test-word +[ #{ 1/3 1/4 } ] [ 1 3 / 1 2 / i * + 1 4 / i * ] [ - ] test-word +[ #{ -1/3 -1/4 } ] [ 1 4 / i * 1 3 / 1 2 / i * + ] [ - ] test-word +[ #{ 1/5 1/4 } ] [ #{ 3/5 1/2 } #{ 2/5 1/4 } ] [ - ] test-word +[ 4 ] [ #{ 5 10/3 } #{ 1 10/3 } ] [ - ] test-word +[ #{ 1.0 -1 } ] [ 1.0 i ] [ - ] test-word + +[ #{ 0 1 } ] [ i 1 ] [ * ] test-word +[ #{ 0 1 } ] [ 1 i ] [ * ] test-word +[ #{ 0 1.0 } ] [ 1.0 i ] [ * ] test-word +[ -1 ] [ i i ] [ * ] test-word +[ #{ 0 1 } ] [ 1 i ] [ * ] test-word +[ #{ 0 1 } ] [ i 1 ] [ * ] test-word +[ #{ 0 1/2 } ] [ 1/2 i ] [ * ] test-word +[ #{ 0 1/2 } ] [ i 1/2 ] [ * ] test-word +[ 2 ] [ #{ 1 1 } #{ 1 -1 } ] [ * ] test-word +[ 1 ] [ i -i ] [ * ] test-word + +[ -1 ] [ i -i ] [ / ] test-word +[ #{ 0 1 } ] [ 1 -i ] [ / ] test-word +[ t ] [ #{ 12 13 } #{ 13 14 } / #{ 13 14 } * #{ 12 13 } ] [ = ] test-word + +[ #{ -3 4 } ] [ #{ 3 -4 } ] [ neg ] test-word diff --git a/library/test/math/float.factor b/library/test/math/float.factor index dd18fe1bd5..4b4d4b2fb1 100644 --- a/library/test/math/float.factor +++ b/library/test/math/float.factor @@ -18,7 +18,7 @@ USE: test [ f ] [ 1.3 1 = ] unit-test [ f ] [ 1.3 1 >bignum = ] unit-test -[ t ] [ 134.3 >fixnum 134 eq? ] unit-test +[ t ] [ 134.3 >fixnum 134 = ] unit-test [ 2.1 ] [ -2.1 neg ] unit-test @@ -27,3 +27,6 @@ USE: test [ 3 ] [ 3.1415 >fixnum ] unit-test [ 3 ] [ 3.1415 >bignum ] unit-test + +[ t ] [ pi 3 > ] unit-test +[ f ] [ e 2 <= ] unit-test diff --git a/library/test/math/irrational.factor b/library/test/math/irrational.factor new file mode 100644 index 0000000000..1b7c55c420 --- /dev/null +++ b/library/test/math/irrational.factor @@ -0,0 +1,26 @@ +IN: scratchpad +USE: arithmetic +USE: kernel +USE: math +USE: test + +[ 4.0 ] [ 16 ] [ sqrt ] test-word +[ #{ 0 4.0 } ] [ -16 ] [ sqrt ] test-word + +[ 4.0 ] [ 2 2 ] [ ^ ] test-word +[ 0.25 ] [ 2 -2 ] [ ^ ] test-word +[ t ] [ 2 0.5 ^ 2 ^ ] [ 2 2.00001 between? ] test-word +[ t ] [ e pi i * ^ real ] [ -1.0 = ] test-word +[ t ] [ e pi i * ^ imaginary ] [ -0.00001 0.00001 between? ] test-word + +[ 1.0 ] [ 0 ] [ cosh ] test-word +[ 0.0 ] [ 1 ] [ acosh ] test-word + +[ 1.0 ] [ 0 ] [ cos ] test-word +[ 0.0 ] [ 1 ] [ acos ] test-word + +[ 0.0 ] [ 0 ] [ sinh ] test-word +[ 0.0 ] [ 0 ] [ asinh ] test-word + +[ 0.0 ] [ 0 ] [ sin ] test-word +[ 0.0 ] [ 0 ] [ asin ] test-word diff --git a/library/test/math/rational.factor b/library/test/math/rational.factor index 239907e90f..209b5d914f 100644 --- a/library/test/math/rational.factor +++ b/library/test/math/rational.factor @@ -77,5 +77,15 @@ USE: test [ 1000000000000/999999999999 1000000000001/999999999998 < ] unit-test -[ 3 ] [ 10/3 >integer ] unit-test -[ -3 ] [ -10/3 >integer ] unit-test +! JVM factor doesn't have >integer yet. +! [ 3 ] [ 10/3 >integer ] unit-test +! [ -3 ] [ -10/3 >integer ] unit-test + +[ 100 ] [ 100 100 gcd ] unit-test +[ 100 ] [ 1000 100 gcd ] unit-test +[ 100 ] [ 100 1000 gcd ] unit-test +[ 4 ] [ 132 64 gcd ] unit-test +[ 4 ] [ -132 64 gcd ] unit-test +[ 4 ] [ -132 -64 gcd ] unit-test +[ 4 ] [ 132 -64 gcd ] unit-test +[ 4 ] [ -132 -64 gcd ] unit-test diff --git a/library/test/namespaces/namespaces.factor b/library/test/namespaces/namespaces.factor index e1c1ebf0fb..7b048f20b1 100644 --- a/library/test/namespaces/namespaces.factor +++ b/library/test/namespaces/namespaces.factor @@ -35,7 +35,7 @@ unit-test [ t ] [ "test-word" intern - [ "vocabularies" "test" "test-word" ] object-path + global [ [ "vocabularies" "test" "test-word" ] object-path ] bind = ] unit-test diff --git a/library/test/parse-number.factor b/library/test/parse-number.factor index 835af1d48a..f0c585695c 100644 --- a/library/test/parse-number.factor +++ b/library/test/parse-number.factor @@ -1,11 +1,9 @@ IN: scratchpad USE: arithmetic USE: parser -USE: stdio USE: strings USE: test - -"Parse number tests" print +USE: unparser [ f ] [ f ] @@ -38,23 +36,23 @@ test-word test-word [ "100.0" ] -[ "1e2" ] -[ parse-number >str ] +[ "1.0e2" ] +[ parse-number unparse ] test-word [ "-100.0" ] -[ "-1e2" ] -[ parse-number >str ] +[ "-1.0e2" ] +[ parse-number unparse ] test-word [ "0.01" ] -[ "1e-2" ] -[ parse-number >str ] +[ "1.0e-2" ] +[ parse-number unparse ] test-word [ "-0.01" ] -[ "-1e-2" ] -[ parse-number >str ] +[ "-1.0e-2" ] +[ parse-number unparse ] test-word [ f ] @@ -64,7 +62,7 @@ test-word [ "3.14" ] [ "3.14" ] -[ parse-number >str ] +[ parse-number unparse ] test-word [ f ] @@ -79,27 +77,22 @@ test-word [ "101.0" ] [ "1.01e2" ] -[ parse-number >str ] +[ parse-number unparse ] test-word [ "-101.0" ] [ "-1.01e2" ] -[ parse-number >str ] +[ parse-number unparse ] test-word [ "1.01" ] -[ "101e-2" ] -[ parse-number >str ] +[ "101.0e-2" ] +[ parse-number unparse ] test-word [ "-1.01" ] -[ "-101e-2" ] -[ parse-number >str ] -test-word - -[ "123456789123456789123456789" ] -[ "123456789123456789123456789" ] -[ parse-number >str ] +[ "-101.0e-2" ] +[ parse-number unparse ] test-word [ 5 ] @@ -139,7 +132,5 @@ test-word [ "33/100" ] [ "66/200" ] -[ parse-number >str ] +[ parse-number unparse ] test-word - -"Parse number tests done" print diff --git a/library/test/test.factor b/library/test/test.factor index f2b07f1c72..0668d2793e 100644 --- a/library/test/test.factor +++ b/library/test/test.factor @@ -58,16 +58,19 @@ USE: vocabularies "namespaces/all" "format" "parser" + "parse-number" "prettyprint" "inspector" "vectors" "unparser" "random" + "math/rational" + "math/float" + "math/complex" + "math/irrational" ! "html" "httpd" - "math" - "parse-number" "jvm-compiler/all" ] [ test diff --git a/native/arithmetic.c b/native/arithmetic.c index a28fbeace2..b3cca3ff2b 100644 --- a/native/arithmetic.c +++ b/native/arithmetic.c @@ -129,3 +129,4 @@ BINARY_OP(less, false, false) BINARY_OP(lesseq, false, false) BINARY_OP(greater, false, false) BINARY_OP(greatereq, false, false) +BINARY_OP(gcd, false, true) diff --git a/native/arithmetic.h b/native/arithmetic.h index bb65d94085..7954a48f23 100644 --- a/native/arithmetic.h +++ b/native/arithmetic.h @@ -36,7 +36,7 @@ CELL OP(CELL x, CELL y) \ case RATIO_TYPE: \ if(integerOnly) \ { \ - type_error(FIXNUM_TYPE,y); \ + type_error(INTEGER_TYPE,y); \ return F; \ } \ else \ @@ -44,7 +44,7 @@ CELL OP(CELL x, CELL y) \ case COMPLEX_TYPE: \ if(integerOnly) \ { \ - type_error(FIXNUM_TYPE,y); \ + type_error(INTEGER_TYPE,y); \ return F; \ } \ else \ @@ -54,7 +54,7 @@ CELL OP(CELL x, CELL y) \ case FLOAT_TYPE: \ if(integerOnly) \ { \ - type_error(FIXNUM_TYPE,y); \ + type_error(INTEGER_TYPE,y); \ return F; \ } \ else \ @@ -63,15 +63,17 @@ CELL OP(CELL x, CELL y) \ if(anytype) \ return OP##_anytype(x,y); \ else \ - type_error(FIXNUM_TYPE,y); \ - return F; \ + { \ + type_error(NUMBER_TYPE,x); \ + return F; \ + } \ } \ \ case RATIO_TYPE: \ \ if(integerOnly) \ { \ - type_error(FIXNUM_TYPE,x); \ + type_error(INTEGER_TYPE,x); \ return F; \ } \ \ @@ -91,15 +93,17 @@ CELL OP(CELL x, CELL y) \ if(anytype) \ return OP##_anytype(x,y); \ else \ - type_error(FIXNUM_TYPE,y); \ - return F; \ + { \ + type_error(NUMBER_TYPE,x); \ + return F; \ + } \ } \ \ case COMPLEX_TYPE: \ \ if(integerOnly) \ { \ - type_error(FIXNUM_TYPE,x); \ + type_error(INTEGER_TYPE,x); \ return F; \ } \ \ @@ -119,8 +123,10 @@ CELL OP(CELL x, CELL y) \ if(anytype) \ return OP##_anytype(x,y); \ else \ - type_error(FIXNUM_TYPE,y); \ - return F; \ + { \ + type_error(NUMBER_TYPE,x); \ + return F; \ + } \ } \ \ case BIGNUM_TYPE: \ @@ -132,7 +138,7 @@ CELL OP(CELL x, CELL y) \ case RATIO_TYPE: \ if(integerOnly) \ { \ - type_error(BIGNUM_TYPE,y); \ + type_error(INTEGER_TYPE,y); \ return F; \ } \ else \ @@ -140,7 +146,7 @@ CELL OP(CELL x, CELL y) \ case COMPLEX_TYPE: \ if(integerOnly) \ { \ - type_error(BIGNUM_TYPE,y); \ + type_error(INTEGER_TYPE,y); \ return F; \ } \ else \ @@ -150,7 +156,7 @@ CELL OP(CELL x, CELL y) \ case FLOAT_TYPE: \ if(integerOnly) \ { \ - type_error(BIGNUM_TYPE,y); \ + type_error(INTEGER_TYPE,y); \ return F; \ } \ else \ @@ -159,15 +165,17 @@ CELL OP(CELL x, CELL y) \ if(anytype) \ return OP##_anytype(x,y); \ else \ - type_error(BIGNUM_TYPE,y); \ - return F; \ + { \ + type_error(NUMBER_TYPE,x); \ + return F; \ + } \ } \ \ case FLOAT_TYPE: \ \ if(integerOnly) \ { \ - type_error(FIXNUM_TYPE,x); \ + type_error(INTEGER_TYPE,x); \ return F; \ } \ \ @@ -184,8 +192,13 @@ CELL OP(CELL x, CELL y) \ case FLOAT_TYPE: \ return OP##_float(x,y); \ default: \ - type_error(FLOAT_TYPE,y); \ - return F; \ + if(anytype) \ + return OP##_anytype(x,y); \ + else \ + { \ + type_error(NUMBER_TYPE,x); \ + return F; \ + } \ } \ \ default: \ @@ -193,8 +206,10 @@ CELL OP(CELL x, CELL y) \ if(anytype) \ return OP##_anytype(x,y); \ else \ - type_error(FIXNUM_TYPE,x); \ - return F; \ + { \ + type_error(NUMBER_TYPE,x); \ + return F; \ + } \ } \ } \ \ @@ -204,6 +219,55 @@ void primitive_##OP(void) \ env.dt = OP(x,y); \ } +#define UNARY_OP(OP,anytype,integerOnly) \ +CELL OP(CELL x) \ +{ \ + switch(type_of(x)) \ + { \ + case FIXNUM_TYPE: \ + return OP##_fixnum(x); \ + case RATIO_TYPE: \ + if(integerOnly) \ + { \ + type_error(INTEGER_TYPE,x); \ + return F; \ + } \ + else \ + return OP##_ratio(x); \ + case COMPLEX_TYPE: \ + if(integerOnly) \ + { \ + type_error(INTEGER_TYPE,x); \ + return F; \ + } \ + else \ + return OP##_complex(x); \ + case BIGNUM_TYPE: \ + return OP##_bignum(x); \ + case FLOAT_TYPE: \ + if(integerOnly) \ + { \ + type_error(INTEGER_TYPE,x); \ + return F; \ + } \ + else \ + return OP##_float(x); \ + default: \ + if(anytype) \ + return OP##_anytype(x); \ + else \ + { \ + type_error(NUMBER_TYPE,x); \ + return F; \ + } \ + } \ +} \ +\ +void primitive_##OP(void) \ +{ \ + env.dt = OP(env.dt); \ +} + bool realp(CELL tagged); bool numberp(CELL tagged); void primitive_numberp(void); @@ -252,3 +316,5 @@ CELL shiftleft(CELL x, CELL y); void primitive_shiftleft(void); CELL shiftright(CELL x, CELL y); void primitive_shiftright(void); +CELL gcd(CELL x, CELL y); +void primitive_gcd(void); diff --git a/native/complex.c b/native/complex.c index eb6916d912..e683593222 100644 --- a/native/complex.c +++ b/native/complex.c @@ -114,7 +114,7 @@ CELL add_complex(CELL x, CELL y) COMPLEX* cy = (COMPLEX*)UNTAG(y); return possibly_complex( add(cx->real,cy->real), - add(cx->imaginary,cy->real)); + add(cx->imaginary,cy->imaginary)); } CELL subtract_complex(CELL x, CELL y) @@ -123,7 +123,7 @@ CELL subtract_complex(CELL x, CELL y) COMPLEX* cy = (COMPLEX*)UNTAG(y); return possibly_complex( subtract(cx->real,cy->real), - subtract(cx->imaginary,cy->real)); + subtract(cx->imaginary,cy->imaginary)); } CELL multiply_complex(CELL x, CELL y) diff --git a/native/complex.h b/native/complex.h index 0a6a4dafac..cb0fc751e4 100644 --- a/native/complex.h +++ b/native/complex.h @@ -9,9 +9,9 @@ INLINE COMPLEX* untag_complex(CELL tagged) return (COMPLEX*)UNTAG(tagged); } -INLINE CELL tag_complex(RATIO* ratio) +INLINE CELL tag_complex(COMPLEX* complex) { - return RETAG(ratio,COMPLEX_TYPE); + return RETAG(complex,COMPLEX_TYPE); } COMPLEX* complex(CELL real, CELL imaginary); diff --git a/native/error.c b/native/error.c index a7a83cf0ab..f39b0c275a 100644 --- a/native/error.c +++ b/native/error.c @@ -15,9 +15,11 @@ void critical_error(char* msg, CELL tagged) void fix_stacks(void) { - if(UNDERFLOW(env.ds,env.ds_bot) || OVERFLOW(env.ds,env.ds_bot)) + if(STACK_UNDERFLOW(env.ds,env.ds_bot) + || STACK_OVERFLOW(env.ds,env.ds_bot)) reset_datastack(); - if(UNDERFLOW(env.cs,env.cs_bot) || OVERFLOW(env.cs,env.cs_bot)) + if(STACK_UNDERFLOW(env.cs,env.cs_bot) + || STACK_OVERFLOW(env.cs,env.cs_bot)) reset_callstack(); } diff --git a/native/error.h b/native/error.h index def830d0d7..2a05135959 100644 --- a/native/error.h +++ b/native/error.h @@ -3,11 +3,11 @@ #define ERROR_TYPE (2<<3) #define ERROR_RANGE (3<<3) #define ERROR_UNDERFLOW (4<<3) -#define ERROR_BAD_PRIMITIVE (5<<3) -#define ERROR_HANDLE_INCOMPAT (6<<3) -#define ERROR_IO (7<<3) -#define ERROR_OVERFLOW (8<<3) -#define ERROR_INCOMPARABLE (9<<3) +#define ERROR_HANDLE_INCOMPAT (5<<3) +#define ERROR_IO (6<<3) +#define ERROR_OVERFLOW (7<<3) +#define ERROR_INCOMPARABLE (8<<3) +#define ERROR_FLOAT_FORMAT (9<<3) void fatal_error(char* msg, CELL tagged); void critical_error(char* msg, CELL tagged); diff --git a/native/factor.h b/native/factor.h index a0f63db657..d7f1941cd8 100644 --- a/native/factor.h +++ b/native/factor.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/native/float.c b/native/float.c index 5d2a8f1e80..48aefb8244 100644 --- a/native/float.c +++ b/native/float.c @@ -31,14 +31,19 @@ void primitive_to_float(void) void primitive_str_to_float(void) { - char* c_str = to_c_string(untag_string(env.dt)); - env.dt = tag_object(make_float(atof(c_str))); + STRING* str = untag_string(env.dt); + char* c_str = to_c_string(str); + char* end = c_str; + double f = strtod(c_str,&end); + if(end != c_str + str->capacity) + general_error(ERROR_FLOAT_FORMAT,tag_object(str)); + env.dt = tag_object(make_float(f)); } void primitive_float_to_str(void) { char tmp[33]; - snprintf(&tmp,32,"%.16g",untag_float(env.dt)->n); + snprintf(&tmp,32,"%.16g",to_float(env.dt)->n); tmp[32] = '\0'; env.dt = tag_object(from_c_string(tmp)); } @@ -107,3 +112,67 @@ CELL greatereq_float(CELL x, CELL y) return tag_boolean(((FLOAT*)UNTAG(x))->n >= ((FLOAT*)UNTAG(y))->n); } + +void primitive_facos(void) +{ + env.dt = tag_object(make_float(acos(to_float(env.dt)->n))); +} + +void primitive_fasin(void) +{ + env.dt = tag_object(make_float(asin(to_float(env.dt)->n))); +} + +void primitive_fatan(void) +{ + env.dt = tag_object(make_float(atan(to_float(env.dt)->n))); +} + +void primitive_fatan2(void) +{ + double x = to_float(env.dt)->n; + double y = to_float(dpop())->n; + env.dt = tag_object(make_float(atan2(y,x))); +} + +void primitive_fcos(void) +{ + env.dt = tag_object(make_float(cos(to_float(env.dt)->n))); +} + +void primitive_fexp(void) +{ + env.dt = tag_object(make_float(exp(to_float(env.dt)->n))); +} + +void primitive_fcosh(void) +{ + env.dt = tag_object(make_float(cosh(to_float(env.dt)->n))); +} + +void primitive_flog(void) +{ + env.dt = tag_object(make_float(log(to_float(env.dt)->n))); +} + +void primitive_fpow(void) +{ + double x = to_float(env.dt)->n; + double y = to_float(dpop())->n; + env.dt = tag_object(make_float(pow(y,x))); +} + +void primitive_fsin(void) +{ + env.dt = tag_object(make_float(sin(to_float(env.dt)->n))); +} + +void primitive_fsinh(void) +{ + env.dt = tag_object(make_float(sinh(to_float(env.dt)->n))); +} + +void primitive_fsqrt(void) +{ + env.dt = tag_object(make_float(sqrt(to_float(env.dt)->n))); +} diff --git a/native/float.h b/native/float.h index a001f22577..b138237519 100644 --- a/native/float.h +++ b/native/float.h @@ -14,10 +14,15 @@ INLINE FLOAT* make_float(double n) return flo; } -INLINE FLOAT* untag_float(CELL tagged) +INLINE double untag_float_fast(CELL tagged) +{ + return ((FLOAT*)UNTAG(tagged))->n; +} + +INLINE double untag_float(CELL tagged) { type_check(FLOAT_TYPE,tagged); - return (FLOAT*)UNTAG(tagged); + return untag_float_fast(tagged); } void primitive_floatp(void); @@ -26,6 +31,7 @@ void primitive_to_float(void); void primitive_str_to_float(void); void primitive_float_to_str(void); void primitive_float_to_bits(void); + CELL number_eq_float(CELL x, CELL y); CELL add_float(CELL x, CELL y); CELL subtract_float(CELL x, CELL y); @@ -36,3 +42,16 @@ CELL less_float(CELL x, CELL y); CELL lesseq_float(CELL x, CELL y); CELL greater_float(CELL x, CELL y); CELL greatereq_float(CELL x, CELL y); + +void primitive_facos(void); +void primitive_fasin(void); +void primitive_fatan(void); +void primitive_fatan2(void); +void primitive_fcos(void); +void primitive_fexp(void); +void primitive_fcosh(void); +void primitive_flog(void); +void primitive_fpow(void); +void primitive_fsin(void); +void primitive_fsinh(void); +void primitive_fsqrt(void); diff --git a/native/primitives.c b/native/primitives.c index 97a61f38ea..a5c944c9fd 100644 --- a/native/primitives.c +++ b/native/primitives.c @@ -72,6 +72,19 @@ XT primitives[] = { primitive_lesseq, primitive_greater, primitive_greatereq, + primitive_gcd, + primitive_facos, + primitive_fasin, + primitive_fatan, + primitive_fatan2, + primitive_fcos, + primitive_fexp, + primitive_fcosh, + primitive_flog, + primitive_fpow, + primitive_fsin, + primitive_fsinh, + primitive_fsqrt, primitive_wordp, primitive_word, primitive_word_primitive, @@ -121,7 +134,7 @@ XT primitives[] = { CELL primitive_to_xt(CELL primitive) { if(primitive < 0 || primitive >= PRIMITIVE_COUNT) - general_error(ERROR_BAD_PRIMITIVE,tag_fixnum(primitive)); + critical_error("Bad primitive number",primitive); return (CELL)primitives[primitive]; } diff --git a/native/primitives.h b/native/primitives.h index fd371c7d8b..d8bf9ff5ff 100644 --- a/native/primitives.h +++ b/native/primitives.h @@ -1,4 +1,4 @@ extern XT primitives[]; -#define PRIMITIVE_COUNT 115 +#define PRIMITIVE_COUNT 128 CELL primitive_to_xt(CELL primitive); diff --git a/native/stack.h b/native/stack.h index f2734f1cbd..8433e1c4e1 100644 --- a/native/stack.h +++ b/native/stack.h @@ -1,15 +1,15 @@ -#define UNDERFLOW_CHECKING +#define STACK_UNDERFLOW_CHECKING -#define UNDERFLOW(stack,bot) ((stack) < UNTAG(bot) + sizeof(ARRAY)) -#define OVERFLOW(stack,bot) ((stack) >= UNTAG(bot) + object_size(bot)) +#define STACK_UNDERFLOW(stack,bot) ((stack) < UNTAG(bot) + sizeof(ARRAY)) +#define STACK_OVERFLOW(stack,bot) ((stack) >= UNTAG(bot) + object_size(bot)) INLINE void check_stacks(void) { -#ifdef UNDERFLOW_CHECKING - if(OVERFLOW(env.ds,env.ds_bot)) +#ifdef STACK_UNDERFLOW_CHECKING + if(STACK_OVERFLOW(env.ds,env.ds_bot)) general_error(ERROR_OVERFLOW,F); - if(OVERFLOW(env.cs,env.cs_bot)) + if(STACK_OVERFLOW(env.cs,env.cs_bot)) general_error(ERROR_OVERFLOW,F); #endif diff --git a/native/types.h b/native/types.h index ea33053de2..8f595e1efc 100644 --- a/native/types.h +++ b/native/types.h @@ -40,6 +40,7 @@ CELL empty; #define INTEGER_TYPE 100 /* FIXNUM or BIGNUM */ #define RATIONAL_TYPE 101 /* INTEGER or RATIO */ #define REAL_TYPE 102 /* RATIONAL or FLOAT */ +#define NUMBER_TYPE 103 /* COMPLEX or REAL */ bool typep(CELL type, CELL tagged); CELL type_of(CELL tagged);