gamber@cosmo.UUCP (Johannes Teich) (09/12/89)
Hi Forthers, here is a question about CREATE . The Forth-83 Standard says: > CREATE -- M,79 > A defining word executed in the form: > CREATE <name> > Creates a dictionary entry for <name>. After <name> is created, > the next available dictionary location is the first byte of > <name>'s parameter field. When <name> is subsequently executed, > the address of the first byte of <name>'s parameter field is > left on the stack. CREATE does not allocate space in <name>'s > parameter field. If I want to create an array with 3 cells, I can write: CREATE ARRAY1 6 ALLOT or VARIABLE ARRAY1 4 ALLOT or (initialized with baud rates): CREATE ARRAY2 110 , 1200 , 2400 , or VARIABLE ARRAY2 -2 ALLOT 110 , 1200 , 2400 , Internally, with a direct threaded Forth it looks like this: (constant) ( variable ) ( array ) +--------------+ +--------------+ +--------------+ RAM ! header ! ! header ! ! header ! """ +--------------+ +--------------+ +--------------+ ! call const ! ! call var ! ! call var ! +--------------+ +--------------+ +--------------+ ! value ! ! value ! ! 1st value ! +--------------+ +--------------+ +--------------+ ! 2nd value ! +--------------+ ! 3rd value ! +--------------+ Apart from the Standard, a ROM-based Forth may look like this: (constant) ( variable ) ( array ) +--------------+ +--------------+ +--------------+ ROM ! header ! ! header ! ! header ! """ +--------------+ +--------------+ +--------------+ ! call const ! ! call const ! ! call const ! +--------------+ +--------------+ +--------------+ ! value ! ! ptr to value --+ ! ptr to array --+ +--------------+ +--------------+ ! +--------------+ ! ! ! +--------------+ ! +--------------+ ! RAM ! value <--+ ! 1st value <--+ """ +--------------+ +--------------+ ! 2nd value ! +--------------+ ! 3rd value ! +--------------+ This ROM-based Forth may have been built by a metacompiler that uses the same syntax and shares the runtime routines (const and var) with the target system. This system may have an interpreter/compiler, so if I press Reset I have a good chance to see "ok" on the connected terminal. With this system I can define new words which are entered into RAM, of course: (constant) ( variable ) ( array ) +--------------+ +--------------+ +--------------+ RAM ! header ! ! header ! ! header ! """ +--------------+ +--------------+ +--------------+ ! call const ! ! call const ! ! call const ! +--------------+ +--------------+ +--------------+ ! value ! ! ptr to value --+ ! ptr to array --+ +--------------+ +--------------+ ! +--------------+ ! ! value <--+ ! 1st value <--+ +--------------+ +--------------+ ! 2nd value ! +--------------+ ! 3rd value ! +--------------+ The above definitions with CREATE have now slightly changed: CREATE ARRAY1 HERE 2+ , 6 ALLOT (changed) VARIABLE ARRAY1 4 ALLOT CREATE ARRAY2 HERE 2+ , 110 , 1200 , 2400 , (changed) VARIABLE ARRAY2 -2 ALLOT 110 , 1200 , 2400 , Where is my question, you ask? - Well, CREATE is no longer compatible with the Standard now, because "after <name> is created, the next available dictionary location is..." NOT "...the first byte of <name>'s parameter field". The array must be preceded by d HERE 2+ , | if I want "...the first byte of <name>'s parameter field left on the stack". If I don't like that, I could perhaps replace that "call var" instruction by "call arr" or so. I tried it, but I cannot redefine CREATE, because the (LMI) metacompiler insists on "var", because it uses the target's runtime routines. Hmmm... what did I want to ask? Sorry... cu Johannes Teich ------------------------------------------------------------------------ UUCP via CosmoNet: unido!cosmo!gamber * FidoNet: TBUS-BBS 2:507/414.20 ------------------------------------------------------------------------
wmb@SUN.COM (Mitch Bradley) (09/12/89)
The ROMability problem with CREATE and ALLOT or , is addressed by a proposal that Andy Kobziar submitted to the ANSI Forth standard committee. The idea is change the specification of ALLOT so that instead of allocating memory in "dictionary space", it instead allocates from "data space", wherever that is. In conventional RAM-base systems, data space and dictionary space would be the same thing. The words , C, CREATE and HERE would be similarly affected, and DOES> would leave the appropriate address on the stack at run-time. The proposal hasn't been acted upon yet. Mitch
jax@well.UUCP (Jack J. Woehr) (09/13/89)
Jo -- Every one of us who vend ROM Forths have chosen roughly the exact solution you chose. The Standard doesn't cover it? Why do you we are making new Standard (ANSI) now? :-) {}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{} {} {} {} jax@well ." Sysop, Realtime Control and Forth Board" FIG {} {} jax@chariot ." (303) 278-0364 3/12/2400 8-n-1 24 hrs." Chapter {} {} JAX on GEnie ." Tell them JAX sent you!" Coordinator {} {} {} {}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}