Path: utzoo!attcan!uunet!decwrl!bacchus.pa.dec.com!granite.pa.dec.com!mwm From: mwm@raven.pa.dec.com (Mike (Real Amigas have keyboard garages) Meyer) Newsgroups: comp.sys.amiga.tech Subject: Re: Whats wrong with self Modifying Code? Message-ID: Date: 9 Jul 90 17:45:59 GMT References: <1990Jul6.201328.24660@csmil.umich.edu> <1990Jul6.201743.24777@csmil.umich.edu> <138523@sun.Eng.Sun.COM> <1990Jul9.163607.18336@sunee.waterloo.edu> Sender: news@wrl.dec.com (News) Organization: Missionaria Phonibalonica Lines: 46 In-Reply-To: gpsteffl@sunee.waterloo.edu's message of 9 Jul 90 16:36:07 GMT In article <1990Jul9.163607.18336@sunee.waterloo.edu> gpsteffl@sunee.waterloo.edu (Glenn Patrick Steffler) writes: Lets take a real world example: A spread sheet program which must perform several thousand iterations of a formula while recalculating. The formula can be "compiled" to the stack, and run such that the execution time is considerably less than if the formula had been interpreted each time. A video device driver or some such that uses raster ops to write values to the video display. (Given the Amiga has a blitter with this ability I do not ask for confirmation of the relevance of this arguement) The driver can "compile" a raster operation fill algorithm into some small code segment and run it. This is indeed self modifying code, but is almost essential for speed, because the user hates to wait for screen refresh. Both examples are from a class that's often confused with self modifying code, but aren't really self modifying unless badly written. I call that class (until somebody suggests something better) self generating code. All programs of this class can be done without modifying code - remember, you're creating it, not modifying it! For the first example (several thousand iterations? trivial) I'd compile to interpreted stack-machine code to run. For large applications (popi, for instance) or those where speed is more critical (your video driver), compile to an array and tell the OS you're launching a task loaded into that chunk of memory, and use that. The OS should take care of making sure the code in that memory actually gets run, and not whatever you put there last time around. Of course, for your video applications, you wouldn't want to use a soft solution anyway. Either a blitter, or a hand-coded library for all the common operations, or a graphics accelerator that does all the real work. In any of those cases, you never need to generate or modify code; that's already been done. For development, you'd want the support code that finally runs the code you're developing to be as straightforward as possible, and raw speed won't be that critical.