parrotcode: Untitled | |
Contents | Language Implementations | TCL |
This object holds the result of parsing a tcl command. Internally, It represents a word as discrete chunks, which are either finalized or require interpolation. Each chunk is marked as such. When the word is used (at interpretation or at execution time), the required interpolation occurs (either variable or command)
Each TclWord has the following attributes:
an array of pairs of (type, content), where type/content is
_Tcl::_get_var
An Integer PMC flag representing whether or not the value we hold is constant. Used as a hint at compile time.
TclWord defines the following methods:
Define the attributes required for the class.
Initialize the attributes for an instance of the class
Given an array of words, append the chunks of a given word to the existing word
Add a constant character to a TclWord
Add a constant string to a TclWord
Add the name of a variable to be interpolated to a TclWord. Takes the name of the var, and an optional index for array variables.
Add a command to be interpolated to a TclWord. Takes the text of the command, and stores the parsed version for later interpretation.
Return a PMC that contains the value of our word. If we're just a command, evaluate the command and return the resulting PMC. If we're just a variable, return the PMC associated with that variable. In any other case, concat the results and return a Stringy PMC.
Stringify - In our case, we take the individual chunks of the words and evaluate them - so if we have a TclWord that came from a string like:
"$a + $b = [expr $a + $b]"
We have split it up internally to look like:
VAR: a
CONST: " + "
VAR: b
CONST: " = "
COMMAND:
WORD:
CONST: "expr"
WORD:
VAR: a
WORD:
CONST: "+"
WORD:
VAR: b
And, when we ask for the string representation, the two variable interpolations are performed, and the command containing "expr" is also evaluated. The resulting string, (assuming values of 1 and 2 for a and b, respectively) is
"1 + 2 = 3"
NB: This isn't quite the normal __get_string
method, and should probably be renamed - it is returning a tcl exit code in addition to the normal string result.
Allow us to be rendered by Data::Dumper
Not tested, uses pmcPerlArray dumper method because of the way Dumper is written. Shouldn't have to.
Return the number of chunks in this tclword.
Not implemented yet, pending delegation of freeze
to objects. (Necessary anymore?)
Not implemented yet, pending delegation of thaw
to objects. (Necessary anymore?)
Returns an integer, 1
if this word is constant, 0
if it requires interpolation.
|