B.4 A Simple Example



next up previous contents
Next: C VOOPS Reference Up: PhD Thesis Franz Fasching Previous: B.3 The Tuple File

B.4 A Simple Example

    

Consider the tuple file definition of Fig. B.2. This file defines a tuple named GeoObject which has three variables associated with it, namely ObjectType, Params, and Volume. The tuple holds three value lists with string values for each variable symbol. The last line defines a LISP function ObjTypU returning the ObjectType string with the first letter uppercased. The argument list of the respective functions is generated through the make-arglist function, which uses a dedicated variable prec-type defining the precision type to be used for the generated functions. This variable is set on the beginning of the tuple file. By redefining this variable and running UNFUG again, a double precision (double type) or single precision (float type) version can be generated with minimum effort. This flexibility is another intrinsic advantage of the UNFUG code generation concept.

Now consider the template file of Fig. B.3 to be used with this tuple. This template defines a C function for computing the volume of the respective object. Running UNFUG on this template with the previous tuple file produces the output shown in Fig. B.4.

Three C functions have been generated by substituting the LISP variables enclosed in angle brackets with their corresponding values on each loop run through the tuple. Note that the ObjTypU LISP function is called with no arguments, since in the template this symbol is enclosed just in angle brackets and not as a LISP function call with additional parentheses. Note further that ObjTypU's return value is only appended to the output file because it is of string type; a return value of any other type would have been silently discarded by UNFUG.



Martin Stiftinger
Tue Nov 29 19:41:50 MET 1994