Author: coke
Date: Mon Nov 7 10:59:51 2005
New Revision: 9821
Modified:
trunk/languages/tcl/README
trunk/languages/tcl/docs/expr.pod
trunk/languages/tcl/docs/hacks.pod
trunk/languages/tcl/docs/howto.pod
trunk/languages/tcl/docs/overview.pod
trunk/languages/tcl/lib/commands/regexp.pir
trunk/languages/tcl/t/cmd_regexp.t
Log:
Flesh out [regexp] (cheat and use p6rules for now since there is no tclARE
engine). add a few more tests, and comments as to what more tests are
needed.
clean up docs a bit.
Modified: trunk/languages/tcl/README
==============================================================================
--- trunk/languages/tcl/README (original)
+++ trunk/languages/tcl/README Mon Nov 7 10:59:51 2005
@@ -1,8 +1,8 @@
=head1 ParTcl
-A from scratch implementation of Tcl on Parrot.
+A from scratch implementation of Tcl on Parrot. (partcl)
-To build the tcl interpreter, first build parrot and the parrot utilities.
+To build the tcl compiler, first build parrot and the parrot utilities.
From the top level parrot directory:
perl Configure.pl && make world
@@ -14,7 +14,7 @@ generate the file C<tcl.pbc> which can t
=head2 Interactive tclsh
-To run ParTcl interactively, simply type:
+To run partcl interactively, type:
make tclsh
@@ -42,15 +42,14 @@ it.)
Given this option, partcl will compile the tcl code to PIR, and output
the PIR on STDOUT. This PIR can then be compiled to parrot bytecode, or
-run directly through parrot. (Works with C<-e>.)
+run directly through parrot. (Works with C<-e>.).
=back
=head2 Examples
To run an example, change to the C<examples>, and type C<make>
-for instructions. Running examples from here automatically handles
-cd'ing to the proper directory to run.
+for instructions.
=head2 Test Suite
Modified: trunk/languages/tcl/docs/expr.pod
==============================================================================
--- trunk/languages/tcl/docs/expr.pod (original)
+++ trunk/languages/tcl/docs/expr.pod Mon Nov 7 10:59:51 2005
@@ -1,6 +1,9 @@
+
+
=head1 OVERVIEW
-This documents how expressions are handled internally.
+This documents how expressions are handled internally. It is outdated and
+should be removed.
=head1 Split the string into an array of chunks
Modified: trunk/languages/tcl/docs/hacks.pod
==============================================================================
--- trunk/languages/tcl/docs/hacks.pod (original)
+++ trunk/languages/tcl/docs/hacks.pod Mon Nov 7 10:59:51 2005
@@ -6,8 +6,8 @@ Prodding by Matt Diephouse to generate d
=item 1
-Things that partcl has done that might be considered hacks -
-things that will likely impair our ability in the distant future to
+Things that partcl has done that might be considered hacks -
+things that will likely impair our ability in the distant future to
cleanly do language interoperability.
=item 2
@@ -15,10 +15,10 @@ cleanly do language interoperability.
Things that partcl hasn't done yet at all because parrot makes them
hard.
-=back
+=back
It is, of course, quite likely that said feature already exists with
-a nice interface, and was just not found by the partcl developers -
+a nice interface, and was just not found by the partcl developers -
If you find something along these lines, let them know on the internals
list.
@@ -34,7 +34,7 @@ and their code. For example:
% proc sum {{a 2} {b 3}} {
return [expr $a + $b]
}
- % sum
+ % sum
5
% info args sum
a b
@@ -48,9 +48,9 @@ and their code. For example:
2
%
-Right now, partcl is using globals to store the argument list and the the body
information.
-It would seem that we'd want to have a builtin mechanism for querying the subs
directly
-rather than storing this information separately.
+Right now, partcl is using globals to store the argument list and the the
+body information. It would seem that we'd want to have a builtin mechanism
+for querying the subs directly rather than storing this information separately.
=item user defined subs; parameter handling.
@@ -60,20 +60,20 @@ our example:
% sum a b c
wrong # args: should be "sum ?a? ?b?"
-Right now, this is handled I<inside> the function definition - it is defined
to take
-an arbitary number of args, and then is checked for correctness internally. It
would
-be nice to have invoke() automatically figure this out and generate an
exception
-that Tcl can use. (This also starts to drag in "how to do Tcl exceptions
cleanly from
-parrot")
+Right now, this is handled I<inside> the function definition - it is defined
+to take an arbitary number of args, and then is checked for correctness
+internally. It would be nice to have invoke() automatically figure this out
+and generate an exception that Tcl can use. (This also starts to drag in
+"how to do Tcl exceptions cleanly from parrot")
=item stack depth
-Cheating and keeping a global around right now, so we can figure out if we
+Cheating and keeping a global around right now, so we can figure out if we
should be using a global or a lexical (and if so, how far down or up).
=item [trace]'ing
-There are two ways we can go about the tracing - either we can keep the
+There are two ways we can go about the tracing - either we can keep the
information about the traces in a global, and check that global every time
the appropriate action is taken; or, we can tie that information into the
actual commands and variables. I think the latter would be somewhat cleaner,
@@ -84,15 +84,15 @@ to interoperate.
There are several cases where we convert TclLists or ResizablePMCArrays to
Arrays so that we can use the splice opcode. Need to have better splice
-support in parrot array classes, as well as our own.
-L<lib/commands/linsert.pir>
+support in parrot array classes, as well as our own. See
+C<lib/commands/linsert.pir>.
=item marshalling/unmarshalling
When compiling, there is currently no easy way to embed a PMC that exists
-at runtime into the compiled code. Because of this, we have to interrogate
+at runtime into the compiled code. Because of this, we have to interrogate
the PMC at compile time for its type, and then handroll the appropriate PIR
-to intialize it's value. We should be able to freeze the PMC during
compilation,
+to intialize its value. We should be able to freeze the PMC during compilation,
And then have in the generated code C<$P1 = thaw "...">.
=back
Modified: trunk/languages/tcl/docs/howto.pod
==============================================================================
--- trunk/languages/tcl/docs/howto.pod (original)
+++ trunk/languages/tcl/docs/howto.pod Mon Nov 7 10:59:51 2005
@@ -8,14 +8,19 @@ patches, but am happy to take complete f
Most of this is mentioned in the TODO - in fact, this document probably
should merge with the TODO to avoid redundancy.
+Since partcl is bundled with the parrot source, svn access is handled via
+the same mechanism as for parrot itself.
+
=head1 BIG STUFF
=over 4
=item compiler bits
-Partcl is now a compiler. Given a section of tcl code, it generates PIR
-instead of an AST, then compiles and invokes the sub.
+partcl is a compiler. Given a section of tcl code, it translates that code
+into an AST (in the form of a Tcl* object from lib/*). Once a section of code
+has been translated, the object's C<compile> method is invoked, which then
+generates PIR which can be compiled by parrot.
When writing a new builtin, preferentially put it in
C<< lib/builtins/<builtin>.pir >> , and write a wrapper in
@@ -33,26 +38,35 @@ is not found at runtime.)
=item speed
-We're currently quite slow, compared to tclsh. Switching over to a compiler
-instead of an interpreter might help here, though I'm having a hard time
-envisioning a compiler that doesn't have to do all the things we already do
-as an interpreter.
-
-We could rewrite parse/interpret/compile in C, either as an NCI or behind
-a PMC object - this would I<possibly> give us an improvement in speed also.
+We're currently slow, compared to tclsh. It's not worth worrying about
+this in terms of specific numbers until we can run C<tcltest> natively. That
+said, any patches that improve speed without harming maintainability will of
+course be applied.
=item features
-We're currently missing some things that require support from parrot
-before we can continue, like [info nameofexecutable]. In general, though,
-a lot of what we need to do is possible with parrot.
+We're currently missing some things that require support from parrot. See
+L<hacks.pod> for a list. In general, though, a lot of what we need to do is
+possible with parrot.
+
+If you're looking for something to todo, check one of:
+
+=over 4
+
+=item TODO tests
+
+in C<t/>;
+
+=item RT tickets
-If you're looking for something to todo, check one of: TODO tests in
-C<t/>; RT
https://rt.perl.org/rt3/NoAuth/parrot/List.html?Field=Lang&Value=tcl
-or by their absence: every actual builtin at
-http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm
-should have a corresponding file in C<lib/commands/>
+
+=item Missing builtins
+
+Every builtin at L<http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm>
+should have a corresponding file in C<lib/builtins/>
+
+=back
=back
@@ -93,9 +107,8 @@ C<lib/returncodes.pir>: C<.throw>, etc.
register or a PMC, the calling conventions will autobox as necessary.
Before adding new functionality, add a test (or a test in an existing) file
-in C<t/> - tests for C<puts>, for example,
-go in C<t/cmd_puts.t> - we use the C<Test::Harness> framework, via
-C<Parrot::Test>.
+in C<t/> - tests for C<puts>, for example, go in C<t/cmd_puts.t> -
+we use the C<Test::Harness> framework, via C<Parrot::Test>.
Our final goal will be to pass (most of) the tcl test suite: run
C<make tcl-test> to checkout the latest version of of the tcl test suite
@@ -108,7 +121,5 @@ be checking partcl-specific functionalii
=back
-
-
=cut
Modified: trunk/languages/tcl/docs/overview.pod
==============================================================================
--- trunk/languages/tcl/docs/overview.pod (original)
+++ trunk/languages/tcl/docs/overview.pod Mon Nov 7 10:59:51 2005
@@ -4,8 +4,7 @@ This was originally written as a perl5 s
I foolishly decided it would be fun to write the parser IN parrot assembly,
esp. as this would help implementing "eval" and "proc" (Of course, in
retrospect, I really wish I had kept with the bootstrapping effort, as I think
-it would have generated usable results sooner. Ah well, I now know more than
-I want to about PIR.
+it would have generated usable results sooner.
=head1 OVERVIEW
@@ -33,16 +32,17 @@ the appropriate namespaces, as well as d
compiler for the C<compile> opcode.
This file is actually built in two steps. The first step uses C<tcl.pl>
-to generate C<lib/tcllib.imc>, using C<tcl.imc_template> as a template.
+to generate C<lib/tcllib.pir>, using C<tcl.pir_template> as a template.
The file is basically passed through unchanged, except for a few C<${ }>
--style substitutions. C<INCLUDES> make sure all the required C<.imc> files
+-style substitutions. C<INCLUDES> make sure all the required C<.pir> files
are included properly. It adds a C<HEADER>, and removes any C<XXX> comments.
=item tcl.pbc
This is roughly equivalent to C<tclsh> - It takes the command line arguments
(currently, the name of the file you wish to parse), and reads in the file,
-and uses the tcl library to parse those contents as tcl.
+and uses the tcl library to parse those contents as tcl. You can also specify
+command line options to be used with this bytecode file.
=back
@@ -50,11 +50,12 @@ and uses the tcl library to parse those
The classes are not user-visible, but are internal helper classes designed
to simplify the parser/interpreter. They are written in PIR and are in
-C<lib>. All the helper classes provide an C<interpret> method, which can be
-called to calculate its value. For C<TclConst>, this is a very
-straightforward return, while for C<TclCommandList> does dynamic lookup on
-the various commands, executing each in turn, returning the value of the
-last command.
+C<lib>. All the helper classes provide a C<compile> method, which can be
+invoked by the top level compiler, or by a container class. For example, in
+C<TclConst>, the compilation is a very straightforward register load, while
+C<TclCommandList> compiles each of the C<TclCommand>s it contains, which in
+turn compile their arguments, and their method name, and setup an invocation
+of the PIR subroutine that corresponds to the tcl proc or builtin.
=over 4
@@ -81,8 +82,9 @@ A TclWord handles the concatenation of a
puts ab$c
-the parser will generate a word containing an "ab" TclConst and a "$c" TclVar.
-The values of these segments are concatenated together and passed to the puts
command.
+the parser will generate a C<TclWord> containing an C<TclConst>==C<ab>
+and a C<TclVar>==C<c>. When compiled, a C<TclWord> compiles each of its
+elements and concatenates the results.
=back
@@ -90,8 +92,9 @@ The values of these segments are concate
The Tcl PMCs (Parrot Magic Cookies) are the user visible data types. These
live in the C<*.pmc> files in C<classes/>. They are compiled into a
-dynamically loadable library. Most of the functionality associated with
-these pmcs is derived from the base parrot classes.
+dynamically loadable library which is loaded with the C<.HLL> directive
+(HLL stands for High Level Language). Most of the functionality associated
+with these PMCS is derived from the base parrot classes, except as noted below.
=over 4
@@ -102,21 +105,23 @@ Scalar string, with an override for the
=item TclInt
Scalar integer, with an override for various math. (For example, parrot
-automatically promotes to float division, while Tcl should not.)
+Integers automatically promote to float division, while Tcl does not.)
=item TclFloat
Scalar float, with an override of the stringification: Tcl floats are
-somewhat unusual in that integer-valued floats stringify with a trailing C<.0>.
+somewhat unusual compared to other parrot HLLs in that integer-valued floats
+stringify with a trailing C<.0>.
=item TclList
-Ordered container, corresponding to C<[list]> values. Overrides the default
-stringification provided by parrot Arrays.
+Ordered container, corresponding to values generated by the C<[list]> builtin.
+Overrides the default stringification provided by parrot Arrays.
=item TclArray
-Hash like container, corresponding to C<[array]> values.
+Hash like container, corresponding to values created with the C<[array]>
+builtin.
=item TclObject
@@ -136,14 +141,12 @@ cvs copy of the tests from the tcl repos
=over 4
-=item 1 Sloooow
+=item 1 Slow
-=item 2 Buggy
+There are a lot of tests, and we setup and breakdown an instance of
+parrot for *each* test we try to run.
-several of the tests hang, you may have to run C<killall parrot> several times
-during the run.
-
-=item 3 Incomplete
+=item 2 Incomplete
We convert the tests to use Perl's TAP instead of running
them natively. The conversion process is flawed, and we don't claim to
@@ -154,5 +157,4 @@ implement 100% of Tcl yet anyway. Expect
=head1 EXAMPLES
There are examples in the C<examples> directory that are vaguely more
-interesting. To run one of the C<foo.tcl> files in that directory, type
-C<make foo>.
+interesting. Change to that directory and type C<make> for directions.
Modified: trunk/languages/tcl/lib/commands/regexp.pir
==============================================================================
--- trunk/languages/tcl/lib/commands/regexp.pir (original)
+++ trunk/languages/tcl/lib/commands/regexp.pir Mon Nov 7 10:59:51 2005
@@ -2,7 +2,26 @@
.sub "®exp"
.param pmc argv :slurpy
+
+ .local int argc
+ argc = argv
+ if argc < 2 goto badargs
+ .local pmc exp, a_string
+
+ exp = shift argv
+ a_string = shift argv
+
+ .local pmc tclARE, rule, match
+
+ # XXX "tclARE"
+ tclARE = find_global "PGE", "p6rule"
+
+ rule = tclARE(exp)
+ match = rule(a_string)
+
+ $I0 = match
+ .return ($I0)
badargs:
.throw("wrong # args: should be \"regexp ?switches? exp string ?matchVar?
?subMatchVar subMatchVar ...?\"")
Modified: trunk/languages/tcl/t/cmd_regexp.t
==============================================================================
--- trunk/languages/tcl/t/cmd_regexp.t (original)
+++ trunk/languages/tcl/t/cmd_regexp.t Mon Nov 7 10:59:51 2005
@@ -2,37 +2,245 @@
use strict;
use lib qw(tcl/t t . ../lib ../../lib ../../../lib);
-use Parrot::Test tests => 3;
+use Parrot::Test tests => 7;
use Test::More;
-
language_output_is("tcl",<<TCL,<<'OUT',"regexp no args");
regexp
TCL
wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar
subMatchVar ...?"
OUT
-
TODO: {
local $TODO="not implemented yet.";
regexp_is ("asdf","asdf","literal, t");
regexp_isnt("asdf","fdsa","literal, f");
+
+ regexp_is ("a*","bbb", "*, true");
+ regexp_is ("a*","bab", "*, true");
+ regexp_is ("a*","baab", "*, true");
+ regexp_is ("a*","baaab", "*, true");
+
+ # +
+
+ # ?
+
+ # {m}
+
+ # {m,}
+
+ # {m,n}
+
+ # *?
+
+ # +?
+
+ # {m}?
+
+ # {m,}?
+
+ # {m,n}?
+
+ # m,n - restricted to 0, 255
+
+ #(re)
+
+ #(?:re)
+
+ #()
+
+ #(?:)
+
+ #[]
+
+ #[^]
+
+ #[a-z]
+
+ #[a-c-e] (boom)
+
+ #[:joe:]
+
+ #[[:<:]]
+
+ #[[:>:]]
+
+ #.
+
+ #\k
+
+ #\c
+
+ #{
+
+ #x
+
+ #^
+
+ #$
+
+ #(?=re)
+
+ #(?!re)
+
+ # Re may NOT end with \
+
+ # \a
+
+ # \b
+
+ # \B
+
+ # \cX
+
+ # \e
+
+ # \f
+
+ # \n
+
+ # \r
+
+ # \t
+
+ # \uwxyz
+
+ # \Ustuvwxyz
+
+ # \v
+
+ # \xhhh
+
+ # \0
+
+ # \xy
+
+ # \xyz
+
+ # \d
+
+ # \s
+
+ # \w
+
+ # \D
+
+ # \S
+
+ # \W
+
+ # Interaction of [] and \d: e.g. [a-c\d] vs. [a-c\D]
+
+ # \A
+
+ # \m
+
+ # \M
+
+ # \y
+
+ # \Y
+
+ # \Z
+
+ # \m
+
+ # \mnn
+
+ # *** (ARE)
+
+ # ***= (literal)
+
+ # (?b)
+
+ # (?c)
+
+ # (?e)
+
+ # (?i)
+
+ # (?m)
+
+ # (?n)
+
+ # (?p)
+
+ # (?q)
+
+ # (?s)
+
+ # (?t)
+
+ # (?w)
+
+ # (?x)
+
+ # Match earliest.
+
+ # Match longest
+
+ # BRE: |
+
+ # BRE: +
+
+ # BRE: ?
+
+ # BRE: \{
+
+ # BRE: \}
+
+ # BRE: \(
+
+ # BRE: \)
+
+ # BRE: ^
+
+ # BRE: $
+
+ # BRE: *
+
+ # BRE: \<
+
+ # BRE: \>
+
+ # -expanded
+
+ # -indices
+
+ # -line
+
+ # -linestop
+
+ # -lineanchor
+
+ # -nocase
+
+ # -all
+
+ # -inline
+
+ # -start
+
+ # --
+
}
-sub regexp_is { regexp_check(@_,1); }
-sub regexp_isnt { regexp_check(@_,0); }
+
+# Helper
+
+sub regexp_is { regexp_check(@_,1) }
+sub regexp_isnt { regexp_check(@_,0) }
sub regexp_check {
my ($pattern,$string,$reason,$flag) = @_;
language_output_is("tcl",<<"TCL",<<"OUT", $reason);
-
+
puts [regexp {$pattern} {$string}]
TCL
$flag
OUT
-
-}
+ }