1.1 --- a/simplify/generator.py Tue Aug 14 00:35:48 2007 +0200
1.2 +++ b/simplify/generator.py Tue Aug 14 00:36:41 2007 +0200
1.3 @@ -103,17 +103,39 @@
1.4 # NOTE: consumption as parameters.
1.5
1.6 for subprogram in invoke.invocations:
1.7 + consumed_args = invoke.consumed_args[subprogram]
1.8
1.9 # NOTE: Generate switch table.
1.10
1.11 - # Reserve the namespace.
1.12 + # Save the current frame.
1.13 +
1.14 + sub.add("SCF")
1.15 +
1.16 + # Extend the stack for the arguments.
1.17 +
1.18 + nparams = len(consumed_args)
1.19 + if not invoke.share_locals:
1.20 + sub.add("ESF", nparams)
1.21 +
1.22 + # For each argument, evaluate the expression.
1.23
1.24 - params = subprogram.paramtypes.keys()
1.25 - nparams = len(params)
1.26 - if not invoke.share_locals:
1.27 + for arg in invoke.args:
1.28 + if arg is None:
1.29 + continue
1.30 +
1.31 + self.dispatch(arg)
1.32 +
1.33 + # Then, save the argument to the correct part of the arguments
1.34 + # frame.
1.35 +
1.36 + pos = self.arg_position(consumed_args, arg)
1.37 + sub.add("MVA", pos)
1.38 +
1.39 + # Reserve the namespace.
1.40 +
1.41 sub.add("NSF", nparams)
1.42
1.43 - sub.add("JAS", subprogram.full_name())
1.44 + sub.add("JAS", "sub$%s$%s" % (subprogram.module.name, subprogram.full_name()))
1.45
1.46 if not invoke.share_locals:
1.47 sub.add("PSF") # previous stack frame
1.48 @@ -156,6 +178,17 @@
1.49 self.current_assemblers.pop()
1.50 self.assemblers.append(sub)
1.51
1.52 + def arg_position(self, consumed_args, arg):
1.53 +
1.54 + """
1.55 + Return, for the specified 'consumed_args', the position of 'arg' in the
1.56 + list, handling keyword arguments appropriately.
1.57 + """
1.58 +
1.59 + if isinstance(arg, Keyword):
1.60 + arg = arg.expr
1.61 + return consumed_args.index(arg)
1.62 +
1.63 # Convenience functions.
1.64
1.65 def generate(module):