Menu

Words defined via defining words forget data after warm boot?

2024-03-30
2024-03-30
  • David C. Norris

    David C. Norris - 2024-03-30

    I find that a word defined with a defining word does not persist intact after warm restart. Specifically, constants that I would understand to be compiled into the word definition apparently get zeroed.

    Here's a simple repro:

    empty  ok<#,ram> 
    ( x "name" -- )  ok<#,ram> 
    : rememberer: create , does> ( -- x ) @ ;  ok<#,ram> 
    #5 rememberer: five  ok<#,ram> 
    five  ok<#,ram> 5 
    warm  FlashForth 5 PIC24 05.03.2024
    
      ok<#,ram> 
    five  ok<#,ram> 0 
    #5 rememberer: five  ALREADY DEFINED
    forget five  ok<#,ram> 
    #5 rememberer: five  ok<#,ram> 
    five  ok<#,ram> 5 
    

    Are words defined via defining words not supposed to have persistent memory? Or have I misunderstood how to create a defining word?

     
  • Mikael Nordman

    Mikael Nordman - 2024-03-30

    David,
    In FF you can select which data section is used for the created word. Default is ram, so that's why your data area is zeroed. You can also use flash, then the data will be there after a restart.
    There is also a data section for eeprom if your chip has eeprom.

    : rememberer: create , does> ( -- x ) @ ;
    flash 
    5 rememberer: five   \ Constant in flash
    variable cal1        \ Variable in flash (occasional updates only) 
    1234 value cal2      \ value in flash (occasional updates only)
    defer executor       \ defer in flash (occasional updates only)
    ram 
    variable counter     \ Variable in ram
    2345 value bla       \ Value in ram
    5 rememberer: six    \ Not useful
    

    The prompt shows the current data section.
    If you want a defining word to always use flash as the data section you can do it like this.

    : rememberer: flash create , ram does> ( -- x ) @ ;
    
     
    👍
    1

    Last edit: Mikael Nordman 2024-04-06
  • David C. Norris

    David C. Norris - 2024-03-30

    Mikael, many thanks for this explanation. In retrospect, I can see that Peter Jacobs's documentation for CREATE indeed clearly states that it "store[s] the current data section pointer"! It had just not occurred to me that a word's instance data might not be contiguous with its code, and I'm aware all instructions on the PIC24 must be in flash.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.