From: Tero K. <te...@us...> - 2005-08-19 00:13:27
|
Update of /cvsroot/openexvis/openexvis In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8769 Modified Files: ChangeLog oevt_python.py openexvis.py visualizer.py Log Message: First steps towards supporting visualization of program structure. Some fixes. Index: oevt_python.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/oevt_python.py,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- oevt_python.py 17 Aug 2005 00:28:45 -0000 1.12 +++ oevt_python.py 18 Aug 2005 15:11:39 -0000 1.13 @@ -52,12 +52,15 @@ # Remove the line number from the data and store it at the beginning of # the visualization commands. viscommands = str(data.pop(0)) + ';' - # In the following, the first list item tells the variable name. If the - # first item is None, it means the value is a constant. The second item - # is the actual value. + # In the following, the first list item tells the variable name. + # If the first item is None, it means the value is a constant. If it's + # oev_function, the value is a function name. + # The second item is the actual value. lastvals = [] # Last loaded values for op in data: - print "DEBUG: op == ", op + #print "DEBUG: lastvals == ", lastvals + #print "DEBUG: variables == ", self.variables + #print "DEBUG: op == ", op if op['opcode'] == 'LOAD_CONST': # Loading a constant. @@ -66,24 +69,41 @@ const = split[2] else: const = op['oparg2'] + if const[0] == "'" and const[-1] == "'": + const = const[1:-1] viscommands += 'GET_CONSTANT:' + const + ';' # Load the given constant to lastval. lastvals.append(['None', const]) - elif op['opcode'] == 'STORE_NAME' or op['opcode'] == 'STORE_ATTR': + elif op['opcode'] == 'STORE_NAME' or op['opcode'] == 'STORE_ATTR' \ + or op['opcode'] == 'STORE_GLOBAL': # Storing the last constant in the given variable. var = op['oparg2'] const_name, const_value = lastvals.pop() + if const_name == 'oev_function': + self.variables[const_value] = const_value + viscommands += 'SHOW_FUNCTION:' + const_value + ';' + continue if self.variables.has_key(var): tmp = self.variables[var] v = [const_value, tmp[0]] else: v = [const_value, ''] self.variables[var] = v - print "DEBUG: variables == ", self.variables viscommands += 'STORE_VARIABLE:' + var + ':' + \ str(v[0]) + ':' + str(v[1]) + ':' + const_name + ';' + elif op['opcode'] == 'MAKE_FUNCTION': + tmp, name = lastvals.pop() + lastvals.append(['oev_function', name]) + + elif op['opcode'] == 'CALL_FUNCTION': + func, name = lastvals.pop() + if func == 'oev_function': + viscommands += 'CREATE_FUNCTION:' + name + ';' + else: + print "Expected a function for CALL_FUNCTION!" + elif op['opcode'] == 'SETUP_LOOP': viscommands += 'BEGIN_LOOP;' @@ -120,12 +140,24 @@ lastvals.append(['eval_result', sum]) elif op['opcode'] == 'BUILD_TUPLE': + if int(op['oparg1']) < 1: + # XXX I'm not sure what to do, but this works reasonably + # well. + continue tail = [] + t = () loops = range(int(op['oparg1'])) for i in loops: - tail.insert(0, lastvals.pop()) + tail.append(lastvals.pop()) for i in loops: - lastvals.append(tail.pop()) + item = tail.pop(), + t = t + item + lastvals.append(t) + + elif op['opcode'] == 'UNPACK_SEQUENCE': + sequence = lastvals.pop() + for i in range(int(op['oparg1'])): + lastvals.append(sequence[-(i+1)]) elif op['opcode'] == 'PRINT_ITEM': name, output = lastvals.pop() Index: openexvis.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/openexvis.py,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- openexvis.py 17 Aug 2005 00:39:43 -0000 1.21 +++ openexvis.py 18 Aug 2005 15:11:39 -0000 1.22 @@ -233,6 +233,10 @@ continue self.draw_show_storing(cmd[1], cmd[2], cmd[3]) + elif cmd[0] == 'SHOW_FUNCTION': + # cmd[1] is the function name. + self.draw_show_function(cmd[1]) + elif cmd[0] == 'SHOW_COMPARISON': # cmd[1] is the comparison sign (==,<,>) # cmd[2] is the variable on the left side of the comparison or @@ -367,6 +371,11 @@ self.vis_steps.append(['oev_delay_pm', self.vis_split_x, \ self.gridh * steps]) + def draw_show_function(self, function): + """Store displaying a function to self.vis_steps.""" + self.vis_steps.append(['const_' + function, self.gridw, self.gridh]) + self.draw_delay(5) + def draw_show_output(self, output, source): """Store drawing an output to self.vis_steps.""" if source == 'None': Index: visualizer.py =================================================================== RCS file: /cvsroot/openexvis/openexvis/visualizer.py,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- visualizer.py 16 Aug 2005 23:14:37 -0000 1.12 +++ visualizer.py 18 Aug 2005 15:11:39 -0000 1.13 @@ -79,25 +79,31 @@ if not cur_vars.has_key(c[1]): cur_vars[c[1]] = [c[2], c[3]] cmd.append(['SHOW_VARIABLES', cur_vars]) + elif c[0] == 'SHOW_FUNCTION': + # c[1] is the function name. + cmd.append(['SHOW_FUNCTION', c[1]]) + elif c[0] == 'CREATE_FUNCTION': + # c[1] is the function name. + cmd.append(['SHOW_FUNCTION', c[1]]) elif c[0] == 'BEGIN_LOOP': cmd.append(['SHOW_LOOP']) elif c[0] == 'COMPARE': # c[1] is the sign of the comparison. - # cmd[2] is the variable on the left side of the comparison or + # c[2] is the variable on the left side of the comparison or # None if the value is a constant. - # cmd[3] is the value of the left side of the comparison. - # cmd[4] is the variable on the right side of the comparison or + # c[3] is the value of the left side of the comparison. + # c[4] is the variable on the right side of the comparison or # None if the value is a constant. - # cmd[5] is the value of the right side of the comparison. + # c[5] is the value of the right side of the comparison. cmd.append(['SHOW_COMPARISON', c[1], c[2], c[3], c[4], c[5]]) elif c[0] == 'SHOW_INT_OPERATION': # c[1] is the sign of the operation. - # cmd[2] is the variable on the left side of the operation or + # c[2] is the variable on the left side of the operation or # None if the value is a constant. - # cmd[3] is the value of the left side of the operation. - # cmd[4] is the variable on the right side of the operation or + # c[3] is the value of the left side of the operation. + # c[4] is the variable on the right side of the operation or # None if the value is a constant. - # cmd[5] is the value of the right side of the operation. + # c[5] is the value of the right side of the operation. cmd.append(['SHOW_OPERATION', c[1], c[2], int(c[3]), \ c[4], int(c[5])]) elif c[0] == 'OUTPUT': Index: ChangeLog =================================================================== RCS file: /cvsroot/openexvis/openexvis/ChangeLog,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- ChangeLog 17 Aug 2005 00:39:43 -0000 1.15 +++ ChangeLog 18 Aug 2005 15:11:39 -0000 1.16 @@ -5,9 +5,14 @@ * Internal restructuring * Improve the animation a lot + * First step to support visualizing the structure of a program + * Support new byte codes in Python translator + + BUILD_TUPLE + + UNPACK_SEQUENCE + + MAKE_FUNCTION + + CALL_FUNCTION * Constants to move now leave from the position of the corresponding static constant - * Support BUILD_TUPLE in Python translator * Moving items to output is now visualized * Storing to variable from evaluation result now better visualized * Draw elements in more intelligent order |