[OpenBIOS] help with compile/run-time code
Programmingkid
programmingkidx at gmail.com
Mon Sep 13 18:23:08 CEST 2010
On Sep 13, 2010, at 4:32 AM, openbios-request at openbios.org wrote:
> Programmingkid wrote:
>
>> I need a little help on how to take compile-time code and change it so that it executes a different set of code at run-time. I want to take this code: "4 -> cat" and change it to "4 cat !" at run-time. The "->" word needs to be able to do this. Would anyone know how?
>>
>> compile time: 4 -> cat
>> run-time: 4 cat !
>
> In the context of local variables, would you be able to get away with
> parsing this as a string?
>
>
> ATB,
>
> Mark.
>
> --
> Mark Cave-Ayland - Senior Technical Architect
> PostgreSQL - PostGIS
> Sirius Corporation plc - control through freedom
> http://www.siriusit.co.uk
> t: +44 870 608 0063
>
> Sirius Labs: http://www.siriusit.co.uk/labs
I was thinking about parsing them as strings, but that would make viewing and debugging the code difficult. I was really hoping for translating the compile-time code into the run-time code I have presented.
I made some code examples that I would like to obtain some feedback on. Tell me which of these run-time code examples seems the most plausible to work.
Example 1:
compile-time code:
: myword { ; dog cat hamster }
4 -> dog
3 -> cat
1 -> hamster
dog @ cat @ +
hamster @ +
cr " animals = " . cr
;
run-time code:
: myword
\ Note: myword_wordlist and standardlist are raw numbers - not variables
myword_wordlist standardlist 2 set-order \ setup dictionary search order
definitions
variable dog
variable cat
variable hamster
4 dog !
3 cat !
1 hamster !
dog @ cat @ +
hamster @ +
cr " animals = " . cr
standardlist 1 set-order \ restore dictionary search order
definitions
;
Another possible run-time code translation:
: myword
variable dog
variable cat
variable hamster
4 dog !
3 cat !
1 hamster !
dog @ cat @ +
hamster @ +
cr " animals = " . cr
forget dog
forget cat
forget hamster
;
Example 2:
compile-time code:
\ assigning top stack value to variables
: myword { dog cat hamster }
dog @ cat @ +
hamster @ +
cr " animals = " . cr
;
run-time code:
: myword
variable dog
variable cat
variable hamster
dog !
cat !
hamster !
dog @ cat @ +
hamster @ +
cr " animals = " . cr
forget dog
forget cat
forget hamster
;
In each example, the compile-time code would be something that the user enters or is found in a boot script.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openbios.org/pipermail/openbios/attachments/20100913/73a0dc42/attachment-0001.html>
More information about the OpenBIOS
mailing list