1 # Copyright (C) 2006-2008, The Perl Foundation.
6 runtime/wmlslang.pir - WMLScript Lang library
10 This library contains a set of functions that are closely related to the
11 WMLScript language core.
13 See "WMLScript Standard Libraries Specification", section 7 "Lang".
20 .HLL 'WMLScript', 'wmls_group'
26 .const .Sub _lang_abs = '_lang_abs'
28 .const .Sub _lang_min = '_lang_min'
30 .const .Sub _lang_max = '_lang_max'
32 .const .Sub _lang_parseInt = '_lang_parseInt'
33 $P0[3] = _lang_parseInt
34 .const .Sub _lang_parseFloat = '_lang_parseFloat'
35 $P0[4] = _lang_parseFloat
36 .const .Sub _lang_isInt = '_lang_isInt'
38 .const .Sub _lang_isFloat = '_lang_isFloat'
39 $P0[6] = _lang_isFloat
40 .const .Sub _lang_maxInt = '_lang_maxInt'
42 .const .Sub _lang_minInt = '_lang_minInt'
44 .const .Sub _lang_float = '_lang_float'
46 .const .Sub _lang_exit = '_lang_exit'
48 .const .Sub _lang_abort = '_lang_abort'
50 .const .Sub _lang_random = '_lang_random'
51 $P0[12] = _lang_random
52 .const .Sub _lang_seed = '_lang_seed'
54 .const .Sub _lang_characterSet = '_lang_characterSet'
55 $P0[14] = _lang_characterSet
65 Returns the absolute value of the given number. If the given number is of
66 type integer then an integer value is returned. If the given number is of type
67 floating-point then a floating-point value is returned.
79 .sub '_lang_abs' :anon
88 =head2 C<min(value1, value2)>
92 Returns the minimum value of the given two numbers. The value and type
93 returned is the same as the value and type of the selected number. The
94 selection is done in the following way:
100 WMLScript operator data type conversion rules for I<integers and
101 floating-points> (see [WMLScript]) must be used to specify the data
102 type (integer or floating-point ) for comparison.
106 Compare the numbers to select the smaller one.
110 If the values are equal then the first value is selected.
126 .sub '_lang_min' :anon
131 $I0 = isa value1, 'WmlsString'
133 $P1 = value1.'parseNumber'()
136 $I0 = isa value2, 'WmlsString'
138 $P2 = value2.'parseNumber'()
141 $I0 = isa $P0, 'WmlsInvalid'
156 =head2 C<max(value1, value2)>
160 Returns the maximum value of the given two numbers. The value and type
161 returned is the same as the value and type of the selected number. The
162 selection is done in the following way:
168 WMLScript operator data type conversion rules for I<integers and
169 floating-points> (see [WMLScript]) must be used to specify the data
170 type (integer or floating-point ) for comparison.
174 Compare the numbers to select the larger one.
178 If the values are equal then the first value is selected.
194 .sub '_lang_max' :anon
199 $I0 = isa value1, 'WmlsString'
201 $P1 = value1.'parseNumber'()
204 $I0 = isa value2, 'WmlsString'
206 $P2 = value2.'parseNumber'()
209 $I0 = isa $P0, 'WmlsInvalid'
224 =head2 C<parseInt(value)>
228 Returns an integer value defined by the string value. The legal integer
229 syntax is specified by the WMLScript (see [WMLScript]) numeric string
230 grammar for I<decimal integer literals> with the following additional parsing
237 Parsing ends when the first character is encountered that is not a
238 leading '+' or '-' or a decimal digit.
242 The result is the parsed string converted to an integer value.
254 In case of a parsing error an C<invalid> value is returned.
258 .sub '_lang_parseInt' :anon
261 $I0 = isa value, 'WmlsString'
263 res = value.'parseInt'()
267 $I0 = isa value, 'WmlsInteger'
269 new res, 'WmlsInvalid'
275 =head2 C<parseFloat(value)>
279 Returns a floating-point value defined by the string value. The legal floatingpoint
280 syntax is specified by the WMLScript (see [WMLScript]) numeric
281 string grammar for I<decimal floating-point literals> with the following additional
288 Parsing ends when the first character is encountered that cannot
289 be parsed as being part of the floating-point representation.
293 The result is the parsed string converted to a floating-point value.
301 Floating-point or invalid.
305 In case of a parsing error an C<invalid> value is returned.
309 .sub '_lang_parseFloat' :anon
312 $I0 = isa value, 'WmlsString'
314 res = value.'parseFloat'()
318 $I0 = isa value, 'WmlsFloat'
320 $I0 = isa value, 'WmlsInteger'
327 new res, 'WmlsInvalid'
333 =head2 C<isInt(value)>
337 Returns a boolean value that is C<true> if the given value can be converted
338 into an integer number by using parseInt(value). Otherwise C<false> is
351 .sub '_lang_isInt' :anon
354 $I0 = isa value, 'WmlsString'
356 $P0 = value.'parseInt'()
360 $I0 = isa value, 'WmlsInvalid'
362 new res, 'WmlsInvalid'
365 new res, 'WmlsBoolean'
366 $I0 = isa value, 'WmlsInteger'
372 =head2 C<isFloat(value)>
376 Returns a boolean value that is C<true> if the given value can be converted
377 into a floating-point number using parseFloat(value). Otherwise C<false> is
390 .sub '_lang_isFloat' :anon
393 $I0 = isa value, 'WmlsString'
395 $P0 = value.'parseFloat'()
399 $I0 = isa value, 'WmlsInvalid'
401 new res, 'WmlsInvalid'
404 new res, 'WmlsBoolean'
405 $I0 = isa value, 'WmlsFloat'
408 $I0 = isa value, 'WmlsInteger'
419 Returns the maximum integer value.
427 .sub '_lang_maxInt' :anon
429 new res, 'WmlsInteger'
439 Returns the minimum integer value.
447 .sub '_lang_minInt' :anon
449 new res, 'WmlsInteger'
459 Returns true if floating-points are supported and false if not.
467 .sub '_lang_float' :anon
469 new res, 'WmlsBoolean'
475 =head2 C<exit(value)>
479 Ends the interpretation of the WMLScript bytecode and returns the control
480 back to the caller of the WMLScript interpreter with the given return value.
481 This function can be used to perform a normal exit from a function in cases
482 where the execution of the WMLScript bytecode should be discontinued.
490 None (this function ends the interpretation).
494 .sub '_lang_exit' :anon
497 $I0 = isa value, 'WmlsString'
499 $P0 = value.'parseInt'()
508 =head2 C<abort(errorDescription)>
512 Aborts the interpretation of the WMLScript bytecode and returns the control
513 back to the caller of the WMLScript interpreter with the return
514 errorDescription. This function can be used to perform an abnormal exit in
515 cases where the execution of the WMLScript should be discontinued due to
516 serious errors detected by the program. If the type of the errorDescription is
517 invalid, string "invalid" is used as the errorDescription instead.
521 errorDescription = String
525 None (this function aborts the interpretation).
529 .sub '_lang_abort' :anon
535 =head2 C<random(value)>
539 Returns an integer value with positive sign that is greater than or equal to 0
540 but less than or equal to the given value. The return value is chosen
541 randomly or pseudo-randomly with approximately uniform distribution over
542 that range, using an implementation-dependent algorithm or strategy.
544 If the value is of type floating-point, Float.int() is first used to calculate the
545 actual integer value.
557 If value is equal to zero (0), the function returns zero.
559 If value is less than zero (0), the function returns C<invalid>.
563 .sub '_lang_random' :anon
567 $I0 = isa value, 'WmlsString'
569 $P0 = value.'parseNumber'()
571 $I0 = isa $P0, 'WmlsInvalid'
579 new res, 'WmlsInteger'
583 new res, 'WmlsInvalid'
589 =head2 C<seed(value)>
593 Initialises the pseudo-random number sequence and returns an empty
594 string. If the value is zero or a positive integer then the given value is used
595 for initialisation, otherwise a random, system dependent initialisation value
596 is used. A seed value of greater than or equal to zero results in a repeatable
597 sequence of pseudo-random numbers. A seed value of less than zero
598 results in a non-repeatable sequence of random numbers.
600 If the value is of type floating-point, Float.int() is first used to calculate the
601 actual integer value. . If the value is non-numeric, invalid is returned and the
602 current seed is unchanged.
614 .sub '_lang_seed' :anon
618 $I0 = isa value, 'WmlsString'
620 $P0 = value.'parseNumber'()
622 $I0 = isa $P0, 'WmlsInvalid'
630 new res, 'WmlsString'
634 new res, 'WmlsInvalid'
640 =head2 C<characterSet()>
644 Returns the character set supported by the WMLScript Interpreter. The
645 return value is an integer that denotes a MIBEnum value assigned by the
646 IANA for all character sets (see [WSP] for more information).
654 .sub '_lang_characterSet' :anon
656 new res, 'WmlsInteger'
673 # vim: expandtab shiftwidth=4 ft=pir: