flagxor / ueforth

Apache License 2.0
96 stars 26 forks source link

How do you use local variables or local variables are very broken #9

Closed craiglindley closed 3 years ago

craiglindley commented 3 years ago

First let me say ESP32forth is a great tool which I am really looking forward to using in many projects. Also, I am a big fan of named parameters and named local variables which make Forth a whole lot easier to program in.

Maybe I don't understand how to use locals in ESP32forth so my problems might be of my own making. Here is a short test that I cannot get to compile:

: bytearray ( size -- ) ( i -- addr ) create allot does> + ;

\ Define an array of pixel values \ Three bytes are required for each pixel 10 3 * bytearray pixels

\ Convert indiviual RGB color components into 24 bit color : color24 { r g b } r 16 << g 8 << b or or ;

\ Set pixel using a 24 bit color value : setPixelColor { color24 pixelNum } color24 16 >> 255 and color24 8 >> 255 and color24 255 and pixelNum setPixelRGB ;

My issues with locals, besides the above not compiling, are:

  1. if you do something like { color24 pixelNum --- } , they don't work
  2. If you define some locals and use them in a do .. loop, they don't work.
  3. You cannot store to them or change their values

If I am using locals wrong, please enlighten me. In the past I have used pForth which has both named parameters and local variable support which was rock solid. That might be a good model to use in ESP32forth.

flagxor commented 3 years ago

Hi! Thanks for catching a very tricky bug! It turns out in addition to the partial locals support, you ran into a thorny alignment issue that was tickled when using both 8 character names and locals.

I've also used this as an opportunity to fix up the locals support which had some gaps (previously didn't support multiple uses or use within a DO LOOP). I've also added support for TO and +TO.

I've just published v7.0.6.4 and v7.0.5.4 (stable) that include the fixes.

You should be good with the above now.

Cheers

-BradN

craiglindley commented 3 years ago

Wow thanks very much for this, I have a lot of forth code that uses locals that I won't have to rewrite

On Mon, Jul 12, 2021 at 12:21 AM Brad Nelson @.***> wrote:

Hi! Thanks for catching a very tricky bug! It turns out in addition to the partial locals support, you ran into a thorny alignment issue that was tickled when using both 8 character names and locals.

I've also used this as an opportunity to fix up the locals support which had some gaps (previously didn't support multiple uses or use within a DO LOOP). I've also added support for TO and +TO.

I've just published v7.0.6.4 and v7.0.5.4 (stable) that include the fixes.

You should be good with the above now.

Cheers

-BradN

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/flagxor/eforth/issues/9#issuecomment-878005815, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH6K5DZLWX75IBEKRII2T6LTXKCXRANCNFSM5AEJBCMA .

-- Craig Lindley / Heather Hubbard

New Recordings are here http://craigandheather.net/spellbound.html

Personal Website is here http://craigandheather.net

Please call the Rockrimmon house. Our cell phones don't work at home. Rockrimmon House: (719) 426-9873 Craig's Cell: (719) 502-7925 Heather's Cell: (719) 571-0944

If you’re one in a million, there are now more than seven thousand people exactly like you.

craiglindley commented 3 years ago

Did you see the new issue with locals that I wrote up? It could have something to do with 8 character names as well.

On Mon, Jul 12, 2021 at 12:21 AM Brad Nelson @.***> wrote:

Hi! Thanks for catching a very tricky bug! It turns out in addition to the partial locals support, you ran into a thorny alignment issue that was tickled when using both 8 character names and locals.

I've also used this as an opportunity to fix up the locals support which had some gaps (previously didn't support multiple uses or use within a DO LOOP). I've also added support for TO and +TO.

I've just published v7.0.6.4 and v7.0.5.4 (stable) that include the fixes.

You should be good with the above now.

Cheers

-BradN

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/flagxor/eforth/issues/9#issuecomment-878005815, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH6K5DZLWX75IBEKRII2T6LTXKCXRANCNFSM5AEJBCMA .

-- Craig Lindley / Heather Hubbard

New Recordings are here http://craigandheather.net/spellbound.html

Personal Website is here http://craigandheather.net

Please call the Rockrimmon house. Our cell phones don't work at home. Rockrimmon House: (719) 426-9873 Craig's Cell: (719) 502-7925 Heather's Cell: (719) 571-0944

If you’re one in a million, there are now more than seven thousand people exactly like you.