mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-15 20:39:24 +02:00
+ Added new directives and most language features
This commit is contained in:
parent
5603092308
commit
58be548b1c
@ -15,6 +15,7 @@
|
||||
A & & \var{\$ASMMODE} & Select assembler mode. \\
|
||||
&\var{\$B} & \var{\$BOOLEVAL} & Use complete boolean evaluation. \\
|
||||
Sa &\var{\$C} & \var{\$ASSERTIONS} & Enable assertion support. \\
|
||||
& & \var{\$CALLING} & Set default calling convention \\
|
||||
d && \var{\$DEFINE} & Define a symbol. \\
|
||||
&& \var{\$ELSE} & Switch conditional compilation. \\
|
||||
&& \var{\$ENDIF} & End conditional compilation. \\
|
||||
@ -37,7 +38,8 @@ Ci &\var{\$I} & \var{\$IOCHECKS} & Include Input/Output checking. \\
|
||||
&\var{\$L} & \var{\$LINK} & Link object file. \\
|
||||
&& \var{\$LINKLIB} & Link to a library. \\
|
||||
&\var{\$M} & \var{\$TYPEINFO} & Generate Run-Time type information. \\
|
||||
Sm && \var{\$MACRO} & Enable macro support. \\
|
||||
Sm & & \var{\$MACRO} & Enable macro support. \\
|
||||
& & \var{\$MAXFPUREGISTER} & set maximum number of FPU registers \\
|
||||
&& \var{\$MESSAGE} & Generate info message. \\
|
||||
&& \var{\$MMX} & Enable Intel MMX support. \\
|
||||
&& \var{\$NOTE} & Generate note message. \\
|
||||
@ -66,21 +68,24 @@ u && \var{\$UNDEF} & Undefine a symbol. \\
|
||||
%\caption{Global compiler switches}
|
||||
\begin{tabularx}{\textwidth}{lllX}
|
||||
\textbf{cmd} & \textbf {short} & \textbf {long} & \textbf{explanation }\\ \hline
|
||||
& & \var{\$APPID} & Set application ID (PalmOS) \\
|
||||
& & \var{\$APPNAME} & Set application name (PalmOS) \\
|
||||
& & \var{\$APPTYPE} & Specify type of application (Win32 only) \\
|
||||
g& \var{\$D} & \var{\$DEBUGINFO} & Include debugging symbols. \\
|
||||
& & \var{\$DESCRIPTION} & Not supported. \\
|
||||
&\var{\$E} & & Enable emulation of coprocessor. \\
|
||||
& & \var{\$G} & Generate 80286 code. \\
|
||||
& \var{\$G}& & Generate 80286 code. \\
|
||||
Fi& & \var{\$INCLUDEPATH} & Specify include file search path. \\
|
||||
&\var{\$L} & \var{\$LOCALSYMBOLS} & Enable local symbol information. \\
|
||||
Fl& & \var{\$LIBRARYPATH} & Specify library search path. \\
|
||||
&\var{\$M} & \var{\$MEMORY} & Specify memory sizes. \\
|
||||
M& & \var{\$MODE} & Specify compiler compatibility mode. \\
|
||||
& & \var{\$N} & Enable numeric processing. \\
|
||||
& & \var{\$O} & Enable overlay code generation. \\
|
||||
& \var{\$N}& & Enable numeric processing. \\
|
||||
& \var{\$O}& & Enable overlay code generation. \\
|
||||
Fo& & \var{\$OBJECTPATH} & Specify object file search path. \\
|
||||
Ct& \var{\$S} & & Use stack checking \\
|
||||
Fu& & \var{\$UNITPATH} & Specify unit file search path. \\
|
||||
& & \var{\$VERSION} & Set DLL version (Windows)\\
|
||||
& \var{\$W} & \var{\$STACKFRAMES} & Generate stackframes. \\
|
||||
b & \var{\$Y} & \var{\$REFERENCEINFO} & Insert browser information. \\ \hline
|
||||
\end{tabularx}
|
||||
|
@ -189,6 +189,7 @@
|
||||
\newcommand{\ostwo}{\textsc{os/2}\xspace}
|
||||
\newcommand{\windows}{\textsc{Windows}\xspace}
|
||||
\newcommand{\windowsnt}{\textsc{Windows NT}\xspace}
|
||||
\newcommand{\macos}{\textsc{mac OS}\xspace}
|
||||
\newcommand{\fpc}{Free Pascal\xspace}
|
||||
\newcommand{\gnu}{\textsc{gnu}\xspace}
|
||||
\newcommand{\atari}{\textsc{Atari}\xspace}
|
||||
|
310
docs/prog.tex
310
docs/prog.tex
@ -204,6 +204,17 @@ is the same as
|
||||
\end{verbatim}
|
||||
This is useful for indication what switch is meant.
|
||||
|
||||
\subsection{\var{\protect\$ELSEC} : Switch conditional compilation}
|
||||
In MAC mode, this directive can be used as an alternative to the \var{\$ELSE}
|
||||
directive. It is supported for compatibility with existing \macos pascal
|
||||
compilers.
|
||||
|
||||
|
||||
\subsection{\var{\protect\$ENDC} : End conditional compilation}
|
||||
In MAC mode, this directive can be used as an alternative to the
|
||||
\var{\$ENDIF} directive. It is supported for compatibility with existing \macos pascal
|
||||
compilers.
|
||||
|
||||
\subsection{\var{\protect\$ENDIF} : End conditional compilation}
|
||||
|
||||
The \var{\{\$ENDIF\}} directive ends the conditional compilation initiated by the
|
||||
@ -380,6 +391,11 @@ the source cannot be used. Macros and symbols may be used, however.
|
||||
More information on this can be found in the section about
|
||||
conditionals.
|
||||
|
||||
\subsection{\var{\protect\$IFC} : Start conditional compilation}
|
||||
In MAC mode, this directive can be used as an alternative to the \var{\$IF}
|
||||
directive. It is supported for compatibility with existing \macos pascal
|
||||
compilers.
|
||||
|
||||
\subsection{\var{\protect\$IFDEF Name} : Start conditional compilation}
|
||||
|
||||
If the symbol \var{Name} is not defined then the \var{\{\$IFDEF name\}}
|
||||
@ -415,6 +431,17 @@ Will compile the writeln statement if generation of type information is on.
|
||||
i.e. \var{\{\$IFOPT TYPEINFO\}} will not be accepted.
|
||||
\end{remark}
|
||||
|
||||
\subsection{\var{\protect\$IMPLICITEXCEPTIONS} : Do not generate
|
||||
finalization code}
|
||||
|
||||
The compiler generates an implicit \var{try}...\var{finally} frame around
|
||||
each procedure that needs initialization or finalization of variables, and
|
||||
finalizes the variables in the \var{finally} block. This
|
||||
slows down these procedures (with 5-10% sometimes). With this directive, the generation of such
|
||||
frames can be disabled. One should be careful with this directive, because
|
||||
it can lead to memory leaks if an exception occurs inside the routine.
|
||||
Therefore, standard it is set to \var{OFF}.
|
||||
|
||||
\subsection{\var{\protect\$INFO} : Generate info message}
|
||||
|
||||
If the generation of info is turned on, through the \var{-vi} command-line
|
||||
@ -440,6 +467,19 @@ By default, \var{Inline} procedures are not allowed. This directive must be
|
||||
specified to use inlined code. The directive is equivalent to the command-line
|
||||
switch \var{-Si}. For more information on inline routines, consult the \refref.
|
||||
|
||||
\subsection{\var{\protect\$INTERFACES\}} : Specify Interface type.}
|
||||
The \var{\{\$INTERFACES\}} directive tells the compiler what it should take
|
||||
as the parent interface of an interface declaration which does not
|
||||
explicitly specify a parent interface. By default the Windows COM \var{IUnknown}
|
||||
interface is used. Other implementations of interfaces (CORBA or Java) do
|
||||
not necessarily have this interface, and for such cases, this directive can
|
||||
be used. It accepts the following three values:
|
||||
\begin{description}
|
||||
\item[COM] Interfaces will descend from \var{IUnknown}.
|
||||
\item[CORBA] Interfaces will not have a parent.
|
||||
\item[DEFAULT] Currently, this is COM.
|
||||
\end{description}
|
||||
|
||||
\subsection{\var{\protect\$I} or \var{\protect\$IOCHECKS} : Input/Output checking}
|
||||
|
||||
The \var{\{\$I-\}} or \var{\{\$IOCHECKS OFF\}} directive tells the compiler
|
||||
@ -900,34 +940,10 @@ This works only on the intel compiler, and MMX support must be on
|
||||
saturation support (\sees{SaturationSupport}) for more information
|
||||
on the effect of this directive.
|
||||
|
||||
\subsection{\var{\protect\$SMARTLINK} : Use smartlinking}
|
||||
|
||||
A unit that is compiled in the \var{\{\$SMARTLINK ON\}} state will be
|
||||
compiled in such a way that it can be used for smartlinking. This means that
|
||||
the unit is chopped in logical pieces: each procedure is put in it's own
|
||||
object file, and all object files are put together in a big archive. When
|
||||
using such a unit, only the pieces of code that you really need or call,
|
||||
will be linked in your program, thus reducing the size of your executable
|
||||
substantially.
|
||||
|
||||
Beware: using smartlinked units slows down the compilation process, because
|
||||
a separate object file must be created for each procedure. If you have units
|
||||
with many functions and procedures, this can be a time consuming process,
|
||||
even more so if you use an external assembler (the assembler is called to
|
||||
assemble each procedure or function code block separately).
|
||||
|
||||
The smartlinking directive should be specified {\em before} the unit
|
||||
declaration part:
|
||||
\begin{verbatim}
|
||||
{$SMARTLINK ON}
|
||||
|
||||
Unit MyUnit;
|
||||
|
||||
Interface
|
||||
...
|
||||
\end{verbatim}
|
||||
|
||||
This directive is equivalent to the \var{-Cx} command-line switch.
|
||||
\subsection{\var{\protect\$SETC} : Define a symbol}
|
||||
In MAC mode, this directive can be used as an alternative to the
|
||||
\var{\$DEFINE} directive. It is supported for compatibility with existing \macos pascal
|
||||
compilers.
|
||||
|
||||
\subsection{\var{\protect\$STATIC} : Allow use of \var{Static} keyword.}
|
||||
|
||||
@ -1046,20 +1062,70 @@ By default, extended syntax is assumed.
|
||||
\label{se:GlobalSwitch}
|
||||
Global directives affect the whole of the compilation process. That is why
|
||||
they also have a command-line counterpart. The command-line counterpart is
|
||||
given for each of the directives.
|
||||
given for each of the directives. They must be specified {\em before} the
|
||||
\var{unit} or \var{program} clause in a source file, or they will have no
|
||||
effect.
|
||||
|
||||
\subsection{\var{\protect\$APPTYPE} : Specify type of application (Win32 and AmigaOS only)}
|
||||
\subsection{\var{\protect\$APPNAME} : Specify application name.}
|
||||
Used on the PALM os only, it can be set to specify the application name,
|
||||
which can be viewed on the Palm only. This directive only makes sense in a
|
||||
program source file, not in a unit.
|
||||
|
||||
The \var{\{\$APPTYPE XXX\}} accepts one argument that can have two possible
|
||||
values: \var{GUI} or \var{CONSOLE}. It is used to tell the \windows
|
||||
Operating system if an application is a console application or a graphical
|
||||
application. By default, a program compiled by \fpc is a console
|
||||
application. Running it will display a console window. Specifying the
|
||||
\var{\{\$APPTYPE GUI\}} directive will mark the application as a graphical
|
||||
application; no console window will be opened when the application is run.
|
||||
If run from the command-line, the command prompt will be returned immediatly
|
||||
after the application was started.
|
||||
\begin{verbatim}
|
||||
{$APPID MyApplication}
|
||||
\end{verbatim}
|
||||
|
||||
\subsection{\var{\protect\$APPNAME} : Specify application name.}
|
||||
Used on the PALM os only, it can be set to specify the application name,
|
||||
which can be viewed on the Palm only. This directive only makes sense in a
|
||||
program source file, not in a unit.
|
||||
|
||||
\begin{verbatim}
|
||||
{$APPNAME My Application, compiled using Free Pascal.}
|
||||
\end{verbatim}
|
||||
|
||||
\subsection{\var{\protect\$APPTYPE} : Specify type of application.}
|
||||
This directive is currently only supported on the following targets:
|
||||
Win32, Mac, OS2 and AmigaOS. On other targets, the directive is ignored.
|
||||
|
||||
The \var{\{\$APPTYPE XXX\}} accepts one argument which specifies what kind
|
||||
of application is compiled. It can have the following
|
||||
values:
|
||||
\begin{description}
|
||||
\item[CONSOLE] A console application. A terminal will be created and
|
||||
standard input, output and standard error file descriptors will be
|
||||
initialized. In Windows, a terminal window will be created. This is the
|
||||
default.
|
||||
|
||||
Note that on \macos such applications cannot take command-line
|
||||
options, nor return a result code. They will run in a special
|
||||
terminal window.
|
||||
|
||||
On \ostwo, these applications can run both full-screen and in a terminal
|
||||
window.
|
||||
|
||||
\linux applications are always console applications. The application itself
|
||||
can decide to close the standard files, though.
|
||||
|
||||
\item[FS] specifies a full-screen VIO application on \ostwo. These
|
||||
applications use a special BIOS-like API to program the screen. \ostwo
|
||||
starts these application allways in full screen.
|
||||
|
||||
\item[GUI] Specifying the \var{\{\$APPTYPE GUI\}} directive will mark the
|
||||
application as a graphical application; no console window will be opened
|
||||
when the application is run. No stanrdard file descriptors will be
|
||||
initialized, using them (with e.g. \var{writeln} statements) will produce a
|
||||
run-time error. If run from the command-line, the command prompt will be
|
||||
returned immediatly after the application was started.
|
||||
|
||||
On \ostwo and \macos, the GUI application type creates a GUI application, as
|
||||
on Windows. On \ostwo, this is a real Presentation Manager application.
|
||||
|
||||
\item[TOOL] this is a special directive for the \macos. It tells the compiler
|
||||
to create a tool application: It initializes input, output, stderr files,
|
||||
it can take parameters and return a result code. It is implemented as an MPW
|
||||
tool which can only be run by MPW or ToolServer.
|
||||
\end{description}
|
||||
Care should be taken when compiling \var{GUI} applications; the \var{Input}
|
||||
and \var{Output} files are not available in a GUI application, and
|
||||
attempting to read from or write to them will result in a run-time error.
|
||||
@ -1069,11 +1135,43 @@ at runtime. The \var{IsConsole} constant, declared in the Win32 and Amiga
|
||||
system units as
|
||||
\begin{verbatim}
|
||||
Const
|
||||
IsConsole : Boolean
|
||||
IsConsole : Boolean;
|
||||
\end{verbatim}
|
||||
contains \var{True} if the application is a console application, \var{False}
|
||||
if the application is a GUI application.
|
||||
|
||||
\subsection{\var{\protect\$CALLING} : Default calling convention}
|
||||
This directive allows to specify the default calling convention used by the
|
||||
compiler, when no calling convention is specified for a procedure or
|
||||
function declaration. It can be one of the following values:
|
||||
\begin{description}
|
||||
\item[CDECL] C compiler calling convention.
|
||||
\item[CPPDECL] C++ compiler calling convention.
|
||||
\item[FAR16] Ignored, but parsed for compatibility reasons.
|
||||
\item[FPCCALL] Older FPC (1.0.X and before) standard calling convention. If
|
||||
a lot of direct assembler blocks are used, this mode should be used for
|
||||
maximum compatibility.
|
||||
\item[INLINE] Use inline code: the code for the function is inserted
|
||||
whenever it is called.
|
||||
\item[PASCAL] Pascal calling convention.
|
||||
\item[REGISTER] Register calling convention.
|
||||
\item[SAFECALL] Safecall calling convention (used in COM): The called
|
||||
procedure/function saves all registers.
|
||||
\item[STDCALL] Windows library calling convention.
|
||||
\item[SOFTFLOAT] For ARM processors.
|
||||
\end{description}
|
||||
It is equivalent to the \var{-Cc} command-line option.
|
||||
|
||||
\subsection{\var{\protect\$COPYRIGHT} specify copyright info}
|
||||
This is intended for the NETWARE version of the compiler: it specifies the
|
||||
copyright information that can be viewed on a module for a Netware OS.
|
||||
|
||||
For example:
|
||||
\begin{verbatim}
|
||||
{$COPYRIGHT GNU copyleft. compiled using Free Pascal}
|
||||
\end{verbatim}
|
||||
|
||||
|
||||
\subsection{\var{\protect\$D} or \var{\protect\$DEBUGINFO} : Debugging symbols}
|
||||
|
||||
When this switch is on,
|
||||
@ -1148,7 +1246,9 @@ Caution is in order when using this directive: If you distribute files, the
|
||||
places of the files may not be the same as on your machine; moreover, the
|
||||
directory structure may be different. In general it would be fair to say
|
||||
that you should avoid using {\em absolute} paths, instead use {\em relative}
|
||||
paths, as in the example above. Only use this directive if you are certain
|
||||
paths, as in the example above. Only
|
||||
|
||||
use this directive if you are certain
|
||||
of the places where the files reside. If you are not sure, it is better
|
||||
practice to use makefiles and makefile variables.
|
||||
|
||||
@ -1215,6 +1315,9 @@ supplied.
|
||||
command-line option.
|
||||
\item[GPC] GNU pascal mode. This is the same as the \var{-Sp} command-line
|
||||
option.
|
||||
\item[MAC] MAC mode. In this mode, the compiler tries to be more compatible
|
||||
to commonly used pascal dialects on the \macos, such as Think Pascal, Metrowerks
|
||||
Pascal, MPW Pascal.
|
||||
\end{description}
|
||||
|
||||
For an exact description of each of these modes, see appendix \ref{ch:AppD},
|
||||
@ -1258,6 +1361,13 @@ paths, as in the example above. Only use this directive if you are certain
|
||||
of the places where the files reside. If you are not sure, it is better
|
||||
practice to use makefiles and makefile variables.
|
||||
|
||||
\subsection{\var{\protect\$PROFILE} : Profiling}
|
||||
|
||||
This directive turns the generation of profiling code on (or off). It is
|
||||
equivalent to the \var{-gp} command-line option. Default is \var{OFF}. This
|
||||
directive only makes sense in a program source file, not in a unit.
|
||||
|
||||
|
||||
\subsection{\var{\protect\$S} : Stack checking}
|
||||
|
||||
The \var{\{\$S+\}} directive tells the compiler to generate stack checking
|
||||
@ -1273,6 +1383,49 @@ The command-line compiler switch \var{-Ct} has the same effect as the
|
||||
|
||||
By default, no stack checking is performed.
|
||||
|
||||
\subsection{\var{\protect\$SMARTLINK} : Use smartlinking}
|
||||
|
||||
A unit that is compiled in the \var{\{\$SMARTLINK ON\}} state will be
|
||||
compiled in such a way that it can be used for smartlinking. This means that
|
||||
the unit is chopped in logical pieces: each procedure is put in it's own
|
||||
object file, and all object files are put together in a big archive. When
|
||||
using such a unit, only the pieces of code that you really need or call,
|
||||
will be linked in your program, thus reducing the size of your executable
|
||||
substantially.
|
||||
|
||||
Beware: using smartlinked units slows down the compilation process, because
|
||||
a separate object file must be created for each procedure. If you have units
|
||||
with many functions and procedures, this can be a time consuming process,
|
||||
even more so if you use an external assembler (the assembler is called to
|
||||
assemble each procedure or function code block separately).
|
||||
|
||||
The smartlinking directive should be specified {\em before} the unit
|
||||
declaration part:
|
||||
\begin{verbatim}
|
||||
{$SMARTLINK ON}
|
||||
|
||||
Unit MyUnit;
|
||||
|
||||
Interface
|
||||
...
|
||||
\end{verbatim}
|
||||
|
||||
This directive is equivalent to the \var{-Cx} command-line switch.
|
||||
|
||||
\subsection{\var{\protect\$THREADNAME} : Set thread name in Netware}
|
||||
This directive can be set to specify the thread name when compiling for
|
||||
Netware.
|
||||
|
||||
\subsection{\var{\protect\$THREADING} : Allow use of threads.}
|
||||
If a program needs threading, this directive must be specified; The compiler
|
||||
will then insert the \var{systhrd} unit in the uses list of the program and
|
||||
will enable some threading features. This directive defines or undefines the
|
||||
\var{FPC\_THREADING} macro symbol.
|
||||
|
||||
Specifying \var{\{\$THREADING OFF\}} will disable threading. The
|
||||
\var{FPC\_THREADING} will be undefined.
|
||||
|
||||
|
||||
\subsection{\var{\protect\$UNITPATH} : Specify unit path.}
|
||||
|
||||
This option serves to specify the unit path, where the compiler looks for
|
||||
@ -1300,6 +1453,26 @@ paths, as in the example above. Only use this directive if you are certain
|
||||
of the places where the files reside. If you are not sure, it is better
|
||||
practice to use makefiles and makefile variables.
|
||||
|
||||
\subsection{\var{\protect\$VERSION} : Specify DLL version.}
|
||||
On \windows, this can be used to specify a version number for a library.
|
||||
This version number will be used when the library is installed, and can be
|
||||
viewed in the Windows Explorer by opening the property sheet of the DLL and
|
||||
looking on the tab 'Version'. The version number consists of minimally one,
|
||||
maximum 3 numbers:
|
||||
\begin{verbatim}
|
||||
{$VERSION 1}
|
||||
\end{verbatim}
|
||||
Or:
|
||||
\begin{verbatim}
|
||||
{$VERSION 1.1}
|
||||
\end{verbatim}
|
||||
And even:
|
||||
\begin{verbatim}
|
||||
{$VERSION 1.1.1}
|
||||
\end{verbatim}
|
||||
This can not yet be used for executables on Windows, but may be activated in
|
||||
the future.
|
||||
|
||||
\subsection{\var{\protect\$W} or \var{\protect\$STACKFRAMES} : Generate stackframes}
|
||||
|
||||
The \var{\{\$W\}} switch directive controls the generation of stackframes.
|
||||
@ -1426,7 +1599,9 @@ will evaluate to \var{True}.
|
||||
|
||||
You can use any Pascal operator to construct your expression: \var{=, <>,
|
||||
>, <, >=, <=, AND, NOT, OR} and you can use round brackets to change the
|
||||
precedence of the operators.
|
||||
precedence of the operators. Additionally, the constants \var{FALSE} and
|
||||
\var{TRUE} can be used, and the operator \var{UNDEFINED}. The \var{UNDEFINED}
|
||||
operator returns \var{TRUE} if a macro was not yet defined.
|
||||
|
||||
The following example shows you many of the possibilities:
|
||||
\begin{verbatim}
|
||||
@ -1526,6 +1701,19 @@ begin
|
||||
{$fatal $if not(0) rejected}
|
||||
{$endif}
|
||||
|
||||
{$IF NOT UNDEFINED FPC}
|
||||
// Detect FPC stuff when compiling on MAC.
|
||||
{$SETC TARGET_RT_MAC_68881:= FALSE}
|
||||
{$SETC TARGET_OS_MAC := (NOT UNDEFINED MACOS)
|
||||
OR (NOT UNDEFINED DARWIN)}
|
||||
{$SETC TARGET_OS_WIN32 := NOT UNDEFINED WIN32}
|
||||
{$SETC TARGET_OS_UNIX := (NOT UNDEFINED UNIX)
|
||||
AND (UNDEFINED DARWIN)}
|
||||
{$SETC TYPE_EXTENDED := TRUE}
|
||||
{$SETC TYPE_LONGLONG := FALSE}
|
||||
{$SETC TYPE_BOOL := FALSE}
|
||||
{$ENDIF}
|
||||
|
||||
{$info *************************************************}
|
||||
{$info * Now have to follow at least 2 error messages: *}
|
||||
{$info *************************************************}
|
||||
@ -5678,7 +5866,7 @@ set with the \var{\$Mode} switch, or by command line switches.
|
||||
\section{FPC mode}
|
||||
This mode is selected by the \var{{\$MODE FPC}} switch. On the command-line,
|
||||
this means that you use none of the other compatibility mode switches.
|
||||
It is the default mode of the compiler. This means essentially:
|
||||
It is the default mode of the compiler (\var{-Mfpc}). This means essentially:
|
||||
\begin{enumerate}
|
||||
\item You must use the address operator to assign procedural variables.
|
||||
\item A forward declaration must be repeated exactly the same by the
|
||||
@ -5696,7 +5884,7 @@ parameters when implementing the function or procedure.
|
||||
\section{TP mode}
|
||||
This mode is selected by the \var{{\$MODE TP}} switch. It tries to emulate,
|
||||
as closely as possible, the behavior of Turbo Pascal 7. On the command-line,
|
||||
this mode is selected by the \var{-So} switch.
|
||||
this mode is selected by the \var{-Mtp} switch.
|
||||
|
||||
\begin{enumerate}
|
||||
\item Enumeration sizes default to a storage size of 1 byte if there
|
||||
@ -5716,7 +5904,7 @@ parameters when implementing the function or procedure.
|
||||
\section{Delphi mode}
|
||||
This mode is selected by the \var{{\$MODE DELPHI}} switch. It tries to emulate,
|
||||
as closely as possible, the behavior of Delphi 4. On the command-line,
|
||||
this mode is selected by the \var{-Sd} switch.
|
||||
this mode is selected by the \var{-Mdelpih} switch.
|
||||
\begin{enumerate}
|
||||
\item You can not use the address operator to assign procedural variables.
|
||||
\item A forward declaration must not be repeated exactly the same by the
|
||||
@ -5735,7 +5923,7 @@ properties (although it is bad programming practice).
|
||||
% GPC Mode
|
||||
\section{GPC mode}
|
||||
This mode is selected by the \var{{\$MODE GPC}} switch. On the command-line,
|
||||
this mode is selected by the \var{-Sp} switch.
|
||||
this mode is selected by the \var{-Mgpc} switch.
|
||||
\begin{enumerate}
|
||||
\item You must use the address operator to assign procedural variables.
|
||||
\item A forward declaration must not be repeated exactly the same by the
|
||||
@ -5751,7 +5939,7 @@ parameters when implementing the function or procedure.
|
||||
% Objfpc mode
|
||||
\section{OBJFPC mode}
|
||||
This mode is selected by the \var{{\$MODE OBJFPC}} switch. On the command-line,
|
||||
this mode is selected by the \var{-S2} switch.
|
||||
this mode is selected by the \var{-Mobjfpc} switch.
|
||||
\begin{enumerate}
|
||||
\item You must use the address operator to assign procedural variables.
|
||||
\item A forward declaration must be repeated exactly the same by the
|
||||
@ -5768,6 +5956,34 @@ consequences of this is that the type \var{Integer} is redefined as
|
||||
properties.
|
||||
\end{enumerate}
|
||||
|
||||
\section{MAC mode}
|
||||
This mode is selected by the \var{{\$MODE MAC}} switch. On the
|
||||
command-line, this mode is selected by the \var{-MMAC} switch. It mainly
|
||||
switches on some extra features:
|
||||
\begin{enumerate}
|
||||
\item Support for the \var{\$SETC} directive.
|
||||
\item Support for the \var{\$IFC}, \var{\$ELSEC} and \var{\$ENDC}
|
||||
directives.
|
||||
\item Support for the \var{UNDEFINED} construct in macros.
|
||||
\item Support for \var{TRUE} and \var{FALSE} as values in macro expressions.
|
||||
\item Macros may be assigned hexadecimal numbers, like \var{\$2345}.
|
||||
\end{enumerate}
|
||||
(Note: Macros are called 'Compiler Variables' in \macos dialects.)
|
||||
|
||||
Currently, the following \macos pascal extensions are not yet supported in
|
||||
\var{MAC} mode:
|
||||
\begin{itemize}
|
||||
\item A nested procedure cannot be an actual parameter to a procedure.
|
||||
\item No anonymous procedure types in formal parameters.
|
||||
\item External procedures declared in the interface must have the directive \var{External}.
|
||||
\item \var{Continue} instead of \var{Cycle}.
|
||||
\item \var{Break} instead of \var{Leave}
|
||||
\item \var{Exit} should not have the name of the procedure to exit as parameter.
|
||||
Instead, for a function the value to return can be supplied as parameter.
|
||||
\item No propagating \var{uses}.
|
||||
\item Compiler directives defined in interface sections are not exported.
|
||||
\end{itemize}
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Appendix E
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
94
docs/ref.tex
94
docs/ref.tex
@ -303,8 +303,9 @@ true
|
||||
\end{verbatim}
|
||||
\end{multicols}
|
||||
\subsection{Modifiers}
|
||||
The following is a list of all modifiers. Contrary to Delphi, \fpc doesn't
|
||||
allow the programmer to redefine these modifiers.
|
||||
The following is a list of all modifiers. They are not exactly reserved
|
||||
words in the sense that they can be used as identifiers, but in specific
|
||||
places, they have a special meaning for the compiler.
|
||||
\begin{multicols}{4}
|
||||
\begin{verbatim}
|
||||
absolute
|
||||
@ -316,7 +317,9 @@ default
|
||||
export
|
||||
external
|
||||
far
|
||||
far16
|
||||
forward
|
||||
fpccall
|
||||
index
|
||||
name
|
||||
near
|
||||
@ -329,7 +332,9 @@ public
|
||||
published
|
||||
read
|
||||
register
|
||||
safecall
|
||||
saveregisters
|
||||
softfloat
|
||||
stdcall
|
||||
virtual
|
||||
write
|
||||
@ -1813,6 +1818,10 @@ can be converted to a variable of this type.
|
||||
Note that expressions involving variants take more time to be evaluated, and
|
||||
should therefore be used with caution. If a lot of calculations need to be
|
||||
made, it is best to avoid the use of variants.
|
||||
|
||||
When considering implicit type conversions (e.g. byte to integer, integer to
|
||||
double, char to string) the compiler will ignore variants unless a variant
|
||||
appears explicitly in the expression.
|
||||
|
||||
\subsection{Variants and interfaces}
|
||||
|
||||
@ -2004,7 +2013,58 @@ end.
|
||||
\end{verbatim}
|
||||
|
||||
The read/write specifiers can be hidden by declaring them in another unit
|
||||
(which must be in the \var{uses} clause of the unit).
|
||||
which must be in the \var{uses} clause of the unit. This can be used to hide
|
||||
the read/write access specifiers for programmers, just as if they were in a
|
||||
\var{private} section of a class (discussed below). For the previous
|
||||
example, this could look as follows:
|
||||
\begin{verbatim}
|
||||
{$mode objfpc}
|
||||
unit testrw;
|
||||
|
||||
Interface
|
||||
|
||||
Function GetMyInt : Integer;
|
||||
Procedure SetMyInt(Value : Integer);
|
||||
|
||||
Implementation
|
||||
|
||||
Uses sysutils;
|
||||
|
||||
Var
|
||||
FMyInt : Integer;
|
||||
|
||||
Function GetMyInt : Integer;
|
||||
|
||||
begin
|
||||
Result:=FMyInt;
|
||||
end;
|
||||
|
||||
Procedure SetMyInt(Value : Integer);
|
||||
|
||||
begin
|
||||
If ((Value mod 2)=1) then
|
||||
Raise Exception.Create('Only even values are allowed');
|
||||
FMyInt:=Value;
|
||||
end;
|
||||
|
||||
end.
|
||||
\end{verbatim}
|
||||
The unit \file{testprop} would then look like:
|
||||
\begin{verbatim}
|
||||
{$mode objfpc}
|
||||
unit testprop;
|
||||
|
||||
Interface
|
||||
|
||||
uses testrw;
|
||||
|
||||
Property
|
||||
MyProp : Integer Read GetMyInt Write SetMyInt;
|
||||
|
||||
Implementation
|
||||
|
||||
end.
|
||||
\end{verbatim}
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Objects
|
||||
@ -2812,7 +2872,7 @@ methods of the parent interface(s).
|
||||
An interface can be uniquely identified by a GUID (GUID is an acronym for
|
||||
Globally Unique Identifier, a 128-bit integer guaranteed always to be
|
||||
unique\footnote{In theory, of course.}. Especially on Windows systems, the
|
||||
GUID of an interface can and most be used when using COM.
|
||||
GUID of an interface can and must be used when using COM.
|
||||
|
||||
The definition of an Interface has the following form:
|
||||
\input{syntax/typeintf.syn}
|
||||
@ -2833,7 +2893,7 @@ hence also \var{override} cannot be present in the definition of a interface
|
||||
definition.
|
||||
\end{itemize}
|
||||
|
||||
\section{Identification: A GUID}
|
||||
\section{Interface identification: A GUID}
|
||||
An interface can be identified by a GUID. This is a 128-bit number, which is
|
||||
represented in a text representation (a string literal):
|
||||
\begin{verbatim}
|
||||
@ -2872,6 +2932,8 @@ Const
|
||||
begin
|
||||
end.
|
||||
\end{verbatim}
|
||||
Normally, the GUIDs are only used in Windows, when using COM interfaces.
|
||||
More on this in the next section.
|
||||
|
||||
\section{Interfaces and COM}
|
||||
When using interfaces on Windows which should be available to the COM
|
||||
@ -2938,6 +3000,20 @@ This declaration should tell the compiler that the \var{MyFunc} method of
|
||||
the \var{IMyInterface} interface is implemented in the \var{MyOtherFunction}
|
||||
method of the \var{TMyClass} class.
|
||||
|
||||
\section{CORBA and other Interfaces}
|
||||
COM is not the only architecture where interfaces are used. CORBA knows
|
||||
interfaces, UNO (the OpenOffice API) uses interfaces, and Java as well.
|
||||
These languages do not know the \var{IUnknown} interface used as the basis of
|
||||
all interfaces in COM. It would therefore be a bad idea if an interface
|
||||
automatically descended from \var{IUnknown} if no parent interface was
|
||||
specified. Therefore, a directive \var{\{\$INTERFACES\}} was introduced in
|
||||
\fpc: it specifies what the parent interface is of an interface, declared
|
||||
without parent. More information about this directive can be found in the
|
||||
\progref.
|
||||
|
||||
Note that COM interfaces are by default reference counted.
|
||||
CORBA interfaces are not necessarily reference counted.
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% Expressions
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
@ -4415,7 +4491,8 @@ assembly-language level, by using it's mangled name (see the \progref).
|
||||
\label{se:register}
|
||||
The \var{register} keyword is used for compatibility with Delphi. In
|
||||
version 1.0.x of the compiler, this directive has no effect on the
|
||||
generated code.
|
||||
generated code. As of the 1.9.X versions, this directive is supported. The
|
||||
first three arguments are passed in registers EAX,ECX and EDX.
|
||||
|
||||
\subsection{saveregisters}
|
||||
If this modifier is specified after a procedure or function, then the
|
||||
@ -4428,11 +4505,14 @@ calling assembler code.
|
||||
|
||||
\subsection{safecall}
|
||||
This modifier ressembles closely the \var{stdcall} modifier. It sends
|
||||
parameters from right to left on the stack.
|
||||
parameters from right to left on the stack. The called procedure saves and
|
||||
restores all registers.
|
||||
|
||||
More information about this modifier can be found in the \progref, in the
|
||||
section on the calling mechanism and the chapter on linking.
|
||||
|
||||
\subsection{softfloat}
|
||||
This modifier makes sense only on the ARM architecture.
|
||||
|
||||
\subsection{stdcall}
|
||||
This modifier pushes the parameters from right to left on the stack,
|
||||
|
@ -1066,8 +1066,12 @@ be used by an Integrated Development Environment (IDE) to provide information
|
||||
on classes, objects, procedures, types and variables in a unit.
|
||||
\item[-bl] \olabel{bl} is the same as \var{-b} but also generates
|
||||
information about local variables, types and procedures.
|
||||
\item[-Cc] set the default calling convention used by the compiler.
|
||||
\item [-CD] Create a dynamic library. This is used to transform units into
|
||||
dynamically linkable libraries on \linux.
|
||||
\item[-CeXXX] set the used floating point emulation.
|
||||
\item[-CfXXX] set the used floating point processor.
|
||||
\item[-Cg] enable generation of PIC code.
|
||||
\item [-Chxxx] \olabel {Ch} Reserves \var{xxx} bytes heap. \var{xxx} should
|
||||
be between 1024 and 67107840.
|
||||
\item [-Ci] \olabel{Ci} Generate Input/Output checking code. In case some
|
||||
@ -1076,6 +1080,7 @@ exit with a run-time error. Which error is generated depends on the I/O error.
|
||||
\item [-Cn] \olabel{Cn} Omit the linking stage.
|
||||
\item [-Co] \olabel{Co} Generate Integer overflow checking code. In case of
|
||||
integer errors, a run-time error will be generated by your program.
|
||||
\item [-CpXXX] set the processor type to XXX
|
||||
\item [-Cr] \olabel{Cr} Generate Range checking code. In case your program
|
||||
acesses an array element with an invalid index, or if it increases an
|
||||
enumerated type beyond it's scope, a run-time error will be generated.
|
||||
@ -1131,7 +1136,15 @@ defines.
|
||||
Instead, the compiler writes a script, \file{PPAS.BAT} under \dos, or
|
||||
\file{ppas.sh} under \linux, which can then be executed to produce an
|
||||
executable. This can be used to speed up the compiling process or to debug
|
||||
the compiler's output.
|
||||
the compiler's output. This option can take some extra parameter, mainly
|
||||
used for cross-compilation.
|
||||
\begin{description}
|
||||
\item[h] Generate script to link on host. The generated script can be run on
|
||||
the compilation platform (host platform).
|
||||
\item[t] Generate script to link on target platform. The generated script
|
||||
can be run on the target platform. (where the binary must be run)
|
||||
\item[r] Skip register allocation phase (optimizations will be disabled).
|
||||
\end{description}
|
||||
\item[-Txxx] \olabel{T} Specifies the target operating system. \var{xxx} can be one of
|
||||
the following:
|
||||
\begin{itemize}
|
||||
@ -1149,6 +1162,18 @@ of the \var{-d} option.
|
||||
recompiled, even when the sources are available. This is useful when making
|
||||
release distributions. This also overrides the \var{-B} option for release
|
||||
mode units.
|
||||
\item[-W] set some \windows or \ostwo attributes of the generated binary. It
|
||||
can be one or more of the following
|
||||
\begin{description}
|
||||
\item[Bhhh] set preferred base address to hhh (a hexadecimal address)
|
||||
\item[C] Generate a console application (+) or a gui application (-).
|
||||
\item[D] Force use of Def file for exports.
|
||||
\item[F] Generate a FS application (+) or a console application (-).
|
||||
\item[G] Generate a GUI application (+) or a console application (-).
|
||||
\item[N] Do not generate relocation section.
|
||||
\item[R] Generate a relocation section.
|
||||
\item[T] Generate a TOOL application (+) or a console application (-).
|
||||
\end{description}
|
||||
\item [-Xx] \olabel{X} executable options. This tells the compiler what
|
||||
kind of executable should be generated. the parameter \var{x}
|
||||
can be one of the following:
|
||||
@ -1174,6 +1199,19 @@ can be one of the following:
|
||||
\label{se:sourceoptions}
|
||||
for more information on these options, see also \progref
|
||||
\begin{description}
|
||||
\item[-Mmode] set language mode to \var{mode}, which can be one of the
|
||||
following:
|
||||
\begin{description}
|
||||
\item[delphi] tries to be Delphi compatible. This is more strict
|
||||
than the \var{objfpc} mode, since some \fpc extensions are switched off.
|
||||
\item[fpc] free pascal dialect (default)
|
||||
\item[gpc] tries to be gpc compatible.
|
||||
\item[mac] tries to be compatible to the macintosh pascal dialects.
|
||||
\item[objfpc] switch some Delphi 2 extensions on. This is different from
|
||||
Delphi mode. because some \fpc constructs are still available.
|
||||
\item[tp] tries to be TP/BP 7.0 compatible. This means, no function overloading
|
||||
etc.
|
||||
\end{description}
|
||||
\item [-Rxxx] \olabel{R} Specifies what kind of assembler you use in
|
||||
your \var{asm} assembler code blocks. Here \var{xxx} is one of the following:
|
||||
\begin{description}
|
||||
@ -1185,15 +1223,13 @@ only replacing certain variables.
|
||||
file.
|
||||
\end{description}
|
||||
\item [-S2] \olabel{Stwo} Switch on Delphi 2 extensions (\var{objfpc} mode).
|
||||
This is different from \var{-Sd} (Delphi mode) because some \fpc constructs
|
||||
are still available.
|
||||
Deprecated, use \var{-Mobjfpc} instead.
|
||||
\item [-Sa] \olabel{Sa} Include assert statements in compiled code. Omitting
|
||||
this option will cause assert statements to be ignored.
|
||||
\item [-Sc] \olabel{Sc} Support C-style operators, i.e. \var{*=, +=, /= and
|
||||
-=}.
|
||||
\item [-Sd] Tells the compiler to be Delphi compatible. This is more strict
|
||||
than the \var{-S2} option, since some \var{fpc} extensions are switched off.
|
||||
\olabel{Sd}
|
||||
\item [-Sd] \olabel{Sd} Tells the compiler to be Delphi compatible. Deprecated, use
|
||||
\var{-Mdelphi} instead.
|
||||
\item [-SeN] \olabel{Se} The compiler stops after the N-th error. Normally,
|
||||
the compiler tries to continue compiling after an error, until 50 errors are
|
||||
reached, or a fatal error is reached, and then it stops. With this switch,
|
||||
@ -1207,11 +1243,12 @@ assember)
|
||||
specified, the compiler will interpret the \var{string} keyword as a
|
||||
ansistring. Otherwise it is supposed to be a short strings (TP style).
|
||||
\item [-Si] \olabel{Si} Support \var{C++} style INLINE.
|
||||
\item [-SIXXX] set interfaces style to XXX.
|
||||
\item [-Sm] \olabel{Sm} Support C-style macros.
|
||||
\item [-So] \olabel{So} Try to be Borland TP 7.0 compatible (no function
|
||||
overloading etc.).
|
||||
\item [-So] \olabel{So} Try to be Borland TP 7.0 compatible. Deprecated, use
|
||||
\var{-Mtp} instead.
|
||||
\item [-Sp] \olabel{Sp} Try to be \file{gpc} (\gnu pascal compiler)
|
||||
compatible.
|
||||
compatible. Deprecated, use \var{-Mgpc} instead.
|
||||
\item [-Ss] \olabel{Ss} The name of constructors must be \var{init}, and the
|
||||
name of destructors should be \var{done}.
|
||||
\item [-St] \olabel{St} Allow the \var{static} keyword in objects.
|
||||
|
Loading…
Reference in New Issue
Block a user