Commit 6f2be4d5 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Some simple, very-ugly hacks for "supporting" long and unicode literals

Just convert them to ints and strings, failing if the conversion isn't possible.
Unicode and str are the same thing, right? :/
parent 98b9cd2d
......@@ -113,6 +113,9 @@ def convert(n, f):
if isinstance(n, _ast.Num):
if isinstance(n.n, int):
f.write('\x10')
elif isinstance(n.n, long):
assert (-1L<<60) < n.n < (1L<<60)
f.write('\x10')
elif isinstance(n.n, float):
f.write('\x20')
else:
......@@ -140,10 +143,18 @@ def convert(n, f):
convert(el, f)
elif isinstance(v, str):
_print_str(v, f)
elif isinstance(v, unicode):
print >>sys.stderr, "Warning, converting unicode string to str!"
sys.stderr.flush()
_print_str(v.encode("ascii"), f)
elif isinstance(v, bool):
f.write(struct.pack("B", v))
elif isinstance(v, int):
f.write(struct.pack(">q", v))
elif isinstance(v, long):
assert (-1L<<60) < v < (1L<<60)
print >>sys.stderr, "Warning, converting long to int!"
f.write(struct.pack(">q", v))
elif isinstance(v, float):
f.write(struct.pack(">d", v))
elif v is None or isinstance(v, _ast.AST):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment