| java.lang.Object kawa.lang.SyntaxTemplate
All known Subclasses: kawa.lang.SyntaxRule,
SyntaxTemplate | public class SyntaxTemplate implements Externalizable(Code) | | The translated form of a (syntax template) .
|
Field Summary | |
final static int | BUILD_CONS Instruction to creat a Pair from sub-expressions.
Instruction BUILD_CONS+4*delta is followed by a
sub-expression for the car
(whose length is delta chars),
followed by the expression for the cdr . | final static int | BUILD_DOTS Instruction BUILD_DOTS+8*i repeats a sub-expression.
The value i is a variable index of a pattern variable
of at least the needed depth. | final static int | BUILD_LIST1 Make following operand into a 1-element list. | final static int | BUILD_LITERAL Instruction BUILD_LITERAL+8*i pushes literal_values[i]. | final static int | BUILD_MISC Template instructions that don't have an operand value. | final static int | BUILD_NIL | final static int | BUILD_SYNTAX Wrap following sub-expression in a SyntaxForm. | final static int | BUILD_VAR Instruction BUILD_VAR+8*i pushes vars[i].
This array contains the values of pattern variables. | final static int | BUILD_VAR_CAR Instruction BUILD_VAR_CAR+8*i pushes car(vars[i]).
It assumes that vars[i] is actually a pair whose car was the
matched pattern variable. | final static int | BUILD_VECTOR Build a vector (an FVector ) from following sub-expression.
The latter must evaluate to a list. | final static int | BUILD_WIDE Unfinished support for "operand" values that need more tahn 13 bits. | final static String | dots3 | Object[] | literal_values | int | max_nesting | String | patternNesting Map variable to ellipsis nesting depth.
The nesting depth of the i 'th pattern variable
is (int) patternNesting.charAt(i)/2 .
The low-order bit indicates that if matched value is the car
of the value saved in the vars array.
(We use a String because it is compact both at runtime
and in .class files. | String | template_program A syntax or syntax-rules template is
translated into a "template program."
The template program is a simple bytecode stored in a string. |
Method Summary | |
public int | convert_template(Object form, SyntaxForm syntax, StringBuffer template_program, int nesting, java.util.Vector literals_vector, Object seen, boolean isVector, Translator tr) Recursively translate a syntax-rule template to a template program.
Parameters: form - the template from the syntax-rule Parameters: syntax - if non-null, the closest surrounding SyntaxForm Parameters: template_program - (output) the translated template Parameters: nesting - the depth of ... | public Object | execute(Object[] vars, TemplateScope templateScope) Expand this template
The compiler translates (syntax template)
to a call to this method. | public Object | execute(Object[] vars, Translator tr, TemplateScope templateScope) | Object | execute(int pc, Object[] vars, int nesting, int[] indexes, Translator tr, TemplateScope templateScope) Parameters: nesting - number of levels of ... | LList | executeToList(int pc, Object[] vars, int nesting, int[] indexes, Translator tr, TemplateScope templateScope) Similar to execute, but return is wrapped in a list.
Normally the result is a single Pair, BUILD_DOTS can return zero
or many Pairs. | Object | get_var(int var_num, Object[] vars, int[] indexes) | static int | indexOf(java.util.Vector vec, Object elem) Similar to vec.indexOf(elem), but uses == (not equals) to compare. | public void | readExternal(ObjectInput in) | public void | writeExternal(ObjectOutput out) |
BUILD_CONS | final static int BUILD_CONS(Code) | | Instruction to creat a Pair from sub-expressions.
Instruction BUILD_CONS+4*delta is followed by a
sub-expression for the car
(whose length is delta chars),
followed by the expression for the cdr .
|
BUILD_DOTS | final static int BUILD_DOTS(Code) | | Instruction BUILD_DOTS+8*i repeats a sub-expression.
The value i is a variable index of a pattern variable
of at least the needed depth. The result is spliced in.
|
BUILD_LIST1 | final static int BUILD_LIST1(Code) | | Make following operand into a 1-element list.
|
BUILD_LITERAL | final static int BUILD_LITERAL(Code) | | Instruction BUILD_LITERAL+8*i pushes literal_values[i].
|
BUILD_MISC | final static int BUILD_MISC(Code) | | Template instructions that don't have an operand value.
|
BUILD_NIL | final static int BUILD_NIL(Code) | | |
BUILD_SYNTAX | final static int BUILD_SYNTAX(Code) | | Wrap following sub-expression in a SyntaxForm.
|
BUILD_VAR | final static int BUILD_VAR(Code) | | Instruction BUILD_VAR+8*i pushes vars[i].
This array contains the values of pattern variables.
|
BUILD_VAR_CAR | final static int BUILD_VAR_CAR(Code) | | Instruction BUILD_VAR_CAR+8*i pushes car(vars[i]).
It assumes that vars[i] is actually a pair whose car was the
matched pattern variable. (This is done so we can preserve
PairWithPosition source positions).
|
BUILD_VECTOR | final static int BUILD_VECTOR(Code) | | Build a vector (an FVector ) from following sub-expression.
The latter must evaluate to a list.
|
BUILD_WIDE | final static int BUILD_WIDE(Code) | | Unfinished support for "operand" values that need more tahn 13 bits.
|
max_nesting | int max_nesting(Code) | | |
patternNesting | String patternNesting(Code) | | Map variable to ellipsis nesting depth.
The nesting depth of the i 'th pattern variable
is (int) patternNesting.charAt(i)/2 .
The low-order bit indicates that if matched value is the car
of the value saved in the vars array.
(We use a String because it is compact both at runtime
and in .class files.
|
template_program | String template_program(Code) | | A syntax or syntax-rules template is
translated into a "template program."
The template program is a simple bytecode stored in a string.
The encoding is designed so that instructions are normally
in the range 1..127, which makes the CONSTANT_Utf8 encoding
used in .class files compact.
The folowing BUILD_XXX are the "opcode" of the encoding,
stored in the low-order 3 bits of a char .
|
SyntaxTemplate | protected SyntaxTemplate()(Code) | | |
SyntaxTemplate | public SyntaxTemplate(String patternNesting, String template_program, Object[] literal_values, int max_nesting)(Code) | | |
convert_template | public int convert_template(Object form, SyntaxForm syntax, StringBuffer template_program, int nesting, java.util.Vector literals_vector, Object seen, boolean isVector, Translator tr)(Code) | | Recursively translate a syntax-rule template to a template program.
Parameters: form - the template from the syntax-rule Parameters: syntax - if non-null, the closest surrounding SyntaxForm Parameters: template_program - (output) the translated template Parameters: nesting - the depth of ... we are inside Parameters: literals_vector - (output) the literal data in the template Parameters: tr - the current Translator the index of a pattern variable (in pattern_names )that is nested at least as much as nesting ;if there is none such, -1 if there is any pattern variable or elipsis;and -2 if the is no pattern variable or elipsis. |
execute | public Object execute(Object[] vars, TemplateScope templateScope)(Code) | | Expand this template
The compiler translates (syntax template)
to a call to this method.
|
execute | Object execute(int pc, Object[] vars, int nesting, int[] indexes, Translator tr, TemplateScope templateScope)(Code) | | Parameters: nesting - number of levels of ... we are nested inside Parameters: indexes - element i (where i in [0 .. nesting-1] specifiesthe iteration index for the i'level of nesting |
executeToList | LList executeToList(int pc, Object[] vars, int nesting, int[] indexes, Translator tr, TemplateScope templateScope)(Code) | | Similar to execute, but return is wrapped in a list.
Normally the result is a single Pair, BUILD_DOTS can return zero
or many Pairs.
|
|
|