June 22, 2000 - WMLScript's Bytecode | WebReference

June 22, 2000 - WMLScript's Bytecode

Yehuda Shiran June 22, 2000
WMLScript's Bytecode
Tips: June 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

To fit the narrow bandwidth in wireless communication, both WML and WMLScript code are compiled into a bytecode on the server and then sent to the user agent. The bytecode is a binary representation of the text-based WML and WMLScript code. It is structured very similarly to binary executable files. It consists of instruction sets, opcodes, addresses, etc. The advantage of bytecode files over binary executable files is that it is machine independent. You compile it once and run on any machine capable of running WMLScript interpreter. From now on, when you hear the term compiled once - run everywhere, you'll know where it is coming from. Let's examine the bytecode of the mortgage example from Column 62. The size of mortgage.wml is 1071 bytes. Its bytecode's length is 446 bytes (more than 2x reduction in size). Here is the top portion of the bytecode:

00000000  01 04 6A 20 70 72 69 6E-63 69 70 61 6C 00 69 6E  ..j principal.in
00000010  74 65 72 65 73 74 00 6E-75 6D 5F 70 61 79 6D 65  terest.num_payme
00000020  6E 74 73 00 7F E7 55 03-63 61 72 64 31 00 36 03  nts..?U.card1.6.
00000030  4D 6F 72 74 67 61 67 65-20 43 61 6C 63 00 23 01  Mortgage Calc.#.

This display can be generated only by an application that can interpret WMLScript. We used the Nokia WAP Toolkit for this. It supports two views: WML and bytecode. The above output is mortgage.wml's bytecode representation. Each byte is represented by two hexadecimal characters and is surrounded by white space. The left column shows the byte number (from the beginning of the file) of next row's first byte (in hexadecimal notation). For example, the top entry on the most-left column is 10, which is 16 in decimal notation. Each line includes 16 bytes, with a separation hypen between the first and last eight. If we start counting from zero, byte number 16 is the first one on the second row. The most-right column tries to interpret each byte as an ASCII character. Some of the interpretations are garbage, of course, but some of them reconstruct the original WML code.

For more on WMLScript and bytecode, go to Column 62, WMLScript Primer.