pitybas 0.2.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pitybas-0.2.0/src/pitybas.egg-info → pitybas-0.4.0}/PKG-INFO +2 -1
- {pitybas-0.2.0 → pitybas-0.4.0}/README.md +1 -0
- pitybas-0.4.0/src/pitybas/__init__.py +1 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas/cli.py +4 -2
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas/expression.py +21 -1
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas/interpret.py +8 -3
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas/io/simple.py +5 -3
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas/io/vt100.py +5 -3
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas/parse.py +20 -3
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas/tokens.py +324 -26
- {pitybas-0.2.0 → pitybas-0.4.0/src/pitybas.egg-info}/PKG-INFO +2 -1
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas.egg-info/SOURCES.txt +4 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/tests/test_control_flow.py +30 -0
- pitybas-0.4.0/tests/test_expressions.py +181 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/tests/test_io_simple.py +4 -24
- {pitybas-0.2.0 → pitybas-0.4.0}/tests/test_known_bugs.py +24 -0
- pitybas-0.4.0/tests/test_list_matrix_arithmetic.py +79 -0
- pitybas-0.4.0/tests/test_matrix_literals.py +38 -0
- pitybas-0.4.0/tests/test_menu.py +56 -0
- pitybas-0.4.0/tests/test_negation.py +158 -0
- pitybas-0.4.0/tests/test_variables.py +245 -0
- pitybas-0.2.0/src/pitybas/__init__.py +0 -1
- pitybas-0.2.0/tests/test_expressions.py +0 -68
- pitybas-0.2.0/tests/test_variables.py +0 -73
- {pitybas-0.2.0 → pitybas-0.4.0}/LICENSE +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/pyproject.toml +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/setup.cfg +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas/__main__.py +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas/common.py +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas/io/__init__.py +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas.egg-info/dependency_links.txt +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas.egg-info/entry_points.txt +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas.egg-info/requires.txt +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/src/pitybas.egg-info/top_level.txt +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/tests/test_bas_programs.py +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/tests/test_cli.py +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/tests/test_common.py +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/tests/test_interpreter_introspection.py +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/tests/test_io.py +0 -0
- {pitybas-0.2.0 → pitybas-0.4.0}/tests/test_parser.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pitybas
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: A TI-BASIC interpreter written in Python
|
|
5
5
|
Author: Ryan Hileman
|
|
6
6
|
Maintainer-email: Thomas Roten <tsr@thomasroten.com>
|
|
@@ -50,6 +50,7 @@ If you run `pb` with no filename, it launches an interactive shell.
|
|
|
50
50
|
-s, --stacktrace always stacktrace
|
|
51
51
|
-v, --verbose verbose output
|
|
52
52
|
-i IO, --io=IO select an IO system: simple (default), vt100
|
|
53
|
+
-x, --strict raise ERR:UNDEFINED instead of silently defaulting unset variables to 0
|
|
53
54
|
|
|
54
55
|
You can also run it as a module without installing the console script:
|
|
55
56
|
|
|
@@ -21,6 +21,7 @@ If you run `pb` with no filename, it launches an interactive shell.
|
|
|
21
21
|
-s, --stacktrace always stacktrace
|
|
22
22
|
-v, --verbose verbose output
|
|
23
23
|
-i IO, --io=IO select an IO system: simple (default), vt100
|
|
24
|
+
-x, --strict raise ERR:UNDEFINED instead of silently defaulting unset variables to 0
|
|
24
25
|
|
|
25
26
|
You can also run it as a module without installing the console script:
|
|
26
27
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.4.0"
|
|
@@ -14,6 +14,8 @@ def main(argv=None):
|
|
|
14
14
|
parser.add_option('-s', '--stacktrace', dest="stacktrace", action="store_true", help="always stacktrace")
|
|
15
15
|
parser.add_option('-v', '--verbose', dest="verbose", action="store_true", help="verbose output")
|
|
16
16
|
parser.add_option('-i', '--io', dest="io", help="select an IO system: simple (default), vt100")
|
|
17
|
+
parser.add_option('-x', '--strict', dest="strict", action="store_true", default=False,
|
|
18
|
+
help="raise ERR:UNDEFINED instead of silently defaulting unset variables to 0")
|
|
17
19
|
|
|
18
20
|
(options, args) = parser.parse_args(argv)
|
|
19
21
|
|
|
@@ -26,11 +28,11 @@ def main(argv=None):
|
|
|
26
28
|
io = vt100
|
|
27
29
|
|
|
28
30
|
if args:
|
|
29
|
-
vm = Interpreter.from_file(args[0], history=20, io=io)
|
|
31
|
+
vm = Interpreter.from_file(args[0], history=20, io=io, strict=options.strict)
|
|
30
32
|
else:
|
|
31
33
|
print('Welcome to pitybas. Press Ctrl-D to exit.')
|
|
32
34
|
print()
|
|
33
|
-
vm = Repl(history=20, io=io)
|
|
35
|
+
vm = Repl(history=20, io=io, strict=options.strict)
|
|
34
36
|
|
|
35
37
|
if options.verbose:
|
|
36
38
|
vm.print_tokens()
|
|
@@ -25,8 +25,15 @@ class Base:
|
|
|
25
25
|
if self.contents:
|
|
26
26
|
prev = self.contents[-1]
|
|
27
27
|
|
|
28
|
+
# Negate (the real calculator's dedicated negation token) is
|
|
29
|
+
# never ambiguous with a binary operator like Minus is, so it
|
|
30
|
+
# always collapses to * -1, regardless of position.
|
|
31
|
+
if isinstance(prev, tokens.Negate):
|
|
32
|
+
self.contents.pop()
|
|
33
|
+
self.contents += [tokens.Value(-1), tokens.Mult()]
|
|
34
|
+
|
|
28
35
|
# the minus sign implies a * -1 when used by itself
|
|
29
|
-
|
|
36
|
+
elif isinstance(prev, tokens.Minus):
|
|
30
37
|
# TODO: fix this the rest of the way
|
|
31
38
|
if len(self.contents) == 1:
|
|
32
39
|
self.contents.pop()
|
|
@@ -280,6 +287,19 @@ class MatrixExpr(Arguments):
|
|
|
280
287
|
priority = Pri.NONE
|
|
281
288
|
end = ']'
|
|
282
289
|
|
|
290
|
+
def append(self, expr):
|
|
291
|
+
# Real hardware writes adjacent matrix literal rows with no
|
|
292
|
+
# separator, e.g. "[[1,2][3,4]]" -- each row parses as its own
|
|
293
|
+
# MatrixExpr. Without this, the inherited Tuple.append() would
|
|
294
|
+
# merge a new row into the same wrapping Expression as the
|
|
295
|
+
# previous one (since nothing ever called .finish() on it),
|
|
296
|
+
# triggering bogus implied multiplication between the two rows
|
|
297
|
+
# instead of starting a new one.
|
|
298
|
+
if isinstance(expr, MatrixExpr) and self.contents:
|
|
299
|
+
self.sep()
|
|
300
|
+
|
|
301
|
+
super().append(expr)
|
|
302
|
+
|
|
283
303
|
def __repr__(self):
|
|
284
304
|
return 'M[%s]' % (', '.join(repr(expr) for expr in self.contents))
|
|
285
305
|
|
|
@@ -24,7 +24,7 @@ class Interpreter(object):
|
|
|
24
24
|
vm.name = os.path.basename(filename)
|
|
25
25
|
return vm
|
|
26
26
|
|
|
27
|
-
def __init__(self, code, history=10, io=None, name=None):
|
|
27
|
+
def __init__(self, code, history=10, io=None, name=None, strict=False):
|
|
28
28
|
if not io: io = IO
|
|
29
29
|
self.io = io(self)
|
|
30
30
|
|
|
@@ -38,11 +38,13 @@ class Interpreter(object):
|
|
|
38
38
|
self.running = []
|
|
39
39
|
self.history = []
|
|
40
40
|
self.hist_len = history
|
|
41
|
+
self.strict = strict
|
|
41
42
|
|
|
42
43
|
self.vars = {}
|
|
43
44
|
self.lists = defaultdict(list)
|
|
44
45
|
self.matrix = {}
|
|
45
46
|
self.fixed = -1
|
|
47
|
+
self.degree_mode = False
|
|
46
48
|
|
|
47
49
|
self.serial = 0
|
|
48
50
|
self.repl_serial = 0
|
|
@@ -64,8 +66,11 @@ class Interpreter(object):
|
|
|
64
66
|
return self.cur()
|
|
65
67
|
|
|
66
68
|
def get_var(self, var, default=None):
|
|
67
|
-
if var not in self.vars
|
|
68
|
-
|
|
69
|
+
if var not in self.vars:
|
|
70
|
+
if self.strict:
|
|
71
|
+
raise ExecutionError('ERR:UNDEFINED')
|
|
72
|
+
if default is not None:
|
|
73
|
+
return default
|
|
69
74
|
return self.vars[var]
|
|
70
75
|
|
|
71
76
|
def set_var(self, var, value):
|
|
@@ -50,15 +50,17 @@ class IO:
|
|
|
50
50
|
self.input('[press enter]', True)
|
|
51
51
|
|
|
52
52
|
def menu(self, menu):
|
|
53
|
-
# menu is a tuple of (title, (desc, label))
|
|
53
|
+
# menu is a tuple of (title, [(desc, label)]) -- title/desc are
|
|
54
|
+
# already-evaluated display strings; label is a raw, unevaluated
|
|
55
|
+
# token for Goto to resolve.
|
|
54
56
|
lookup = []
|
|
55
57
|
while True:
|
|
56
58
|
i = 1
|
|
57
59
|
|
|
58
60
|
for title, entries in menu:
|
|
59
|
-
print('-[ %s ]-' %
|
|
61
|
+
print('-[ %s ]-' % title)
|
|
60
62
|
for name, label in entries:
|
|
61
|
-
print('%i: %s' % (i,
|
|
63
|
+
print('%i: %s' % (i, name))
|
|
62
64
|
lookup.append(label)
|
|
63
65
|
i += 1
|
|
64
66
|
|
|
@@ -259,7 +259,9 @@ class IO:
|
|
|
259
259
|
self.input('[press enter]', True)
|
|
260
260
|
|
|
261
261
|
def menu(self, menu):
|
|
262
|
-
# menu is a tuple of (title, (desc, label))
|
|
262
|
+
# menu is a tuple of (title, [(desc, label)]) -- title/desc are
|
|
263
|
+
# already-evaluated display strings; label is a raw, unevaluated
|
|
264
|
+
# token for Goto to resolve.
|
|
263
265
|
# TODO: implement this in VT terms
|
|
264
266
|
|
|
265
267
|
lookup = []
|
|
@@ -268,9 +270,9 @@ class IO:
|
|
|
268
270
|
i = 1
|
|
269
271
|
|
|
270
272
|
for title, entries in menu:
|
|
271
|
-
print('-[ %s ]-' %
|
|
273
|
+
print('-[ %s ]-' % title)
|
|
272
274
|
for name, label in entries:
|
|
273
|
-
print('%i: %s' % (i,
|
|
275
|
+
print('%i: %s' % (i, name))
|
|
274
276
|
lookup.append(label)
|
|
275
277
|
i += 1
|
|
276
278
|
|
|
@@ -202,14 +202,21 @@ class Parser:
|
|
|
202
202
|
elif '0' <= char <= '9' or char == '.'\
|
|
203
203
|
or isinstance(self.token(sub=True, inc=False), tokens.Minus) and self.number(test=True):
|
|
204
204
|
result = tokens.Value(self.number())
|
|
205
|
-
elif char in u'
|
|
205
|
+
elif char in u'lL∟' and self.more(self.pos+1) and self.source[self.pos+1] in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789':
|
|
206
206
|
result = self.list()
|
|
207
207
|
elif char.isalpha():
|
|
208
208
|
result = self.token()
|
|
209
|
+
elif char == '"':
|
|
210
|
+
# " is ambiguous: it's both the string-quote token and the
|
|
211
|
+
# DMS seconds symbol (30°15'20"). Only treat it as DMS
|
|
212
|
+
# seconds when it directly follows a minutes value (') -
|
|
213
|
+
# otherwise it opens a string, same as always.
|
|
214
|
+
if self.dms_seconds_pending():
|
|
215
|
+
result = self.symbol()
|
|
216
|
+
else:
|
|
217
|
+
result = tokens.Value(self.string())
|
|
209
218
|
elif char in self.SYMBOLS:
|
|
210
219
|
result = self.symbol()
|
|
211
|
-
elif char == '"':
|
|
212
|
-
result = tokens.Value(self.string())
|
|
213
220
|
else:
|
|
214
221
|
self.error('could not tokenize: %s' % repr(char))
|
|
215
222
|
|
|
@@ -253,6 +260,16 @@ class Parser:
|
|
|
253
260
|
while self.stack:
|
|
254
261
|
self.add(self.stack.pop())
|
|
255
262
|
|
|
263
|
+
def dms_seconds_pending(self):
|
|
264
|
+
if self.stack:
|
|
265
|
+
items = getattr(self.stack[-1], 'contents', None)
|
|
266
|
+
elif self.lines and self.line < len(self.lines):
|
|
267
|
+
items = self.lines[self.line]
|
|
268
|
+
else:
|
|
269
|
+
items = None
|
|
270
|
+
|
|
271
|
+
return bool(items) and len(items) >= 2 and isinstance(items[-2], tokens.MinuteSymbol)
|
|
272
|
+
|
|
256
273
|
def symbol(self):
|
|
257
274
|
token = self.token(True)
|
|
258
275
|
if token:
|