From: craig a. h. <ca...@gm...> - 2013-11-14 19:41:25
|
I'm trying to create a label defining word which I would like to work as follows: xPos yPos s" this is the labels text" label: labelName I tried this code: \ Define a label that places itself : label: ( x y addr count --- ) create , , , , does> dup over over 3 + @i swap 2 + @i moveCursor 1+ @i @i ; which at run time I want to return the addr and count of the labels text in flash. The problem is, I think, that s" doesn't compile to flash outside of a definition. How can I change this code to force the label's text to be stored in flash? -- Craig Lindley |
From: craig a. h. <ca...@gm...> - 2013-11-14 21:02:13
|
Matthias I tried your suggesting but sliteral cannot be compiled into another definition for some reason. It is not found even though I can see it in my words list and I can ' sliteral . and it is found. Is it on some non-default wordlist ? Maybe a better question to ask is "Is there another word like s" but which compiles the string into flash when executed outside of a word definition?" -- Craig Lindley |
From: Matthias T. <mt...@we...> - 2013-11-15 14:58:24
|
Hi Craig, > I tried your suggesting but sliteral cannot be compiled into another > definition for some reason. sliteral is an immediate word. That means that you will have to use postpone to compile it. Sorry, I forgot it.. Is the following at least somehow in the direction of what you want to achieve? A bit rough, I admit. (ATmega32)> #include postpone.frt |D=#include postpone.frt |I=getting filenames on the host |I= Reading . |I=using postpone.frt from/home/mt/Forth/amforth/amforth/lib/ans94/core **** /home/mt/Forth/amforth/amforth |I=getting MCU name.. |I=successfully loaded register definitions for atmega32 |F=/home/mt/Forth/amforth/amforth/lib/ans94/core/postpone.frt |C| 1|\ always compile the next word |C| 2|\ Implementation by Ulrich Hoffmann |W| 3| |S| 4|: postpone ( -- ) |S| 5| parse-name find-name dup 0< |S| 6| if \ immediate word found |S| 7| drop compile compile , exit |S| 8| then |S| 9| if \ normal word found |S| 10| , exit |S| 11| then |S| 12| drop |S| 13| -&13 throw |S| 14|; immediate **** /home/mt/Forth/amforth/amforth/lib/ans94/core (ATmega32)> : label: create postpone sliteral , does> dup u. ; ok (ATmega32)> 42 s" hello" label: example ok (ATmega32)> words example label: postpone ... (ATmega32)> example 3824 ok (ATmega32)> 1+ icount itype hello ok (ATmega32)> example 1+ icount 2/ 1+ + @i . 3824 42 ok (ATmega32)> The "icount 2/ 1+ +" sequence calculates the address of the number compiled after the sliteral. It is due to the fact that strings are stored with 2 characters per flash cell. The initial 1+ is to skip the execution token of the runtime of sliteral, which is needed to work for the s" in compile mode. I'm not sure if that could be considered a bug, now that you point your fingers at it... I'll think about it... "dup u." is only a debugging aid. Matthias |
From: Matthias T. <mt...@we...> - 2013-11-15 18:39:20
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Craig, > >> I tried your suggesting but sliteral cannot be compiled into >> another definition for some reason. > > sliteral is an immediate word. That means that you will have to use > postpone to compile it. Sorry, I forgot it.. A even better solution would be using s, (s-comma) : label: create s, , does> dup . ; With this definition, the at least problematic 1+ to skip an XT is no longer necessary > (ATmega32)> 42 s" hello" label: example ok (ATmega32)> words > example label: postpone ... (ATmega32)> example 3824 ok > (ATmega32)> icount itype hello ok (ATmega32)> example icount 2/ 1+ > + @i . 3824 42 ok (ATmega32)> HTH Matthias -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlKGakkACgkQ9bEHdGEMFjOjFACfXlmGKXS0R+Q+bCveJ6XTcMaj LboAniAKrEaBEYpRQe2/DloHMQiDlSM+ =Ol5b -----END PGP SIGNATURE----- |
From: Matthias T. <mt...@we...> - 2013-11-14 20:00:57
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Craig, > I'm trying to create a label defining word which I would like to > work as follows: > > xPos yPos s" this is the labels text" label: labelName > > I tried this code: > > \ Define a label that places itself : label: ( x y addr > count --- ) create , , , , does> dup over over 3 + @i swap 2 + @i > moveCursor 1+ @i @i ; > > which at run time I want to return the addr and count of the labels > text in flash. > > The problem is, I think, that s" doesn't compile to flash outside > of a definition. Indeed. something like : label: create sliteral , , does> ... ; may work (haven't tested it) The sliteral takes the addr/len pair that is left from the s" in interpreter mode and compiles it into the flash. The does> part gets the flash address instead of the RAM addresses. Note that when using the label: word, the s" ... " and the "label:" must be on the same line, line breaks wont work, since the s" leaves addresses from the terminal input buffer and does not copy the string elsewhere. Matthias -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlKFK+gACgkQ9bEHdGEMFjPsNgCg+cI99xTZB+8lE0xPwceVznYn V4MAn2QS/PYbemMkz6jjOgGLd0TL/VBs =LVxu -----END PGP SIGNATURE----- |