gforth
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gforth] Tutorial - Memory Section - 3 issues


From: Carsten Strotmann (private)
Subject: Re: [gforth] Tutorial - Memory Section - 3 issues
Date: Sun, 07 Mar 2010 19:00:49 +0100
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-GB; rv:1.9.1.8) Gecko/20100216 Thunderbird/3.0.2

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello Terrence,

On 3/7/10 6:50 PM, Terrence Brannon wrote:
> Re: 
> http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Memory-Tutorial.html#Memory-Tutorial
> 
> Issue One -  CREATE does not push an address onto the stack, yet ALLOT
> seems to know where to start allocating cells...
> 
> We read:
> 
> """
>  create v2 20 cells allot
>      v2 20 cells dump
> creates a word v2 and reserves 20 uninitialized cells; the address
> pushed by v2 points to the start of these 20 cells.
> """
> 
> ... it says "address pushed by v2" but create does not push an address
> (at least not onto the data stack), so how does alloc find the address
> that was assigned to v2?

right, the word "create" does not push an address, but the word created
by CREATE, named "v2" in this example, does, that is what the sentence
tries to document. I'm not an native english speaker, so there might be
a better, unambigous way to describe the behavior.

ALLOT allocates memory from the dictionary. The current memory address
of the next free memory location in the dictionary can be pushed to the
stack with HERE.

> 
> Issue Two - It is a fact that both VARIABLE and CREATE create words
> which are simply the address of a memory location.

CREATE just creates a word header that will push it's address on the
stack, while VARIABLE creates a word header AND reserved enough space to
hold the variable.

VARIABLE can be implemented as

: VARIABLE CREATE 1 CELLS ALLOT DOES> @ ;

> 
> However, the docs confuse this fact, by stating that VARIABLE creates
> global variables while CREATE creates a word.

But that it what it does.

> I dont think it helps a beginner to use the term global variable and
> word interchangeably. Because they start thinking there are two
> different programmatic constructs when they are not.
> 
> Issue Three - How does VARIABLE differ from CREATE?

see above. The small but important difference is the memory allocation
of one cell size "1 CELLS ALLOT"

Carsten

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkuT6dEACgkQsUJ3c+pomYFYagCgpdoUdXE5FQB/bCrFNi0aLiO6
txoAoJoWXtNCCfkZvuLNxFBg1/k5MWsl
=FASq
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]