Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!mcsun!unido!cosmo2!gamber@cosmo.UUCP From: gamber@cosmo.UUCP (Johannes Teich) Newsgroups: comp.lang.forth Subject: create ... Keywords: ROM-based Forth Message-ID: <3897@cosmo2.UUCP> Date: 11 Sep 89 23:31:57 GMT Sender: news@cosmo2.UUCP Reply-To: gamber@cosmo.UUCP (Johannes Teich) Organization: CosmoNet, D-3000 Hannover 1, FRG Lines: 104 Hi Forthers, here is a question about CREATE . The Forth-83 Standard says: > CREATE -- M,79 > A defining word executed in the form: > CREATE > Creates a dictionary entry for . After is created, > the next available dictionary location is the first byte of > 's parameter field. When is subsequently executed, > the address of the first byte of 's parameter field is > left on the stack. CREATE does not allocate space in '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 is created, the next available dictionary location is..." NOT "...the first byte of 's parameter field". The array must be preceded by d HERE 2+ , | if I want "...the first byte of '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 ------------------------------------------------------------------------