Difference between revisions of "Mode MacPas"

From Lazarus wiki
Jump to navigationJump to search
(More MacPas constructs added)
(+ mention no support for goto between different nesting levels)
(2 intermediate revisions by the same user not shown)
Line 15: Line 15:
 
* Procedures declared in the interface section which do not have a counterpart in the implementation section is considered external (we call them implicit external)
 
* Procedures declared in the interface section which do not have a counterpart in the implementation section is considered external (we call them implicit external)
 
* $ALIGN MAC68K, POWER, RESET
 
* $ALIGN MAC68K, POWER, RESET
 +
* OTHERWISE (is already supported even for Turbo Pascal)
  
New 2004-07-05:
+
Added after 2004-07-05:
 
* In Mode MacPas, files may have the extension .p.
 
* 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.
 
* Compiler directive $PUSH and $POP which saves/restores the current state of all local compiler switches.
Line 24: Line 25:
 
* Operator |�same as boolean OR, & same as boolean AND.
 
* Operator |�same as boolean OR, & same as boolean AND.
 
* $ERRORC directive, similar to $ERROR
 
* $ERRORC directive, similar to $ERROR
 
+
* Compiler option $J makes a variable external
New 2004-07-15:
+
* Compiler option $Z makes variables and procedures externally visible
* Compiler directive $J makes a variable external
 
* Compiler directive $Z makes variables and procedures externally visible
 
 
* External directive after a procedure declaration
 
* External directive after a procedure declaration
 
* Ord function can take a pointer as argument
 
* 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.
  
...more will be added
+
==Planned==
 +
* Export of compiler directives defined in the interface of a unit.
 +
* BAND BOR etc
 +
* Open (for files)
  
 
==Not Supported==
 
==Not Supported==
Here is an (incomplete) list of mac pascal constructs which are not supported at the moment, some of them will hopefully be supported in the future:
+
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.
 
* A nested procedure cannot be an actual parameter to a procedure.
 
* No anonymous procedure types in formal parameters.
 
* No anonymous procedure types in formal parameters.
 
* No propagating uses
 
* No propagating uses
* Compiler directives defined in the interface are not exported
 
 
* No arithmetic compiler variable expressions
 
* No arithmetic compiler variable expressions
 +
* Use of OSType constants directly as parameters.
 +
* No goto between different nesting levels (e.g., no goto from a nested procedure to a parent procedure)
  
 
==Compiling Apple's Universal Headers==
 
==Compiling Apple's Universal Headers==
Line 77: Line 81:
  
 
Note:
 
Note:
* The varaible qd in Quickdraw needs to be allocated somewhere, since it is declared with $J directive in UI. So it is defined in System.pp.
+
* 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 )

Revision as of 21:27, 8 August 2004

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

Compiler variables is currently equivalent to what is called macro in fpc/turbo/delphi terminology. They might be separated in the future (for mode macpas), to correspond better with the mac world.

  • $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)
  • $ALIGN MAC68K, POWER, RESET
  • OTHERWISE (is already supported even for Turbo Pascal)

Added after 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.

Planned

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

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 propagating uses
  • No arithmetic compiler variable expressions
  • Use of OSType constants directly as parameters.
  • No goto between different nesting levels (e.g., no goto from a nested procedure to a parent procedure)

Compiling Apple's Universal Headers

The work to make Universal Headers 3.4 compile by FPC is on the way. It is possible to compile all units normally used in a traditionally classic MacOS application, except for unit fp.p. Unfortunatelly at the moment, unit Carbon.p does not compile, since it depends on fp.p..

But 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 some other files, some argument names are "object". Change to something else, e g obj.

Note:

  • 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 )