home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!utcsri!skule.ecf!torn!news.ccs.queensu.ca!mast.queensu.ca!dmurdoch
- From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
- Subject: Re: Turbo and Procs/Fns as params..
- Message-ID: <dmurdoch.289.722191926@mast.queensu.ca>
- Lines: 52
- Sender: news@knot.ccs.queensu.ca (Netnews control)
- Organization: Queen's University, Kingston
- 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
- Date: Thu, 19 Nov 1992 16:52:06 GMT
-
- In article <S2861785.92Nov19085756@techst02.technion.ac.il> s2861785@techst02.technion.ac.il (Alon Ziv) writes:
- >This is just one example of the serious defect in TP Func/Proc
- >parameters: that is, all that is passed is a pointer to the code, and
- >not the scope. This limits the use of Func/Proc parameters to global
- >procedures and functions, and disallows passing the address of a
- >nested function, for instance.
-
- There's a fairly easy way to remedy this, which I suggested to Borland but
- which they didn't choose to implement in BP 7. It is to allow special
- procedures and functions (nested procs, object methods, etc.) to be
- assignment compatible with a procedural type in which all the hidden
- parameters are made explicit.
-
- For example, the call to a nested procedure has a hidden parameter containing
- a pointer to the stack frame of the parent procedure. A procedure "nested"
- with declaration
-
- procedure parent;
- procedure nested;
- begin
- end;
- begin
- end;
-
- should be assignment compatible with a procedural type
-
- type
- nestedproc = procedure(context:word);
-
- In order to get this to work, there'd need to be a procedure to return stack
- frame pointers; that's easy to write in assembler, and should be in the
- standard library. I implemented it as
-
- function context(n:word):word; assembler;
- { Returns the BP value n stack frames back }
- asm
- push bp
- mov cx,n
- inc cx
- @1:
- mov bp,[bp]
- loop @1
- mov ax,bp
- pop bp
- end;
-
- For passing object methods around in procedural types, you'd need to add the
- hidden Self parameter to the type declaration; constructors also have a VMT
- pointer.
-
- Duncan Murdoch
- dmurdoch@mast.queensu.ca
-