Newsgroups: comp.lang.forth Path: utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!geac!maccs!innovus!rob From: rob@innovus.uucp (Rob Sciuk) Subject: Re: Memory Management/PIC Message-ID: <1991Jun17.193747.12338@innovus.uucp> Organization: Innovus Inc. References: <2890.UUL1.3#5129@willett.pgh.pa.us> Date: Mon, 17 Jun 91 19:37:47 GMT In article <2890.UUL1.3#5129@willett.pgh.pa.us> ForthNet@willett.pgh.pa.us (ForthNet articles from GEnie) writes: >Category 10, Topic 36 >Message 32 Fri Jun 14, 1991 >D.RUFFER [Dennis] at 20:53 EDT > >To: X3J14 watchers > >From: Elizabeth Rather (as an individual, this time) >P.S. A search of BASIS 16 reveals that the _only_ word that returns a possibly >unaligned address is HERE, and that can only become unaligned as a result of >an arbitrary argument to ALLOT or an odd # of C,'s - meaning, _you_ as a >programmer _know_ & _control_ whether addresses are aligned. I have implemented Forth-83 in C from the standard specification which runs on Intel, RISC, Motorola, and other proprietary platforms, many of which have strict alignment rules. Elizabeth points out that any standard defining word should take care to align words, (bodies, headers, and fields contained therein) on appropriate boundaries. Further, `ALLOT' and `,' should align on CELL boundaries, and `C,' should ensure that the next invocation of `HERE', `ALLOT', `,' etc. will utilize a CELL boundary appropriate to the processor [mine]. My solution was to maintain a separate byte aligned pointer for `C,' which is checked against the dictionary pointer. If not pointing at a cell boundary, the equivalent of an ALLOT is done, and two pointers, one for byte, and one for word allocation type words use are maintained. The byte pointer need be accessible ONLY from within the `C,' word itself. By having my language take care of this, I have clearly defined semantics (I'm the only user), and have increased portability of FORTH applications between machines. The following excerpted sequence will show the mechanism used ... (I apologize for posting C source, but the result should be clear). void zz_Ccomma() /* "C,", 0, ( 8b --- ) */ { if( !CDP || ( CDP == (UChar_ptr) DP ) || ( ( (UChar_ptr) DP - CDP ) > (sizeof(CELL) - 1 ) ) ) CDP = (UChar_ptr) DP++ ; *(CDP++) = (UCHAR) POP ; } Again, I don't want to get hung up on implementation details, but by having the language take care of this one little detail, an awful lot of porting headaches can be avoided (I'm in the porting business!). Elizabeth, forgive me if the BASIS 16 standard has addressed this, I have just printed it, and have not had time to read it just yet, but I do not believe that this was covered in the last BASIS I read (10). -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Rob Sciuk rob@innovus.com OR rob@innovus.on.ca Innovus Inc. 204-200 James St S. Hamilton, Ont. Phone: (416) 529-8117 {not a flame ... merely a glimmer ...} Fax: (416) 572-9586 -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Rob Sciuk rob@innovus.com OR rob@innovus.on.ca Innovus Inc. 204-200 James St S. Hamilton, Ont. Phone: (416) 529-8117 {not a flame ... merely a glimmer ...} Fax: (416) 572-9586