Extension:StackFunctions/Internals

From MediaWiki.org
Jump to navigation Jump to search

Design Considerations[edit]

Remain as close as possible to the PostScript programming language. 
As that language has been developed and used for many years, it has achieved a high degree of conceptual soundness and completeness. My personal experience until now confirms that anything you need can be expressed with the given operators and underlying concepts. It even happened several times that I found a need to enhance my implementation, and the solution was a modification which made my implementation more similar to the PostScript implementation.
A drawback is that some parts, first of all string handling, are rather cumbersome while it would be easy to create something much simpler with php. But is it less easy to do this in a sound and complete way that is easy to understand, to document and to use. As a compromise, future versions of StackFunctions are likely to contain additional string functions for purposes like number formatting, replacement functions and such.
Create an extension that executes fast. 
As StackFunctions is an interpreter run itself in an interpreter language, it is a priori slow. As my personal experience tells that the usefulness of a MediaWiki installation heavily depends on the time it takes to display pages, I tried to write StackFunctions in a way to execute as fast as possible; suggestions for further enhancement are particularly welcome.

Representation of Data[edit]

Booleans, numbers, literal strings and null are implemented with the corresponding PHP types. Arrays, dictionaries, marks, names, executable strings and built-in operators are represented by arrays consisting of a type and a value item. Hence strings and executable strings are represented in two totally different ways; to my opinion this is however a good compromise because literal strings (which are the vast majority of occurences in real code) are handled efficiently, but there is still the possibility to have executable ones (which make it possible to execute dynamic code with the exec operator. Fortunately, the different representations regard a few number of methods only: dumpObject, execObject, op_cvlit, op_cvx, ob_type, op_xcheck, pop_string.