|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r61312 - in trunk/libs/spirit/example/scheme: example example/scheme test test/scheme
From: joel_at_[hidden]
Date: 2010-04-16 00:46:27
Author: djowel
Date: 2010-04-16 00:46:25 EDT (Fri, 16 Apr 2010)
New Revision: 61312
URL: http://svn.boost.org/trac/boost/changeset/61312
Log:
separating examples from tests
Added:
trunk/libs/spirit/example/scheme/example/scheme/factorial1.cpp
- copied unchanged from r61310, /trunk/libs/spirit/example/scheme/example/scheme/scheme_test2.cpp
trunk/libs/spirit/example/scheme/example/scheme/factorial2.cpp
- copied unchanged from r61310, /trunk/libs/spirit/example/scheme/example/scheme/scheme_test3.cpp
trunk/libs/spirit/example/scheme/test/scheme/
trunk/libs/spirit/example/scheme/test/scheme/factorial.scm (contents, props changed)
trunk/libs/spirit/example/scheme/test/scheme/scheme_test1.cpp (contents, props changed)
trunk/libs/spirit/example/scheme/test/scheme/scheme_test1.scm (contents, props changed)
trunk/libs/spirit/example/scheme/test/scheme/scheme_test2.cpp (contents, props changed)
trunk/libs/spirit/example/scheme/test/scheme/scheme_test3.cpp (contents, props changed)
Removed:
trunk/libs/spirit/example/scheme/example/scheme/scheme_test1.cpp
trunk/libs/spirit/example/scheme/example/scheme/scheme_test1.scm
trunk/libs/spirit/example/scheme/example/scheme/scheme_test2.cpp
trunk/libs/spirit/example/scheme/example/scheme/scheme_test3.cpp
Text files modified:
trunk/libs/spirit/example/scheme/example/Jamfile | 5 ++---
trunk/libs/spirit/example/scheme/test/Jamfile | 3 +++
2 files changed, 5 insertions(+), 3 deletions(-)
Modified: trunk/libs/spirit/example/scheme/example/Jamfile
==============================================================================
--- trunk/libs/spirit/example/scheme/example/Jamfile (original)
+++ trunk/libs/spirit/example/scheme/example/Jamfile 2010-04-16 00:46:25 EDT (Fri, 16 Apr 2010)
@@ -27,9 +27,8 @@
generate_qiexpr/generate_qiexpr.cpp
;
-exe scheme_test1 : scheme/scheme_test1.cpp ;
-exe scheme_test2 : scheme/scheme_test2.cpp ;
-exe scheme_test3 : scheme/scheme_test3.cpp ;
+exe factorial1 : scheme/factorial1.cpp ;
+exe factorial2 : scheme/factorial2.cpp ;
Deleted: trunk/libs/spirit/example/scheme/example/scheme/scheme_test1.cpp
==============================================================================
--- trunk/libs/spirit/example/scheme/example/scheme/scheme_test1.cpp 2010-04-16 00:46:25 EDT (Fri, 16 Apr 2010)
+++ (empty file)
@@ -1,112 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-#include <boost/config/warning_disable.hpp>
-
-#include <input/parse_sexpr_impl.hpp>
-#include <scheme/compiler.hpp>
-#include <utree/io.hpp>
-#include <iostream>
-#include <fstream>
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int main(int argc, char **argv)
-{
- { // testing the c++ side
-
- using scheme::if_;
- using scheme::plus;
- using scheme::times;
- using scheme::minus;
- using scheme::lte;
- using scheme::_1;
- using scheme::_2;
- using scheme::lambda;
-
- std::cout << "result: " << plus(11, 22, 33) () << std::endl;
- std::cout << "result: " << plus(11, 22, _1) (33) << std::endl;
- std::cout << "result: " << plus(11, _1, _2) (22, 33) << std::endl;
- std::cout << "result: " << plus(11, plus(_1, _2)) (22, 33) << std::endl;
-
- lambda factorial;
- factorial = if_(lte(_1, 0), 1, times(_1, factorial(minus(_1, 1))));
-
- std::cout << "result: " << factorial(_1) (10) << std::endl;
- }
-
- char const* filename = NULL;
- if (argc > 1)
- {
- filename = argv[1];
- }
- else
- {
- std::cerr << "Error: No input file provided." << std::endl;
- return 1;
- }
-
- std::ifstream in(filename, std::ios_base::in);
-
- if (!in)
- {
- std::cerr << "Error: Could not open input file: "
- << filename << std::endl;
- return 1;
- }
-
- // Ignore the BOM marking the beginning of a UTF-8 file in Windows
- char c = in.peek();
- if (c == '\xef')
- {
- char s[3];
- in >> s[0] >> s[1] >> s[2];
- s[3] = '\0';
- if (s != std::string("\xef\xbb\xbf"))
- {
- std::cerr << "Error: Unexpected characters from input file: "
- << filename << std::endl;
- return 1;
- }
- }
-
- scheme::utree program;
- if (scheme::input::parse_sexpr_list(in, program))
- {
- std::cout << "success: " << std::endl;
- scheme::environment env;
- scheme::build_basic_environment(env);
- scheme::actor_list fragments;
- scheme::actor_list flist;
- compile_all(program, env, flist, fragments);
-
- scheme::actor_list::iterator i = flist.begin();
-
- std::cout << "the 1st is the define dbl:" << std::endl;
- std::cout << "(dbl 555): " << (*i++)(555) << std::endl;
- std::cout << "the 2nd is the define len:" << std::endl;
- std::cout << "len: " << (*i++)() << std::endl;
- std::cout << "the 3rd is a function call:" << std::endl;
- std::cout << "(dbl len): " << (*i++)() << std::endl;
- std::cout << "the 4th is the define factorial:" << std::endl;
- std::cout << "(factorial 5): " << (*i++)(5) << std::endl;
- std::cout << "the 5th is a function call:" << std::endl;
- std::cout << "(factorial 10): " << (*i++)() << std::endl;
- std::cout << "the 6th is the define fib:" << std::endl;
- std::cout << "(fib 5): " << (*i++)(5) << std::endl;
- std::cout << "the 7th is a function call:" << std::endl;
- std::cout << "(fib 10): " << (*i++)() << std::endl;
- }
- else
- {
- std::cout << "parse error" << std::endl;
- }
-
- return 0;
-}
-
-
Deleted: trunk/libs/spirit/example/scheme/example/scheme/scheme_test1.scm
==============================================================================
--- trunk/libs/spirit/example/scheme/example/scheme/scheme_test1.scm 2010-04-16 00:46:25 EDT (Fri, 16 Apr 2010)
+++ (empty file)
@@ -1,24 +0,0 @@
-; These tests demostrate the functionality of the scheme
-; compiler/interpreter
-
-(define (dbl x) (+ x x))
-
-(define len 123)
-
-(dbl len) ; 246
-
-; The hello-world for interpreters ;-)
-(define (factorial n)
- (if (<= n 0) 1
- (* n (factorial (- n 1)))))
-
-(factorial 10) ; 3628800
-
-; Fibonacci using lambda
-(define fib
- (lambda (n)
- (if (< n 2)
- n
- (+ (fib (- n 1)) (fib (- n 2))))))
-
-(fib 10) ; 55
\ No newline at end of file
Deleted: trunk/libs/spirit/example/scheme/example/scheme/scheme_test2.cpp
==============================================================================
--- trunk/libs/spirit/example/scheme/example/scheme/scheme_test2.cpp 2010-04-16 00:46:25 EDT (Fri, 16 Apr 2010)
+++ (empty file)
@@ -1,53 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-#include <boost/config/warning_disable.hpp>
-
-#include <scheme/compiler.hpp>
-#include <utree/io.hpp>
-#include <iostream>
-#include <fstream>
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int main()
-{
- char const* filename = "factorial.scm";
- std::ifstream in(filename, std::ios_base::in);
-
- if (!in)
- {
- std::cerr << "Error: Could not open input file: "
- << filename << std::endl;
- return 1;
- }
-
- // Ignore the BOM marking the beginning of a UTF-8 file in Windows
- char c = in.peek();
- if (c == '\xef')
- {
- char s[3];
- in >> s[0] >> s[1] >> s[2];
- s[3] = '\0';
- if (s != std::string("\xef\xbb\xbf"))
- {
- std::cerr << "Error: Unexpected characters from input file: "
- << filename << std::endl;
- return 1;
- }
- }
-
- using scheme::interpreter;
- using scheme::_1;
-
- scheme::interpreter factorial(in);
- std::cout << factorial(10) << std::endl;
-
- return 0;
-}
-
-
Deleted: trunk/libs/spirit/example/scheme/example/scheme/scheme_test3.cpp
==============================================================================
--- trunk/libs/spirit/example/scheme/example/scheme/scheme_test3.cpp 2010-04-16 00:46:25 EDT (Fri, 16 Apr 2010)
+++ (empty file)
@@ -1,29 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-#include <boost/config/warning_disable.hpp>
-
-#include <input/sexpr.hpp>
-#include <input/parse_sexpr_impl.hpp>
-#include <scheme/compiler.hpp>
-#include <utree/io.hpp>
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int main()
-{
- using scheme::interpreter;
- using scheme::utree;
-
- utree src = "(define (factorial n) (if (<= n 0) 1 (* n (factorial (- n 1)))))";
- scheme::interpreter factorial(src);
- std::cout << factorial(10) << std::endl;
-
- return 0;
-}
-
-
Modified: trunk/libs/spirit/example/scheme/test/Jamfile
==============================================================================
--- trunk/libs/spirit/example/scheme/test/Jamfile (original)
+++ trunk/libs/spirit/example/scheme/test/Jamfile 2010-04-16 00:46:25 EDT (Fri, 16 Apr 2010)
@@ -22,6 +22,9 @@
# run utree tests
[ run utree/utree_test.cpp : : : : ]
+ [ run scheme/scheme_test1.cpp : scheme/scheme_test1.scm : : : ]
+ [ run scheme/scheme_test2.cpp : scheme/factorial.scm : : : ]
+ [ run scheme/scheme_test3.cpp : : : : ]
;
}
Added: trunk/libs/spirit/example/scheme/test/scheme/factorial.scm
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/test/scheme/factorial.scm 2010-04-16 00:46:25 EDT (Fri, 16 Apr 2010)
@@ -0,0 +1,4 @@
+; The hello-world for interpreters ;-)
+(define (factorial n)
+ (if (<= n 0) 1
+ (* n (factorial (- n 1)))))
Added: trunk/libs/spirit/example/scheme/test/scheme/scheme_test1.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/test/scheme/scheme_test1.cpp 2010-04-16 00:46:25 EDT (Fri, 16 Apr 2010)
@@ -0,0 +1,84 @@
+/*=============================================================================
+ Copyright (c) 2001-2010 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/config/warning_disable.hpp>
+
+#include <input/parse_sexpr_impl.hpp>
+#include <scheme/compiler.hpp>
+#include <utree/io.hpp>
+#include <iostream>
+#include <fstream>
+
+///////////////////////////////////////////////////////////////////////////////
+// Main program
+///////////////////////////////////////////////////////////////////////////////
+int main(int argc, char **argv)
+{
+ using scheme::utree;
+
+ { // testing the c++ side
+
+ using scheme::if_;
+ using scheme::plus;
+ using scheme::times;
+ using scheme::minus;
+ using scheme::lte;
+ using scheme::_1;
+ using scheme::_2;
+ using scheme::lambda;
+
+ BOOST_TEST(plus(11, 22, 33) () == utree(66));
+ BOOST_TEST(plus(11, 22, _1) (33) == utree(66));
+ BOOST_TEST(plus(11, _1, _2) (22, 33) == utree(66));
+ BOOST_TEST(plus(11, plus(_1, _2)) (22, 33) == utree(66));
+
+ lambda factorial;
+ factorial = if_(lte(_1, 0), 1, times(_1, factorial(minus(_1, 1))));
+
+ BOOST_TEST(factorial(_1) (10) == utree(3628800));
+ }
+
+ BOOST_TEST(argc > 1);
+ char const* filename = filename = argv[1];
+ std::ifstream in(filename, std::ios_base::in);
+
+ BOOST_TEST(in);
+
+ // Ignore the BOM marking the beginning of a UTF-8 file in Windows
+ char c = in.peek();
+ if (c == '\xef')
+ {
+ char s[3];
+ in >> s[0] >> s[1] >> s[2];
+ s[3] = '\0';
+ BOOST_TEST(s != std::string("\xef\xbb\xbf"));
+ }
+
+ scheme::utree program;
+ BOOST_TEST(scheme::input::parse_sexpr_list(in, program));
+
+ scheme::environment env;
+ scheme::build_basic_environment(env);
+ scheme::actor_list fragments;
+ scheme::actor_list flist;
+ compile_all(program, env, flist, fragments);
+
+ scheme::actor_list::iterator i = flist.begin();
+
+ BOOST_TEST((*i++)(555) == 1110);
+ BOOST_TEST((*i++)() == 123);
+ BOOST_TEST((*i++)() == 246);
+ BOOST_TEST((*i++)(5) == 120);
+ BOOST_TEST((*i++)() == 3628800);
+ BOOST_TEST((*i++)(5) == 5);
+ BOOST_TEST((*i++)() == 55);
+
+ return boost::report_errors();
+}
+
+
+
Added: trunk/libs/spirit/example/scheme/test/scheme/scheme_test1.scm
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/test/scheme/scheme_test1.scm 2010-04-16 00:46:25 EDT (Fri, 16 Apr 2010)
@@ -0,0 +1,24 @@
+; These tests demostrate the functionality of the scheme
+; compiler/interpreter
+
+(define (dbl x) (+ x x))
+
+(define len 123)
+
+(dbl len) ; 246
+
+; The hello-world for interpreters ;-)
+(define (factorial n)
+ (if (<= n 0) 1
+ (* n (factorial (- n 1)))))
+
+(factorial 10) ; 3628800
+
+; Fibonacci using lambda
+(define fib
+ (lambda (n)
+ (if (< n 2)
+ n
+ (+ (fib (- n 1)) (fib (- n 2))))))
+
+(fib 10) ; 55
\ No newline at end of file
Added: trunk/libs/spirit/example/scheme/test/scheme/scheme_test2.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/test/scheme/scheme_test2.cpp 2010-04-16 00:46:25 EDT (Fri, 16 Apr 2010)
@@ -0,0 +1,47 @@
+/*=============================================================================
+ Copyright (c) 2001-2010 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/config/warning_disable.hpp>
+
+#include <scheme/compiler.hpp>
+#include <utree/io.hpp>
+#include <iostream>
+#include <fstream>
+
+///////////////////////////////////////////////////////////////////////////////
+// Main program
+///////////////////////////////////////////////////////////////////////////////
+int main(int argc, char **argv)
+{
+ using scheme::utree;
+
+ BOOST_TEST(argc > 1);
+ char const* filename = filename = argv[1];
+ std::ifstream in(filename, std::ios_base::in);
+
+ BOOST_TEST(in);
+
+ // Ignore the BOM marking the beginning of a UTF-8 file in Windows
+ char c = in.peek();
+ if (c == '\xef')
+ {
+ char s[3];
+ in >> s[0] >> s[1] >> s[2];
+ s[3] = '\0';
+ BOOST_TEST(s != std::string("\xef\xbb\xbf"));
+ }
+
+ using scheme::interpreter;
+ using scheme::_1;
+
+ scheme::interpreter factorial(in);
+ BOOST_TEST(factorial(10) == 3628800);
+
+ return boost::report_errors();
+}
+
+
Added: trunk/libs/spirit/example/scheme/test/scheme/scheme_test3.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/test/scheme/scheme_test3.cpp 2010-04-16 00:46:25 EDT (Fri, 16 Apr 2010)
@@ -0,0 +1,30 @@
+/*=============================================================================
+ Copyright (c) 2001-2010 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/config/warning_disable.hpp>
+
+#include <input/sexpr.hpp>
+#include <input/parse_sexpr_impl.hpp>
+#include <scheme/compiler.hpp>
+#include <utree/io.hpp>
+
+///////////////////////////////////////////////////////////////////////////////
+// Main program
+///////////////////////////////////////////////////////////////////////////////
+int main()
+{
+ using scheme::interpreter;
+ using scheme::utree;
+
+ utree src = "(define (factorial n) (if (<= n 0) 1 (* n (factorial (- n 1)))))";
+ scheme::interpreter factorial(src);
+ BOOST_TEST(factorial(10) == 3628800);
+
+ return boost::report_errors();
+}
+
+
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk