Merge branch 'master' of git://factorcode.org/git/factor
commit
5dfd1c70f0
|
@ -1,14 +1,15 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel combinators alien alien.strings alien.syntax
|
USING: kernel combinators alien alien.strings alien.syntax
|
||||||
prettyprint.backend prettyprint.custom prettyprint.sections ;
|
math.parser prettyprint.backend prettyprint.custom
|
||||||
|
prettyprint.sections ;
|
||||||
IN: alien.prettyprint
|
IN: alien.prettyprint
|
||||||
|
|
||||||
M: alien pprint*
|
M: alien pprint*
|
||||||
{
|
{
|
||||||
{ [ dup expired? ] [ drop \ BAD-ALIEN pprint-word ] }
|
{ [ dup expired? ] [ drop \ BAD-ALIEN pprint-word ] }
|
||||||
{ [ dup pinned-c-ptr? not ] [ drop "( displaced alien )" text ] }
|
{ [ dup pinned-c-ptr? not ] [ drop "( displaced alien )" text ] }
|
||||||
[ \ ALIEN: [ alien-address pprint* ] pprint-prefix ]
|
[ \ ALIEN: [ alien-address >hex text ] pprint-prefix ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
M: dll pprint* dll-path dup "DLL\" " "\"" pprint-string ;
|
M: dll pprint* dll-path dup "DLL\" " "\"" pprint-string ;
|
||||||
|
|
|
@ -9,7 +9,7 @@ HELP: DLL"
|
||||||
|
|
||||||
HELP: ALIEN:
|
HELP: ALIEN:
|
||||||
{ $syntax "ALIEN: address" }
|
{ $syntax "ALIEN: address" }
|
||||||
{ $values { "address" "a non-negative integer" } }
|
{ $values { "address" "a non-negative hexadecimal integer" } }
|
||||||
{ $description "Creates an alien object at parse time." }
|
{ $description "Creates an alien object at parse time." }
|
||||||
{ $notes "Alien objects are invalidated between image saves and loads, and hence source files should not contain alien literals; this word is for interactive use only. See " { $link "alien-expiry" } " for details." } ;
|
{ $notes "Alien objects are invalidated between image saves and loads, and hence source files should not contain alien literals; this word is for interactive use only. See " { $link "alien-expiry" } " for details." } ;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ IN: alien.syntax
|
||||||
|
|
||||||
SYNTAX: DLL" lexer get skip-blank parse-string dlopen parsed ;
|
SYNTAX: DLL" lexer get skip-blank parse-string dlopen parsed ;
|
||||||
|
|
||||||
SYNTAX: ALIEN: scan string>number <alien> parsed ;
|
SYNTAX: ALIEN: 16 scan-base <alien> parsed ;
|
||||||
|
|
||||||
SYNTAX: BAD-ALIEN <bad-alien> parsed ;
|
SYNTAX: BAD-ALIEN <bad-alien> parsed ;
|
||||||
|
|
||||||
|
|
|
@ -472,15 +472,15 @@ cell 8 = [
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ ALIEN: 123 ] [
|
[ ALIEN: 123 ] [
|
||||||
123 [ <alien> ] compile-call
|
HEX: 123 [ <alien> ] compile-call
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ ALIEN: 123 ] [
|
[ ALIEN: 123 ] [
|
||||||
123 [ { fixnum } declare <alien> ] compile-call
|
HEX: 123 [ { fixnum } declare <alien> ] compile-call
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ ALIEN: 123 ] [
|
[ ALIEN: 123 ] [
|
||||||
[ 123 <alien> ] compile-call
|
[ HEX: 123 <alien> ] compile-call
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ f ] [
|
[ f ] [
|
||||||
|
@ -522,8 +522,8 @@ cell 8 = [
|
||||||
[ ALIEN: 1234 ALIEN: 2234 ] [
|
[ ALIEN: 1234 ALIEN: 2234 ] [
|
||||||
ALIEN: 234 [
|
ALIEN: 234 [
|
||||||
{ c-ptr } declare
|
{ c-ptr } declare
|
||||||
[ 1000 swap <displaced-alien> ]
|
[ HEX: 1000 swap <displaced-alien> ]
|
||||||
[ 2000 swap <displaced-alien> ] bi
|
[ HEX: 2000 swap <displaced-alien> ] bi
|
||||||
] compile-call
|
] compile-call
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,6 @@ M: openbsd statvfs>file-system-info ( file-system-info statvfs -- file-system-in
|
||||||
|
|
||||||
M: openbsd file-systems ( -- seq )
|
M: openbsd file-systems ( -- seq )
|
||||||
f 0 0 getfsstat dup io-error
|
f 0 0 getfsstat dup io-error
|
||||||
<statvfs-array>
|
<statfs-array>
|
||||||
[ dup byte-length 0 getfsstat io-error ]
|
[ dup byte-length 0 getfsstat io-error ]
|
||||||
[ [ f_mntonname>> utf8 alien>string file-system-info ] { } map-as ] bi ;
|
[ [ f_mntonname>> utf8 alien>string file-system-info ] { } map-as ] bi ;
|
||||||
|
|
|
@ -55,7 +55,7 @@ cell 8 = [
|
||||||
] unit-test
|
] unit-test
|
||||||
] when
|
] when
|
||||||
|
|
||||||
[ "ALIEN: 1234" ] [ 1234 <alien> unparse ] unit-test
|
[ "ALIEN: 1234" ] [ HEX: 1234 <alien> unparse ] unit-test
|
||||||
|
|
||||||
[ ] [ 0 B{ 1 2 3 } <displaced-alien> drop ] unit-test
|
[ ] [ 0 B{ 1 2 3 } <displaced-alien> drop ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -282,12 +282,12 @@ HELP: fp-bitwise=
|
||||||
{ $examples
|
{ $examples
|
||||||
"Not-a-number equality:"
|
"Not-a-number equality:"
|
||||||
{ $example
|
{ $example
|
||||||
"USING: math prettyprint ;"
|
"USING: kernel math prettyprint ;"
|
||||||
"0.0 0.0 / dup number= ."
|
"0.0 0.0 / dup number= ."
|
||||||
"f"
|
"f"
|
||||||
}
|
}
|
||||||
{ $example
|
{ $example
|
||||||
"USING: math prettyprint ;"
|
"USING: kernel math prettyprint ;"
|
||||||
"0.0 0.0 / dup fp-bitwise= ."
|
"0.0 0.0 / dup fp-bitwise= ."
|
||||||
"t"
|
"t"
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,7 @@ HELP: fp-bitwise=
|
||||||
}
|
}
|
||||||
{ $example
|
{ $example
|
||||||
"USING: math prettyprint ;"
|
"USING: math prettyprint ;"
|
||||||
"-0.0 0.0 = ."
|
"-0.0 0.0 number= ."
|
||||||
"t"
|
"t"
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
|
@ -5,7 +5,7 @@ IN: math.parser
|
||||||
ARTICLE: "number-strings" "Converting between numbers and strings"
|
ARTICLE: "number-strings" "Converting between numbers and strings"
|
||||||
"These words only convert between real numbers and strings. Complex numbers are constructed by the parser (" { $link "parser" } ") and printed by the prettyprinter (" { $link "prettyprint" } ")."
|
"These words only convert between real numbers and strings. Complex numbers are constructed by the parser (" { $link "parser" } ") and printed by the prettyprinter (" { $link "prettyprint" } ")."
|
||||||
$nl
|
$nl
|
||||||
"Note that only integers can be converted to and from strings using a representation other than base 10. Calling a word such as " { $link >oct } " on a float will give a result in base 10."
|
"Integers can be converted to and from arbitrary bases. Floating point numbers can only be converted to and from base 10 and 16."
|
||||||
$nl
|
$nl
|
||||||
"Converting numbers to strings:"
|
"Converting numbers to strings:"
|
||||||
{ $subsection number>string }
|
{ $subsection number>string }
|
||||||
|
@ -93,7 +93,19 @@ HELP: >oct
|
||||||
|
|
||||||
HELP: >hex
|
HELP: >hex
|
||||||
{ $values { "n" real } { "str" string } }
|
{ $values { "n" real } { "str" string } }
|
||||||
{ $description "Outputs a string representation of a number using base 16." } ;
|
{ $description "Outputs a string representation of a number using base 16." }
|
||||||
|
{ $examples
|
||||||
|
{ $example
|
||||||
|
"USING: math.parser prettyprint ;"
|
||||||
|
"3735928559 >hex ."
|
||||||
|
"\"deadbeef\""
|
||||||
|
}
|
||||||
|
{ $example
|
||||||
|
"USING: math.parser prettyprint ;"
|
||||||
|
"-15.5 >hex ."
|
||||||
|
"\"-f.8p0\""
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
HELP: string>float ( str -- n/f )
|
HELP: string>float ( str -- n/f )
|
||||||
{ $values { "str" string } { "n/f" "a real number or " { $link f } } }
|
{ $values { "str" string } { "n/f" "a real number or " { $link f } } }
|
||||||
|
|
|
@ -59,20 +59,25 @@ ARTICLE: "syntax-ratios" "Ratio syntax"
|
||||||
"More information on ratios can be found in " { $link "rationals" } ;
|
"More information on ratios can be found in " { $link "rationals" } ;
|
||||||
|
|
||||||
ARTICLE: "syntax-floats" "Float syntax"
|
ARTICLE: "syntax-floats" "Float syntax"
|
||||||
"Floating point literals must contain a decimal point, and may contain an exponent:"
|
"Floating point literals can be input in base 10 or 16. Base 10 literals must contain a decimal point, and may contain an exponent after " { $snippet "e" } ":"
|
||||||
{ $code
|
{ $code
|
||||||
"10.5"
|
"10.5"
|
||||||
"-3.1456"
|
"-3.1456"
|
||||||
"7.e13"
|
"7.e13"
|
||||||
"1.0e-5"
|
"1.0e-5"
|
||||||
}
|
}
|
||||||
"There are three special float values:"
|
"Base 16 literals use " { $snippet "p" } " instead of " { $snippet "e" } " for the exponent, which is still decimal:"
|
||||||
|
{ $example
|
||||||
|
"10.125 HEX: 1.44p3 = ."
|
||||||
|
"t"
|
||||||
|
}
|
||||||
|
"Syntax for special float values:"
|
||||||
{ $table
|
{ $table
|
||||||
{ "Positive infinity" { $snippet "1/0." } }
|
{ "Positive infinity" { $snippet "1/0." } }
|
||||||
{ "Negative infinity" { $snippet "-1/0." } }
|
{ "Negative infinity" { $snippet "-1/0." } }
|
||||||
{ "Not-a-number" { $snippet "0/0." } }
|
{ "Not-a-number" { $snippet "0/0." } }
|
||||||
}
|
}
|
||||||
"A Not-a-number with an arbitrary payload can be parsed in:"
|
"A Not-a-number with an arbitrary payload can also be parsed in:"
|
||||||
{ $subsection POSTPONE: NAN: }
|
{ $subsection POSTPONE: NAN: }
|
||||||
"More information on floats can be found in " { $link "floats" } "." ;
|
"More information on floats can be found in " { $link "floats" } "." ;
|
||||||
|
|
||||||
|
@ -612,8 +617,8 @@ HELP: NAN:
|
||||||
{ $examples
|
{ $examples
|
||||||
{ $example
|
{ $example
|
||||||
"USE: prettyprint"
|
"USE: prettyprint"
|
||||||
"NAN: deadbeef ."
|
"NAN: 80000deadbeef ."
|
||||||
"NAN: deadbeef"
|
"NAN: 80000deadbeef"
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue