[pure-lang-svn] SF.net SVN: pure-lang:[613] pure/trunk
Status: Beta
Brought to you by:
agraef
|
From: <ag...@us...> - 2008-08-26 00:00:13
|
Revision: 613
http://pure-lang.svn.sourceforge.net/pure-lang/?rev=613&view=rev
Author: agraef
Date: 2008-08-26 00:00:13 +0000 (Tue, 26 Aug 2008)
Log Message:
-----------
Macro regression tests.
Modified Paths:
--------------
pure/trunk/ChangeLog
Added Paths:
-----------
pure/trunk/test/test022.log
pure/trunk/test/test022.pure
Modified: pure/trunk/ChangeLog
===================================================================
--- pure/trunk/ChangeLog 2008-08-25 23:58:55 UTC (rev 612)
+++ pure/trunk/ChangeLog 2008-08-26 00:00:13 UTC (rev 613)
@@ -1,5 +1,7 @@
2008-08-26 Albert Graef <Dr....@t-...>
+ * test/test022.pure: Add macro test script.
+
* lib/prelude.pure: Add optimization rules for ($) and (.) so that
they are expanded at compile time if possible.
Added: pure/trunk/test/test022.log
===================================================================
--- pure/trunk/test/test022.log (rev 0)
+++ pure/trunk/test/test022.log 2008-08-26 00:00:13 UTC (rev 613)
@@ -0,0 +1,100 @@
+def foo (bar x/*0:11*/) = foo x/*0:11*/+1;
+def foo x/*0:1*/ = x/*0:1*/;
+x;
+x
+x+1;
+x+1
+x+1+1;
+x+1+1
+x+1+1+1;
+x+1+1+1
+def goo (bar x/*0:11*/) = goo x/*1:11*/+y/*0:*/ when y/*0:*/ = x/*0:11*/+1 end with bar x/*0:1*/ = 0 end;
+def goo x/*0:1*/ = x/*0:1*/;
+(baz/*2*/ x/*2:*/+y/*0:*/ when y/*0:*/ = baz/*1*/ x/*1:*/+1 {
+ rule #0: y = baz x+1
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end with bar x/*0:1*/ = 0 {
+ rule #0: bar x = 0
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end)+y/*0:*/ when y/*0:*/ = bar (baz/*0*/ x/*0:*/)+1 {
+ rule #0: y = bar (baz x)+1
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end with bar x/*0:1*/ = 0 {
+ rule #0: bar x = 0
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end with baz x/*0:1*/ = x/*0:1*/+1 {
+ rule #0: baz x = x+1
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end when x/*0:*/ = 99 {
+ rule #0: x = 99
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end;
+201+(bar 100+1)
+(baz/*2*/ y/*2:*/+y/*0:*/ when y/*0:*/ = baz/*1*/ y/*1:*/+1 {
+ rule #0: y = baz y+1
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end with bar x/*0:1*/ = 0 {
+ rule #0: bar x = 0
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end)+y/*0:*/ when y/*0:*/ = bar (baz/*0*/ y/*0:*/)+1 {
+ rule #0: y = bar (baz y)+1
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end with bar x/*0:1*/ = 0 {
+ rule #0: bar x = 0
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end with baz x/*0:1*/ = x/*0:1*/+1 {
+ rule #0: baz x = x+1
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end when y/*0:*/ = 99 {
+ rule #0: y = 99
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end;
+201+(bar 100+1)
+bar/*0*/ (bar/*0*/ x/*0:*/) with bar x/*0:1*/ = x/*0:1*/+1 {
+ rule #0: bar x = x+1
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end when x/*0:*/ = 99 {
+ rule #0: x = 99
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end;
+101
+bar/*0*/ (bar/*0*/ y/*0:*/) with bar x/*0:1*/ = x/*0:1*/+1 {
+ rule #0: bar x = x+1
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end when y/*0:*/ = 99 {
+ rule #0: y = 99
+ state 0: #0
+ <var> state 1
+ state 1: #0
+} end;
+101
Added: pure/trunk/test/test022.pure
===================================================================
--- pure/trunk/test/test022.pure (rev 0)
+++ pure/trunk/test/test022.pure 2008-08-26 00:00:13 UTC (rev 613)
@@ -0,0 +1,30 @@
+
+// Macro substitution tests. (Pure 0.6)
+
+/* This macro just removes a 'bar' from its argument and turns it into '+1'.
+ This is done recursively so that bar (...(n times)...(bar x)...) turns
+ into x+1+...(n times)...+1. */
+
+def foo (bar x) = foo x+1;
+def foo x = x;
+
+foo x;
+foo (bar x);
+foo (bar (bar x));
+foo (bar (bar (bar x)));
+
+/* Test for possible name capture issues. Pure is supposed to have hygienic
+ macros. If everything is all right, these tests should both return
+ 201+(bar 100+1). */
+
+def goo (bar x) = goo x+y when y = x+1 end with bar x = 0 end;
+def goo x = x;
+
+goo (bar (bar (baz x))) with baz x = x+1 end when x = 99 end;
+goo (bar (bar (baz y))) with baz x = x+1 end when y = 99 end;
+
+/* These will return just 101, since the 'bar' is locally bound, so the first
+ goo rule doesn't apply. */
+
+goo (bar (bar x)) with bar x = x+1 end when x = 99 end;
+goo (bar (bar y)) with bar x = x+1 end when y = 99 end;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|