Path: ns-mx!uunet!comp.vuw.ac.nz!actrix!David.Empson From: David.Empson@actrix.gen.nz (David Empson) Newsgroups: comp.sys.apple2 Subject: Re: Orca/C code geenration Message-ID: <1991Aug26.154919.26967@actrix.gen.nz> Date: 26 Aug 91 15:49:19 GMT References: <1089@generic.UUCP> Organization: Actrix Information Exchange, Wellington, New Zealand Lines: 107 Comment-To: ericmcg@pnet91.cts.com In article <1089@generic.UUCP> ericmcg@pnet91.cts.com (Eric Mcgillicuddy) writes: > >The only difference between ORCA/Pascal and ORCA/C calling sequences > >is the order of parameter passing: right-to-left for ORCA/C, > >left-to-right for ORCA/Pascal (or for 'pascal' functions in ORCA/C). > > > >-- > >David Empson > > You are saying that Orca/C doesn't use C parameter passing at any time? Then > why would pascal have to be specified in the header files? > My definitions of 'C-style' and 'Pascal-style' parameter passing are those used by APW C. ORCA/C uses different definitions for 'C-style' and 'Pascal-style'. I happen to prefer APW C's definitions, since they seem to be more commonly used on other systems. In addition, APW C's 'Pascal-style' is used by the IIgs toolbox, making it a 'standard'. In the following text, 'function' should be read as 'procedure or function' when referring to Pascal. Here is a table describing the differences: Param Order When Pulled Return Value APW C Right to Left After Return In Registers ORCA/C Right to Left Before Return In Registers ORCA/Pascal Left to Right Before Return In Registers APW C 'pascal' Left to Right Before Return On Stack Key: Param Order Defines which order the calling function pushes parameters onto the stack. When Pulled Defines when the parameters are pulled off the stack (when the called function returns). Return Value Defines where a function places its return value (if any). Notes: - ORCA/C 'pascal' conventions are just like ORCA/Pascal. - The IIgs toolbox works like APW C's 'pascal' functions. The other differences between C and Pascal that affect function calls: - C is case-sensitive, but Pascal is not. This means that all Pascal function names are output to the object file as upper-case. The same applies to 'pascal' functions declared in C programs. - C supports functions with a variable number of parameters, such as printf(). Pascal doesn't allow such functions. [WriteLn, etc. are not really functions - the compiler handles them specially and splits each WriteLn call into multiple library routine calls]. Hence ORCA/C's 'pascal' directive tells the compiler three things: 1. Pass parameters in left to right order. 2. The function name should be capitalized when output to the object file. 3. The function cannot support variable parameter lists (if prototyping is used). Since the IIgs toolbox uses a different definition of 'Pascal-style' from ORCA/Pascal, both ORCA/C and ORCA/Pascal have a ToolParms directive, which tells the compiler that the following function(s) should return values on the stack, not in registers. Such functions cannot be called directly by ORCA/C or ORCA/Pascal, only by the toolbox. This is used for any code in your program that the toolbox calls, such as control definition procedures, standard file filter functions, etc. The ORCA/C header files define all toolbox routines as 'pascal' so that the parameters will be passed to the toolbox in the correct (left to right) order. In addition, ORCA/C and ORCA/Pascal handle toolbox calls specially, using the inline or Tool directive to specify the call number. This directive tells ORCA that the function results will be stored on the stack, and a special call has to be made (load X with call number, JSL $E10000, and store the value in A for error processing). Because of these conflicting 'standards', it is very difficult to write a program that combines code written in APW C with code written in ORCA/C or ORCA/Pascal. [There are several reasons for this, but the main one is the conflicting function call standards]. You can often simply recompile APW C code in ORCA/C, but there are several differences between the two compilers and their libraries that get in the way. I believe the original TML Pascal compiler for APW used APW C's definition of the Pascal calling conventions, so APW C and TML Pascal could be used together. Assembly language can be used where necessary to interface between various standards. For example, HyperCard IIgs's XCMD interface uses toolbox (i.e. APW C 'pascal') calling conventions. A lot of messy code has to be written to write ORCA/C and ORCA/Pascal XCMDs and XFCNs. I've written a library that allows this. The library was written in assembly language, and it involves a large amount of stack rearrangement to get parameters and return values into the right places. ORCA/Pascal functions can't return records or strings, which doesn't help matters either... -- David Empson USENET: David.Empson@bbs.actrix.gen.nz