Mode MacPas

From Lazarus wiki
Revision as of 21:53, 13 September 2004 by 131.155.228.51 (talk)
Jump to navigationJump to search

Mode MacPas tries to be compatible with the Pascal dialects commonly used on Macintosh, that is Think Pascal, Metrowerks Pascal, MPW Pascal.

Extensions to Free Pascal

  • $SETC <compvar>:= <expr> -- sets a compiler variable's value to an expression. ":=" as well as "=" are allowed. If not already defined it's defined.
  • $IFC, $ELSEC, $ENDC -- as their counterparts $IF, $ELSE, $END
  • UNDEFINED <compvar> -- in compiler variable expressions
  • TRUE, FALSE -- as values in compiler variable expressions
  • compiler variables may be assigned hexadecimal numbers, like $2345
  • UNIV modifer for types in parameter lists is accepted, but does nothing.
  • C directive for procedure declarations. Same as CDECL.
  • ... in procedure declaration, denoting a C var arg style funtion.
  • IMPLEMENTATION is not needed in units if empty.
  • Procedures declared in the interface section which do not have a counterpart in the implementation section is considered external (we call them implicit external). Their external name is prefixed with the C_prefix of the target. On MacOS this is an empty string, whereas on Darwin/Mac OS X, it is an underscore, so that it will properly link with Mac OS X's libraries (which is compiled with gcc).
  • $ALIGN MAC68K, POWER, RESET
  • OTHERWISE (is already supported even for Turbo Pascal)

Added after 1.9.4 2004-07-05:

  • In Mode MacPas, files may have the extension .p.
  • Compiler directive $PUSH and $POP which saves/restores the current state of all local compiler switches.
  • Function Exit(procname) which work like Exit, but accept the procname as parameter. Procname must be the name of the procedure in which Exit is used in. Non-local exit (as allowed in some mac pascal implementations is not allowed)
  • Function Leave, does the same as Break
  • Function Cycle, does the same as Continue
  • Operator | same as boolean OR, & same as boolean AND.
  • $ERRORC directive, similar to $ERROR
  • Compiler option $J makes a variable external
  • Compiler option $Z makes variables and procedures externally visible
  • External directive after a procedure declaration
  • Ord function can take a pointer as argument
  • Compile time function OPTION(X) which returns weather the compiler option X is set. Work for one letter options only.

Added to cvs (after 2004-08-16)

  • Compiler directive LibExport is recognized, but does nothing at the moment, may be implemented in the future.
  • The unit MacPas.pp is automatically included whenever mode MacPas is used. It should contains such stuff which is normally built in into mac pascal compiler.
  • Use of FourCharCode ( e. g. OSType, ResType) constants directly as parameters. Is done by an overloaded assignment operator defined in the file MacPas.pp
  • Compile time variables are now different from macros. However they are related. In the FPC documantation, what is written about macros is often also valid for compile time variables. The difference is that macro substitution is only done with real macros (which are defined by $DEFINEC). Compile time variables on the other hand is defined by $SETC.
  • $DEFINEC <macro> <content> defines a macro <macro> whose substitution text is <content>. It works the same as $DEFINE. Note that macros in FPC do not take parameters.

Planned

  • Export of compiler directives defined in the interface of a unit.
  • BAND BOR etc
  • Open (for files)
  • Propagating uses

Not Supported

Here is an (incomplete) list of mac pascal constructs which are not supported at the moment, perhaps some of them will be supported in the future:

  • A nested procedure cannot be an actual parameter to a procedure.
  • No anonymous procedure types in formal parameters.
  • No arithmetic compiler variable expressions
  • No goto between different nesting levels (e.g., no goto from a nested procedure to a parent procedure)
  • No exit between different nesting levels.

Compiling Apple's Universal Interfaces

The work to make Universal Interfaces 3.4.2 compile by FPC is on the way. It is possible to compile all units normally used in a traditionally classic MacOS application, and also Carbon.p.

The following changes is to be applied to the UI in order to make it compile. Line numbers referer to UI 3.4.2

The following info about FPC must be added in ConditionalMacros.p, please add it above the MPW Pascal section. An {$ENDC} must be added at the end of the compiler description sections.

{$IFC NOT UNDEFINED FPC}

   {
       Free Pascal Compiler, an open source compiler,
       see http://www.freepascal.org
   }
   {$SETC TARGET_CPU_PPC               := NOT UNDEFINED CPUPOWERPC}
   {$SETC TARGET_CPU_68K               := NOT UNDEFINED CPUM68K}
   {$SETC TARGET_CPU_X86               := NOT UNDEFINED CPUI386}
   {$SETC TARGET_CPU_MIPS              := FALSE}
   {$SETC TARGET_CPU_SPARC             := NOT UNDEFINED CPUSPARC}
   {$SETC TARGET_RT_MAC_CFM            := NOT UNDEFINED MACOS}
   {$SETC TARGET_RT_MAC_MACHO          := NOT UNDEFINED DARWIN}
   {$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 TARGET_RT_LITTLE_ENDIAN      := NOT UNDEFINED FPC_LITTLE_ENDIAN}
   {$SETC TARGET_RT_BIG_ENDIAN         := NOT UNDEFINED FPC_BIG_ENDIAN}
   {$SETC TYPE_EXTENDED                := TRUE}
   {$SETC TYPE_LONGLONG                := FALSE}
   {$SETC TYPE_BOOL                    := FALSE}
   {$SETC TYPED_FUNCTION_POINTERS      := TRUE}

{$ELSEC}

Other tweaks needed:

  • In Multiprocessing.p and couple of other files, some argument and record field names are "object". Change to something else, e g "obj".
  • Not strictly necessary, but handy if you want to avoid a lot of typecasting: in MacTypes.p, change line 207 into "Ptr = pchar;"

Mac OS X specific (thanks to Rolf Jansen):

  • In fp.p, deactivate all routines with LongDouble by changing two {$IFC TARGET_CPU_PPC} conditionals to {$IFC TARGET_CPU_PPC AND NOT TARGET_API_MAC_OSX} (on lines 1256 and 1825)
  • in AEMach.p, add the following round line 79:

TYPE

 mach_port_t       = UInt32;
 mach_msg_header_t = record
     msgh_bits        : UInt32;
     msgh_size        : UInt32;
     msgh_remote_port : UInt32;
     msgh_local_port  : UInt32;
     msgh_reserved    : UInt32;
     msgh_id          : SInt32;
   end;

Note:

  • For classic MacOS: The variable qd in Quickdraw is defined in System.pp (which is included in every FPC program), since it needs to be allocated somewhere. ( It is declared with $J directive in the UI )