From afcb610960a312c396742ffd15be43336081e322 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 6 Jun 2014 10:54:57 -0700 Subject: [PATCH] core: Throw an error when defining MAIN: with a stack effect other than ( -- ). Fixes #1060. --- core/effects/effects.factor | 7 +++++++ core/syntax/syntax.factor | 5 +++-- core/vocabs/vocabs.factor | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core/effects/effects.factor b/core/effects/effects.factor index bcc2b1e4f6..d875b8e1d1 100644 --- a/core/effects/effects.factor +++ b/core/effects/effects.factor @@ -127,3 +127,10 @@ M: effect clone [ in>> length ] [ out>> length ] [ terminated?>> ] tri pick 0 = [ [ 1 + ] dip ] [ [ 1 - ] 2dip ] if [ [ "x" ] bi@ ] dip ; + +ERROR: bad-stack-effect word expected got ; + +: check-stack-effect ( word effect -- ) + [ dup stack-effect ] dip + 2dup effect= + [ 3drop ] [ bad-stack-effect ] if ; diff --git a/core/syntax/syntax.factor b/core/syntax/syntax.factor index 7c6ca98764..c115a3c369 100644 --- a/core/syntax/syntax.factor +++ b/core/syntax/syntax.factor @@ -4,11 +4,11 @@ USING: accessors arrays byte-arrays byte-vectors classes.algebra.private classes.builtin classes.intersection classes.maybe classes.mixin classes.parser classes.predicate classes.singleton classes.tuple classes.tuple.parser -classes.union combinators compiler.units definitions +classes.union combinators compiler.units definitions effects effects.parser generic generic.hook generic.math generic.parser generic.standard hash-sets hashtables io.pathnames kernel lexer math namespaces parser quotations sbufs sequences slots -source-files splitting strings strings.parser vectors +source-files splitting strings strings.parser vectors vocabs vocabs.parser words words.alias words.constant words.symbol ; IN: bootstrap.syntax @@ -233,6 +233,7 @@ IN: bootstrap.syntax "MAIN:" [ scan-word + dup ( -- ) check-stack-effect [ current-vocab main<< ] [ file get [ main<< ] [ drop ] if* ] bi ] define-core-syntax diff --git a/core/vocabs/vocabs.factor b/core/vocabs/vocabs.factor index 77b3d681d3..1d1b1b5d91 100644 --- a/core/vocabs/vocabs.factor +++ b/core/vocabs/vocabs.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2007, 2009 Eduardo Cavazos, Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors assocs definitions kernel namespaces sequences -sorting splitting strings ; +USING: accessors assocs definitions kernel namespaces +sequences sorting splitting strings ; IN: vocabs SYMBOL: dictionary -- 2.34.1