cvsuser 05/03/29 21:57:21
Modified: dynclasses tclparser.pmc
Log:
move many variables into pmc-static variables.
eliminate a goto
Revision Changes Path
1.7 +37 -29 parrot/dynclasses/tclparser.pmc
Index: tclparser.pmc
===================================================================
RCS file: /cvs/public/parrot/dynclasses/tclparser.pmc,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- tclparser.pmc 29 Mar 2005 21:09:48 -0000 1.6
+++ tclparser.pmc 30 Mar 2005 05:57:21 -0000 1.7
@@ -1,7 +1,7 @@
/* TclParser.pmc
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: tclparser.pmc,v 1.6 2005/03/29 21:09:48 chromatic Exp $
+ * $Id: tclparser.pmc,v 1.7 2005/03/30 05:57:21 coke Exp $
* Overview:
* A container for methods related to tcl parsing.
* Data Structure and Algorithms:
@@ -24,8 +24,31 @@
#include "parrot/parrot.h"
+static INTVAL TclList,StringClass,IntegerClass,TclWord;
+static STRING *bs_nl, *nl, *cb, *cp, *space;
+static STRING *ConcatWords, *ConcatConst, *ConcatConst, *ConcatVariable;
+static STRING *ConcatChar, *ConcatCommand;
+
pmclass TclParser dynpmc group tcl_group {
+ void class_init() {
+ if (pass) {
+ TclList = Parrot_PMC_typenum(INTERP, "TclList");
+ StringClass = Parrot_PMC_typenum(INTERP, "String");
+ IntegerClass = Parrot_PMC_typenum(INTERP, "Integer");
+ bs_nl = string_from_const_cstring(INTERP, "\\\n",2);
+ nl = string_from_const_cstring(INTERP, "\n",1);
+ cb = string_from_const_cstring(INTERP, "\175",1);
+ cp = string_from_const_cstring(INTERP, ")",1);
+ space = string_from_const_cstring(INTERP, " ",1);
+ ConcatWords = string_from_const_cstring(INTERP, "concat_words",12);
+ ConcatConst = string_from_const_cstring(INTERP, "concat_const",12);
+ ConcatVariable = string_from_const_cstring(INTERP,
"concat_variable",15);
+ ConcatChar = string_from_const_cstring(INTERP, "concat_char",11);
+ ConcatCommand = string_from_const_cstring(INTERP,
"concat_command", 14);
+ }
+ }
+
/*
=item C<void init()>
@@ -54,7 +77,6 @@
*/
METHOD PMC* parse(PMC *code, PMC *psw, PMC *bi) {
- /* Get the types of TclWord and TclList */
INTVAL start_word=0; /* position of the start of the word */
INTVAL word_length; /* length of the word */
INTVAL word_trailing_length; /* include the last char in the word? */
@@ -63,22 +85,6 @@
INTVAL end_of_word; /* Boolean, is the word done? */
PMC *commands; /* List of all the commands parsed */
PMC *command; /* The current command */
- /* XXX bs_nl and Tcl* are constant. define them once in the PMC */
- INTVAL TclList = Parrot_PMC_typenum(INTERP, "TclList");
- INTVAL String = Parrot_PMC_typenum(INTERP, "String");
- INTVAL Integer = Parrot_PMC_typenum(INTERP, "Integer");
- INTVAL TclWord = Parrot_PMC_typenum(INTERP, "TclWord");
- /* backslash newline */
- STRING *bs_nl = string_from_const_cstring(INTERP, "\\\n",2);
- STRING *nl = string_from_const_cstring(INTERP, "\n",1);
- STRING *cb = string_from_const_cstring(INTERP, "\175",1);
- STRING *cp = string_from_const_cstring(INTERP, ")",1);
- STRING *space = string_from_const_cstring(INTERP, " ",1);
- STRING *ConcatWords = string_from_const_cstring(INTERP,
"concat_words",12);
- STRING *ConcatConst = string_from_const_cstring(INTERP,
"concat_const",12);
- STRING *ConcatVariable = string_from_const_cstring(INTERP,
"concat_variable",15);
- STRING *ConcatChar = string_from_const_cstring(INTERP,
"concat_char",11);
- STRING *ConcatCommand = string_from_const_cstring(INTERP,
"concat_command", 14);
INTVAL bs_marker = 0;
INTVAL bs_pos;
INTVAL bs_retval;
@@ -86,12 +92,15 @@
INTVAL bs_a_byte;
INTVAL buffer_length;
INTVAL old_length,chunk_start,escape_length,temppos;
+
+ /* XXX running this in class_init is apparently too soon, so run it
here */
+ TclWord = Parrot_PMC_typenum(INTERP, "TclWord");
STRING *buffer = Parrot_PMC_get_string(INTERP, code);
INTVAL preserve_whitespace = Parrot_PMC_get_intval(INTERP, psw);
INTVAL block_interpolation = Parrot_PMC_get_intval(INTERP, bi);
- STRING *Tcl,*parse;
- PMC *parser,*retval,*word;
+ STRING *Tcl;
+ PMC *retval,*word;
INTVAL I0,I1,I2;
STRING *S0, *S1;
PMC *P0,*P1,*P2,*P3,*P4;
@@ -390,11 +399,11 @@
/* XXX Really need to switch parse to not need PMC's passed in,
basic types are really what we need */
- P1 = pmc_new(INTERP, String);
+ P1 = pmc_new(INTERP, StringClass);
Parrot_PMC_set_string(INTERP, P1, S0);
- P2 = pmc_new(INTERP, Integer);
+ P2 = pmc_new(INTERP, IntegerClass);
VTABLE_set_integer_native(INTERP,P2,1);
- P3 = pmc_new(INTERP, Integer);
+ P3 = pmc_new(INTERP, IntegerClass);
VTABLE_set_integer_native(INTERP,P3,0);
P0 = Parrot_TclParser_parse(INTERP, SELF, P1, P2, P3);
@@ -602,13 +611,12 @@
goto bad_block;
}
- /* if there's any word so far, save it*/
- if (old_length == 0) {
- goto command_save;
+ if (old_length) {
+ /* if there's any word so far, save it*/
+ S0 = string_substr(INTERP, buffer, start_word, old_length, NULL, 0);
+ P1 = VTABLE_find_method(INTERP, word, ConcatConst);
+ Parrot_call_method(INTERP, P1, word, ConcatConst, "vS", S0);
}
- S0 = string_substr(INTERP, buffer, start_word, old_length, NULL, 0);
- P1 = VTABLE_find_method(INTERP, word, ConcatConst);
- Parrot_call_method(INTERP, P1, word, ConcatConst, "vS", S0);
command_save:
/* Save this as a command (skip the []'s)*/