prettyprint: Print .b .o .h with prefixes so it's not super confusing. Fixes #1351.
parent
4d222cc69a
commit
30d158ccce
|
@ -68,7 +68,7 @@ HELP: flags{
|
|||
"IN: scratchpad"
|
||||
"CONSTANT: x 0x1"
|
||||
"flags{ 0x20 x 0b100 } .h"
|
||||
"25"
|
||||
"0x25"
|
||||
}
|
||||
} ;
|
||||
|
||||
|
|
|
@ -35,20 +35,20 @@ HELP: bitfield
|
|||
HELP: bits
|
||||
{ $values { "m" integer } { "n" integer } { "m'" integer } }
|
||||
{ $description "Keep only n bits from the integer m." }
|
||||
{ $example "USING: math.bitwise prettyprint ;" "0x123abcdef 16 bits .h" "cdef" } ;
|
||||
{ $example "USING: math.bitwise prettyprint ;" "0x123abcdef 16 bits .h" "0xcdef" } ;
|
||||
|
||||
HELP: bit-range
|
||||
{ $values { "x" integer } { "high" integer } { "low" integer } { "y" integer } }
|
||||
{ $description "Extract a range of bits from an integer, inclusive of each boundary." }
|
||||
{ $example "USING: math.bitwise prettyprint ;" "0b1100 3 2 bit-range .b" "11" } ;
|
||||
{ $example "USING: math.bitwise prettyprint ;" "0b1100 3 2 bit-range .b" "0b11" } ;
|
||||
|
||||
HELP: bitroll
|
||||
{ $values { "x" integer } { "s" "a shift integer" } { "w" "a wrap integer" } { "y" integer }
|
||||
}
|
||||
{ $description "Roll n by s bits to the left, wrapping around after w bits." }
|
||||
{ $examples
|
||||
{ $example "USING: math.bitwise prettyprint ;" "1 -1 32 bitroll .b" "10000000000000000000000000000000" }
|
||||
{ $example "USING: math.bitwise prettyprint ;" "0xffff0000 8 32 bitroll .h" "ff0000ff" }
|
||||
{ $example "USING: math.bitwise prettyprint ;" "1 -1 32 bitroll .b" "0b10000000000000000000000000000000" }
|
||||
{ $example "USING: math.bitwise prettyprint ;" "0xffff0000 8 32 bitroll .h" "0xff0000ff" }
|
||||
} ;
|
||||
|
||||
{ bit? set-bit clear-bit } related-words
|
||||
|
@ -83,11 +83,11 @@ HELP: bitroll-32
|
|||
{ $examples
|
||||
{ $example "USING: math.bitwise prettyprint ;"
|
||||
"0x1 10 bitroll-32 .h"
|
||||
"400"
|
||||
"0x400"
|
||||
}
|
||||
{ $example "USING: math.bitwise prettyprint ;"
|
||||
"0x1 -10 bitroll-32 .h"
|
||||
"400000"
|
||||
"0x400000"
|
||||
}
|
||||
} ;
|
||||
|
||||
|
@ -100,11 +100,11 @@ HELP: bitroll-64
|
|||
{ $examples
|
||||
{ $example "USING: math.bitwise prettyprint ;"
|
||||
"0x1 10 bitroll-64 .h"
|
||||
"400"
|
||||
"0x400"
|
||||
}
|
||||
{ $example "USING: math.bitwise prettyprint ;"
|
||||
"0x1 -10 bitroll-64 .h"
|
||||
"40000000000000"
|
||||
"0x40000000000000"
|
||||
}
|
||||
} ;
|
||||
|
||||
|
@ -119,7 +119,7 @@ HELP: clear-bit
|
|||
{ $examples
|
||||
{ $example "USING: math.bitwise kernel prettyprint ;"
|
||||
"0xff 7 clear-bit .h"
|
||||
"7f"
|
||||
"0x7f"
|
||||
}
|
||||
} ;
|
||||
|
||||
|
@ -190,7 +190,7 @@ HELP: mask
|
|||
{ $examples
|
||||
{ $example "USING: math.bitwise kernel prettyprint ;"
|
||||
"0b11111111 0b101 mask .b"
|
||||
"101"
|
||||
"0b101"
|
||||
}
|
||||
} ;
|
||||
|
||||
|
@ -203,7 +203,7 @@ HELP: mask-bit
|
|||
{ $examples
|
||||
{ $example "USING: math.bitwise kernel prettyprint ;"
|
||||
"0xff 2 mask-bit .b"
|
||||
"100"
|
||||
"0b100"
|
||||
}
|
||||
} ;
|
||||
|
||||
|
@ -248,11 +248,11 @@ HELP: on-bits
|
|||
{ $examples
|
||||
{ $example "USING: math.bitwise kernel prettyprint ;"
|
||||
"6 on-bits .h"
|
||||
"3f"
|
||||
"0x3f"
|
||||
}
|
||||
{ $example "USING: math.bitwise kernel prettyprint ;"
|
||||
"64 on-bits .h"
|
||||
"ffffffffffffffff"
|
||||
"0xffffffffffffffff"
|
||||
}
|
||||
} ;
|
||||
|
||||
|
@ -266,11 +266,11 @@ HELP: toggle-bit
|
|||
{ $examples
|
||||
{ $example "USING: math.bitwise kernel prettyprint ;"
|
||||
"0 3 toggle-bit .b"
|
||||
"1000"
|
||||
"0b1000"
|
||||
}
|
||||
{ $example "USING: math.bitwise kernel prettyprint ;"
|
||||
"0b1000 3 toggle-bit .b"
|
||||
"0"
|
||||
"0b0"
|
||||
}
|
||||
} ;
|
||||
|
||||
|
@ -283,7 +283,7 @@ HELP: set-bit
|
|||
{ $examples
|
||||
{ $example "USING: math.bitwise kernel prettyprint ;"
|
||||
"0 5 set-bit .h"
|
||||
"20"
|
||||
"0x20"
|
||||
}
|
||||
} ;
|
||||
|
||||
|
@ -303,7 +303,7 @@ HELP: unmask
|
|||
{ $examples
|
||||
{ $example "USING: math.bitwise kernel prettyprint ;"
|
||||
"0xff 0x0f unmask .h"
|
||||
"f0"
|
||||
"0xf0"
|
||||
}
|
||||
} ;
|
||||
|
||||
|
@ -408,7 +408,7 @@ HELP: wrap
|
|||
{ $example
|
||||
"USING: math.bitwise prettyprint ;"
|
||||
"0xffff 8 wrap .h"
|
||||
"7"
|
||||
"0x7"
|
||||
}
|
||||
} ;
|
||||
|
||||
|
|
|
@ -38,9 +38,9 @@ IN: prettyprint
|
|||
: error-in-pprint ( obj -- str )
|
||||
class-of name>> "~pprint error: " "~" surround ;
|
||||
|
||||
: .b ( n -- ) >bin print ;
|
||||
: .o ( n -- ) >oct print ;
|
||||
: .h ( n -- ) >hex print ;
|
||||
: .b ( n -- ) >bin "0b" prepend print ;
|
||||
: .o ( n -- ) >oct "0o" prepend print ;
|
||||
: .h ( n -- ) >hex "0x" prepend print ;
|
||||
|
||||
: stack. ( seq -- )
|
||||
[
|
||||
|
|
|
@ -150,8 +150,8 @@ HELP: bitand
|
|||
{ $values { "x" integer } { "y" integer } { "z" integer } }
|
||||
{ $description "Outputs a new integer where each bit is set if and only if the corresponding bit is set in both inputs." }
|
||||
{ $examples
|
||||
{ $example "USING: math prettyprint ;" "0b101 0b10 bitand .b" "0" }
|
||||
{ $example "USING: math prettyprint ;" "0b110 0b10 bitand .b" "10" }
|
||||
{ $example "USING: math prettyprint ;" "0b101 0b10 bitand .b" "0b0" }
|
||||
{ $example "USING: math prettyprint ;" "0b110 0b10 bitand .b" "0b10" }
|
||||
}
|
||||
{ $notes "This word implements bitwise and, so applying it to booleans will throw an error. Boolean and is the " { $link and } " word." } ;
|
||||
|
||||
|
@ -159,8 +159,8 @@ HELP: bitor
|
|||
{ $values { "x" integer } { "y" integer } { "z" integer } }
|
||||
{ $description "Outputs a new integer where each bit is set if and only if the corresponding bit is set in at least one of the inputs." }
|
||||
{ $examples
|
||||
{ $example "USING: math prettyprint ;" "0b101 0b10 bitor .b" "111" }
|
||||
{ $example "USING: math prettyprint ;" "0b110 0b10 bitor .b" "110" }
|
||||
{ $example "USING: math prettyprint ;" "0b101 0b10 bitor .b" "0b111" }
|
||||
{ $example "USING: math prettyprint ;" "0b110 0b10 bitor .b" "0b110" }
|
||||
}
|
||||
{ $notes "This word implements bitwise inclusive or, so applying it to booleans will throw an error. Boolean inclusive or is the " { $link and } " word." } ;
|
||||
|
||||
|
@ -168,15 +168,15 @@ HELP: bitxor
|
|||
{ $values { "x" integer } { "y" integer } { "z" integer } }
|
||||
{ $description "Outputs a new integer where each bit is set if and only if the corresponding bit is set in exactly one of the inputs." }
|
||||
{ $examples
|
||||
{ $example "USING: math prettyprint ;" "0b101 0b10 bitxor .b" "111" }
|
||||
{ $example "USING: math prettyprint ;" "0b110 0b10 bitxor .b" "100" }
|
||||
{ $example "USING: math prettyprint ;" "0b101 0b10 bitxor .b" "0b111" }
|
||||
{ $example "USING: math prettyprint ;" "0b110 0b10 bitxor .b" "0b100" }
|
||||
}
|
||||
{ $notes "This word implements bitwise exclusive or, so applying it to booleans will throw an error. Boolean exclusive or is the " { $link xor } " word." } ;
|
||||
|
||||
HELP: shift
|
||||
{ $values { "x" integer } { "n" integer } { "y" integer } }
|
||||
{ $description "Shifts " { $snippet "x" } " to the left by " { $snippet "n" } " bits if " { $snippet "n" } " is positive, or " { $snippet "-n" } " bits to the right if " { $snippet "n" } " is negative. A left shift of a fixnum may overflow, yielding a bignum. A right shift may result in bits “falling off” the right hand side and being discarded." }
|
||||
{ $examples { $example "USING: math prettyprint ;" "0b101 5 shift .b" "10100000" } { $example "USING: math prettyprint ;" "0b11111 -2 shift .b" "111" } } ;
|
||||
{ $examples { $example "USING: math prettyprint ;" "0b101 5 shift .b" "0b10100000" } { $example "USING: math prettyprint ;" "0b11111 -2 shift .b" "111" } } ;
|
||||
|
||||
HELP: bitnot
|
||||
{ $values { "x" integer } { "y" integer } }
|
||||
|
|
Loading…
Reference in New Issue