Memory management in Forth

前端 未结 5 391
有刺的猬
有刺的猬 2021-02-02 16:47

So I\'m just learning Forth and was curious if anyone could help me understand how memory management generally works. At the moment I only have (some) experience with the C stac

5条回答
  •  独厮守ぢ
    2021-02-02 17:30

    Some Forth implementations support local variables on the return stack frame and allocating memory blocks. For example in SP-Forth:

    lib/ext/locals.f
    lib/ext/uppercase.f
    
    100 CONSTANT /buf
    
    : test ( c-addr u -- ) { \ len [ /buf 1 CHARS + ] buf }
      buf SWAP /buf UMIN DUP TO len CMOVE
      buf len UPPERCASE
      0 buf len + C! \ just for illustration
      buf len TYPE
    ;
    
    S" abc" test \ --> "ABC"
    

提交回复
热议问题