From e0196da1c8a3dd0af3a71d39ba720b83e8f8e251 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 6 Apr 2010 16:42:30 -0400 Subject: [PATCH 1/2] combinators: call( now throws an error if a quotation that was declared as never returning actually returns --- core/combinators/combinators-tests.factor | 18 ++++++++++++++++++ core/combinators/combinators.factor | 9 +++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/core/combinators/combinators-tests.factor b/core/combinators/combinators-tests.factor index b239b1eac9..1e7a61daaa 100644 --- a/core/combinators/combinators-tests.factor +++ b/core/combinators/combinators-tests.factor @@ -35,6 +35,24 @@ IN: combinators.tests [ 7 ] [ 1 3 [ 2 * ] [ + ] compose compile-call(-test-1 ] unit-test [ 4 ] [ 1 3 [ { + } [ ] like call ] compile-call(-test-1 ] unit-test +[ [ ] call( -- * ) ] must-fail + +: compile-call(-test-2 ( -- ) [ ] call( -- * ) ; + +[ compile-call(-test-2 ] [ wrong-values? ] must-fail-with + +: compile-call(-test-3 ( quot -- ) call( -- * ) ; + +[ [ ] compile-call(-test-3 ] [ wrong-values? ] must-fail-with + +: compile-execute(-test-3 ( a -- ) \ . execute( value -- * ) ; + +[ 10 compile-execute(-test-3 ] [ wrong-values? ] must-fail-with + +: compile-execute(-test-4 ( a word -- ) execute( value -- * ) ; + +[ 10 \ . compile-execute(-test-4 ] [ wrong-values? ] must-fail-with + ! Compiled : cond-test-1 ( obj -- str ) { diff --git a/core/combinators/combinators.factor b/core/combinators/combinators.factor index 7ef2ed5f9f..7ef8ef68ea 100644 --- a/core/combinators/combinators.factor +++ b/core/combinators/combinators.factor @@ -30,11 +30,12 @@ SLOT: out : call-effect ( quot effect -- ) ! Don't use fancy combinators here, since this word always ! runs unoptimized - [ datastack ] 2dip 2dup [ - [ dip ] dip - dup in>> length swap out>> length - check-datastack + [ [ datastack ] dip dip ] dip + dup terminated?>> [ 2drop f ] [ + dup in>> length swap out>> length + check-datastack + ] if ] 2dip rot [ 2drop ] [ wrong-values ] if ; From 0d00160f4c03ec3c89d400487f4c8bd5479e28c5 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 6 Apr 2010 16:48:30 -0400 Subject: [PATCH 2/2] combinators: fix load error --- core/combinators/combinators.factor | 1 + 1 file changed, 1 insertion(+) diff --git a/core/combinators/combinators.factor b/core/combinators/combinators.factor index 7ef8ef68ea..bbfee30b3d 100644 --- a/core/combinators/combinators.factor +++ b/core/combinators/combinators.factor @@ -26,6 +26,7 @@ ERROR: wrong-values quot call-site ; ! We can't USE: effects here so we forward reference slots instead SLOT: in SLOT: out +SLOT: terminated? : call-effect ( quot effect -- ) ! Don't use fancy combinators here, since this word always