Tcl Source Code

View Ticket
Login
Ticket UUID: 1237040
Title: dict compiler
Type: Patch Version: None
Submitter: dkf Created on: 2005-07-12 23:54:53
Subsystem: 47. Bytecode Compiler Assigned To: dkf
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2005-08-28 19:42:57
Resolution: Accepted Closed By: dkf
    Closed on: 2005-08-28 12:42:57
Description:
This is a first hack at compiling the [dict] command.
It passes the test suite cleanly for me (clock.test is
a pretty good workout of many of the features that are
compiled.)
User Comments: dkf added on 2005-08-28 19:42:55:
Logged In: YES 
user_id=79902

the dict compiler has been in the HEAD for a while now

dkf added on 2005-07-15 17:46:26:
Logged In: YES 
user_id=79902

By automatic variable, do you mean a local temporary Var or
a C variable or what?

Storing the Tcl_DictSearch in the bytecode structure won't
work because of recursion. Putting the value in a
(stack-allocated) C variable could work, but it'd be tricky
to get right because you can nest iterations (and we really
want to reduce the amount of stack space required for TEBC
anyway) which means you'd have to keep an array (or list) of
them; you could do it, but it'd be a lot of work to get
right (not that we couldn't do this in the future, of
course, but it would break the TDK compiler if we did it
whereas my current solution remains compatible on this front
at least). The easiest way is to store the iterator context
in a Var, since they're handled right anway, which is what I
do. :^)

dgp added on 2005-07-15 11:22:41:
Logged In: YES 
user_id=80530

Um, ignore my last comment.

Clearly nested [dict for] commands
will compile to a stream of bytecode
that would execute in many iterations
through TEBC, but not nested TEBC
calls.  Dynamic allocation is correct.

dgp added on 2005-07-15 00:54:16:
Logged In: YES 
user_id=80530


line 5076 of tclExecute.c
dynamically allocates a
Tcl_DictSearch.  Any reason
not to use an automatic variable
instead?

dkf added on 2005-07-14 21:04:40:

File Deleted - 141861: 



File Added - 142041: bccDict_2.diff

Logged In: YES 
user_id=79902

Here's an updated patch that includes compilation of [dict
append] and [dict lappend] as well.

dkf added on 2005-07-14 21:00:07:
Logged In: YES 
user_id=79902

1: wordTokenPtr[0].type is correct (but better written as
wTP->type). I didn't write the way tokens operate...
2: I hadn't thought of doing that, but it's not a major
issue. I do worry about having a table of subcommands in two
locations though.
3: I'm trying to ensure that the compilation works, and
extending coverage to all possible prefixes is a low-value
issue, since it is Good Practice to not rely on prefixes at all.
4: I'm not going to do anything about this in this patch.
5: It's a cargo-cultist copying from the [incr] compiler.
i.e. yet another thing to fix outside the context of this
patch :-)

dgp added on 2005-07-14 04:47:18:
Logged In: YES 
user_id=80530


I don't see the value of the
TclLooksLikeInt() call in
the compile of [dict incr].
It tells us approximately whether
we have an int value, by at
least rejecting string that
do not "look" right.

If it passes, we move on to
an actual Tcl_GetIntFromObj()
call which tells us for sure whether
we have an int value.

I don't see the point of a half-test
right before the real test.  I suppose
it could help us fail faster, but is
that really important?  The check
also makes us succeed slower,
and success ought to be the normal
mode.

dgp added on 2005-07-14 04:31:56:
Logged In: YES 
user_id=80530


This is true about pre-existing code
as well, but might as well mention it:

The variable name "nameChars" is
misleading as the value it holds is
a number of bytes, not a number of
characters.  Would be a good idea
to change them all.

dgp added on 2005-07-14 04:26:42:
Logged In: YES 
user_id=80530


I note that the direct evaluation
implementation of [dict] does
accept unique prefixes, so it seems
strange that the [dict] compiler
refuses to compile them.  That
suggests to me that copying
the [string] compiler routine is
the way to go.

dgp added on 2005-07-14 04:24:27:
Logged In: YES 
user_id=80530


On the subcommand parsing
topic, I note that the [string]
compiler accepts unique prefixes
of subcommands for compiling
([string comp] for example).  Will
have to consider whether the
[dict] compiler will copy that.

dgp added on 2005-07-14 04:15:51:
Logged In: YES 
user_id=80530


I'm a bit surprised to see
TclCompileDictCmd use
repeated strncmp() calls
for subcommand parsing.

Wouldn't it make more sense
to copy TclCompileStringCmd()'s
technique of using Tcl_GetIndexFromObj() ?

If not, does it make sense to do the
reverse, and have the [string] subcommands
parsed as the [dict] ones are?

I think it would be best not to use two
different techniques in the same
source code file without a really
good reason.

dgp added on 2005-07-14 04:12:56:
Logged In: YES 
user_id=80530


On line 2774 of the patched
tclCompCmds.c, shouldn't

(wordTokenPtr[0].type == TCL_TOKEN_SIMPLE_WORD)

be

(wordTokenPtr[1].type == TCL_TOKEN_SIMPLE_WORD)

?

dkf added on 2005-07-13 06:54:53:

File Added - 141861: bccDict.diff

Attachments: