On Mon, Nov 15, 2010 at 8:45 AM, Shaping <shap...@charter.net> wrote:
> I'm also thinking that the stack-effect data could be more binding than it > currently is. I noticed while compiling some new words that the compiler > will infer a stack-effect, and tell you when you've written it incorrectly. > This looks almost binding. So my suggestion/question is: Can we use the > stack effects to check at least the superficial (type- and count-based) > correctness of a forth expression, as it is assembled on a Listener command > line? The stack effects are already binding. When you enter a word definition, and the compiler determines that the code's stack effect does not match the declared effect, you'll get an immediate compiler error. The one exception to this is "inline" higher-order words (words such as "map" that take a quotation as input)—for these words, stack checking will be deferred to call sites that use the inline higher-order word, because the stack checking can't be done thoroughly without a quotation to fill in the parameter. If the word declares a static stack effect for its quotations, the effect will be enforced on the caller: -- ( scratchpad ) : foo ( x quot: ( x -- ) -- ) call ; inline ( scratchpad ) : bar ( x y -- ) [ + . ] foo ; ! "bar" should cause an "Input quotation to foo doesn't match its expected effect" error -- If the word declares a polymorphic effect (using "..a" style stack variables to represent a variable number of values), the arities of the stack variables will be unified, and an error raised if unification fails: -- ( scratchpad ) \ if see : if ( ..a ? true: ( ..a -- ..b ) false: ( ..a -- ..b ) -- ..b ) ? call ; ( scratchpad ) : bas ( x y z? -- ) [ + ] [ neg ] if ; ! "bas" should cause an "Input quotations to “if” don't match their expected effects" error -- If a higher-order word declares no stack effect for its quotation arguments, the overall stack effect of the caller will still be checked when the body of the higher-order word and its arguments have been inlined. -Joe ------------------------------------------------------------------------------ Centralized Desktop Delivery: Dell and VMware Reference Architecture Simplifying enterprise desktop deployment and management using Dell EqualLogic storage and VMware View: A highly scalable, end-to-end client virtualization framework. Read more! http://p.sf.net/sfu/dell-eql-dev2dev _______________________________________________ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk