Jordan de la Houssaye

started andy integration. cloned from abcd

#!/usr/bin/env python
import snakes.utils.andy.main as andymain
andymain.main()
"""This package features the ABCD compiler, this is mainly a
command-line tool but it can be called also from Python. The API is
very simple and mimics the command line interface
### Function `snakes.utils.abcd.main.main` ###
:::python
def main (args=sys.argv[1:], src=None) : ...
Entry point of the compiler
##### Call API #####
* `list args`:
* `str src`:
* `return PetriNet`:
##### Exceptions #####
* `DeclarationError`: when
* `CompilationError`: when
"""
# apidoc stop
from snakes import SnakesError
class CompilationError (SnakesError) :
pass
class DeclarationError (SnakesError) :
pass
This diff is collapsed. Click to expand it.
import heapq
from snakes.nets import StateGraph
import snakes.lang
import snkast as ast
class Checker (object) :
def __init__ (self, net) :
self.g = StateGraph(net)
self.f = [self.build(f) for f in net.label("asserts")]
def build (self, tree) :
src = """
def check (_) :
return %s
""" % tree.st.source()[7:]
ctx = dict(self.g.net.globals)
ctx["bounded"] = self.bounded
exec(src, ctx)
fun = ctx["check"]
fun.lineno = tree.lineno
return fun
def bounded (self, marking, max) :
return all(len(marking(p)) == 1 for p in marking)
def run (self) :
for state in self.g :
marking = self.g.net.get_marking()
for place in marking :
if max(marking(place).values()) > 1 :
return None, self.trace(state)
for check in self.f :
try :
if not check(marking) :
return check.lineno, self.trace(state)
except :
pass
return None, None
def path (self, tgt, src=0) :
q = [(0, src, ())]
visited = set()
while True :
(c, v1, path) = heapq.heappop(q)
if v1 not in visited :
path = path + (v1,)
if v1 == tgt :
return path
visited.add(v1)
for v2 in self.g.successors(v1) :
if v2 not in visited :
heapq.heappush(q, (c+1, v2, path))
def trace (self, state) :
path = self.path(state)
return tuple(self.g.successors(i)[j]
for i, j in zip(path[:-1], path[1:]))
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
<div class="about">
<p><span class="title">ABCD simulator is part of the SNAKES
toolkit</span><br/> (C) 2014 Franck Pommereau</p>
<p><a href="http://www.ibisc.univ-evry.fr/~fpommereau/SNAKES"
target="_blank">SNAKES homepage</a></p>
</div>
Well, you can tell by the way I use my walk,
I'm a woman's man: no time to talk.
Music loud and women warm, I've been kicked around
Since I was born.
And now it's all right. it's ok.
And you may look the other way.
We can try to understand
The new york times effect on man.
Whether you're a brother or whether you're a mother,
You're stayin alive, stayin alive.
Feel the city breakin and everybody shakin,
And were stayin alive, stayin alive.
Ah, ha, ha, ha, stayin alive, stayin alive.
Ah, ha, ha, ha, stayin alive.
Well now, I get low and I get high,
And if I can't get either, I really try.
Got the wings of heaven on my shoes.
I'm a dancin man and I just can't lose.
You know it's all right.its ok.
I'll live to see another day.
We can try to understand
The new york times effect on man.
Whether you're a brother or whether you're a mother,
You're stayin alive, stayin alive.
Feel the city breakin and everybody shakin,
And were stayin alive, stayin alive.
Ah, ha, ha, ha, stayin alive, stayin alive.
Ah, ha, ha, ha, stayin alive.
Life goin nowhere.somebody help me.
Somebody help me, yeah.
Life goin nowhere.somebody help me.
Somebody help me, yeah. stayin alive.
Well, you can tell by the way I use my walk,
I'm a woman's man: no time to talk.
Music loud and women warm,
I've been kicked around since I was born.
And now it's all right. it's ok.
And you may look the other way.
We can try to understand
The new york times effect on man.
Whether you're a brother or whether you're a mother,
You're stayin alive, stayin alive.
Feel the city breakin and everybody shakin,
And were stayin alive, stayin alive.
Ah, ha, ha, ha, stayin alive, stayin alive.
Ah, ha, ha, ha, stayin alive.
Life goin nowhere.somebody help me.
Somebody help me, yeah.
Life goin nowhere.somebody help me, yeah.
I'm stayin alive.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff could not be displayed because it is too large.
<!DOCTYPE html>
<html>
<head>
<link type="text/css" href="r/css/bootstrap-theme.css" rel="stylesheet"/>
<link type="text/css" href="r/css/bootstrap.css" rel="stylesheet"/>
<link type="text/css" href="r/css/docs.css" rel="stylesheet"/>
<link type="text/css" href="r/simulator.css" rel="stylesheet"/>
<link type="text/css" href="r/model.css" rel="stylesheet"/>
<script src="r/jquery.min.js"></script>
<script src="r/js/bootstrap.min.js"></script>
<script src="r/jquery.periodic.js"></script>
<script src="r/js/bootstrap.file-input.js"></script>
<script src="r/d3.min.js"></script>
<script src="r/js/petri.js"></script>
<script src="r/simulator.js"></script>
</head>
<style>
path {
stroke: steelblue;
stroke-width: 2;
fill: none;
}
line {
stroke: black;
}
text {
font-family: Arial;
font-size: 9pt;
}
</style>
<body>
<header class="navbar navbar-static-top">
<div class="container">
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header"><button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-6"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Simulation SNAKES</a></div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-6">
<ul id="nav_sim" class="nav navbar-nav">
<li><a href="#" id="ui-reset">Reset Simulation</a></li>
<li><a href="#" id="ui-quit">Stop Simulation</a></li>
<li><a href="#" id="ui-help">Help</a></li>
</ul>
</div>
</div>
</nav>
</div>
</header>
<div class="container">
%(model)s
<div class="modal fade" id="about" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Petri Net</h4>
</div>
<div class="modal-body">
<p><span class="title">ABCD simulator is part of the SNAKES toolkit</span><br /> (C) 2014 Franck Pommereau</p>
<p><a href="http://www.ibisc.univ-evry.fr/~fpommereau/SNAKES" target="_blank">SNAKES homepage</a></p>
</div>
<div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$.simisc({
"nav":{
"about": {
"text": "About",
"attr": {
"id":"ui-about",
"data-toggle": "modal",
"data-target": "#about"
}
},
"net": {
"text": "Petri Net",
"attr": {
"id":"ui-net",
"data-toggle": "modal",
"data-target": "#net"
}
}
},
"graph": {
"activate": false
}
});
});
</script>
</body>
</html>
This diff could not be displayed because it is too large.
/*!
* jQuery periodic plugin
*
* Copyright 2010, Tom Anderson
* Dual licensed under the MIT or GPL Version 2 licenses.
*
*/
$.periodic = function (options, callback) {
// if the first argument is a function then assume the options aren't being passed
if (jQuery.isFunction(options)) {
callback = options;
options = {};
}
// Merge passed settings with default values
var settings = jQuery.extend({}, jQuery.periodic.defaults, {
ajax_complete : ajaxComplete,
increment : increment,
reset : reset,
cancel : cancel
}, options);
// bookkeeping variables
settings.cur_period = settings.period;
settings.tid = false;
var prev_ajax_response = '';
run();
// return settings so user can tweak them externally
return settings;
// run (or restart if already running) the looping construct
function run() {
// clear/stop existing timer (multiple calls to run() won't result in multiple timers)
cancel();
// let it rip!
settings.tid = setTimeout(function() {
// set the context (this) for the callback to the settings object
callback.call(settings);
// compute the next value for cur_period
increment();
// queue up the next run
if(settings.tid)
run();
}, settings.cur_period);
}
// utility function for use with ajax calls
function ajaxComplete(xhr, status) {
if (status === 'success' && prev_ajax_response !== xhr.responseText) {
// reset the period whenever the response changes
prev_ajax_response = xhr.responseText;
reset();
}
}
// compute the next delay
function increment() {
settings.cur_period *= settings.decay;
if (settings.cur_period < settings.period) {
// don't let it drop below the minimum
reset();
} else if (settings.cur_period > settings.max_period) {
settings.cur_period = settings.max_period;
if (settings.on_max !== undefined) {
// call the user-supplied callback if we reach max_period
settings.on_max.call(settings);
}
}
}
function reset() {
settings.cur_period = settings.period;
// restart with the new timeout
run();
}
function cancel() {
clearTimeout(settings.tid);
settings.tid = null;
}
// other functions we might want to implement
function pause() {}
function resume() {}
function log() {}
};
jQuery.periodic.defaults = {
period : 4000, // 4 sec.
max_period : 1800000, // 30 min.
decay : 1.5, // time period multiplier
on_max : undefined // called if max_period is reached
};
\ No newline at end of file
/*
Bootstrap - File Input
======================
This is meant to convert all file input tags into a set of elements that displays consistently in all browsers.
Converts all
<input type="file">
into Bootstrap buttons
<a class="btn">Browse</a>
*/
$(function() {
$.fn.bootstrapFileInput = function() {
this.each(function(i,elem){
var $elem = $(elem);
// Maybe some fields don't need to be standardized.
if (typeof $elem.attr('data-bfi-disabled') != 'undefined') {
return;
}
// Set the word to be displayed on the button
var buttonWord = 'Browse';
if (typeof $elem.attr('title') != 'undefined') {
buttonWord = $elem.attr('title');
}
// Start by getting the HTML of the input element.
// Thanks for the tip http://stackoverflow.com/a/1299069
var input = $('<div>').append( $elem.eq(0).clone() ).html();
var className = '';
if (!!$elem.attr('class')) {
className = ' ' + $elem.attr('class');
}
// Now we're going to replace that input field with a Bootstrap button.
// The input will actually still be there, it will just be float above and transparent (done with the CSS).
$elem.replaceWith('<a class="file-input-wrapper btn btn-default' + className + '">'+buttonWord+input+'</a>');
})
// After we have found all of the file inputs let's apply a listener for tracking the mouse movement.
// This is important because the in order to give the illusion that this is a button in FF we actually need to move the button from the file input under the cursor. Ugh.
.promise().done( function(){
// As the cursor moves over our new Bootstrap button we need to adjust the position of the invisible file input Browse button to be under the cursor.
// This gives us the pointer cursor that FF denies us
$('.file-input-wrapper').mousemove(function(cursor) {
var input, wrapper,
wrapperX, wrapperY,
inputWidth, inputHeight,
cursorX, cursorY;
// This wrapper element (the button surround this file input)
wrapper = $(this);
// The invisible file input element
input = wrapper.find("input");
// The left-most position of the wrapper
wrapperX = wrapper.offset().left;
// The top-most position of the wrapper
wrapperY = wrapper.offset().top;
// The with of the browsers input field
inputWidth= input.width();
// The height of the browsers input field
inputHeight= input.height();
//The position of the cursor in the wrapper
cursorX = cursor.pageX;
cursorY = cursor.pageY;
//The positions we are to move the invisible file input
// The 20 at the end is an arbitrary number of pixels that we can shift the input such that cursor is not pointing at the end of the Browse button but somewhere nearer the middle
moveInputX = cursorX - wrapperX - inputWidth + 20;
// Slides the invisible input Browse button to be positioned middle under the cursor
moveInputY = cursorY- wrapperY - (inputHeight/2);
// Apply the positioning styles to actually move the invisible file input
input.css({
left:moveInputX,
top:moveInputY
});
});
$('.file-input-wrapper input[type=file]').change(function(){
var fileName;
fileName = $(this).val();
// Remove any previous file names
$(this).parent().next('.file-input-name').remove();
if (!!$(this).prop('files') && $(this).prop('files').length > 1) {
fileName = $(this)[0].files.length+' files';
//$(this).parent().after('<span class="file-input-name">'+$(this)[0].files.length+' files</span>');
}
else {
// var fakepath = 'C:\\fakepath\\';
// fileName = $(this).val().replace('C:\\fakepath\\','');
fileName = fileName.substring(fileName.lastIndexOf('\\')+1,fileName.length);
}
$(this).parent().after('<span class="file-input-name">'+fileName+'</span>');
});
});
};
// Add the styles before the first stylesheet
// This ensures they can be easily overridden with developer styles
var cssHtml = '<style>'+
'.file-input-wrapper { overflow: hidden; position: relative; cursor: pointer; z-index: 1; }'+
'.file-input-wrapper input[type=file], .file-input-wrapper input[type=file]:focus, .file-input-wrapper input[type=file]:hover { position: absolute; top: 0; left: 0; cursor: pointer; opacity: 0; filter: alpha(opacity=0); z-index: 99; outline: 0; }'+
'.file-input-name { margin-left: 8px; }'+
'</style>';
$('link[rel=stylesheet]').eq(0).before(cssHtml);
});
\ No newline at end of file
This diff is collapsed. Click to expand it.
$(document).ready(function(){
$(".abcd .action, .abcd .instance").each(function(){
var objet = this;
$(".action, .instance").each(function(){
if ($(this).attr("data-abcd") == "#" + $(objet).attr("id")){
$(this).html($(objet).html());
}
});
});
$(".action, .instance, .buffer, .proto").mouseover(function(){
$(this).addClass("highlight_simul");
$($(this).attr("data-abcd")).addClass("highlight_simul");
$($(this).attr("data-tree")).addClass("highlight_simul");
$($(this).attr("data-net")).addClass("highlight_simul");
}).mouseout(function(){
$(this).removeClass("highlight_simul");
$($(this).attr("data-abcd")).removeClass("highlight_simul");
$($(this).attr("data-tree")).removeClass("highlight_simul");
$($(this).attr("data-net")).removeClass("highlight_simul");
});
});
\ No newline at end of file
/* ABCD source code */
#model .abcd .comment {
color: #888;
}
#model .abcd .ident {
color: #808;
}
#model .abcd .string {
color: #088;
}
#model .abcd .kw {
color: #800;
font-weight: bold;
}
#model .abcd .flow {
color: #800;
font-weight: bold;
}
#model .abcd .buffer .decl {
color: #080;
font-weight: bold;
}
#model .abcd .net .decl {
color: #008;
font-weight: bold;
}
#model .abcd .instance .name {
color: #008;
}
#model .abcd .action .delim {
font-weight: bold;
}
#model .abcd .action .name {
color: #080;
}
#model .abcd .active {
background-color: #B6F8AE;
}
#model .abcd .highlight_simul {
background-color: yellow;
}
#model .tree .buffer .kw {
color: #800;
font-weight: bold;
}
#model .tree .buffer .name {
color: #080;
font-weight: bold;
}
#model .tree .ident {
color: #808;
}
#model .tree .instance .name {
color: #008;
}
#model .tree .action .delim {
font-weight: bold;
}
#model .tree .action .name {
color: #080;
}
#model .tree .string {
color: #088;
}
#model .tree .modes li {
margin: 12px 0px;
}
#model .tree .modes a {
background-color: #B6F8AE;
border: solid 1px #AAA;
border-radius: 5px;
padding: 5px 10px;
text-decoration: none;
color: #333;
}
#model .tree .modes a:hover {
color: #A33;
background-color: #F8B6AE;
}
#model .tree .active {
background-color: #B6F8AE;
}
#model .tree .highlight_simul {
background-color: yellow;
}
<div class="page-header">
<h1><tt>%(filename)s</tt> <small> powered by Franck</small></h1>
</div>
<div class="row">
<div class="col-md-3">
<div class="row">
<h3>Player</h3>
<div id="player"></div>
</div>
</div>
</div>
<div id="model" class="row">
<div class="col-md-6">
<div class="row">
<h3>ABCD</h3>
<div class="abcd">%(abcd)s</div>
</div>
</div>
<div class=col-md-6>
<div class="row">
<h3>Tree</h3>
<div class="tree">%(tree)s</div>
</div>
</div>
<div class="col-md-12">
<div id="trace_zone"></div>
</div>
</div>
<div class="modal fade" id="net" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" style="width:auto;">
<div class="modal-content" style="overflow: scroll;">
%(net)s
</div>
</div>
</div>
\ No newline at end of file
var nodeColor;
function abcdon () {
obj = $(this);
if (obj.attr("class") == "node") {
node = obj.children().children().first();
nodeColor = node.attr("fill");
node.attr("fill", "yellow");
} else {
obj.addClass("highlight");
}
$(obj.attr("data-abcd")).addClass("highlight");
};
function abcdoff () {
obj = $(this);
if (obj.attr("class") == "node") {
node = obj.children().children().first();
node.attr("fill", nodeColor);
} else {
obj.removeClass("highlight");
}
$(obj.attr("data-abcd")).removeClass("highlight");
};
function treeon () {
obj = $(this);
if (obj.attr("class") != "node") {
obj.addClass("highlight");
}
$(obj.attr("data-tree")).addClass("highlight");
};
function treeoff () {
obj = $(this);
if (obj.attr("class") != "node") {
obj.removeClass("highlight");
}
$(obj.attr("data-tree")).removeClass("highlight");
};
function neton () {
obj = $(this);
$(obj.attr("data-net")).each(function () {
node = $(this).children().children().first();
nodeColor = node.attr("fill");
node.attr("fill", "yellow");
});
obj.addClass("highlight");
};
function netoff () {
obj = $(this);
$(obj.attr("data-net")).each(function () {
node = $(this).children().children().first();
node.attr("fill", nodeColor);
});
obj.removeClass("highlight");
};
$(document).ready(function() {
$("#model [data-abcd]").hover(abcdon, abcdoff);
$("#model [data-tree]").hover(treeon, treeoff);
$("#model [data-net]").hover(neton, netoff);
$(".tree .instance, .tree .action").each(function () {
obj = $(this);
obj.html($(obj.attr("data-abcd")).html());
});
});
body {
font-family: sans-serif;
}
#alive {
border: solid 1px #AAA;
border-radius: 5px;
padding: 5px 10px;
margin: 5px;
background-color: #DDD;
overflow:auto;
}
#alive .ui {
display: inline;
list-style: none;
margin: 0px;
padding: 0px;
}
#alive .ui li {
display: inline;
border: solid 1px #AAA;
padding: 5px 10px;
margin: 0px 3px;
background-color: #EEE;
}
#alive .ui a {
text-decoration: none;
color: #333;
}
#alive .ui li:hover {
background-color: #FFF;
}
#alive .ui a:hover {
color: #A33;
}
#alive .ping {
color: #DDD;
float: right;
}
#model {
border: solid 1px #AAA;
border-radius: 5px;
padding: 5px 10px;
margin: 5px;
background-color: #EEE;
overflow:auto;
}
#trace {
border: solid 1px #AAA;
border-radius: 5px;
padding: 5px 10px;
margin: 5px;
background-color: #EEE;
overflow:auto;
}
#about {
display: none;
}
#dialog {
display: none;
position: fixed;
z-index: 2;
top: 10%;
left: 20%;
width: 60%;
border: solid 2px #AAA;
border-radius: 5px;
padding: 20px;
background-color: #FFF;
overflow:auto;
}
#dialog-bg {
display: none;
position: fixed;
z-index: 1;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: #000;
margin: 0px;
}
#dialog-close {
/* TODO: fix position when dialog has a horizontal scrollbar */
display: block;
float: right;
border: solid 1px #AAA;
padding: 5px 10px;
margin: 0px 3px;
background-color: #EEE;
text-decoration: none;
color: #333;
}
#dialog-close:hover {
background-color: #FFF;
color: #A33;
}
.dialog p {
margin: 10px 20px 0px 20px;
}
.dialog .title {
margin: 0px 20px 5px 20px;
font-weight: bold;
text-align: center;
}
.dialog .subtitle {
margin: 0px 20px 5px 20px;
text-align: center;
}
\ No newline at end of file
This diff is collapsed. Click to expand it.
from snakes.utils.simul import BaseSimulator, BaseHTTPSimulator
import snakes.utils.abcd.html as html
class ABCDSimulator (BaseSimulator) :
def __init__ (self, node, net, gv) :
BaseSimulator.__init__(self, net)
a2html = html.ABCD2HTML(node)
n2html = html.Net2HTML(net, gv, a2html)
self.info = {"filename" : node.st.filename,
"abcd" : a2html.html(),
"tree" : n2html.html(),
"net" : n2html.svg()}
self.tree = {}
for node in net.node() :
nid = gv.nodemap[node.name]
if nid in n2html.n2t :
self.tree[node.name] = "#" + n2html.n2t[nid]
self.places = [place.name for place in net.place()
if place.name in self.tree]
self.abcd = {}
self.transid = []
for trans in net.transition() :
nid = gv.nodemap[trans.name]
self.transid.append(self.tree[trans.name])
if nid in n2html.n2a :
self.abcd[trans.name] = ", ".join("#" + i for i in
n2html.n2a[nid])
def init (self, state=-1) :
res = BaseSimulator.init(self, state)
res.update(self.info)
res["help"] = self.init_help()
return res
def init_help (self) :
help = BaseSimulator.init_help(self)
help.update({
"#model .abcd" : {
"title" : "Source",
"content" : "ABCD source code"
},
"#model .tree" : {
"title" : "State",
"content" : "hierarchy of ABCD objects",
},
"#model .petrinet" : {
"title" : "Net",
"content" : "Petri nets semantics"
}})
return help
def getstate (self, state) :
marking = self.states[state]
modes = dict((t, []) for t in self.transid)
for i, (trans, mode) in enumerate(marking.modes) :
modes[self.tree[trans.name]].append({"state" : state,
"mode" : i,
"html" : str(mode)})
return {"id" : state,
"states" :
[{"do" : "dropclass",
"select" : "#model .active",
"class" : "active"}]
+ [{"do" : "addclass",
"select" : self.abcd[trans.name],
"class" : "active"} for trans, mode in marking.modes]
+ [{"do" : "addclass",
"select" : self.tree[trans.name],
"class" : "active"} for trans, mode in marking.modes]
+ [{"do" : "settext",
"select" : "%s .content" % self.tree[place],
"text" : "{}"} for place in self.places
if place not in marking]
+ [{"do" : "settext",
"select" : "%s .content" % self.tree[place],
"text" : str(marking[place])} for place in marking
if place in self.tree],
"modes" : [{"select" : "%s + .modes" % trans,
"items" : items}
for trans, items in modes.items()],
}
class Simulator (BaseHTTPSimulator) :
def __init__ (self, node, net, gv, port) :
simul = ABCDSimulator(node, net, gv)
BaseHTTPSimulator.__init__(self, net, simulator=simul, port=port)
def init_model (self) :
return self.res["model.html"] % self.simul.info
def init_ui (self) :
return BaseHTTPSimulator.init_ui(self)[:-1] + [{
"label" : "Show net",
"id" : "ui-shownet",
"href" : "#",
"script" : "dialog($('#model .petrinet').html())"
}]
from snakes.lang.abcd.parser import ast
class NodeCopier (ast.NodeTransformer) :
def copy (self, node, **replace) :
args = {}
for name in node._fields + node._attributes :
old = getattr(node, name, None)
if name in replace :
new = replace[name]
elif isinstance(old, list):
new = []
for val in old :
if isinstance(val, ast.AST) :
new.append(self.visit(val))
else :
new.append(val)
elif isinstance(old, ast.AST):
new = self.visit(old)
else :
new = old
args[name] = new
if hasattr(node, "st") :
args["st"] = node.st
return node.__class__(**args)
def generic_visit (self, node) :
return self.copy(node)
class ArgsBinder (NodeCopier) :
def __init__ (self, args, buffers, nets, tasks) :
NodeCopier.__init__(self)
self.args = args
self.buffers = buffers
self.nets = nets
self.tasks = tasks
def visit_Name (self, node) :
if node.id in self.args :
return self.copy(self.args[node.id])
else :
return self.copy(node)
def visit_Instance (self, node) :
if node.net in self.nets :
return self.copy(node, net=self.nets[node.net])
else :
return self.copy(node)
def _visit_access (self, node) :
if node.buffer in self.buffers :
return self.copy(node, buffer=self.buffers[node.buffer])
else :
return self.copy(node)
def visit_SimpleAccess (self, node) :
return self._visit_access(node)
def visit_FlushAccess (self, node) :
return self._visit_access(node)
def visit_SwapAccess (self, node) :
return self._visit_access(node)
def _visit_task (self, node) :
if node.net in self.tasks :
return self.copy(node, net=self.tasks[node.net])
else :
return self.copy(node)
def visit_Spawn (self, node) :
return self._visit_task(node)
def visit_Wait (self, node) :
return self._visit_task(node)
def visit_Suspend (self, node) :
return self._visit_task(node)
def visit_Resume (self, node) :
return self._visit_task(node)
def visit_AbcdNet (self, node) :
args = self.args.copy()
buffers = self.buffers.copy()
nets = self.nets.copy()
tasks = self.tasks.copy()
netargs = ([a.arg for a in node.args.args + node.args.kwonlyargs]
+ [node.args.vararg, node.args.kwarg])
copy = True
for a in netargs :
for d in (args, buffers, nets, tasks) :
if a in d :
del d[a]
copy = False
if copy :
return self.copy(node)
else :
return self.__class__(args, buffers, nets, tasks).visit(node)
if __name__ == "__main__" :
import doctest
doctest.testmod()