jamesbowman / swapforth

Swapforth is a cross-platform ANS Forth
BSD 3-Clause "New" or "Revised" License
275 stars 55 forks source link

Python Emulator Issues #68

Open PythonLinks opened 4 years ago

PythonLinks commented 4 years ago

First thank you for this Python emulator. A great way for a Python developer to learn about the J1 CPU.

So I fired it up. python3 nuc.py nuc.py:765: DeprecationWarning: tostring() is deprecated. Use tobytes() instead. self.SFIND() nuc.py:463: DeprecationWarning: tostring() is deprecated. Use tobytes() instead. self.defining = self.pops().upper() nuc.py:716: DeprecationWarning: tostring() is deprecated. Use tobytes() instead. was = self.pops() nuc.py:522: DeprecationWarning: tostring() is deprecated. Use tobytes() instead. self.SFIND() nuc.py:449: DeprecationWarning: tostring() is deprecated. Use tobytes() instead. c() Loaded 306 words +

All that looks quite easy to fix. Then I played around with it some. And after a while I made a mistake. Let me reproduce it here. With an empty stack, I asked it to print the top of stack.

+. Of course that did not work. The error message is below.
Basically the emulator hangs. I do not yet have enough understanding of this cpu to figure out the appropriate fix to the emulator. Does the actual CPU recover from errors? It is easy for me to fix the Python. What is hard is to know what the CPU would do. Should I check for bounds somewhere? Should I put a try except in the dup method. Should I put it in the input method? I guess I am more interested in an accurate emulator than in a easy-to-use Forth. Maybe I am most interested in an accurate emulator of an easy-to-use Forth CPU.

Anyhow thank you for an interesting, rich and diverse project. I also took a look at the H2 cpu. It is writen in VHDL and supports interrupts. That project has a C language Emulator. A Python emulator is easier to work with.

Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "nuc.py", line 819, in __init__ self.CATCH() File "nuc.py", line 147, in CATCH self.EXECUTE() File "nuc.py", line 428, in EXECUTE self.xts[x - 1000]() File "nuc.py", line 774, in interpret ][i]() File "nuc.py", line 428, in EXECUTE self.xts[x - 1000]() File "nuc.py", line 449, in inner c() File "nuc.py", line 449, in inner c() File "nuc.py", line 250, in DUP self.d.append(self.d[-1]) IndexError: list index out of range