New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal for easy generation of SDL code from within SDL. #313
Comments
Interesting idea. I often create pre-computed SDL files too though usually with some other scripting language. I'll admit I do it not so much for performance, but because I have access to a good many more features in the outside scripting language or the other language is where I am really working and POV-Ray is effectively a utility in those situations. Initial thoughts:
FYI. I'm still mostly busy elsewhere though the email on this proposal caught my eye. |
Per Christoph's request the original longer comment here moved to the thread: http://news.povray.org/povray.general/thread/%3Cweb.59d95c8e31ae2f125cafe28e0%40news.povray.org%3E/ The points made therein as they might apply to this proposal given all or parts of the input SDL will need to be scanned to implement this feature and that this feature's primary aim is performance:
|
Please note that this is a feature suggestion for a syntax to generate SDL files from within SDL; turning it into a generic discussion about parsing performance is far beside the point. @wfpokorny: Please review your latest comments and see if you can trim them down to the portions actually relevant for this particular issue. |
Hi, |
@JustJanush In my own space I often code in a tcl parallel to sdl which today generates flat sdl and, yes, it is often useful during debugging. I too can capture flat versions in files for later includes - which relates some to the original proposal herein. It doesn't flatten completely in that for example SDL defined entities are still defined SDL 'IDs'. Variables are still available as variables for example. I assume this is the kind of dumping of a parsed scene dump you are suggesting. Another even flatter kind is possible - though likely of more use to POV-Ray developers. Namely, something which generates global space SDL from the internal memory representation of a parsed scene. Maybe with some filtering options on object type or bounding box(es) so we need not dump everything ever time. I've had in my head a while such an (optional?) post parse examine in memory pass could be useful for certain kinds of sanity checking too. Anyway, I'm thinking aloud... |
Sometimes scenes need complex computations that take quite a while to parse, in which case a common solution is to use
#fopen
and#write
to generate an include file, and from then on just include that file. However, the generated code may become difficult to read and debug due to the added overhead of the#write
statements, including double quotes, commas, and end-of-line escape sequences. Also, the logic to decide whether to re-generate the file may be tricky.I hereby propose the following mechanism to simplify such generation of SDL files "on the fly":
Syntax and Operation:
When a
#generate
directive is encountered, the following steps are performed:#end
token, generally ignoring all other tokens, but digesting them into a hash along the way. (The hash should be designed to ignore comments and extra whitespace.)force
parameter is omitted or set to false, the first line of the file is read; if that line matches the marker string, the parser simply proceeds normally after the#end
token, and the following steps are skipped entirely.#generate
block.#end
token, generally ignoring all other tokens, but dumping them verbatim to the file, except as follows:#foo
) are not dumped to the file, but rather parsed normally in their entirety. This can be prevented by prepending another hash sign (e.g.##include
), in which case the extra hash sign is stripped and the directive is just dumped to the file.#precompute
are not dumped to the file verbatim, but rather by value.compact
option is used, comments and/or extra whitespace are not dumped to the file, but rather ignored entirely.The
#precompute
directive behaves similar to the#local
directive, except that identifiers defined by it exhibit special behaviour in#generate
blocks, and that it supports only a limited set of data types (numbers, vectors, colours and strings).Rationale and Further Considerations:
The hash-and-tag mechanism is intended to operate as follows:
#generate
block itself (except trivial cosmetics) and automatically trigger re-generation of the file in such cases.#generate
block. Whenever its value is updated to indicate such a change, re-generation is also triggered automatically.force
parameter serves as an override to trigger re-generation on user-defined conditions. For instance, at times when a user is tweaking relevant code outside the#generate
block frequently, they may not want to update the tag each time, and instead useforce on
to unconditionally enable re-generation.An alternative to the hash mechanism would be to compare the timestamp of the generated file with that of the generating file. However, this would trigger re-generation indiscriminatingly, even if the changes are entirely unrelated to the
#generate
block in question, which might be undesired in most cases.For the sake of optimum performance, it may be worthwhile to cache the
#generate
block using the same mechanism already in use for macro caching.The text was updated successfully, but these errors were encountered: