1.1 --- a/encoders.py Wed Oct 12 00:05:08 2016 +0200
1.2 +++ b/encoders.py Wed Oct 12 18:07:48 2016 +0200
1.3 @@ -138,6 +138,33 @@
1.4
1.5
1.6
1.7 +# Instruction representation encoding.
1.8 +
1.9 +def encode_instruction(instruction):
1.10 +
1.11 + """
1.12 + Encode the 'instruction' - a sequence starting with an operation and
1.13 + followed by arguments, each of which may be an instruction sequence or a
1.14 + plain value - to produce a function call string representation.
1.15 + """
1.16 +
1.17 + op = instruction[0]
1.18 + args = instruction[1:]
1.19 +
1.20 + if args:
1.21 + a = []
1.22 + for i in args:
1.23 + if isinstance(i, tuple):
1.24 + a.append(encode_instruction(i))
1.25 + else:
1.26 + a.append(i or "{}")
1.27 + argstr = "(%s)" % ", ".join(a)
1.28 + return "%s%s" % (op, argstr)
1.29 + else:
1.30 + return op
1.31 +
1.32 +
1.33 +
1.34 # Output program encoding.
1.35
1.36 def encode_function_pointer(path):