POV-Ray : Newsgroups : povray.newusers : if inside a macro syntax (if...else) : Re: if inside a macro syntax (if...else) Server Time
30 Jul 2024 00:21:37 EDT (-0400)
  Re: if inside a macro syntax (if...else)  
From: Warp
Date: 30 Dec 2004 09:07:56
Message: <41d40bbc@news.povray.org>
Mike Williams <nos### [at] econymdemoncouk> wrote:
> When you use a macro, POV replaces the call at parse time with a copy of
> the *code* contained within the macro. The macro itself is not executed
> independently.

  The actual parsing process is a bit more complicated than that, but one
can perfectly think that there's a replacement being done (except for
#local commands, which are handled in a special way).

  It's difficult to come up with a short expression to describe what
POV-Ray is actually doing when it calls a macro. The closest term would
perhaps be "subroutine call", although it's not quite that either.

  When the parser encounters a macro call at some point in the file
being parsed, the parser will "write down" the location of the call
and then literally jump to the place where the macro was defined.
It really does this literally by opening the file where the macro
was located as necessary if it was a different file than the current
one and seeking to the location where the macro (with the C file
seeking functions). Then the parser continues parsing from this
point forward in the usual way. When it encounters the #end of
the macro, it jumps back to the calling location (again by seeking
the file).

  There's no literal code replacement being done here (as is the
case with eg. the C preprocessor #define macros) but a kind of
subroutine call. However, the net effect of this process is that
the macro works as if the call was being replaced by the body
of the macro. The body of the macro is parsed as if it was located
at the calling location (although the file is literally being parsed
in a completely different place).

  #local is the one single thing which makes POV-Ray #macros different
from true replacement macros (such the C preprocessor macros). They
are not parsed as if they were located at the calling location but
are instead parsed as if they were truely inside a subroutine. The
mixed technique POV-Ray uses to handle macros makes this possible,
and is in fact very handy. POV-Ray macros kind of combine the advantages
of true replacement macros and the advantages of true subroutines.
(Of course the mixing of two metaphors causes sometimes confusion
to people.)

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.