Skip to content

Commit e83c662

Browse files
committed
Fix classes to work with Python 2.7
1 parent 1770d70 commit e83c662

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

Diff for: src/basically_ti_basic/__main__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ def compile_file(inputfile, outputfile):
99
for line in f:
1010
file_lines.append(line)
1111

12-
compiled_file = PrgmCompiler.compile(file_lines)
12+
compiler = PrgmCompiler()
13+
compiled_file = compiler.compile(file_lines)
1314
if outputfile == "stdout":
1415
print("".join(compiled_file.prgmdata))
1516
else:
@@ -18,7 +19,8 @@ def compile_file(inputfile, outputfile):
1819
def decompile_file(inputfile, outputfile):
1920
tifile = TIPrgmFile(inputfile)
2021

21-
decompiled = PrgmCompiler.decompile(tifile)
22+
compiler = PrgmCompiler()
23+
decompiled = compiler.decompile(tifile)
2224
if outputfile == 'stdout':
2325
print("\n".join(decompiled))
2426
else:

Diff for: src/basically_ti_basic/compiler/__init__.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class PrgmCompiler(object):
88
program files
99
"""
1010

11-
def compile(raw_text):
11+
def compile(self, raw_text=None):
1212
"""
1313
Compiles to 8Xp format. This logic works, but the TIFile class is
1414
incomplete so the file may not work properly on the TI calculator.
@@ -18,6 +18,14 @@ def compile(raw_text):
1818
Returns:
1919
TIFile
2020
"""
21+
# To be compatible with Python 2.7 without changing
22+
# the public class API, we do some gross magic. This
23+
# has a side effect that we can use this method either
24+
# as a static method or not.
25+
# FIXME
26+
if not isinstance(self, PrgmCompiler):
27+
raw_text = self
28+
2129
tifile = TIPrgmFile()
2230
tifile.prgmdata = []
2331
tokens = get_inverse_tokens()
@@ -45,7 +53,7 @@ def compile(raw_text):
4553
return tifile
4654

4755

48-
def decompile(tifile):
56+
def decompile(self, tifile=None):
4957
"""
5058
Decompiles to plaintext.
5159
@@ -54,6 +62,15 @@ def decompile(tifile):
5462
Returns:
5563
Array[string]
5664
"""
65+
66+
# To be compatible with Python 2.7 without changing
67+
# the public class API, we do some gross magic. This
68+
# has a side effect that we can use this method either
69+
# as a static method or not.
70+
# FIXME
71+
if not isinstance(self, PrgmCompiler):
72+
tifile = self
73+
5774
prgm_data = tifile.prgmdata
5875
plaintext = []
5976
tokens = get_tokens()

0 commit comments

Comments
 (0)