pibfi
.
This module implements collecting options from the command line.
When invoking pibfi
from the command line, the
following syntax can be used:
erl -noshell options -run pibfi run filename
The following options are recognized.
-dontstrip s
, where s is a string of
characters, default null (empty), specifies the set of characters
(beyond the 8 basic Brainf*ck instructions)
which
will not be stripped from the parsed source prior to optimization.
Note that if this option if given without an argument, it is assumed
to be the set of all applicable characters - in other words, nothing
at all will be stripped.-optimize n
, where n is an integer,
default 1, sets the optimization level of the parser.
At optimization level 0, no optimization occurs.
At optimization level 1, run-length encoding is performed on the
instructions. Further optimization levels may be defined in the
future. Note that if this option if given without an argument,
it is assumed to be asking for the most thorough yet quickly
available optimization.-statuscmd c
, where c may be
any single-character string of the term undefined
,
default "#" (octalthorpe), specifies
which symbol, when encountered, is treated
as a debugging instruction which displays a status report.-heredoc c
, where c may be
a single-character string or the term undefined
,
default undefined
, specifies which symbol when encountered,
is treated as the marker that signifies that input is embedded in
the program source code following it. This input will be stripped
from the source (even if it contains valid Brainf*ck instructions)
and will be made available to -infile heredoc
(see
below.) Note that if this option is given with no argument,
"!" (exclamation point) is assumed.-tapemodule m
, where n is the name of
an Erlang module conforming to the pibfi_tape
behaviour,
defaulting to whatever pibfi
determines would be optimal
for the given sourcecode, (currently always pibfi_tape_ets
),
names the module which implements the backing for the simulated tape.-maxcell n
, where n is any integer or the
term infinity
, default infinity
, sets the
highest value that can be placed into a cell on the tape.-mincell n
, where n is any integer or the
term infinity
, default 0, sets the
lowest value that can be placed into a cell on the tape.
(Note that infinity
actually represents negative infinity
here.)-wrapcell b
, where b is a boolean
(true
or false
), default false
,
determines what happens when either limit of any cell in the tape is
exceeded. When -wrapcell
is true
, the limits
will be taken as modulus boundaries, and the value will 'wrap around'
to the opposite limit. When -wrapcell
is false
,
an exception will be generated. Note that if b is omitted
after -wrapcell
, true
is assumed.
Also note that -wrapcell true
is not compatible with
either -maxcell infinity
or -mincell infinity
(for what should be obvious reasons.)-maxtape n
, where n is any integer or the
term infinity
, default infinity
, sets the
rightmost position to which the tape head can move. Note that the initial
position of the tape head is considered position 0.-mintape n
, where n is any integer or the
term infinity
, default 0, sets the
leftmost position to which the tape head can move.
(Note that infinity
actually represents negative infinity
here.)-wraptape b
, where b is a boolean,
default false
, determines what happens when either limit
of the tape head is exceeded. With -wraptape true
,
the limits will be taken as modulus boundaries,
and the position of the tape head will 'wrap around' to the
opposite limit. With -wraptape false
,
an exception will be generated when this happens.
Note that if b is omitted
after -wraptape
, true
is assumed. Also note
that -wraptape true
is not compatible with either
-maxtape infinity
or -mintape infinity
.-infile s
, where s is a filename or
one of the terms tty
or heredoc
,
default tty
, sets the
source of the input to the Brainf*ck program.
tty
indicates an interactive terminal session with
"standard input".
heredoc
indicates input will come from the
"here-doc" portion of the program source code (note that the
-heredoc
option must also be given to parse the
source code.)
Using this option is preferred
over redirecting standard I/O with the shell, as it is a hint to the
interpreter that the program is not being run interactively.-outfile s
, where s is a filename or
the term tty
, default tty
, sets the
destination of the output of the Brainf*ck program. This is preferred
to redirecting standard I/O with the shell, as it is a hint to the
interpreter that the program is not being run interactively.-maxout n
, where n is any integer or the
term infinity
, default infinity
, sets the
maximum character value which can be output.-minout n
, where n is any integer or the
term infinity
, default 0, sets the minimum character
value which can be output.
(Note that infinity
actually represents negative infinity
here.)-wrapout b
, where b is a boolean,
default false
, determines what happens when either limit
of character output is exceeded. With -wrapout true
,
the limits will be taken as modulus boundaries,
and the actual character output will be computed by 'wrapping around'
the rquested value to the opposite limit.
With -wrapout false
,
an exception will be generated. Note that if b is omitted
after -wrapout
, true
is assumed. Also note
that -wrapout true
is not compatible with either
-maxout infinity
or -minout infinity
.-maxin n
, where n is any integer or the
term infinity
, default infinity
, sets the
maximum character value which can be input.-minin n
, where n is any integer or the
term infinity
, default 0, sets the minimum character
value which can be input.
(Note that infinity
actually represents negative infinity
here.)-wrapin b
, where b is a boolean,
default false
, determines what happens when either limit
of character input is exceeded. With -wrapin true
,
the limits will be taken as modulus boundaries,
and the actual character input will be computed by 'wrapping around'
the rquested value to the opposite limit.
With -wrapin false
,
an exception will be generated. Note that if b is omitted
after -wrapin
, true
is assumed. Also note
that -wrapin true
is not compatible with either
-maxin infinity
or -minin infinity
.-xlatout s
, where s is string
in the form given below,
default value #10=#nl, specifies a mapping between
characters the Brainf*ck program sees itself as sending to output,
and the characters that the operating system actually receives.
The syntax for the mapping specification is described by this mini-grammar:
-xlatout
option is present
with no argument, this means that there should be no translation
mapping between Brainf*ck output and operating system output.-xlatin s
, where s is a string
in the form given above,
default value #nl=#10, specifies a complementary mapping between
characters on the operating system's input and
the Brainf*ck program's input.
Note that if the -xlatin
option is present
with no argument, this means that there should be no translation
mapping of input.-eof i
, where i is any integer
or one of the terms halt
, stop
,
or nop
, default 0,
determines the single ASCII character that will be given repeatedly to
the Brainf*ck program during execution of the ,
instruction
at and after the end of input is encountered.
If halt
is given for eof
, the Brainf*ck
program will be halted with an error
if it attempts to read past the end of user input.
If stop
is given for eof
, the Brainf*ck
program will be terminated normally if it attempts to read past
the end of user input.
If nop
is given for eof
, the Brainf*ck
program will act as if nothing at all happened if it attempts
to read past the end of user input (the tape will not be altered in
any way.)-quiet
, if given, suppresses all startup
output generated by the interpreter. It does not suppress
status reports.-autopsy
, if given, causes the interpreter to
issue a status report after the program terminates normally.-statusevery n
, where n is an
integer specifying a duration or the term undefined
,
default undefined
, tells pibfi
to generate periodic status reports at the given interval,
if it is not undefined
. If the duration is given
as a plain integer, units of milliseconds are assumed. The
duration may also be given as an integer followed immediately
by s
, m
, or h
, in which
case the units of measurement will be taken to be seconds,
minutes, or hours, respectively.Exported Functions | |
---|---|
get_flag/1 | Gets a switch from the command line. |
get_option/3 | Gets an option from a list of (already parsed) option tuples. |
get_opts/1 | Gets a set of options from the command line. |
Internal Documented Functions | |
convert/2 | Converts an option value specified on the command line to a
term that pibfi can work with internally. |
missing/1 | Gets the default value for an option specified with no value on the command line. |
unescape/1 | Transforms escape codes in a string into embedded characters. |
get_flag(Switch::atom()) -> true | false
Gets a switch from the command line.
get_option(Options::[{atom(), term()}], Option::atom(), Default::term()) -> term()
Gets an option from a list of (already parsed) option tuples.
get_opts([atom()]) -> [{atom(), term()}]
Gets a set of options from the command line.
convert(atom(), string()) -> term()
Converts an option value specified on the command line to a
term that pibfi
can work with internally.
missing(atom()) -> term()
Gets the default value for an option specified with no value on the command line.
unescape(string()) -> string()
Transforms escape codes in a string into embedded characters. The escape code #i where i is a decimal integer of from one to three digits is converted into an ASCII character of that value.