Difference between revisions of "FPC New Features Trunk"

From Lazarus wiki
Jump to navigationJump to search
(→‎Language changes: nested procvar support)
m (language changes -> language)
Line 5: Line 5:
 
== All systems ==
 
== All systems ==
  
=== Language changes ===
+
=== Language ===
  
 
==== Better support for Delphi-compatible classes ====
 
==== Better support for Delphi-compatible classes ====

Revision as of 19:39, 24 December 2010

About this page

Below you can find a list of new features introduced since the previous release, along with some background information and examples.

All systems

Language

Better support for Delphi-compatible classes

  • Overview: Support has been added for nested types (including other classes), class variables and class-local constants.
  • Notes: Delphi-compatible.
  • More information: class_extensions_examples lists several examples that make use of these features.

Scoped enumerations

Custom deprecated messages

  • Overview: Deprecated can now be applied to virtually any syntactic element (including constants and units), and it is also possible to specify a custom deprecation message.
  • Notes: Delphi-compatible
  • More information:

<delphi> Todo: write example </delphi>

Support for Objective-Pascal dialect

  • Overview: On Mac OS X, most system frameworks are written in Objective-C. While it is possible to interface them via a procedural API, this is not very convenient. For this reason, we have created a new dialect called Objective-Pascal that enables seamless interacting with Objective-C code.
  • Notes: This new dialect is currently only supported on Darwin-based platforms (including iOS) using the Apple Objective-C runtime. Patches to add support for the GNUStep runtime are welcome.
  • More information:
    • FPC_PasCocoa explains the basic language definitions.
    • FPC_PasCocoa/Differences explains some of the differences between Objective-Pascal and on the one hand Object Pascal, and on the other hand Objective-C.

Constref parameter modifier

  • Overview: Apart from the existing var, const and out parameter modifiers, a new modifier called constref has been added. This modifier means that the compiler can assume that the parameter is constant, and that it must be passed by reference. Its most obvious usage is to translate const * parameters from C headers.
  • Notes: The main reason it was introduced was to enable writing a cross-platform interface for XPCOM, as explained on the User_Changes_Trunk page. Note that in general, it should only be used for interfacing with external code or when writing assembler routines. In other cases, letting the compiler decide how to pass the parameter is more likely to result in optimal code on most platforms.
  • More information:

<delphi> procedure test(constref l: longint); begin

 writeln('This parameter has been passed by reference, although the Pascal code does not really care about that: ',l);

end;

begin

 test(5);

end. </delphi>

Support for nested procedural variables

  • Overview: It is now possible to define procedural variables to which you can assign nested procedures or functions. This feature is enabled by default in {$mode macpas} and {$mode iso}, and can be enabled in other syntax modes by adding {$modeswitch nestedprocvars} to your source file. Note that it is possible to assign a regular (non-nested) procedure/function to a nested procedural variable, and to call it that way.
  • Notes: Enabling this feature changes the calling convention used for nested procedures/functions. This will break code from the Turbo Pascal era that uses nested procedures/functions as callbacks from collection iterators in the objects unit.
  • More information: a procedural variable type can hold references to nested routines in two cases:
    • when it is declared inline the parameter list of another function/procedure (ISO-style declaration)
    • when it is declared as is nested, similar to of object for "procedure of object" types. Note that in this second case, it is possible to write invalid code: if you assign a nested routine to nested procedural variable and then exit the nested routine's parent stack frame, calling the nested procedural variable will result in undefined bahaviour.

ARM systems

Support for VFPv2 and VFPv3

  • Overview: Support has been added for the ARM Vector Floating Point (VFP) units versions 2 and 3. This is the floating point units that's usually included on, a.o., Cortex A8 and A9 family CPUs, and in the iOS-based devices.
  • Notes: When targeting a CPU that implements the ARMv6 or later architecture, you must also use -Cparmv6 at the same time. The reason is that saving/restoring the VFP unit's context must occur using different instructions prior to ARMv6. -Cparmv6 is enabled by default for iOS targets though, because all such devices are at least ARMv6. Additionally, FPC only supports the so-called softfp ABI for VFP: the VFP unit is used to perform the calculations, but the used calling convention to pass floating point values is the same as for soft-float.
  • More information: Activate using the -Cfvfpv2 resp. -Cfvfpv3 command line parameters.

Support for Thumb-2

  • Overview: Support has been added to generate Thumb-2 code for the ARMv7-M architecture as implemented in the Cortex-M3 family.
  • Notes: This architecture is currently only supported for no-OS targets (embedded); it does not yet work for iOS or Linux.
  • More information: Activate using the -Cparmv7m or -Cpcortexm3 command line parameters.

IA32/i386 systems

Support for the iPhoneSim target

  • Overview: As of Xcode 3.2.4, the iPhoneSimulator target uses a different Objective-C ABI than regular i386 code. Therefore a new target called iphonesim was added to the compiler.
  • Notes: If you are still using an earlier version of Xcode to develop iPhoneSimulator-based code, use the regular Darwin/i386 target.
  • More information: use the -Tiphonesim command line parameter to select this target. When compiling the FPC packages for this target, this will also compile special versions of MacOSAll and CocoaAll that only contain APIs available for this target.