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.
File compiler/base/utils.dylan
Pretty-print error messages.
Parameters
| stream | An instance of <stream>. |
| string | An instance of <byte-string>. |
| args | An instance of <object>. |
Return ValuesNone
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.
A method that uses pretty-format.
Parameters
| stream | An instance of <stream>. |
| control-string | An instance of <byte-string>. |
| args | An instance of <object>. |
Return ValuesNone
Description
This method prints error messages using
pretty-format. It works by shadowing the
condition-format method defined on
(<stream>, <string>).
Print an object's classname to a stream.
Parameters
| thing | An instance of <object>. |
| stream | An instance of <object>. |
Return ValuesNone
Description
This print's thing's
object-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.)
Prints the address of an object
Parameters
| thing | An instance of <object>. |
| stream | An instance of <object>. |
Return ValuesNone
Description
Prints the hexadecimal address of object
to the stream stream.
Used to print an object and its fields
Parameters
| thing | An instance of <object>. |
| stream | An instance of <object>. |
| fields | An instance of <object>. Plist of fieldnames and values. |
Return ValuesNone
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.
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.
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.
Parameters
| int | An instance of <integer>. |
as: | An instance of one-of(#"cardinal", #"ordinal"). |
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 keyword as: 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.