Skip to content

Commit b8891dc

Browse files
committed
Add "mprogram"
"mprogram" is like "info program" for Mathics3-related stack entries.
1 parent 389d23a commit b8891dc

File tree

3 files changed

+186
-2
lines changed

3 files changed

+186
-2
lines changed

ChangeLog-spell-corrected

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2025-07-27 rocky <[email protected]>
2+
3+
* admin-tools/git2cl, trepan3k_mathics3/version.py: Get ready for
4+
release 1.0.0.dev0
5+
6+
2025-07-27 rocky <[email protected]>
7+
8+
* Makefile, admin-tools/make-dist.sh, pyproject.toml: Administrivia
9+
for release
10+
11+
2025-07-26 rocky <[email protected]>
12+
13+
* pyproject.toml: Administrivia Use released trepan3k release 1.4.0 or greater. The licensing
14+
administrative dance Python imposes on developers
15+
16+
2025-06-06 rocky <[email protected]>
17+
18+
* trepan3k_mathics3/__init__.py, trepan3k_mathics3/mframe.py,
19+
trepan3k_mathics3/printelement.py: Add mframe
20+
21+
2025-06-06 R. Bernstein <[email protected]>
22+
23+
* README.rst: Update README.rst
24+
25+
2025-06-06 rocky <[email protected]>
26+
27+
* .gitignore, README.rst: Administrivia
28+
29+
2025-06-06 rocky <[email protected]>
30+
31+
* README.rst: Update ReadME.rst
32+
33+
2025-01-20 rocky <[email protected]>
34+
35+
* .gitignore, CHANGES.rst, MANIFEST.in, Makefile,
36+
admin-tools/make-dist.sh, admin-tools/pyenv-versions,
37+
pyproject.toml, trepan3k_mathics3/version.py: Get ready for release
38+
1.0.0
39+
40+
2024-12-30 rocky <[email protected]>
41+
42+
* trepan3k_mathics3/__init__.py: Adjust docstring for mup and mdown
43+
44+
2024-12-30 rocky <[email protected]>
45+
46+
* trepan3k_mathics3/__init__.py, trepan3k_mathics3/mdown.py: Add
47+
mdown command
48+
49+
2024-12-03 rocky <[email protected]>
50+
51+
* trepan3k_mathics3/mathics3.py, trepan3k_mathics3/mbacktrace.py,
52+
trepan3k_mathics3/mup.py, trepan3k_mathics3/printelement.py: Track
53+
debugger name change
54+
55+
2024-09-26 rocky <[email protected]>
56+
57+
* trepan3k_mathics3/__init__.py, trepan3k_mathics3/mathics3.py,
58+
trepan3k_mathics3/mbacktrace.py, trepan3k_mathics3/mup.py: Add mbt
59+
60+
2024-09-23 rocky <[email protected]>
61+
62+
* trepan3k_mathics3/__init__.py, trepan3k_mathics3/mup.py,
63+
trepan3k_mathics3/printelement.py: Add mup and printelement... But only printelement works properly
64+
65+
2024-09-22 rocky <[email protected]>
66+
67+
* Start Mathics3 debugger from trepan3k side
68+

trepan3k_mathics3/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
2323
"""
2424
__docformat__ = "restructuredtext"
25-
from trepan3k_mathics3 import mathics3, mbacktrace, mdown, mframe, mup, printelement
25+
from trepan3k_mathics3 import mathics3, mabort, mbacktrace, mdown, mframe, mprogram, mup, printelement
2626
from trepan3k_mathics3.version import __version__
2727

2828
mdown.DownCommand.__doc__ = mdown.DownCommand.__doc__.replace("down", "mdown")
2929
mframe.FrameCommand.__doc__ = mframe.FrameCommand.__doc__.replace("frame", "mframe")
3030
mup.UpCommand.__doc__ = mup.UpCommand.__doc__.replace("up", "mup")
3131

32-
__all__ = ["__version__", "mathics3", "mbacktrace", "mdown", "mframe", "mup", "printelement"]
32+
__all__ = ["__version__", "mabort", "mathics3", "mbacktrace", "mdown", "mframe", "mprogram", "mup", "printelement"]

trepan3k_mathics3/mprogram.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (C) 2025 Rocky Bernstein <[email protected]>
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
from mathics.eval.stackframe import get_eval_Expression
18+
from trepan.processor.command.base_cmd import DebuggerCommand
19+
from pymathics.trepan.lib.format import format_element, pygments_format
20+
from pymathics.trepan.lib.location import format_location
21+
from pymathics.trepan.lib.stack import print_stack_trace
22+
23+
24+
class MProgramCommand(DebuggerCommand):
25+
"""**mprogram**
26+
27+
Execution status of the program. Listed are:
28+
29+
* Most recent Mathics3 expression
30+
31+
* Reason the program is stopped.
32+
33+
"""
34+
35+
min_abbrev = 2 # Need at least "info pr"
36+
max_args = 0
37+
need_stack = True
38+
short_help = "Execution status of the program"
39+
40+
DebuggerCommand.setup(locals(), category="support", max_args=0)
41+
42+
def run(self, args):
43+
"""Execution status of the program."""
44+
proc = self.proc
45+
event = proc.event
46+
if event:
47+
msg = f"Mathics3 stop via a '{event}' event."
48+
self.msg(msg)
49+
50+
style=self.settings["style"]
51+
52+
event_arg = proc.event_arg
53+
if isinstance(event_arg, tuple) and len(event_arg) > 0:
54+
event_arg = event_arg[0]
55+
if hasattr(event_arg, "location") and event_arg.location:
56+
mess = format_location(style, event_arg.location)
57+
self.msg(mess)
58+
return
59+
60+
if (eval_expression := get_eval_Expression()) is not None:
61+
eval_expression_str = format_element(eval_expression, allow_python=False, use_operator_form=True)
62+
formatted_expression = pygments_format(eval_expression_str, style=style)
63+
self.msg(f"Expression: {formatted_expression}")
64+
65+
if event == "evalMethod":
66+
callback_arg = self.core.arg
67+
formatted_function = pygments_format(f"{callback_arg[0]}[]", style=style)
68+
69+
self.msg(f"Built-in Function: {formatted_function}")
70+
# TODO get function from the target of the FunctionApplyRule if that
71+
# is what we have
72+
73+
self.msg(f"method_function: {callback_arg[1]}")
74+
self.msg(f"args: {callback_arg[2]}")
75+
self.msg(f"kwargs: {callback_arg[3]}")
76+
elif event == "mpmath":
77+
callback_arg = self.core.arg
78+
formatted_function = pygments_format(f"{callback_arg[0]}()", style=style)
79+
self.msg(f"mpmath function: {formatted_function}")
80+
# self.msg(f"mpmath method: {callback_arg[1]}")
81+
elif event == "SymPy":
82+
callback_arg = self.core.arg
83+
formatted_function = pygments_format(f"{callback_arg[0]}()", style=style)
84+
self.msg(f"SymPy function: {formatted_function}")
85+
# self.msg(f"mpmath method: {callback_arg[1]}")
86+
87+
88+
print_stack_trace(
89+
self.proc,
90+
1,
91+
style=style,
92+
opts={"expression": True, "builtin": False},
93+
)
94+
print_stack_trace(
95+
self.proc,
96+
1,
97+
style=style,
98+
opts={"expression": True, "builtin": True},
99+
)
100+
return
101+
102+
def setup(debugger, instance):
103+
"""
104+
Setup we need to do in order to make the Mathics3 Debugger code in ``instance`` work in the
105+
trepan3k debugger object ``debugger``
106+
"""
107+
# Make sure we hook into debugger interface
108+
instance.debugger.intf = debugger.intf
109+
110+
if __name__ == "__main__":
111+
from pymathics.trepan.lib.repl import DebugREPL
112+
113+
d = DebugREPL()
114+
cp = d.core.processor
115+
command = MProgram(cp)
116+
command.run(["program"])

0 commit comments

Comments
 (0)