Skip to content

Commit

Permalink
add turbo draw option
Browse files Browse the repository at this point in the history
  • Loading branch information
TabulateJarl8 committed Jul 8, 2021
1 parent 019b907 commit 2b827e6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ optional arguments:
Do not attempt to fix implicit multiplication. For example, AB -> A*B and A(1) -> A*(1)
--no-fix-floating-point
Do not attempt to fix floating point arithmetic errors. For example, 1.1 * 3 would normally say 3.3000000000000003 instead of 3.3
--turbo-draw Remove the 0.1 second delay between drawing actions
-r, --run Runs the program after it's done transpiling. Will not print to stdout
-V, --version show program's version number and exit
```
Expand All @@ -87,7 +88,7 @@ from ti842py import transpile

transpile("tiprogram.txt", "tiprogram.py")
```
Again, if the second argument is not supplied, the program will be written to `stdout`. The `transpile` command can be supplied with 4 optional arguments, `decompileFile`, `forceDecompile`, `multiplication`, `floating_point`, and `run`. `decompileFile`, `multiplication`, and `floating_point` default to `True`, and `forceDecompile` and `run` default to `False`
Again, if the second argument is not supplied, the program will be written to `stdout`. The `transpile` command can be supplied with optional arguments. `decompileFile`, `multiplication`, and `floating_point` default to `True`, and `forceDecompile`, `run`, and `turbo_draw` default to `False`

The last way that ti842py can be ran is by running the main python file. After cloning the repository, cd into the repository and run `python ti842py/main.py inputfile.txt`. You can supply any arguments that you would supply with the `ti842py` command.

Expand Down
2 changes: 1 addition & 1 deletion ti842py/__version__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__title__ = "ti842py"
__description__ = "TI-BASIC to Python 3 Transpiler"
__url__ = "https://github.com/TabulateJarl8/ti842py"
__version__ = "0.7.2"
__version__ = "0.7.3"
__author__ = "Tabulate"
__author_email__ = "[email protected]"
__license__ = "GPLv3"
Expand Down
14 changes: 10 additions & 4 deletions ti842py/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def isUTF8(file):
return True


def transpile(infile, outfile="stdout", decompileFile=True, forceDecompile=False, multiplication=True, floating_point=True, run=False):
def transpile(infile, outfile="stdout", decompileFile=True, forceDecompile=False, multiplication=True, floating_point=True, turbo_draw=False, run=False):

decode = not isUTF8(infile) and decompileFile is True

Expand All @@ -36,7 +36,7 @@ def transpile(infile, outfile="stdout", decompileFile=True, forceDecompile=False
with tempfile.NamedTemporaryFile() as f:
btb.decompile_file(infile, f.name)
with open(f.name, 'r') as fp:
pythonCode = TIBasicParser([line.strip() for line in fp.readlines()], multiplication, floating_point).toPython()
pythonCode = TIBasicParser([line.strip() for line in fp.readlines()], multiplication, floating_point, turbo_draw).toPython()

else:
# Dont decompile
Expand All @@ -45,7 +45,7 @@ def transpile(infile, outfile="stdout", decompileFile=True, forceDecompile=False
with open(infile, 'r') as f:
file_lines = [line.strip() for line in f.readlines()]

pythonCode = TIBasicParser(file_lines, multiplication, floating_point).toPython()
pythonCode = TIBasicParser(file_lines, multiplication, floating_point, turbo_draw).toPython()

# Write to outfile
if outfile == "stdout":
Expand Down Expand Up @@ -114,6 +114,12 @@ def main():
dest='floating_point'
)

parser.add_argument(
'--turbo-draw',
action='store_true',
help='Remove the 0.1 second delay between drawing actions'
)

parser.add_argument(
'-r',
'--run',
Expand All @@ -130,7 +136,7 @@ def main():
)

args = parser.parse_args()
transpile(args.infile[0], args.outfile, args.n, args.d, args.multiplication, args.floating_point, args.run)
transpile(args.infile[0], args.outfile, args.n, args.d, args.multiplication, args.floating_point, args.turbo_draw, args.run)


if __name__ == "__main__":
Expand Down
6 changes: 5 additions & 1 deletion ti842py/tiParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


class TIBasicParser:
def __init__(self, basic, multiplication, floating_point):
def __init__(self, basic, multiplication, floating_point, turbo_draw):
if isinstance(basic, list):
self.basic = basic
elif isinstance(basic, str):
Expand All @@ -23,6 +23,7 @@ def __init__(self, basic, multiplication, floating_point):

self.multiplication = multiplication
self.floating_point = floating_point
self.turbo_draw = turbo_draw

# Utility Functions
self.UTILS = {"wait": {"code": [""], "imports": ["import time"], "enabled": False}, "menu": {"code": [""], "imports": ["import dialog"], "enabled": False}, "math": {"code": [""], "imports": ["import math"], "enabled": False}, 'random': {'code': [''], 'imports': ['import random'], 'enabled': False}}
Expand All @@ -38,6 +39,9 @@ def __init__(self, basic, multiplication, floating_point):
if self.floating_point:
self.UTILS['fix_floating_point']['enabled'] = True

if self.turbo_draw:
self.UTILS['draw']['code'] = [line for line in self.UTILS['draw']['code'] if '@_slow' not in line]

self.drawLock = False

def convertLine(self, index, line):
Expand Down

0 comments on commit 2b827e6

Please sign in to comment.