[pypy-svn] r7005 - in pypy/trunk/src/pypy/translator: . tool tool/pygame
arigo at codespeak.net
arigo at codespeak.net
Mon Oct 18 14:01:38 CEST 2004
Author: arigo
Date: Mon Oct 18 14:01:37 2004
New Revision: 7005
Modified:
pypy/trunk/src/pypy/translator/genc.h
pypy/trunk/src/pypy/translator/tool/make_dot.py
pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py
pypy/trunk/src/pypy/translator/tool/pygame/graphdisplay.py
Log:
Code reformatting.
Added multicolor blocks in flow graphs for the upcoming graph transformation
tools.
Modified: pypy/trunk/src/pypy/translator/genc.h
==============================================================================
--- pypy/trunk/src/pypy/translator/genc.h (original)
+++ pypy/trunk/src/pypy/translator/genc.h Mon Oct 18 14:01:37 2004
@@ -221,63 +221,59 @@
/* for Python 2.2 only */
static PyObject* PyObject_GetItem1(PyObject* obj, PyObject* index)
{
- int start, stop, step;
- if (!PySlice_Check(index))
- return PyObject_GetItem(obj, index);
- if (((PySliceObject*) index)->start == Py_None)
- start = -INT_MAX-1;
- else
- {
- start = PyInt_AsLong(((PySliceObject*) index)->start);
- if (start == -1 && PyErr_Occurred()) return NULL;
- }
- if (((PySliceObject*) index)->stop == Py_None)
- stop = INT_MAX;
- else
- {
- stop = PyInt_AsLong(((PySliceObject*) index)->stop);
- if (stop == -1 && PyErr_Occurred()) return NULL;
- }
- if (((PySliceObject*) index)->step != Py_None)
- {
- step = PyInt_AsLong(((PySliceObject*) index)->step);
- if (step == -1 && PyErr_Occurred()) return NULL;
- if (step != 1) {
- PyErr_SetString(PyExc_ValueError, "obj[slice]: no step allowed");
- return NULL;
- }
- }
- return PySequence_GetSlice(obj, start, stop);
+ int start, stop, step;
+ if (!PySlice_Check(index))
+ return PyObject_GetItem(obj, index);
+ if (((PySliceObject*) index)->start == Py_None)
+ start = -INT_MAX-1;
+ else {
+ start = PyInt_AsLong(((PySliceObject*) index)->start);
+ if (start == -1 && PyErr_Occurred()) return NULL;
+ }
+ if (((PySliceObject*) index)->stop == Py_None)
+ stop = INT_MAX;
+ else {
+ stop = PyInt_AsLong(((PySliceObject*) index)->stop);
+ if (stop == -1 && PyErr_Occurred()) return NULL;
+ }
+ if (((PySliceObject*) index)->step != Py_None) {
+ step = PyInt_AsLong(((PySliceObject*) index)->step);
+ if (step == -1 && PyErr_Occurred()) return NULL;
+ if (step != 1) {
+ PyErr_SetString(PyExc_ValueError,
+ "obj[slice]: no step allowed");
+ return NULL;
+ }
+ }
+ return PySequence_GetSlice(obj, start, stop);
}
static PyObject* PyObject_SetItem1(PyObject* obj, PyObject* index, PyObject* v)
{
- int start, stop, step;
- if (!PySlice_Check(index))
- return PyObject_SetItem(obj, index, v);
- if (((PySliceObject*) index)->start == Py_None)
- start = -INT_MAX-1;
- else
- {
- start = PyInt_AsLong(((PySliceObject*) index)->start);
- if (start == -1 && PyErr_Occurred()) return NULL;
- }
- if (((PySliceObject*) index)->stop == Py_None)
- stop = INT_MAX;
- else
- {
- stop = PyInt_AsLong(((PySliceObject*) index)->stop);
- if (stop == -1 && PyErr_Occurred()) return NULL;
- }
- if (((PySliceObject*) index)->step != Py_None)
- {
- step = PyInt_AsLong(((PySliceObject*) index)->step);
- if (step == -1 && PyErr_Occurred()) return NULL;
- if (step != 1) {
- PyErr_SetString(PyExc_ValueError, "obj[slice]: no step allowed");
- return NULL;
- }
- }
- return PySequence_SetSlice(obj, start, stop, v);
+ int start, stop, step;
+ if (!PySlice_Check(index))
+ return PyObject_SetItem(obj, index, v);
+ if (((PySliceObject*) index)->start == Py_None)
+ start = -INT_MAX-1;
+ else {
+ start = PyInt_AsLong(((PySliceObject*) index)->start);
+ if (start == -1 && PyErr_Occurred()) return NULL;
+ }
+ if (((PySliceObject*) index)->stop == Py_None)
+ stop = INT_MAX;
+ else {
+ stop = PyInt_AsLong(((PySliceObject*) index)->stop);
+ if (stop == -1 && PyErr_Occurred()) return NULL;
+ }
+ if (((PySliceObject*) index)->step != Py_None) {
+ step = PyInt_AsLong(((PySliceObject*) index)->step);
+ if (step == -1 && PyErr_Occurred()) return NULL;
+ if (step != 1) {
+ PyErr_SetString(PyExc_ValueError,
+ "obj[slice]: no step allowed");
+ return NULL;
+ }
+ }
+ return PySequence_SetSlice(obj, start, stop, v);
}
#endif
Modified: pypy/trunk/src/pypy/translator/tool/make_dot.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/make_dot.py (original)
+++ pypy/trunk/src/pypy/translator/tool/make_dot.py Mon Oct 18 14:01:37 2004
@@ -110,7 +110,7 @@
lines.append("")
numblocks = len(block.exits)
color = "black"
- fillcolor = "white"
+ fillcolor = getattr(block, "fillcolor", "white")
if not numblocks:
shape = "box"
fillcolor="green"
Modified: pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py (original)
+++ pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py Mon Oct 18 14:01:37 2004
@@ -19,6 +19,14 @@
}
re_nonword=re.compile(r'(\W+)')
+def getcolor(name, default):
+ if name in COLOR:
+ return COLOR[name]
+ elif name.startswith('#') and len(name) == 7:
+ return (int(name[1:3],16), int(name[3:5],16), int(name[5:7],16))
+ else:
+ return default
+
class GraphLayout:
@@ -233,8 +241,8 @@
xcenter, ycenter = self.map(node.x, node.y)
boxwidth = int(node.w * self.scale)
boxheight = int(node.h * self.scale)
- fgcolor = COLOR.get(node.color, (0,0,0))
- bgcolor = COLOR.get(node.fillcolor, (255,255,255))
+ fgcolor = getcolor(node.color, (0,0,0))
+ bgcolor = getcolor(node.fillcolor, (255,255,255))
text = node.label
lines = text.replace('\l','\l\n').replace('\r','\r\n').split('\n')
@@ -307,7 +315,7 @@
edgebodycmd = []
edgeheadcmd = []
for edge in self.graphlayout.edges:
- fgcolor = COLOR.get(edge.color, (0,0,0))
+ fgcolor = getcolor(edge.color, (0,0,0))
points = [self.map(*xy) for xy in edge.bezierpoints()]
def drawedgebody(points=points, fgcolor=fgcolor):
Modified: pypy/trunk/src/pypy/translator/tool/pygame/graphdisplay.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/pygame/graphdisplay.py (original)
+++ pypy/trunk/src/pypy/translator/tool/pygame/graphdisplay.py Mon Oct 18 14:01:37 2004
@@ -114,7 +114,10 @@
else:
edge = self.viewer.edge_at_position(pos)
if edge:
- if not self.look_at_node(edge.head):
+ if (self.distance_to_node(edge.head) >=
+ self.distance_to_node(edge.tail)):
+ self.look_at_node(edge.head)
+ else:
self.look_at_node(edge.tail)
def sethighlight(self, word=None):
@@ -139,6 +142,11 @@
self.ANIM_STEP = self.ANIM_STEP * 0.9 + frametime * 0.1
yield 1.0
+ def distance_to_node(self, node):
+ cx1, cy1 = self.viewer.getcenter()
+ cx2, cy2 = node.x, node.y
+ return (cx2-cx1)*(cx2-cx1) + (cy2-cy1)*(cy2-cy1)
+
def look_at_node(self, node):
"""Shift the node in view."""
endscale = min(float(self.width-40) / node.w,
More information about the Pypy-commit
mailing list