1.1 --- a/bytecode.py Sun Nov 14 00:44:54 2004 +0100
1.2 +++ b/bytecode.py Sun Nov 14 01:02:55 2004 +0100
1.3 @@ -1766,10 +1766,10 @@
1.4 # NOTE: The code below should use dictionary-based dispatch for better performance.
1.5 program.load_fast(1) # Stack: arguments
1.6 for method, fn in methods:
1.7 + program.setup_loop()
1.8 program.dup_top() # Stack: arguments, arguments
1.9 - program.load_const(1)
1.10 - program.store_fast(2) # found = 1
1.11 - program.setup_loop()
1.12 + program.load_const(1) # Stack: arguments, arguments, 1
1.13 + program.store_fast(2) # Stack: arguments, arguments (found = 1)
1.14 # Emit a list of parameter types.
1.15 descriptor_types = method.get_descriptor()[0]
1.16 for descriptor_type in descriptor_types:
1.17 @@ -1778,84 +1778,83 @@
1.18 if python_type == "instance":
1.19 # NOTE: This will need extending.
1.20 python_type = object_type
1.21 - program.load_global(python_type) # Stack: arguments, type, ...
1.22 + program.load_global(python_type) # Stack: arguments, arguments, type, ...
1.23 program.build_list(len(descriptor_types))
1.24 - # Stack: arguments, types
1.25 + # Stack: arguments, arguments, types
1.26 # Make a map of arguments and types.
1.27 - program.load_const(None) # Stack: arguments, types, None
1.28 - program.rot_three() # Stack: None, arguments, types
1.29 - program.build_tuple(3) # Stack: tuple
1.30 - program.load_global("map") # Stack: tuple, map
1.31 - program.rot_two() # Stack: map, tuple
1.32 - program.load_global("apply") # Stack: map, tuple, apply
1.33 - program.rot_three() # Stack: apply, map, tuple
1.34 - program.call_function(2) # Stack: tuple (mapping arguments to types)
1.35 + program.load_const(None) # Stack: arguments, arguments, types, None
1.36 + program.rot_three() # Stack: arguments, None, arguments, types
1.37 + program.build_tuple(3) # Stack: arguments, tuple
1.38 + program.load_global("map") # Stack: arguments, tuple, map
1.39 + program.rot_two() # Stack: arguments, map, tuple
1.40 + program.load_global("apply") # Stack: arguments, map, tuple, apply
1.41 + program.rot_three() # Stack: arguments, apply, map, tuple
1.42 + program.call_function(2) # Stack: arguments, list (mapping arguments to types)
1.43 # Loop over each pair.
1.44 - program.get_iter() # Stack: iter
1.45 - program.for_iter() # Stack: iter, (argument, type)
1.46 - program.unpack_sequence(2) # Stack: iter, type, argument
1.47 - program.dup_top() # Stack: iter, type, argument, argument
1.48 - program.load_const(None) # Stack: iter, type, argument, argument, None
1.49 - program.compare_op("is") # Stack: iter, type, argument, result
1.50 + program.get_iter() # Stack: arguments, iter
1.51 + program.for_iter() # Stack: arguments, iter, (argument, type)
1.52 + program.unpack_sequence(2) # Stack: arguments, iter, type, argument
1.53 + program.dup_top() # Stack: arguments, iter, type, argument, argument
1.54 + program.load_const(None) # Stack: arguments, iter, type, argument, argument, None
1.55 + program.compare_op("is") # Stack: arguments, iter, type, argument, result
1.56 # Missing argument?
1.57 program.jump_to_label(0, "present")
1.58 - program.pop_top() # Stack: iter, type, argument
1.59 - program.pop_top() # Stack: iter, type
1.60 - program.pop_top() # Stack: iter
1.61 - program.load_const(0)
1.62 - program.store_fast(2) # found = 0
1.63 + program.pop_top() # Stack: arguments, iter, type, argument
1.64 + program.pop_top() # Stack: arguments, iter, type
1.65 + program.pop_top() # Stack: arguments, iter
1.66 + program.load_const(0) # Stack: arguments, iter, 0
1.67 + program.store_fast(2) # Stack: arguments, iter (found = 0)
1.68 program.break_loop()
1.69 # Argument was present.
1.70 program.start_label("present")
1.71 - program.pop_top() # Stack: iter, type, argument
1.72 - program.rot_two() # Stack: iter, argument, type
1.73 - program.dup_top() # Stack: iter, argument, type, type
1.74 - program.load_const(None) # Stack: iter, argument, type, type, None
1.75 - program.compare_op("is") # Stack: iter, argument, type, result
1.76 + program.pop_top() # Stack: arguments, iter, type, argument
1.77 + program.rot_two() # Stack: arguments, iter, argument, type
1.78 + program.dup_top() # Stack: arguments, iter, argument, type, type
1.79 + program.load_const(None) # Stack: arguments, iter, argument, type, type, None
1.80 + program.compare_op("is") # Stack: arguments, iter, argument, type, result
1.81 # Missing parameter type?
1.82 program.jump_to_label(0, "present")
1.83 - program.pop_top() # Stack: iter, argument, type
1.84 - program.pop_top() # Stack: iter, argument
1.85 - program.pop_top() # Stack: iter
1.86 - program.load_const(0)
1.87 - program.store_fast(2) # found = 0
1.88 + program.pop_top() # Stack: arguments, iter, argument, type
1.89 + program.pop_top() # Stack: arguments, iter, argument
1.90 + program.pop_top() # Stack: arguments, iter
1.91 + program.load_const(0) # Stack: arguments, iter, 0
1.92 + program.store_fast(2) # Stack: arguments, iter (found = 0)
1.93 program.break_loop()
1.94 # Parameter was present.
1.95 program.start_label("present")
1.96 - program.pop_top() # Stack: iter, argument, type
1.97 - program.build_tuple(2) # Stack: iter, (argument, type)
1.98 - program.load_global("isinstance") # Stack: iter, (argument, type), isinstance
1.99 - program.rot_two() # Stack: iter, isinstance, (argument, type)
1.100 - program.load_global("apply") # Stack: iter, isinstance, (argument, type), apply
1.101 - program.rot_three() # Stack: iter, apply, isinstance, (argument, type)
1.102 - program.call_function(2) # Stack: iter, result
1.103 + program.pop_top() # Stack: arguments, iter, argument, type
1.104 + program.build_tuple(2) # Stack: arguments, iter, (argument, type)
1.105 + program.load_global("isinstance") # Stack: arguments, iter, (argument, type), isinstance
1.106 + program.rot_two() # Stack: arguments, iter, isinstance, (argument, type)
1.107 + program.load_global("apply") # Stack: arguments, iter, isinstance, (argument, type), apply
1.108 + program.rot_three() # Stack: arguments, iter, apply, isinstance, (argument, type)
1.109 + program.call_function(2) # Stack: arguments, iter, result
1.110 program.jump_to_label(1, "match")
1.111 - program.pop_top() # Stack: iter
1.112 - program.load_const(0)
1.113 - program.store_fast(2) # found = 0
1.114 + program.pop_top() # Stack: arguments, iter
1.115 + program.load_const(0) # Stack: arguments, iter, 0
1.116 + program.store_fast(2) # Stack: arguments, iter (found = 0)
1.117 program.break_loop()
1.118 # Argument type and parameter type matched.
1.119 program.start_label("match")
1.120 - program.pop_top() # Stack: iter
1.121 - program.end_loop() # Stack: iter
1.122 + program.pop_top() # Stack: arguments, iter
1.123 + program.end_loop() # Stack: arguments
1.124 # If all the parameters matched, call the method.
1.125 - program.load_fast(2) # Stack: iter, match
1.126 + program.load_fast(2) # Stack: arguments, match
1.127 program.jump_to_label(0, "failed")
1.128 # All the parameters matched.
1.129 - program.pop_top() # Stack: iter
1.130 - program.load_fast(1) # Stack: arguments
1.131 - program.load_fast(0) # Stack: arguments, self
1.132 + program.pop_top() # Stack: arguments
1.133 + program.dup_top() # Stack: arguments, arguments
1.134 + program.load_fast(0) # Stack: arguments, arguments, self
1.135 program.load_attr(str(method.get_python_name()))
1.136 - # Stack: arguments, method
1.137 - program.rot_two() # Stack: method, arguments
1.138 - program.load_global("apply") # Stack: method, arguments, apply
1.139 - program.rot_three() # Stack: apply, method, arguments
1.140 - program.call_function(2) # Stack: result
1.141 + # Stack: arguments, arguments, method
1.142 + program.rot_two() # Stack: arguments, method, arguments
1.143 + program.load_global("apply") # Stack: arguments, method, arguments, apply
1.144 + program.rot_three() # Stack: arguments, apply, method, arguments
1.145 + program.call_function(2) # Stack: arguments, result
1.146 program.return_value()
1.147 # Try the next method if arguments or parameters were missing or incorrect.
1.148 program.start_label("failed")
1.149 - program.pop_top() # Stack: iter
1.150 - program.pop_top() # Stack:
1.151 + program.pop_top() # Stack: arguments
1.152 # Raise an exception if nothing matched.
1.153 # NOTE: Improve this.
1.154 program.load_const("No matching method")