Author: mdiep
Date: Sat Aug 13 13:37:40 2005
New Revision: 8943
Removed:
trunk/languages/tcl/lib/get_var.pir
Modified:
trunk/MANIFEST
trunk/config/gen/makefiles/tcl.in
trunk/languages/tcl/TODO
trunk/languages/tcl/lib/commands/unset.pir
trunk/languages/tcl/lib/expression.pir
Log:
tcl: Use parse_variable instead of expr_get_variable in expr code and get rid
of get_var.
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST (original)
+++ trunk/MANIFEST Sat Aug 13 13:37:40 2005
@@ -1418,7 +1418,6 @@ languages/tcl/lib/commands/upvar.pir
languages/tcl/lib/commands/while.pir [tcl]
languages/tcl/lib/conversions.pir [tcl]
languages/tcl/lib/expression.pir [tcl]
-languages/tcl/lib/get_var.pir [tcl]
languages/tcl/lib/interpret.pir [tcl]
languages/tcl/lib/list.pir [tcl]
languages/tcl/lib/list_to_string.pir [tcl]
Modified: trunk/config/gen/makefiles/tcl.in
==============================================================================
--- trunk/config/gen/makefiles/tcl.in (original)
+++ trunk/config/gen/makefiles/tcl.in Sat Aug 13 13:37:40 2005
@@ -61,7 +61,6 @@ lib${slash}commands${slash}upvar.pir \
lib${slash}commands${slash}while.pir \
lib${slash}conversions.pir \
lib${slash}expression.pir \
-lib${slash}get_var.pir \
lib${slash}interpret.pir \
lib${slash}list.pir \
lib${slash}list_to_string.pir \
Modified: trunk/languages/tcl/TODO
==============================================================================
--- trunk/languages/tcl/TODO (original)
+++ trunk/languages/tcl/TODO Sat Aug 13 13:37:40 2005
@@ -61,18 +61,6 @@ TclList's new_from_string method should
=over 4
-=item __set/__read
-
-All commands should use the __set and __read functions defined in
-variables.pir instead of get_var. __read's interface conflicts slightly
-with the way tclparser splits things up - it over-helpfully tries to
-break the variable part out into array and index - while read is
-already doing that for us.
-
-On a related note: No builtins or library code should be dealing with var
-sigils (i.e. C<$>) other than __set and __read {{ possibly array, since
-it needs to fetch the entire array: gen a new sub for this }}
-
=item implement default globals, etc.
global variables provided by tcl libary. L<tclvars>.
Modified: trunk/languages/tcl/lib/commands/unset.pir
==============================================================================
--- trunk/languages/tcl/lib/commands/unset.pir (original)
+++ trunk/languages/tcl/lib/commands/unset.pir Sat Aug 13 13:37:40 2005
@@ -27,7 +27,6 @@
call_level = $P0
.local pmc search_variable
- # XXX Should use get_var?
push_eh catch
if call_level goto get_lexical
search_variable = find_global "Tcl", sigil_varname
Modified: trunk/languages/tcl/lib/expression.pir
==============================================================================
--- trunk/languages/tcl/lib/expression.pir (original)
+++ trunk/languages/tcl/lib/expression.pir Sat Aug 13 13:37:40 2005
@@ -109,44 +109,16 @@ get_paren_done:
goto chunk_loop
get_variable:
- .local pmc varname
-
- # XXX expr_get_variable should just call __get_var for us,
- # so we don't have to jump through these hoops.
-
- (op_length,retval) = __expr_get_variable(expr,chunk_start)
- if op_length == 0 goto get_function
-
- $I0 = retval
- if $I0 == 2 goto got_array
- $S0 = retval[0]
- ($I0,retval) = __get_var($S0)
- goto get_variable_continue
-got_array:
- $S0 = retval[0]
- $S1 = retval[1]
- ($I0,retval) = __get_var($S0,$S1)
-
-get_variable_continue:
- # XXX This is a hack until we deal with types better in
- $N1 = retval
- retval = new TclFloat
+ (retval, chunk_start) = parse_variable(expr, chunk_start)
+ $P0 = retval."interpret"()
+ $N1 = $P0
+ retval = new TclInt
retval = $N1
- #print "__get_var returned something of type:"
- $S0 = typeof retval
- #print $S0
- #print "\n"
- # XXX ignoring $I0 at the minute.
- #(return_type,retval) = __expression($P0)
- #error_S = retval
- #if return_type == TCL_ERROR goto die_horribly
- # Temporarily pump this out to the array.
+
chunk = new TclList
chunk[0] = INTEGER
chunk[1] = retval
push chunks, chunk
-
- chunk_start = chunk_start + op_length
dec chunk_start
goto chunk_loop
@@ -746,114 +718,6 @@ real_done:
.return(pos,INTEGER,value)
.end
-# given a string, starting at position, return the length
-# of the variable name found at that position. return 0
-# if this doesn't look like a variable. If the return value
-# is non zero, also return a array-ish PMC that either has a
-# single element ($name or ${name}), or two elements
-# $name{index}
-
-.sub __expr_get_variable
- .param string expr
- .param int start
-
- .local int pos
- pos = 0
-
- .local pmc varname
- varname = new FixedPMCArray
-
- .local int expr_length
- expr_length = length expr
-
- # is this even a variable?
- $I0 = ord expr, start
- if $I0 != 36 goto real_done
-
- inc start
- $I0 = ord expr, start
- if $I0 == 123 goto braced
-
- pos = start
-var_loop:
- # a regular variable, "letter, digit, underscore, two or more colons"
- # (XXX not really handling multiple colons right now)
-
- # paren - 40
- # digit 48-57
- # colon 58
- # LETTER 65-90
- # underscore 95
- # letter 97-122
-
- if pos >= expr_length goto var_loop_done
-
- $I0 = ord expr, pos
- if $I0 == 40 goto indexed_var
- if $I0 < 48 goto var_loop_done
- if $I0 <= 58 goto var_loop_next
- if $I0 < 65 goto var_loop_done
- if $I0 <= 90 goto var_loop_next
- if $I0 == 95 goto var_loop_next
- if $I0 < 97 goto var_loop_done
- if $I0 > 122 goto var_loop_done
- # (only thing left is a letter, so fall through)
-
-var_loop_next:
- inc pos
- goto var_loop
-
-var_loop_done:
-
- $I0 = pos - start
-
- $S0 = substr expr, start, $I0
- varname = 1
- varname[0] = $S0
- goto real_done
-
-indexed_var:
- # just like var_loop_done, mark the name of the var
- dec pos
- $I0 = pos - start
- $S0 = substr expr, start, $I0
- varname = 2
- varname[0] = $S0
-
- # now, move to the beginning of the index, find the closing paren
- pos = pos + 2
- index $I1, ")", expr, pos
-
- $I2 = $I1 - pos
- $S0 = substr expr, pos, $I2
- varname[1] = $S0
- goto real_done
-
-braced:
- inc start # now at the character right after the {
- # "may contain any characters whatsoever except for close braces"
- # (so, next close brace closes us.) - 125
- index $I0, expr, "}", start
- if $I0 == -1 goto real_done # XXX need to somehow error here.
- pos = $I0
-
- $I1 = $I0 - start
- $S0 = substr expr, start, $I1
- varname[0] = $S0
-
-
-real_done:
-
-dd:
- #print "pos is"
- #print pos
- #print "\n&&varname is"
- #print $S0
- #print "\n"
-
- .return(pos,varname)
-.end
-
.sub __expr_get_function
.param string expr
.param int start