[PicForth] Case implementation
David McNab
david at rebirthing.co.nz
Sat Nov 20 11:33:13 CET 2004
easlab at absamail.co.za wrote:
>>From distant past memories of a p-code implementation, CASE is either:
> 1. mere syntax-sugar for repeated IFELSE
True to an extent.
However, in trad Forth, the value being tested is kept on the return
stack, hidden from the match statement blocks, revealed to the 'default'
statement block, then dropped entirely at the end of the switch.
Also, Forth allows case statements to be infinitely nested (well, to the
limit of the size of the return stack anyway).
As it happens, I've hacked my PicForth preprocessor (which I'll release
to the wiki if people are interested and request it), so that it
translates 'case/of/endof/.../of/endof/endcase' statements to 'dup val1
= if drop ... else dup val2 = if drop ... else ... then*'.
> or
> 2. provided the 'density' between the lowest and highest cases is
> sufficient: efficiently implementated by indexed jumps.
> Which is probably nice with PICasm, but I don't know how it
> fits with picforth.
Forth aims to get totally away from the 'spaghetti-coding' mindset of
assembler. However, PicForth provides hooks which allow programmers to
enjoy the best of both worlds.
> PS. I think that attempting to 'ape' C on a proper micro-processor
> with forth on a PIC can be taken too far -- well beyond 'productive
> optimum'.
Agreed - the C programming model is a poor fit for tiny uProcs.
> * what does PIC say for: "7 -> W" ?
movlw 7
--
Cheers
David
More information about the PicForth
mailing list