This manual describes features made available by the licenced xsolp and xsolc compilers. To obtain these compilers, you have just to type the "install" command, but you need for a key file to run them (order it at www.scriptol.com). Note that xsolc and xsolc are identical to solc and solp, but the program tests for the name given to it, and it can allows for additional features according to the name. Currently, the extended features are fast arrays of integers or texts.
Typed arrays (Enterprise Edition)
Typed arrays hold a unique type of objets. They are very more efficient than common arrays because they are indexed and not associative and hold directly 32 bits or 64 bits objects or pointers rather than dynamic variables. A typed array of integer is 100 times faster than a standard one, according to the test included in the distribution. (This is for binary executables, there is no difference in a Php target.) Typed arrays are dynamic also, you are not limited by the size, and boundary overflow is controled. Currently, two types of typed array exists:
Array of int
The syntax is: int[] i = int(x, y, ....) Once it is declared, it is used as a common mixed array, but only integer numbers may be added to the array. If you use a single argument: int(10), for example, this can be assigned either to a variable or to an array of int. At declaration the left side of the assignement determines the type of constructor at right side. In an expression a such constructor is an array. You should use functions as intval, strval, for scalar variables.
Array of texts
The declaration is: text[] t = text(a, b, "demo", ...) Same rules apply to text array.
Array of objects
The declaration is: class someclass ... /class someclass object1 someclass object2 object[] = object(object1, object2, ...)
Compatibility issues
- With Php 4.3, inserting an object inside an array causes the values of attributes inserted, not the object itself! I consider this is a bug and so you can't insert directly objects, but you can insert an array of objects, even with a single object inside, instead. - The Php's array_diff function doesn't work with arrays holding objects, so substracting such arrays is not possible.
Methods
Virtual methods of typed arrays are identical to that of mixed arrays. Read the common reference manual for the list.
Assignment and conversion
- You can assign a typed array to a mixed array: Ex: int[] i = int(... array a = i - You can't, of course, assign a mixed array to a typed array since the values may have different types, unless you push the elements one by one. A literal array with prefix is considered to be a mixed array. Thus you can't assign it to a typed array. Ex: (1,2,3) ... this is a mixed array even with integer items. int[] i = (1,2,3) ... NOT VALID you must write instead: int[] i = int(1,2,3) ... valid. - You can also create a mixed array from a typed one: array a = array(i) - You can't create a mixed array with a constructor of typed array: array a = int(1,2) ... NOT VALID array a = array(int(1,2)) ... NOT VALID In both cases, this is useless.
Using typed array with dyn
You can assign a typed array to a dyn. int[] i = int(1,2) dyn d = dyn(i) Two new dyn methods are provided to use a such dyn: arrayType() return the type of the typed array assigned to a dyn. toList(int = 0) return a typed array assigned to a dyn. The parameter is the type (see below) and is required only if the dyn is assigned a classical array and it allows to convert to a typed one. If the dyn is assigned a scalar (integer, text, etc...), a one-element typed array is created from the scalar and returned. Types currently recognized are: $TYPE_INT array of integers $TYPE_TEXT array of strings Example of use: d = dyn(int(1,2)) if d.arrayType() = $TYPE_INT: int[] i = d.toList() = $TYPE_TEXT: text[] t = d.toList() /if
Random assignment
For compatibility with Php, adding an element to an array outside the boundary, has same effect than pushing it on top of the array. For example: int[] i = nil i[10] = 10 this is equivalent to: i.push(10) Pushing values is the right way to fill an array in fact. If you want really putting element at fixed location, you have to fill the array with some values... for int k in 0 .. 10 let i.push(0) you can then assign specific locations inside the size of array.
Limitations
- You can't apply a method directly to a element of a typed array. Ex: i[10].toText() .. not valid Ex: int x = i[10] .. valid x.toText() - You can't compare directly an element and a string. Ex: text[] t = text("one", "two") if t[0] = "one" .. not valid Ex: text t2 = t[0] .. valid if t2 = "one" - The statement text("somestring") inside an expression may be confusing for the compiler. If this is a string, use strval instead. If this is a one-element array, create an array: text[] t = "somestring"