This module provides an interface to the standard Erlang compiler. It can generate either a new file which contains the object code, or return a binary which can be loaded directly.
Is the same as file(File,
[verbose,report_errors,report_warnings])
.
file(File, Options) -> CompRet
CompRet = ModRet | BinRet | ErrRet
ModRet = {ok,ModuleName} | {ok,ModuleName,Warnings}
BinRet = {ok,ModuleName,Binary} | {ok,ModuleName,Binary,Warnings}
ErrRet = error | {error,Errors,Warnings}
Compiles the code in the file File
, which is an
Erlang source code file without the .erl
extension. Options
determine the behavior of the compiler.
Returns {ok,ModuleName}
if successful, or
error
if there are errors. An object code file is created if the compilation succeeds with no errors.
The elements of Options
can be selected as
follows:
binary
{ok,ModuleName,Binary}
'P'
<File>.P
.
No object file is produced.
'E'
<File>.E
.
No object file is produced.
'S'
<File>.S
.
No object file is produced.
trace
erlang:trace/3
.
For Beam, see the section about the object code format below for
more information about the trace option.
report_errors/report_warnings
report
report_errors
and
report_warnings
.
return_errors
{error,ErrorList,WarningList}
is returned when
there are errors.
return_warnings
WarningList
is added to the tuples returned on
success.
return
return_errors
and
return_warnings
.
verbose
{outdir,Dir}
export_all
{i,Dir}
Dir
to the list of directories to be searched
when including a file.
{d,Macro}
{d,Macro,Value}
Macro
to have the value
Value
. The default is true
).
{parse_transform,Module}
Module:parse_transform/2
to be applied to the
parsed code before the code is checked for errors.
jam
beam
Note that all the options except the include path can also
be given in the file with a -compile([Option,...])
.
attribute.
Unrecognized options are ignored.
Both WarningList
and ErrorList
have the
following format:
[{FileName,[ErrorInfo]}].
ErrorInfo
is described below. The file name
has been included here as the compiler uses the Erlang
pre-processor epp
, which allows the code to be included in
other files. For this reason, it is important to know to
which file an error or warning line number refers.
format_error(ErrorDescriptor) -> string()
ErrorDescriptor = errordesc()
Uses an ErrorDescriptor
and returns a string
which describes the error. This function is usually called
implicitly when an ErrorInfo
structure is processed.
See below.
Parse transformations are used when a programmer wants to use Erlang syntax but with different semantics. The original Erlang code is then transformed into other Erlang code.
This type of activity is strongly discouraged.
The ErrorInfo
mentioned above is the standard
ErrorInfo
structure which is returned from all IO
modules. It has the following format
{ErrorLine, Module, ErrorDescriptor}
A string describing the error is obtained with the following call:
apply(Module, format_error, ErrorDescriptor)
The first part of the header for Beam object file is documented here.
trace/3
BIF. The other bits are reserved. Tools
that turn the trace bit on or off must preserve the other bits.
-vsn('1.0')
, the attribute will be stored like this in the object
code: "vsn=1.0\0"
.
epp, erl_id_trans
If Erlang crashes during compilation, <File>.ja#
files
may be created in the current directory. Such files can be
safely deleted.