Skip to content

Commit

Permalink
Merge pull request #7 from TabulateJarl8/development
Browse files Browse the repository at this point in the history
Small updates
  • Loading branch information
TabulateJarl8 committed May 13, 2023
2 parents e59019a + 78a88a2 commit a392eaf
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ ti842py is a TI-BASIC to Python 3 transpiler. A transpiler is a piece of softwar
- Matrices
- `Ans`
- `prgm`
- `round()`

### Planned Features
- `round()`
- `Return`
- `eval()`/`expr()`

Expand Down Expand Up @@ -124,7 +124,7 @@ The last way that ti842py can be ran is by running the main python file. After c
# Special functions
----

- `getKey` - The `getKey` function works just like it does in normal TI-BASIC, except with some special rules. Any key on the keyboard pressed will be converted to the corresponding key on the calculator. This works for letters, numbers, arrow keys, enter, delete, and symbols. As for the buttons not on a keyboard, the top 5 keys are the F1-F5 keys on the keyboard, `2nd` is grave `` ` ``, and `alpha` is tilda `~`. `mode` is F6, `stat` is f7, `vars` is F8, `clear` is F9, and the `X,T,θ,n` key is F10.
- `getKey` - The `getKey` function works just like it does in normal TI-BASIC, except with some special rules. Any key on the keyboard pressed will be converted to the corresponding key on the calculator. This works for letters, numbers, arrow keys, enter, delete, and symbols. As for the buttons not on a keyboard, the top 5 keys are the F1-F5 keys on the keyboard, `2nd` is grave `` ` ``, and `alpha` is tilda `~`. `mode` is F6, `stat` is f7, `vars` is F8, the `X,T,θ,n` key is F9, and `clear` is backspace.

- `If` - `If` blocks with `Then` after the `If` must be ended with `End`, they cannot be left open. `If` blocks on 2 lines without a `Then` cannot be closed with `End`

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[metadata]
description-file = README.md
description_file = README.md
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.9.9"
__version__ = "0.9.10"
__author__ = "Tabulate"
__author_email__ = "tabulatejarl8@gmail.com"
__license__ = "GPLv3"
Expand Down
25 changes: 21 additions & 4 deletions ti842py/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import tempfile
import sys
import subprocess
import io
import pty

try:
Expand Down Expand Up @@ -97,7 +96,7 @@ def transpile(infile, outfile="stdout", decompileFile=True, forceDecompile=False

def main():
parser = argparse.ArgumentParser(description='TI-BASIC to Python 3 Transpiler')
infile_argument = parser.add_argument(
parser.add_argument(
'infile',
metavar='infile',
nargs='?',
Expand Down Expand Up @@ -148,6 +147,13 @@ def main():
help='Remove the 0.1 second delay between drawing actions'
)

parser.add_argument(
'--reset-persistant-data',
action='store_true',
help='Reset the ti842py persistant data (variables, matrices, etc)',
dest='reset_data'
)

parser.add_argument(
'-r',
'--run',
Expand All @@ -160,18 +166,29 @@ def main():
'-V',
'--version',
action='version',
version='ti842py {version}'.format(version=__version__)
version=f'ti842py {__version__}'
)

args = parser.parse_args()

if args.reset_data:
user_confirm = ''
while user_confirm not in {'y', 'n'}:
user_confirm = input('Are you sure you would like to remove the persistant data? [y/n] ').lower()
if user_confirm == 'y':
os.remove(os.path.expanduser('~/.ti842py-persistant'))
print('Removed persistant data')
else:
print('Cancelled removal of persistant data')

if hasattr(args.infile, '__getitem__'):
infile = args.infile[0]
else:
infile = args.infile

if infile is None:
raise argparse.ArgumentError(infile_argument, 'the infile argument is required')
parser.print_help()
sys.exit(1)

transpile(infile, args.outfile, args.n, args.d, args.multiplication, args.floating_point, args.turbo_draw, args.run)

Expand Down
10 changes: 7 additions & 3 deletions ti842py/ti_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ def convert_line(self, index, line):
elif line.startswith("DelVar"):
statement = "del " + line[7:]
# Prompt
# TODO: Fix prompt after Output going over output
elif line.startswith("Prompt"):
variable = line[7:]
if "," in variable:
Expand Down Expand Up @@ -328,11 +327,12 @@ def convert_line(self, index, line):
line.startswith("toString(") or \
line.startswith('randInt(') or \
line.startswith('rand') or \
line.startswith('round(') or \
re.search(r'^\[[A-J]\]', line):
statement = line
else:
statement = "# UNKNOWN INDENTIFIER: {}".format(line)
logger.warning("Unknown indentifier on line %s", index + 1)
statement = f"# UNKNOWN INDENTIFIER: {line}"
logger.warning(f"Unknown indentifier on line {index + 1}")

if isinstance(statement, str):
statement = [statement]
Expand Down Expand Up @@ -384,6 +384,10 @@ def convert_line(self, index, line):
if 'dim(' in ' '.join(statement):
statement = parsing_utils.noStringReplace(r'dim\(', 'len(', statement)

if 'round(' in ' '.join(statement):
statement = parsing_utils.noStringReplace(r'round\(', 'ti_round(', statement)
self.UTILS['round']['enabled'] = True

if re.search(r'l[1-6]\([0-9A-Za-z]+\)', ' '.join(statement)):
# List subscription
try:
Expand Down
4 changes: 2 additions & 2 deletions ti842py/utils/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def __init__(self):
self.points = {}
self.texts = {}
self.colors = {'10': 'blue', '11': 'red', '12': 'black', '13': 'magenta', '14': 'green', '15': 'orange', '16': 'brown', '17': 'navy', '18': 'light sky blue', '19': 'yellow', '20': 'white', '0': 'white', '21': 'light gray', '22': 'dark gray', '23': 'gray', '24': 'dark slate gray'}
for _ in range(1, 10):
self.colors[str(_)] = 'blue'
for i in range(1, 10):
self.colors[str(i)] = 'blue'
self.currentTextColor = 'blue'

def _slow(function):
Expand Down
2 changes: 1 addition & 1 deletion ti842py/utils/getkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self):
"b": 42,
"c": 43,
pynput.keyboard.Key.f8: 44,
pynput.keyboard.Key.f9: 45,
pynput.keyboard.Key.backspace: 45,
"d": 51,
"e": 52,
"f": 53,
Expand Down
9 changes: 8 additions & 1 deletion ti842py/utils/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,20 @@ def __neg__(self):
new_matrix[i][j] = -new_matrix[i][j]
return Matrix(new_matrix)

def __round__(self, digits):
new_matrix = copy.deepcopy(self.matrix)
for i in range(len(new_matrix)):
for j in range(len(new_matrix[i])):
new_matrix[i][j] = round(new_matrix[i][j], digits)
return Matrix(new_matrix)

def __eq__(self, other):
return 1 if self.matrix == other.matrix else 0

def __ne__(self, other):
return not self.__eq__(other)

def __repr__(self):
def __str__(self):
return '\n'.join(['[' + ' '.join([str(num) for num in sublist]) + ']' for sublist in self.matrix])

def __getitem__(self, index):
Expand Down
5 changes: 5 additions & 0 deletions ti842py/utils/round.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def ti_round(value, decimals):
if isinstance(value, list):
return [round(item, decimals) for item in value]
else:
return round(value, decimals)
2 changes: 1 addition & 1 deletion ti842py/utils/to_number.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def toNumber(string):
def to_number(string):
try:
return int(string)
except ValueError:
Expand Down

0 comments on commit a392eaf

Please sign in to comment.