[pure-lang-svn] SF.net SVN: pure-lang: [144] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-05-27 09:28:37
|
Revision: 144 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=144&view=rev Author: agraef Date: 2008-05-27 02:28:46 -0700 (Tue, 27 May 2008) Log Message: ----------- Disable TCO of logical operators, it's broken by design. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/interpreter.cc pure/trunk/interpreter.hh pure/trunk/lib/prelude.pure pure/trunk/test/prelude.log Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-05-27 09:18:50 UTC (rev 143) +++ pure/trunk/ChangeLog 2008-05-27 09:28:46 UTC (rev 144) @@ -1,10 +1,10 @@ 2008-05-27 Albert Graef <Dr....@t-...> * interpreter.cc (toplevel_codegen): Experimental support for - tail-recursive short-circuit logical operators (&& and ||). Note - that this makes these operations behave slightly differently (more - like if-then-else) if they form the right-hand side of an - equation. But the advantages seem to outweigh the semantic quirks. + tail-recursive logical operators (&& and ||). This works but is + disabled, since it makes these operations behave in different ways + depending on the context, which is a really bad idea because it + violates referential transparency. 2008-05-26 Albert Graef <Dr....@t-...> Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-05-27 09:18:50 UTC (rev 143) +++ pure/trunk/interpreter.cc 2008-05-27 09:28:46 UTC (rev 144) @@ -3224,6 +3224,11 @@ return 0; } +/* Experimental support for tail-recursive logical operators (&& and ||). This + works, but is inherently broken (e.g., 0||-1 might return either -1 or 1, + depending on whether the code is TCO'ed or not). Never use this. */ +#define TAILOPS 0 + void interpreter::toplevel_codegen(expr x) { #if USE_FASTCC Modified: pure/trunk/interpreter.hh =================================================================== --- pure/trunk/interpreter.hh 2008-05-27 09:18:50 UTC (rev 143) +++ pure/trunk/interpreter.hh 2008-05-27 09:28:46 UTC (rev 144) @@ -28,11 +28,6 @@ /* Experimental support for the "fast" calling convention which is needed to get tail call elimination. */ #define USE_FASTCC 1 -/* Experimental support for tail-recursive short-circuit logical operators (&& - and ||). This will only have an effect if USE_FASTCC is enabled. Note that - if you disable this option, && and || will still be short-curcuit, they - just won't be tail-recursive in their second operand any more. */ -#define TAILOPS 1 using namespace std; Modified: pure/trunk/lib/prelude.pure =================================================================== --- pure/trunk/lib/prelude.pure 2008-05-27 09:18:50 UTC (rev 143) +++ pure/trunk/lib/prelude.pure 2008-05-27 09:28:46 UTC (rev 144) @@ -98,12 +98,12 @@ ()==() = 1; (x,xs)==() = 0; ()==(x,xs) = 0; -(x,xs)==(y,ys) = x==y && xs==ys; +(x,xs)==(y,ys) = if x==y then xs==ys else 0; ()!=() = 0; (x,xs)!=() = 1; ()!=(x,xs) = 1; -(x,xs)!=(y,ys) = x!=y || xs!=ys; +(x,xs)!=(y,ys) = if x!=y then 1 else xs!=ys; null () = 1; null (x,xs) = 0; @@ -136,12 +136,12 @@ []==[] = 1; (x:xs)==[] = 0; []==(x:xs) = 0; -(x:xs)==(y:ys) = x==y && xs==ys; +(x:xs)==(y:ys) = if x==y then xs==ys else 1; []!=[] = 0; (x:xs)!=[] = 1; []!=(x:xs) = 1; -(x:xs)!=(y:ys) = x!=y || xs!=ys; +(x:xs)!=(y:ys) = if x!=y then 1 else xs!=ys; null [] = 1; null (x:xs) = 0; @@ -214,10 +214,10 @@ to make them tail-recursive. */ all p [] = 1; -all p (x:xs) = p x && all p xs; +all p (x:xs) = if p x then all p xs else 0; any p [] = 0; -any p (x:xs) = p x || any p xs; +any p (x:xs) = if p x then 1 else any p xs; do f [] = (); do f (x:xs) = do f xs when _ = f x end; Modified: pure/trunk/test/prelude.log =================================================================== --- pure/trunk/test/prelude.log 2008-05-27 09:18:50 UTC (rev 143) +++ pure/trunk/test/prelude.log 2008-05-27 09:28:46 UTC (rev 144) @@ -338,11 +338,11 @@ ()==() = 1; (x/*0:0101*/,xs/*0:011*/)==() = 0; ()==(x/*0:101*/,xs/*0:11*/) = 0; -(x/*0:0101*/,xs/*0:011*/)==(y/*0:101*/,ys/*0:11*/) = x/*0:0101*/==y/*0:101*/&&xs/*0:011*/==ys/*0:11*/; +(x/*0:0101*/,xs/*0:011*/)==(y/*0:101*/,ys/*0:11*/) = if x/*0:0101*/==y/*0:101*/ then xs/*0:011*/==ys/*0:11*/ else 0; ()!=() = 0; (x/*0:0101*/,xs/*0:011*/)!=() = 1; ()!=(x/*0:101*/,xs/*0:11*/) = 1; -(x/*0:0101*/,xs/*0:011*/)!=(y/*0:101*/,ys/*0:11*/) = x/*0:0101*/!=y/*0:101*/||xs/*0:011*/!=ys/*0:11*/; +(x/*0:0101*/,xs/*0:011*/)!=(y/*0:101*/,ys/*0:11*/) = if x/*0:0101*/!=y/*0:101*/ then 1 else xs/*0:011*/!=ys/*0:11*/; null () = 1; null (x/*0:101*/,xs/*0:11*/) = 0; #() = 0; @@ -412,11 +412,11 @@ []==[] = 1; x/*0:0101*/:xs/*0:011*/==[] = 0; []==x/*0:101*/:xs/*0:11*/ = 0; -x/*0:0101*/:xs/*0:011*/==y/*0:101*/:ys/*0:11*/ = x/*0:0101*/==y/*0:101*/&&xs/*0:011*/==ys/*0:11*/; +x/*0:0101*/:xs/*0:011*/==y/*0:101*/:ys/*0:11*/ = if x/*0:0101*/==y/*0:101*/ then xs/*0:011*/==ys/*0:11*/ else 1; []!=[] = 0; x/*0:0101*/:xs/*0:011*/!=[] = 1; []!=x/*0:101*/:xs/*0:11*/ = 1; -x/*0:0101*/:xs/*0:011*/!=y/*0:101*/:ys/*0:11*/ = x/*0:0101*/!=y/*0:101*/||xs/*0:011*/!=ys/*0:11*/; +x/*0:0101*/:xs/*0:011*/!=y/*0:101*/:ys/*0:11*/ = if x/*0:0101*/!=y/*0:101*/ then 1 else xs/*0:011*/!=ys/*0:11*/; null [] = 1; null (x/*0:101*/:xs/*0:11*/) = 0; #[] = 0; @@ -640,9 +640,9 @@ state 1: #0 }) n/*0:01*/; all p/*0:01*/ [] = 1; -all p/*0:01*/ (x/*0:101*/:xs/*0:11*/) = p/*0:01*/ x/*0:101*/&&all p/*0:01*/ xs/*0:11*/; +all p/*0:01*/ (x/*0:101*/:xs/*0:11*/) = if p/*0:01*/ x/*0:101*/ then all p/*0:01*/ xs/*0:11*/ else 0; any p/*0:01*/ [] = 0; -any p/*0:01*/ (x/*0:101*/:xs/*0:11*/) = p/*0:01*/ x/*0:101*/||any p/*0:01*/ xs/*0:11*/; +any p/*0:01*/ (x/*0:101*/:xs/*0:11*/) = if p/*0:01*/ x/*0:101*/ then 1 else any p/*0:01*/ xs/*0:11*/; do f/*0:01*/ [] = (); do f/*0:01*/ (x/*0:101*/:xs/*0:11*/) = do f/*1:01*/ xs/*1:11*/ when _/*0:*/ = f/*0:01*/ x/*0:101*/ { rule #0: _ = f x This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |