d2c API Reference | ||
---|---|---|
Prev | Chapter 2. Library compiler-base |
Unsurprisingly, this module is a grab-bag of various useful functions and methods the used by modules in the rest of the compiler. Some of this stuff is actually quite useful in contexts beyond writing a compiler, and should probably be moved into some of the common libraries rather than living in compiler base.
pretty-format | [Method] |
Pretty-print error messages.
Synopsis
pretty-format (stream, string, #rest args) => ()
Parameters
stream An instance of <stream>
.string An instance of <byte-string>
.args Instances of <object>
.
Return Values
None.
Description
Used for error message printing. Turns each space in the control string into a conditional newline, and turns literal newlines into a mandatory newline and 2 space indent.
condition-format | [Method] |
A method that uses
pretty-format
.
Synopsis
condition-format (stream, control-string, #rest args) => ()
Parameters
stream An instance of <stream>
.control-string An instance of <byte-string>
.args Instances of <object>
.
Return Values
None.
Description
This method prints error messages using
pretty-format
. It works by shadowing thecondition-format
method defined on(<stream>, <string>)
.
write-class-name | [Method] |
Print an object's classname to a stream.
Synopsis
write-class-name (thing, stream) => ()
Parameters
thing An instance of <object>
.stream An instance of <object>
.
Return Values
None.
Description
This print's
thing
'sobject-class
's name to the stream. If the class is anonymous, the default representation of classes is printed to the stream. (This should never happen until d2c learns how to make anonymous classes.)
write-address | [Method] |
Prints the address of an object
Synopsis
write-address (thing, stream) => ()
Parameters
thing An instance of <object>
.stream An instance of <object>
.
Return Values
None.
Description
Prints the hexadecimal address of
object
to the streamstream
.
pprint-fields | [Method] |
Used to print an object and its fields
Synopsis
pprint-fields (thing, stream, #rest fields) => ()
Parameters
thing An instance of <object>
.stream An instance of <object>
.fields Instances of <object>
. Plist of fieldnames and values.
Return Values
None.
Description
This method is a tool used to print the constituents of an object. The
#rest
argument is a list of symbols alternating with values -- the symbols are used as the field names for the values.
$thousand-cardinals | [Variable] |
Vector of English names for numbers.
Type
<vector>
Description
This vector contains the names that are prefixed by numbers less than a hundred -- "thousand", "million", etc. It is used in the method
integer-to-english
.
$ten-cardinals | [Variable] |
Vector of the English tens units.
Type
<vector>
Description
This vector contains the names of multiples of ten -- "twenty", "thirty", etc. It is used in the method
integer-to-english
.
$unit-cardinals | [Variable] |
Vector of English words for 0 to 20.
Type
<vector>
Description
This vector contains strings naming the integers from 0 to 20. It is used in the method
integer-to-english
.
$thousand-ordinals | [Variable] |
Like $thousand-cardinals
, except
to name positions.
Type
<vector>
Description
This vector lists the ordinals for numbers bigger than 1000 -- "millionth", "billionth" and so on. It is used in the method
integer-to-english
.
$ten-ordinals | [Variable] |
Like $ten-cardinals
, except to
name positions.
Type
<vector>
Description
This vector lists the ordinals for small integers from 0 to 20 -- "zeroth", "first", etc. It is used in the method
integer-to-english
.
integer-to-english | [Method] |
Convert an integer to an English string.
Synopsis
integer-to-english (int, #key as) => (res)
Parameters
int An instance of <integer>
.as:
An instance of one-of(#"cardinal", #"ordinal")
. Defaults to#"cardinal"
.
Return Values
res An instance of <byte-string>
.
Description
This method converts an
<integer>
object into the English string for the number it represents. If the keywordas:
is set to#"ordinal"
, then the English string is the name of the n-th position; otherwise it is just the name of the number.