tclbdd

Check-in [adf349c020]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:added corovar notation rather than the fugly 'upvar #1'
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:adf349c0205688ce6906b44d5d79c9723887fab5
User & Date: kbk 2013-12-28 05:33:34
Context
2014-01-01
05:59
Major refactor - stratification simplified by the fact that scc generates components in postorder. Finished execution planning. check-in: e6862c5093 user: kbk tags: trunk
2013-12-28
05:33
added corovar notation rather than the fugly 'upvar #1' check-in: adf349c020 user: kbk tags: trunk
05:06
Added the Datalog compiler (under construction - only the parser and the stratification pass are implemented so far). check-in: a24b8ef7c3 user: kbk tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added library/coroutine_corovar.tcl.

























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# coroutine_corovar.tcl --
#
#	Implements a 'corovar' command that declares a set of variables
#	to be coroutine-global
#
# Copyright (c) 2013 by Kevin B. Kenny
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
#------------------------------------------------------------------------------

package require Tcl 8.6

namespace eval coroutine {
    namespace eval corovar {
	namespace export corovar
    }
}

# coroutine::corovar::corovar --
#
#	Declares a set of variables to be coroutine-global
#
# Usage:
#	coroutine::corovar::corovar ?var?...
#
# Parameters:
#	var - Name of a variable to make coroutine-global
#
# Results:
#	None
#
# Side effects:
#	Imports the given coroutine-global vars into the caller's scope.

proc coroutine::corovar::corovar {args} {
    foreach var $args {
	uplevel 1 [list upvar #1 $var $var]
    }
    return
}

package provide coroutine::corovar 1.0

Changes to library/datalog.tcl.

7
8
9
10
11
12
13

14

15

16
17


18
19
20
21
22
23
24
...
388
389
390
391
392
393
394


395
396
397
398
399
400
401
...
424
425
426
427
428
429
430
431
432
433
434

435
436
437
438
439
440
441

442
443
444
445
446
447
448
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
#------------------------------------------------------------------------------

source [file dirname [info script]]/coroutine_iterator.tcl; # TEMP



package require Tcl 8.6

package require coroutine::iterator 1.0
package require grammar::aycock 1.0



namespace eval bdd {
    namespace eval datalog {
	namespace export lex parse compile
    }
}

................................................................................
#		   in this procedure.
#
# Results:
#	Yields the sets of nodes that form strongly connected components.

proc bdd::datalog::SCC_coro {outedges} {
    # outedges is coroutine-global


    set index 0;		# Coroutine global: Current node's index
    set S {};			# Coroutine global: Stack of nodes on the
    				# path from a root to the current node
    set vindex {};		# Coroutine global: Dictionary whose keys are
    				# node names, and whose values are node indices
    set lowlink {};		# Coroutine global: Dictionary whose keys are
    				# node names, and whose values are node indices
................................................................................
# Results:
#	None.
#
# This procedure performs a depth-first traversal, identifying back edges
# and strongly connected components.

proc bdd::datalog::SCC_coro_worker {v edges} {
    upvar #1 outedges outedges;	# Coroutine global: adjacency lists
    upvar #1 index index;	# Coroutine global: index for the next
    				# unexamined node
    upvar #1 S S;		# Coroutine global: stack of nodes traversed

    				# from a root
    upvar #1 vindex vindex;	# Coroutine global: dictionary whose keys are
				# names of nodes and whose values are node
    				# indices
    upvar #1 lowlink lowlink;	# Coroutine global: dictionary whose keys are
				# names of nodes and whose values are the
    				# indices of the other end of back edges


    # Set the index and lowlink of the node to point to itself, and put
    # the node on the stack.
    dict set vindex $v $index
    dict set lowlink $v $index
    incr index
    lappend S $v







>

>

>


>
>







 







>
>







 







|
<
|
|
>
|
|
<
<
<
<
<
>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
...
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
...
431
432
433
434
435
436
437
438

439
440
441
442
443





444
445
446
447
448
449
450
451
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
#------------------------------------------------------------------------------

source [file dirname [info script]]/coroutine_iterator.tcl; # TEMP
source [file dirname [info script]]/coroutine_corovar.tcl; # TEMP


package require Tcl 8.6
package require coroutine::corovar 1.0
package require coroutine::iterator 1.0
package require grammar::aycock 1.0

namespace import coroutine::corovar::corovar

namespace eval bdd {
    namespace eval datalog {
	namespace export lex parse compile
    }
}

................................................................................
#		   in this procedure.
#
# Results:
#	Yields the sets of nodes that form strongly connected components.

proc bdd::datalog::SCC_coro {outedges} {
    # outedges is coroutine-global

    # Coroutine-global variables:
    set index 0;		# Coroutine global: Current node's index
    set S {};			# Coroutine global: Stack of nodes on the
    				# path from a root to the current node
    set vindex {};		# Coroutine global: Dictionary whose keys are
    				# node names, and whose values are node indices
    set lowlink {};		# Coroutine global: Dictionary whose keys are
    				# node names, and whose values are node indices
................................................................................
# Results:
#	None.
#
# This procedure performs a depth-first traversal, identifying back edges
# and strongly connected components.

proc bdd::datalog::SCC_coro_worker {v edges} {
    corovar outedges;		# Adjacency lists

    corovar index;		# Index of next unexamined node
    corovar S;			# Stack of nodes traversed from root to current
    corovar vindex;		# Dictionary mapping node to node index
    corovar lowlink;		# Dictionary mapping node to the other
    				# end of a back edge.







    # Set the index and lowlink of the node to point to itself, and put
    # the node on the stack.
    dict set vindex $v $index
    dict set lowlink $v $index
    incr index
    lappend S $v