Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UNRAVEL from HMSL #193

Closed
philburk opened this issue Jan 5, 2025 · 7 comments · Fixed by #197
Closed

Add UNRAVEL from HMSL #193

philburk opened this issue Jan 5, 2025 · 7 comments · Fixed by #197
Assignees

Comments

@philburk
Copy link
Owner

philburk commented Jan 5, 2025

Implementation at:

https://github.com/philburk/hmsl/blob/cf49471aee4543ae4dd045e5bae4693a7629b08e/hmsl/fth/errormsg.fth#L22

@robzed
Copy link
Contributor

robzed commented Jan 5, 2025

I have currently have -fsanitize=address turned on in my pForth build and I immediately get a "ERROR: AddressSanitizer: heap-buffer-overflow" - I assume because it's walking into memory below the return stack with the 20 0 do. I assume we'd need to have a R0 or RP0 command and use the commented out code only to print out the used return stack area?

@robzed
Copy link
Contributor

robzed commented Jan 5, 2025

When I test (with unravel inside LOAD_GRAPHICS) I get this:
run
Calling sequence: LOAD_GRAPHICS RUN 0
=================================================================
==29158==ERROR: AddressSanitizer: heap-buffer-overflow

@robzed
Copy link
Contributor

robzed commented Jan 5, 2025

From the command line:

rp@    ok
Stack<10> 107820859018496 

From the command line:

: tt1 rp@ . 3 >r 4 >r  rp@ . R> r> drop drop ;    ok
Stack<10> 
tt1 107820859018488 107820859018472    ok

Actually I prototyped it in a nested include with:
rp@ value rp0

Gives:

Stack<10> 
rp0 . 107820859018416    ok
Stack<10> 

Inside first include:

." Default stack = " rp0 . cr

Default stack = 107820859018456

@robzed
Copy link
Contributor

robzed commented Jan 5, 2025

Inside top level include
rp@ 40 + value rp0

(the 40 + is to adjust for the fact this is defined in an include. In my opinion, this should be a primitive).

Anywhere else afterwards:

: UNRAVEL  ( -- , show names on stack )
    >newline ." Calling sequence:" cr
    rp0 rp@ - cell / 
    ." (Levels = " dup . ." )" cr    ( added for test purposes )
\    2+
   50 min 0
\    20 0
    ?DO  4 spaces
        rp@ i 2+ cell* + @
        dup code> >name ?dup
        IF id. drop
        ELSE .hex
        THEN cr?
    LOOP cr
;

Gives:

run 
Calling sequence:
(Levels = 3 )
    LOAD_GRAPHICS    RUN    0 

No crash.

Some questions:

  • Should the number of levels be 2?
  • Why is it printing the 0?
  • What was the 2+ I commented out for?
  • What is the 2+ in the loop for?

@philburk
Copy link
Owner Author

philburk commented Jan 5, 2025

Thanks for experimenting with this.
I agree that RP0 or R0 should be in the kernel.
In JForth we defined R0
http://www.jforth.org/Glos_RT.html

I cannot find R0 or RP0 in the ANS standard. Do you know of any standard references?
FIG Forth defined R0.

Should the number of levels be 2?

Probably. I need to ponder this.

Why is it printing the 0?

Not sure. It may be from the DO LOOP

What was the 2+ I commented out for?

I think that was from some old JForth code.

What is the 2+ in the loop for?

I think it is to get past the DO LOOP internal values and the call to UNRAVEL.

@philburk philburk self-assigned this Jan 6, 2025
philburk added a commit that referenced this issue Jan 6, 2025
@philburk
Copy link
Owner Author

philburk commented Jan 6, 2025

@robzed - please take a look at #197

@robzed
Copy link
Contributor

robzed commented Jan 13, 2025

Happy to merge. Did you want me to do more on this?

philburk added a commit that referenced this issue Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants