June 17, 2000 - Compilation Units and Pragmas | WebReference

June 17, 2000 - Compilation Units and Pragmas

Yehuda Shiran June 17, 2000
Compilation Units and Pragmas
Tips: June 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

WMLScript is a compiled language and uses Compilation Units and Pragmas. A certain application may include separate scripts that were individually and independently compiled. A compilation unit can call functions that are defined in another compilation unit. WMLScript uses pragmas to identify other compilation units that it uses.

The use url pragma specifies the location (URL) of the external WMLScript resource and gives it a local name. This name can then be used inside a function declarations to make external function calls. Let's examine the following example:

use url DocJS "http://www.docjavascript.com/mylibs/mywmlscript"
function divide(nom, denom) {
  if (denominator == 0) return invalid;
  return DocJS#mydiv(nom, denom);
}

The sequence of operations that take place here is fairly intuitive. The use url pragma specifies a URL to a WMLScript compilation unit, http://www.docjavascript.com/mylibs/mywmlscript. If the file extension is omitted (as above), the user agent will look for the extension .wmlsc, i.e. it will look for http://www.docjavascript.com/mylibs/mywmlscript.wmlsc. As we explained in Column 61Introducing WML and WMLScript, WMLScript scripts are stored under .wmls file extension and their compilation results are stored under .wmlsc.

Once the file is found, the function call DocJS#mydiv() triggers the loading of the external compilation unit, http://www.docjavascript.com/mylibs/mywmlscript.wmlsc. Upon successful loading of the external resource, its content is verified to have the definition of the mydiv() function, and it is actually executed with the calling parameters, mydiv(nom, denom). The use url pragma has its own name space for local names, but they must be unique within the same compilation unit.

For more on WMLScript, go to WMLScript Primer.