howerj / embed

An embeddable, tiny Forth interpreter with metacompiler.
MIT License
98 stars 19 forks source link

Doubt regarding infinite loop tests #4

Closed crodnun closed 6 years ago

crodnun commented 6 years ago

Hi, We are trying to debug an infinite loop scenario, executing the following commands:

1) First we define the following word:

: looping begin 1 - dup dup . 0 = until ;

2) And then we run an infinite loop like this:

-1 looping

The VM runs fine, we show the expected outputs, even we have integrated the yield and putc callbacks!! (we yield and resume the VM later) but after a while it stops at this position for the internal pointers:

VM finished: pc [274] t [18432] rp [32759] sp [9216]

At this point, the VM considers that the command was completed and finishes its execution.

Are we doing something wrong with the loop definition? What is the root cause of this stop?

Thanks and regards

howerj commented 6 years ago

Hi!

That doesn't look like an infinite loop, it that will keep decrementing by 1 from -1 (or 65535) until it reaches zero. If you run in this in the normal interpreter, you see that it terminates quite quickly after outputting 2^16 - 1 numbers.

For an actual infinite loop, you could either use:

: looping begin 1- dup . 0 until ;

Or:

: looping begin 1- dup . again ;

Does this make sense?

Thanks, Richard

crodnun commented 6 years ago

Thanks Richard, this was then our mistake, we were not using the right loop statement. We can close this issue/question