1.1 --- a/translator.py Wed Aug 30 01:49:28 2023 +0200
1.2 +++ b/translator.py Fri Sep 01 22:46:09 2023 +0200
1.3 @@ -1314,7 +1314,7 @@
1.4 # Start with result target and context arguments for each invocation.
1.5
1.6 args = [result_target, context_arg]
1.7 - argstart = 2
1.8 + reserved_args = 2
1.9
1.10 # Complete the array with null values, permitting tests for a complete
1.11 # set of arguments.
1.12 @@ -1366,7 +1366,7 @@
1.13 except ValueError:
1.14 raise TranslateError("Argument %s is not recognised." % arg.name,
1.15 self.get_namespace_path(), n)
1.16 - args[argnum+argstart] = argexprstr
1.17 + args[argnum + reserved_args] = argexprstr
1.18
1.19 # Otherwise, store the details in a separate collection.
1.20
1.21 @@ -1380,7 +1380,7 @@
1.22
1.23 else:
1.24 try:
1.25 - args[i+argstart] = argexprstr
1.26 + args[i + reserved_args] = argexprstr
1.27 except IndexError:
1.28 raise TranslateError("Too many arguments specified.",
1.29 self.get_namespace_path(), n)
1.30 @@ -1404,8 +1404,8 @@
1.31
1.32 for i, (argname, default) in enumerate(function_defaults):
1.33 argnum = parameters.index(argname)
1.34 - if not args[argnum+argstart]:
1.35 - args[argnum+argstart] = "__GETDEFAULT(%s, %d)" % (target_structure, i)
1.36 + if not args[argnum + reserved_args]:
1.37 + args[argnum + reserved_args] = "__GETDEFAULT(%s, %d)" % (target_structure, i)
1.38
1.39 elif known_parameters:
1.40
1.41 @@ -1416,7 +1416,7 @@
1.42 i = len(n.args)
1.43 pos = i - (num_parameters - num_defaults)
1.44 while i < num_parameters:
1.45 - args[i+argstart] = "__GETDEFAULT(%s.value, %d)" % (target_var, pos)
1.46 + args[i + reserved_args] = "__GETDEFAULT(%s.value, %d)" % (target_var, pos)
1.47 i += 1
1.48 pos += 1
1.49
1.50 @@ -1432,7 +1432,7 @@
1.51 # the number of values. The result target and context are excluded.
1.52
1.53 if literal_instantiation:
1.54 - argstr = "%d, %s" % (len(args) - 2, ", ".join(args[2:]))
1.55 + argstr = "%d, %s" % (len(args) - reserved_args, ", ".join(args[reserved_args:]))
1.56 else:
1.57 argstr = ", ".join(args)
1.58
1.59 @@ -1670,7 +1670,8 @@
1.60 # function names to references.
1.61
1.62 elif n.name.startswith("$L") or n.name.startswith("$op") or \
1.63 - n.name.startswith("$seq") or n.name.startswith("$print"):
1.64 + n.name.startswith("$seq") or n.name.startswith("$print") or \
1.65 + n.name == "$loop_exit":
1.66
1.67 ref, paths = self.importer.get_module(self.name).special[n.name]
1.68 return TrResolvedNameRef(n.name, ref)
1.69 @@ -1800,7 +1801,7 @@
1.70 else:
1.71 exc = self.process_structure_node(n.expr1)
1.72
1.73 - if isinstance(exc, TrInstanceRef):
1.74 + if isinstance(exc, TrInstanceRef) or exc.is_well_defined_instance():
1.75 self.writestmt("__Raise(%s);" % exc)
1.76 else:
1.77 self.writestmt("__Raise(__ensure_instance(%s));" % exc)