home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / lang / tml_proc.txt < prev    next >
Text File  |  1986-02-22  |  7KB  |  193 lines

  1. 21-Feb-86 19:21:23-PST,6723;000000000001
  2. Return-Path: <oster%ucblapis@BERKELEY.EDU>
  3. Received: from ucbvax.berkeley.edu by SUMEX-AIM.ARPA with TCP; Fri 21 Feb 86 19:21:00-PST
  4. Received: by ucbvax.berkeley.edu (5.45/1.9)
  5.     id AA02188; Fri, 21 Feb 86 17:30:14 PST
  6. Received: from ucblapis.Berkeley.Edu (ucblapis.ARPA)
  7.     by ucbjade.Berkeley.Edu (4.19/4.41.3)
  8.     id AA17260; Fri, 21 Feb 86 13:05:47 pst
  9. Received: by ucblapis.Berkeley.Edu (4.19/4.41)
  10.     id AA08756; Fri, 21 Feb 86 12:03:57 pst
  11. Date: Fri, 21 Feb 86 12:03:57 pst
  12. From: oster%ucblapis@BERKELEY.EDU
  13. Message-Id: <8602212003.AA08756@ucblapis.Berkeley.Edu>
  14. To: info-mac@sumex-aim.arpa
  15. Subject: T.M.L. review and bug workaround
  16.  
  17. I like and use T.M.L. Pascal.  The price to value ratio can't be beat.
  18. I've found it quite compatible with Lisa Pascal, and it is such a pleasure to 
  19. get out of the stupid Lisa environment.
  20.  
  21. Also, unlike C, I get strict type checking of pointers and the ability to
  22. pass procedures to the ROM without a lot of in-line assembly language
  23. or glue routines. (And, unlike C, Inside Mac directly applies!) (Please,
  24. no flames, It's just I find C without lint or make to be pretty undebuggable.
  25. (This is solely a reflection on MY abilities as a programmer.))
  26.  
  27. Since the compiler generates .Rel files directly, by default, (though it will
  28. generate .Asm on request), the compilation is faster than with compilers that
  29. can only generate .Asm files.
  30. { --- --- --- --- }
  31. Incompatibilities:
  32.   A.) No support for separate compiliation -- this is by far the worst thing 
  33.   about the compiler.
  34.     To create a seperately compiled unit, basically, you must 
  35.     1.) ask the compiler to generate an .Asm file instead of its normal .Rel, 
  36.     2.) edit the .Asm file to remove global entrypoints you don't want 
  37.       (such as the one for the program starting address) 
  38.     3.) compile it with the MDS assembler.  
  39.     4.) Then edit the Pascal source code for the unity to create a .iPas file 
  40.       of external declarations to be included in everything that uses the unit.
  41.       this .iPas file should also incude a {$U file} directive so that the
  42.       .Link file produced by compilation will include a reference to the
  43.       compiled code.
  44.  
  45.     The good part of all this labor is that you really think about your code 
  46.     before you undertake to break it up.  You wind up writing managers, in the
  47.     style of the Mac managers.
  48.  
  49.   B.) In Lisa Pascal, INLINEs may be as long as you like. In T.M.L. INLINEs must 
  50.     be  2 bytes long.
  51.   C.) Although you can create pointers to procedures, you can't execute them.
  52.     The following two files are a work around for this.  They define a function,
  53.     Apply, that takes a collection of arguments and a ProcPtr and applies the
  54.     ProcPtr to the arguments.  Since Pascal does not allow Variadic functions,
  55.     you need a different version of Apply for each class of use.  So, I 
  56.     predefine a .Rel file that has Apply0 to Apply9 defined, and add Pascal
  57.     declarations to the .iPas file as I need them.
  58.  
  59.     Sure made writing QuickSort easier!.
  60.  
  61. { --- --- CUT HERE --- --- }
  62. ;File: Apply.Asm
  63. ;Author: David Phillip Oster
  64. ;Date: 12/25/85
  65. ;Purpose: Provide the glue by which TML Pascal can use PorcPtrs.
  66. ;Distribution: This file is in the public domain.
  67.  
  68.     XDEF    Apply0
  69.     XDEF    Apply1
  70.     XDEF    Apply2
  71.     XDEF    Apply3
  72.     XDEF    Apply4
  73.     XDEF    Apply5
  74.     XDEF    Apply6
  75.     XDEF    Apply7
  76.     XDEF    Apply8
  77.     XDEF    Apply9
  78.  
  79. Apply0:
  80. Apply1:
  81. Apply2:
  82. Apply3:
  83. Apply4:
  84. Apply5:
  85. Apply6:
  86. Apply7:
  87. Apply8:
  88. Apply9:
  89.     MOVE.L    (SP)+,A0    ;Pop Return Address
  90.     MOVE.L    (SP)+,A1    ;Pop Last argument, i.e., ProcPtr
  91.     MOVE.L    A0,-(SP)    ;Push Return Address
  92.     JMP    (A1)        ;Dispatch to ProcPtr
  93. { --- --- CUT HERE --- --- }
  94. {$U Apply }
  95. { Author: David Phillip Oster
  96.   Date: 12/25/85
  97.   Title: Apply.iPas
  98.   Distribution: This file is in the public domain.
  99.   **************
  100.   TML Pascal does not support procedures to functions, but this takes
  101.   a procPtr as a last argument, and applies it to previous arguments.
  102.   Since it cannot be written in Pascal, it is in Assembly.  This is
  103.   the interface file.
  104.   **************
  105.   Declare new versions of Apply as required!
  106.   (The procPtr must be the last argument!)
  107.   **************
  108. }
  109. FUNCTION Apply0(a, b:Ptr; Func:ProcPtr) : Boolean; EXTERNAL;
  110. PROCEDURE Apply1(a : WindowPtr; Func:ProcPtr); EXTERNAL;
  111. FUNCTION Apply2(a : StringPtr; Func : ProcPtr) : Char; EXTERNAL;
  112. FUNCTION Apply3(s : Str255; Func:ProcPtr) : Boolean; EXTERNAL;
  113. {
  114. Apply4
  115. Apply5
  116. Apply6
  117. Apply7
  118. Apply8
  119. Apply9
  120. }
  121. { --- --- CUT HERE --- --- }
  122. { --- --- --- --- }
  123. { Bug1.
  124.   According to the pascal standard, you should be able to assign to
  125.   a function name from inside an inner procedure.  Not allowed in TML.}
  126. FUNCTION F(x : Integer) : Integer;
  127.  
  128.   PROCEDURE FInner(y : Integer);
  129.   BEGIN
  130.     F := y;    {should be legal, isn't }
  131.   END; { of FInner }
  132.  
  133. BEGIN
  134.   Finner(x+1);
  135. END;
  136. { the following is a work around }
  137. VAR FResult : Integer;    { thank God you can mix VARs and PROCs ! }
  138. FUNCTION F(x : Integer) : Integer;
  139.  
  140.   PROCEDURE FInner(y : Integer);
  141.   BEGIN
  142.     FResult := y;    {should be legal, isn't }
  143.   END; { of FInner }
  144.  
  145. BEGIN
  146.   Finner(x+1);
  147.   F := FResult;
  148. END;
  149. { --- --- --- --- }
  150. {Bug 2.
  151. The following is a compatibility bug in TML pascal:
  152. T.M.L. appears to pack solitary byte sized elements of structures
  153. differently from Lisa Pascal. Example:
  154.  
  155. {'Style' is defined as a set in QuickDraw.iPas:
  156.      StyleItem =  (bold,italic,underline,outline,shadow,condense,extend);
  157.      Style     =  SET OF StyleItem;
  158. Lisa Pascal, (and therefore, the mac ROM), has it taking one byte.
  159. followed by a filler byte in the def of a grafport:
  160.           txFont:      INTEGER;
  161.           txFace:      Style;
  162.           txMode:      INTEGER;
  163. In T.M.L. you get the filler first!
  164. If you say: "SetFace([outline])";
  165. then: "Ord(thePort^.txStyle) = 0"
  166. will be true in T.M.L.
  167.  
  168. The work around is to say:
  169. TYPE
  170.   MyStyle : SignedByte; { 8 bit type in Lisa Pascal }
  171.   
  172. ...          txFont:      INTEGER;
  173.           mytxFace:      MyStyle;
  174.           txFiller :   SignedByte;
  175.           txMode:      INTEGER;
  176. ...
  177. PROCEDURE MyTextFace(v : Integer); INLINE $A888;
  178. { * * * * * * }
  179. Now, when you say: SetFace([outline])
  180. then "Ord(thePort^.myTxFace) <> 0"
  181. will be true.
  182. { --- --- --- --- }
  183. Errors in preceding review:
  184. unlike the claim in review a few days ago:
  185. For the type Str255 (which is used uniformly by Inside Mac,
  186. for almost all strings), Str[n] := Chr(13) works just fine,
  187. { --- --- --- --- }
  188. Conclusion:
  189. I've written programs for the Mac in Consualire C, in Aztec C, in MDS
  190. Assembler, in ExperLisp, in Portable Standard Lisp, in Xlisp, in MacPascal,
  191. in MacForth, in Forth-83, and in Lisa Pascal.  My favorite language for 
  192. development on the Mac is T.M.L.
  193.