Re: Case implementation
David McNab <[email protected]> Sat, 20 Nov 2004 23:33:13 +1300
| Newsgroups | gmane.comp.lang.forth.picforth |
|---|---|
| Message-ID | <[email protected]> |
[email protected] 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