home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6729 < prev    next >
Encoding:
Text File  |  1992-11-19  |  2.3 KB  |  64 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!utcsri!skule.ecf!torn!news.ccs.queensu.ca!mast.queensu.ca!dmurdoch
  3. From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
  4. Subject: Re: Turbo and Procs/Fns as params..
  5. Message-ID: <dmurdoch.289.722191926@mast.queensu.ca>
  6. Lines: 52
  7. Sender: news@knot.ccs.queensu.ca (Netnews control)
  8. Organization: Queen's University, Kingston
  9. References: <1992Nov4.190755.25383@polaris.utu.fi> <mByRTB4w165w@digsol.jpunix.com> <1992Nov11.104939.14727@jyu.fi> <1992Nov11.111534.1@uwovax.uwo.ca> <1e6qnoINNnr6@matt.ksu.ksu.edu> <dmurdoch.163.721919129@mast.queensu.ca> <SHEN.92Nov16212135@nil.IRO.UMoOrganization: Queen's University
  10. Date: Thu, 19 Nov 1992 16:52:06 GMT
  11.  
  12. In article <S2861785.92Nov19085756@techst02.technion.ac.il> s2861785@techst02.technion.ac.il (Alon Ziv) writes:
  13. >This is just one example of the serious defect in TP Func/Proc
  14. >parameters: that is, all that is passed is a pointer to the code, and
  15. >not the scope. This limits the use of Func/Proc parameters to global
  16. >procedures and functions, and disallows passing the address of a
  17. >nested function, for instance. 
  18.  
  19. There's a fairly easy way to remedy this, which I suggested to Borland but 
  20. which they didn't choose to implement in BP 7.  It is to allow special 
  21. procedures and functions (nested procs, object methods, etc.) to be 
  22. assignment compatible with a procedural type in which all the hidden 
  23. parameters are made explicit.
  24.  
  25. For example, the call to a nested procedure has a hidden parameter containing
  26. a pointer to the stack frame of the parent procedure.  A procedure "nested"
  27. with declaration 
  28.  
  29.   procedure parent;
  30.     procedure nested; 
  31.     begin
  32.     end;
  33.   begin
  34.   end;
  35.  
  36. should be assignment compatible with a procedural type
  37.  
  38.   type
  39.     nestedproc = procedure(context:word);
  40.  
  41. In order to get this to work, there'd need to be a procedure to return stack 
  42. frame pointers; that's easy to write in assembler, and should be in the 
  43. standard library.  I implemented it as
  44.  
  45. function context(n:word):word;  assembler;
  46.  { Returns the BP value n stack frames back }
  47.  asm
  48.    push bp
  49.    mov cx,n
  50.    inc cx
  51.  @1:
  52.    mov bp,[bp]
  53.    loop @1
  54.    mov ax,bp
  55.    pop bp
  56.  end;
  57.  
  58. For passing object methods around in procedural types, you'd need to add the 
  59. hidden Self parameter to the type declaration; constructors also have a VMT 
  60. pointer.
  61.  
  62. Duncan Murdoch
  63. dmurdoch@mast.queensu.ca
  64.