Skip to content

Commit

Permalink
Merge pull request #2 from thenaterhood/develop
Browse files Browse the repository at this point in the history
Fix classes to work with Python 2.7
  • Loading branch information
thenaterhood authored Sep 22, 2016
2 parents 1770d70 + e83c662 commit 2cadb1b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/basically_ti_basic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def compile_file(inputfile, outputfile):
for line in f:
file_lines.append(line)

compiled_file = PrgmCompiler.compile(file_lines)
compiler = PrgmCompiler()
compiled_file = compiler.compile(file_lines)
if outputfile == "stdout":
print("".join(compiled_file.prgmdata))
else:
Expand All @@ -18,7 +19,8 @@ def compile_file(inputfile, outputfile):
def decompile_file(inputfile, outputfile):
tifile = TIPrgmFile(inputfile)

decompiled = PrgmCompiler.decompile(tifile)
compiler = PrgmCompiler()
decompiled = compiler.decompile(tifile)
if outputfile == 'stdout':
print("\n".join(decompiled))
else:
Expand Down
21 changes: 19 additions & 2 deletions src/basically_ti_basic/compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PrgmCompiler(object):
program files
"""

def compile(raw_text):
def compile(self, raw_text=None):
"""
Compiles to 8Xp format. This logic works, but the TIFile class is
incomplete so the file may not work properly on the TI calculator.
Expand All @@ -18,6 +18,14 @@ def compile(raw_text):
Returns:
TIFile
"""
# To be compatible with Python 2.7 without changing
# the public class API, we do some gross magic. This
# has a side effect that we can use this method either
# as a static method or not.
# FIXME
if not isinstance(self, PrgmCompiler):
raw_text = self

tifile = TIPrgmFile()
tifile.prgmdata = []
tokens = get_inverse_tokens()
Expand Down Expand Up @@ -45,7 +53,7 @@ def compile(raw_text):
return tifile


def decompile(tifile):
def decompile(self, tifile=None):
"""
Decompiles to plaintext.
Expand All @@ -54,6 +62,15 @@ def decompile(tifile):
Returns:
Array[string]
"""

# To be compatible with Python 2.7 without changing
# the public class API, we do some gross magic. This
# has a side effect that we can use this method either
# as a static method or not.
# FIXME
if not isinstance(self, PrgmCompiler):
tifile = self

prgm_data = tifile.prgmdata
plaintext = []
tokens = get_tokens()
Expand Down

0 comments on commit 2cadb1b

Please sign in to comment.