summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-11-30 08:36:07 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-11-30 08:36:07 +0000
commitcd7dae28b034deebc9c2c2469ed9d8f1f3dab1ed (patch)
tree80cead86cff364718c968849e1c185121a79892d /sca-cpp/trunk
parenta9941f3ba6624b88ef62a2a7bf260f50761ffbf9 (diff)
Added debug macros and cleaned up debug logging. Added locking macros used when compiling for multithreading. Fixed value conversions to numbers. Fixed compile warnings.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@885348 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk')
-rw-r--r--sca-cpp/trunk/kernel/cache.hpp46
-rw-r--r--sca-cpp/trunk/kernel/debug.hpp68
-rw-r--r--sca-cpp/trunk/kernel/dynlib-test.cpp3
-rw-r--r--sca-cpp/trunk/kernel/function.hpp43
-rw-r--r--sca-cpp/trunk/kernel/gc.hpp30
-rw-r--r--sca-cpp/trunk/kernel/kernel-test.cpp14
-rw-r--r--sca-cpp/trunk/kernel/list.hpp51
-rw-r--r--sca-cpp/trunk/kernel/monad.hpp3
-rw-r--r--sca-cpp/trunk/kernel/parallel.hpp5
-rw-r--r--sca-cpp/trunk/kernel/value.hpp141
-rw-r--r--sca-cpp/trunk/modules/eval/driver.hpp4
-rw-r--r--sca-cpp/trunk/modules/eval/environment.hpp6
-rw-r--r--sca-cpp/trunk/modules/eval/eval-test.cpp12
-rw-r--r--sca-cpp/trunk/modules/eval/eval.hpp8
-rw-r--r--sca-cpp/trunk/modules/eval/io.hpp26
-rw-r--r--sca-cpp/trunk/modules/eval/primitive.hpp49
-rw-r--r--sca-cpp/trunk/modules/json/json.hpp2
-rw-r--r--sca-cpp/trunk/modules/server/mod-wiring.cpp38
-rw-r--r--sca-cpp/trunk/test/store-function/currency.hpp3
-rw-r--r--sca-cpp/trunk/test/store-object/currency.hpp3
20 files changed, 417 insertions, 138 deletions
diff --git a/sca-cpp/trunk/kernel/cache.hpp b/sca-cpp/trunk/kernel/cache.hpp
index 28ab38c76f..4cab4e4e9b 100644
--- a/sca-cpp/trunk/kernel/cache.hpp
+++ b/sca-cpp/trunk/kernel/cache.hpp
@@ -26,6 +26,9 @@
* Simple local cache monad implementation.
*/
+#ifdef _REENTRANT
+#include <pthread.h>
+#endif
#include <sys/stat.h>
#include <string>
@@ -40,25 +43,37 @@ namespace tuscany {
*/
template<typename V> class cached {
public:
- cached() : mtime(0) {
+ cached() : mutex(mutex_init()), mtime(0) {
}
- cached(const lambda<V()>& lvalue, const lambda<unsigned long()> ltime) : lvalue(lvalue), ltime(ltime), mtime(0) {
+ cached(const lambda<V()>& lvalue, const lambda<unsigned long()> ltime) : mutex(mutex_init()), lvalue(lvalue), ltime(ltime), mtime(0) {
}
- cached(const lambda<V()>& lvalue, const lambda<unsigned long()> ltime, const unsigned long mtime, const V& v) : lvalue(lvalue), ltime(ltime), mtime(mtime), v(v) {
+ cached(const lambda<V()>& lvalue, const lambda<unsigned long()> ltime, const unsigned long mtime, const V& v) : mutex(mutex_init()), lvalue(lvalue), ltime(ltime), mtime(mtime), v(v) {
}
- cached(const cached<V>& c) : lvalue(c.lvalue), ltime(c.ltime), mtime(c.mtime), v(c.v) {
+ cached(const cached<V>& c) : mutex(mutex_init()), lvalue(c.lvalue), ltime(c.ltime), mtime(c.mtime), v(c.v) {
+ }
+
+ ~cached() {
+#ifdef _REENTRANT
+ pthread_mutex_destroy(mutex);
+#endif
}
const cached<V>& operator=(const cached<V>& c) {
if(this == &c)
return *this;
+#ifdef _REENTRANT
+ pthread_mutex_lock(mutex);
+#endif
this->lvalue = c.lvalue;
this->ltime = c.ltime;
this->mtime = c.mtime;
this->v = c.v;
+#ifdef _REENTRANT
+ pthread_mutex_unlock(mutex);
+#endif
return *this;
}
@@ -69,10 +84,31 @@ public:
const bool operator==(const cached<V>& m) const {
if (this == &m)
return true;
- return mtime == m.mtime && v == m.v;
+#ifdef _REENTRANT
+ pthread_mutex_lock(mutex);
+#endif
+ const bool r = mtime == m.mtime && v == m.v;
+#ifdef _REENTRANT
+ pthread_mutex_unlock(mutex);
+#endif
+ return r;
}
private:
+#ifdef _REENTRANT
+ pthread_mutex_t* mutex;
+ pthread_mutex_t* mutex_init() {
+ pthread_mutex_t* mx = new pthread_mutex_t();
+ pthread_mutex_init(mx, NULL);
+ return mx;
+ }
+#else
+ void* mutex;
+ void* mutex_init() {
+ return NULL;
+ }
+#endif
+
lambda<V()> lvalue;
lambda<time_t()> ltime;
unsigned long mtime;
diff --git a/sca-cpp/trunk/kernel/debug.hpp b/sca-cpp/trunk/kernel/debug.hpp
new file mode 100644
index 0000000000..8dad5fdd3c
--- /dev/null
+++ b/sca-cpp/trunk/kernel/debug.hpp
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+#ifndef tuscany_debug_hpp
+#define tuscany_debug_hpp
+
+/**
+ * Functions to help log and debug.
+ */
+
+namespace tuscany
+{
+
+#ifdef _DEBUG
+
+/**
+ * Debug log.
+ */
+template<typename V> const bool debug(const V& v, const std::string& msg) {
+ std::cerr<< msg << ": " << v << std::endl;
+ return true;
+}
+
+/**
+ * Increment / decrement a debug counter.
+ */
+bool debug_inc(long int& c) {
+ c++;
+ return true;
+}
+
+bool debug_dec(long int& c) {
+ c--;
+ return true;
+}
+
+#define unused __attribute__ ((unused))
+
+#else
+
+#define debug(v, msg)
+
+#define debug_inc(c)
+#define debug_dec(c)
+#define unused
+
+#endif
+
+}
+#endif /* tuscany_debug_hpp */
diff --git a/sca-cpp/trunk/kernel/dynlib-test.cpp b/sca-cpp/trunk/kernel/dynlib-test.cpp
index 0123b5ec79..3cc666df1a 100644
--- a/sca-cpp/trunk/kernel/dynlib-test.cpp
+++ b/sca-cpp/trunk/kernel/dynlib-test.cpp
@@ -24,6 +24,7 @@
*/
#include "function.hpp"
+#include "debug.hpp"
namespace tuscany {
namespace test {
@@ -41,7 +42,7 @@ extern "C" {
return tuscany::test::cppsquare(x);
}
- const tuscany::lambda<int(int)> csquarel(const int x) {
+ const tuscany::lambda<int(int)> csquarel() {
return tuscany::lambda<int(int)>(tuscany::test::cppsquare);
}
diff --git a/sca-cpp/trunk/kernel/function.hpp b/sca-cpp/trunk/kernel/function.hpp
index c99ee5dbad..fb2ad296d7 100644
--- a/sca-cpp/trunk/kernel/function.hpp
+++ b/sca-cpp/trunk/kernel/function.hpp
@@ -28,9 +28,12 @@
#include <iostream>
#include "gc.hpp"
+#include "debug.hpp"
namespace tuscany {
+#ifdef _DEBUG
+
/**
* Debug counters.
*/
@@ -47,6 +50,10 @@ bool resetLambdaCounters() {
return true;
}
+bool checkLambdaCounters() {
+ return countLambdas == 0;
+}
+
bool printLambdaCounters() {
std::cout << "countLambdas " << countLambdas << std::endl;
std::cout << "countELambdas " << countELambdas << std::endl;
@@ -58,6 +65,14 @@ bool printLambdaCounters() {
return true;
}
+#else
+
+#define resetLambdaCounters()
+#define checkLambdaCounters() true
+#define printLambdaCounters()
+
+#endif
+
/**
* Lambda function type.
*/
@@ -77,17 +92,17 @@ public:
template<typename F> class Proxy: public Callable {
public:
Proxy(const F& f) : function(f) {
- countProxies++;
- countFProxies ++;
+ debug_inc(countProxies);
+ debug_inc(countFProxies);
}
Proxy(const Proxy& p) : function(p.function) {
- countProxies++;
- countCProxies ++;
+ debug_inc(countProxies);
+ debug_inc(countCProxies);
}
~Proxy() {
- countProxies--;
+ debug_dec(countProxies);
}
virtual const R operator() (P... p) const {
@@ -108,11 +123,11 @@ private:
unsigned int refCount;
unsigned int acquire() {
- return __sync_add_and_fetch(&refCount, 1);
+ return gc_add_and_fetch(refCount, (unsigned int)1);
}
unsigned int release() {
- return __sync_sub_and_fetch(&refCount, 1);
+ return gc_sub_and_fetch(refCount, (unsigned int)1);
}
};
@@ -121,21 +136,21 @@ template<typename S> class lambda;
template<typename R, typename... P> class lambda<R(P...)> {
public:
lambda() : callable(0) {
- countLambdas++;
- countELambdas++;
+ debug_inc(countLambdas);
+ debug_inc(countELambdas);
}
template<typename F> lambda(const F f) : callable(0) {
typedef typename CallableType::template Proxy<F> ProxyType;
- countLambdas++;
- countFLambdas++;
+ debug_inc(countLambdas);
+ debug_inc(countFLambdas);
callable = gc_counting_ptr<CallableType>(new ProxyType(f));
}
lambda(const lambda& l) {
- countLambdas++;
- countCLambdas++;
+ debug_inc(countLambdas);
+ debug_inc(countCLambdas);
callable = l.callable;
}
@@ -147,7 +162,7 @@ public:
}
~lambda() {
- countLambdas--;
+ debug_dec(countLambdas);
}
const bool operator==(const lambda& l) const {
diff --git a/sca-cpp/trunk/kernel/gc.hpp b/sca-cpp/trunk/kernel/gc.hpp
index 7739e714c2..bb5bbccb24 100644
--- a/sca-cpp/trunk/kernel/gc.hpp
+++ b/sca-cpp/trunk/kernel/gc.hpp
@@ -33,6 +33,24 @@
namespace tuscany
{
+/**
+ * Macros used to add or subtract values to reference counters.
+ * In a multithreaded environment, define MTHREAD_GC to use
+ * the GCC __sync_add_and_fetch and __sync_sub_and_fetch built
+ * in functions.
+ */
+#ifdef MTHREAD_GC
+
+#define gc_add_and_fetch(t, v) __sync_add_and_fetch(&(t), v)
+#define gc_sub_and_fetch(t, v) __sync_sub_and_fetch(&(t), v)
+
+#else
+
+#define gc_add_and_fetch(t, v) ((t) = (t) + (v))
+#define gc_sub_and_fetch(t, v) ((t) = (t) - (v))
+
+#endif
+
template<typename T> class gc_ptr {
public:
gc_ptr(T* p = 0) throw() : countingRef(p == 0? 0 : new CountingRef(p)) {
@@ -95,12 +113,12 @@ private:
void acquire(CountingRef* ref) throw() {
if(ref)
- __sync_add_and_fetch(&ref->count, 1);
+ gc_add_and_fetch(ref->count, (unsigned int)1);
}
void release() throw() {
if(countingRef) {
- unsigned rc = __sync_sub_and_fetch(&countingRef->count, 1);
+ unsigned rc = gc_sub_and_fetch(countingRef->count, (unsigned int)1);
if(rc == 0) {
delete countingRef->ptr;
delete countingRef;
@@ -178,12 +196,12 @@ private:
void acquire(CountingRef* ref) throw() {
if(ref)
- __sync_add_and_fetch(&ref->count, 1);
+ gc_add_and_fetch(ref->count, (unsigned int)1);
}
void release() throw() {
if(countingRef) {
- unsigned rc = __sync_sub_and_fetch(&countingRef->count, 1);
+ unsigned rc = gc_sub_and_fetch(countingRef->count, (unsigned int)1);
if(rc == 0) {
delete[] countingRef->ptr;
delete countingRef;
@@ -311,11 +329,11 @@ private:
}
unsigned int acquire() {
- return __sync_add_and_fetch(&refCount, 1);
+ return gc_add_and_fetch(refCount, (unsigned int)1);
}
unsigned int release() {
- return __sync_sub_and_fetch(&refCount, 1);
+ return gc_sub_and_fetch(refCount, (unsigned int)1);
}
};
diff --git a/sca-cpp/trunk/kernel/kernel-test.cpp b/sca-cpp/trunk/kernel/kernel-test.cpp
index 24d67e1a9a..388fbf7436 100644
--- a/sca-cpp/trunk/kernel/kernel-test.cpp
+++ b/sca-cpp/trunk/kernel/kernel-test.cpp
@@ -81,7 +81,7 @@ bool testLambda() {
bool testLambdaGC() {
resetLambdaCounters();
testLambda();
- assert(countLambdas == 0);
+ assert(checkLambdaCounters());
return true;
}
@@ -140,8 +140,8 @@ bool testListGC() {
countElements = 0;
testCons();
testSet();
- assert(countLambdas == 0);
- assert(countlists == 0);
+ assert(checkLambdaCounters());
+ assert(checkListCounters());
assert(countElements == 0);
return true;
}
@@ -296,7 +296,7 @@ double testSeqMap(double x) {
return x;
}
-double testSeqReduce(double v, double accum) {
+double testSeqReduce(unused double v, double accum) {
return accum + 1.0;
}
@@ -351,9 +351,9 @@ bool testValueGC() {
resetListCounters();
resetValueCounters();
testValue();
- assert(countValues == 0);
- assert(countLambdas == 0);
- assert(countlists == 0);
+ assert(checkValueCounters());
+ assert(checkLambdaCounters());
+ assert(checkListCounters());
return true;
}
diff --git a/sca-cpp/trunk/kernel/list.hpp b/sca-cpp/trunk/kernel/list.hpp
index c21efe173b..da00a5a40d 100644
--- a/sca-cpp/trunk/kernel/list.hpp
+++ b/sca-cpp/trunk/kernel/list.hpp
@@ -28,27 +28,46 @@
#include <iostream>
#include "function.hpp"
+#include "debug.hpp"
namespace tuscany {
-long countlists = 0;
-long countIlists = 0;
-long countClists = 0;
-long countElists = 0;
+#ifdef _DEBUG
+
+/**
+ * Debug counters.
+ */
+long countLists = 0;
+long countILists = 0;
+long countCLists = 0;
+long countELists = 0;
bool resetListCounters() {
- countlists = countIlists = countClists = countElists = 0;
+ countLists = countILists = countCLists = countELists = 0;
return true;
}
+bool checkListCounters() {
+ return countLists == 0;
+}
+
bool printListCounters() {
- std::cout << "countlists " << countlists << std::endl;
- std::cout << "countElists " << countElists << std::endl;
- std::cout << "countIlists " << countIlists << std::endl;
- std::cout << "countClists " << countClists << std::endl;
+ std::cout << "countLists " << countLists << std::endl;
+ std::cout << "countELists " << countELists << std::endl;
+ std::cout << "countILists " << countILists << std::endl;
+ std::cout << "countCLists " << countCLists << std::endl;
return true;
}
+#else
+
+#define resetListCounters()
+#define checkListCounters() true
+#define printListCounters()
+
+#endif
+
+
/**
* A car/cdr lisp-like pair, base structure to construct lists.
*/
@@ -57,20 +76,20 @@ template<typename T> class list {
public:
list() {
- countlists++;
- countElists++;
+ debug_inc(countLists);
+ debug_inc(countELists);
}
list(const T car, const lambda<list<T> ()>& cdr) :
car(car), cdr(cdr) {
- countlists++;
- countIlists++;
+ debug_inc(countLists);
+ debug_inc(countILists);
}
list(const list& p) :
car(p.car), cdr(p.cdr) {
- countlists++;
- countClists++;
+ debug_inc(countLists);
+ debug_inc(countCLists);
}
const list& operator=(const list<T>& p) {
@@ -82,7 +101,7 @@ public:
}
~list() {
- countlists--;
+ debug_dec(countLists);
}
const bool operator==(const list<T>& p) const {
diff --git a/sca-cpp/trunk/kernel/monad.hpp b/sca-cpp/trunk/kernel/monad.hpp
index 1a45640c32..31eb390f1c 100644
--- a/sca-cpp/trunk/kernel/monad.hpp
+++ b/sca-cpp/trunk/kernel/monad.hpp
@@ -28,7 +28,9 @@
#include <string>
#include <iostream>
+
#include "function.hpp"
+#include "debug.hpp"
namespace tuscany
{
@@ -280,6 +282,7 @@ template<typename V, typename F> const lambda<failable<V, F>(V)> success() {
* Returns a failable monad with a failure in it.
*/
template<typename V, typename F> const failable<V, F> mkfailure(const F& f) {
+ debug(f, "failable::mkfailure");
return failable<V, F>(false, f);
}
diff --git a/sca-cpp/trunk/kernel/parallel.hpp b/sca-cpp/trunk/kernel/parallel.hpp
index c2a948bbeb..987d662e23 100644
--- a/sca-cpp/trunk/kernel/parallel.hpp
+++ b/sca-cpp/trunk/kernel/parallel.hpp
@@ -28,6 +28,7 @@
#include <pthread.h>
#include <sys/syscall.h>
+
#include "function.hpp"
namespace tuscany {
@@ -59,11 +60,11 @@ private:
}
unsigned int acquire() {
- return __sync_add_and_fetch(&refCount, 1);
+ return __sync_add_and_fetch(&refCount, (unsigned int)1);
}
unsigned int release() {
- return __sync_sub_and_fetch(&refCount, 1);
+ return __sync_sub_and_fetch(&refCount, (unsigned int)1);
}
bool set(const T& v) {
diff --git a/sca-cpp/trunk/kernel/value.hpp b/sca-cpp/trunk/kernel/value.hpp
index d602b30623..a99309869f 100644
--- a/sca-cpp/trunk/kernel/value.hpp
+++ b/sca-cpp/trunk/kernel/value.hpp
@@ -32,10 +32,16 @@
#include "gc.hpp"
#include "function.hpp"
#include "list.hpp"
+#include "debug.hpp"
namespace tuscany
{
+#ifdef _DEBUG
+
+/**
+ * Debug counters.
+ */
long int countValues = 0;
long int countEValues = 0;
long int countCValues = 0;
@@ -46,6 +52,10 @@ bool resetValueCounters() {
return true;
}
+bool checkValueCounters() {
+ return countValues == 0;
+}
+
bool printValueCounters() {
std::cout << "countValues " << countValues << std::endl;
std::cout << "countEValues " << countEValues << std::endl;
@@ -54,6 +64,14 @@ bool printValueCounters() {
return true;
}
+#else
+
+#define resetValueCounters()
+#define checkValueCounters() true
+#define printValueCounters()
+
+#endif
+
class value;
class value {
@@ -65,13 +83,13 @@ public:
value() :
type(value::Undefined) {
- countValues++;
- countEValues++;
+ debug_inc(countValues);
+ debug_inc(countEValues);
}
value(const value& v) {
- countValues++;
- countCValues++;
+ debug_inc(countValues);
+ debug_inc(countCValues);
type = v.type;
switch(type) {
case value::List:
@@ -127,73 +145,73 @@ public:
}
virtual ~value() {
- countValues--;
+ debug_dec(countValues);
}
value(const lambda<value(list<value>&)>& func) :
type(value::Lambda), data(vdata(func)) {
- countValues++;
- countVValues++;
+ debug_inc(countValues);
+ debug_inc(countVValues);
}
value(const std::string& str) :
type(value::String), data(vdata(result(str))) {
- countValues++;
- countVValues++;
+ debug_inc(countValues);
+ debug_inc(countVValues);
}
value(const char* str) :
type(value::Symbol), data(vdata(result(std::string(str)))) {
- countValues++;
- countVValues++;
+ debug_inc(countValues);
+ debug_inc(countVValues);
}
value(const list<value>& lst) :
type(value::List), data(vdata(result(lst))) {
- countValues++;
- countVValues++;
+ debug_inc(countValues);
+ debug_inc(countVValues);
}
value(const list<list<value> >& l) :
type(value::List), data(vdata(result(listOfValues(l)))) {
- countValues++;
- countVValues++;
+ debug_inc(countValues);
+ debug_inc(countVValues);
}
value(const double num) :
type(value::Number), data(vdata(result(num))) {
- countValues++;
- countVValues++;
+ debug_inc(countValues);
+ debug_inc(countVValues);
}
value(const int num) :
type(value::Number), data(vdata(result((double)num))) {
- countValues++;
- countVValues++;
+ debug_inc(countValues);
+ debug_inc(countVValues);
}
value(const bool boo) :
type(value::Bool), data(vdata(result(boo))) {
- countValues++;
- countVValues++;
+ debug_inc(countValues);
+ debug_inc(countVValues);
}
value(const char chr) :
type(value::Char), data(vdata(result(chr))) {
- countValues++;
- countVValues++;
+ debug_inc(countValues);
+ debug_inc(countVValues);
}
value(const gc_ptr<value> ptr) :
type(value::Ptr), data(vdata(result(ptr))) {
- countValues++;
- countVValues++;
+ debug_inc(countValues);
+ debug_inc(countVValues);
}
value(const gc_pool_ptr<value> ptr) :
type(value::PoolPtr), data(vdata(result(ptr))) {
- countValues++;
- countVValues++;
+ debug_inc(countValues);
+ debug_inc(countVValues);
}
const bool operator!=(const value& v) const {
@@ -237,11 +255,6 @@ public:
operator const std::string() const {
switch(type) {
- case value::List:
- case value::Lambda:
- case value::Ptr:
- case value::PoolPtr:
- return "";
case value::Symbol:
case value::String:
return str()();
@@ -250,12 +263,8 @@ public:
sos << num()();
return sos.str();
}
- case value::Bool: {
- if(boo()())
- return "true";
- else
- return "false";
- }
+ case value::Bool:
+ return boo()()? "true" : "false";
case value::Char: {
std::ostringstream sos;
sos << chr()();
@@ -267,19 +276,67 @@ public:
}
operator const double() const {
- return num()();
+ switch(type) {
+ case value::Symbol:
+ case value::String:
+ return atof(str()().c_str());
+ case value::Number:
+ return (double)num()();
+ case value::Bool:
+ return boo()()? 1.0 : 0.0;
+ case value::Char:
+ return (double)chr()();
+ default:
+ return 0.0;
+ }
}
operator const int() const {
- return num()();
+ switch(type) {
+ case value::Symbol:
+ case value::String:
+ return atoi(str()().c_str());
+ case value::Number:
+ return (int)num()();
+ case value::Bool:
+ return boo()()? 1 : 0;
+ case value::Char:
+ return (int)chr()();
+ default:
+ return 0;
+ }
}
operator const bool() const {
- return boo()();
+ switch(type) {
+ case value::Symbol:
+ case value::String:
+ return str()() == "true";
+ case value::Number:
+ return (int)num()() != 0;
+ case value::Bool:
+ return boo()();
+ case value::Char:
+ return (int)chr()() != 0;
+ default:
+ return 0;
+ }
}
operator const char() const {
- return chr()();
+ switch(type) {
+ case value::Symbol:
+ case value::String:
+ return 0;
+ case value::Number:
+ return (char)num()();
+ case value::Bool:
+ return (char)boo()();
+ case value::Char:
+ return chr()();
+ default:
+ return 0;
+ }
}
operator const gc_ptr<value>() const {
diff --git a/sca-cpp/trunk/modules/eval/driver.hpp b/sca-cpp/trunk/modules/eval/driver.hpp
index 4c69ecb0a1..3076e677c4 100644
--- a/sca-cpp/trunk/modules/eval/driver.hpp
+++ b/sca-cpp/trunk/modules/eval/driver.hpp
@@ -37,12 +37,12 @@ const std::string evalOutputPrompt("; ");
const std::string evalInputPrompt("=> ");
const bool promptForInput(const std::string str, std::ostream& out) {
- out << "\n\n" << str;
+ out << std::endl << std::endl << str;
return true;
}
const bool announceOutput(const std::string str, std::ostream& out) {
- out << "\n" << str;
+ out << std::endl << str;
return true;
}
diff --git a/sca-cpp/trunk/modules/eval/environment.hpp b/sca-cpp/trunk/modules/eval/environment.hpp
index fa9667b1ba..3a19c01deb 100644
--- a/sca-cpp/trunk/modules/eval/environment.hpp
+++ b/sca-cpp/trunk/modules/eval/environment.hpp
@@ -82,7 +82,7 @@ const bool isDotVariable(const value& var) {
const Frame makeBinding(const Frame& frameSoFar, const list<value>& variables, const list<value> values) {
if (isNil(variables)) {
if (!isNil(values))
- std::cout << "Too many arguments supplied " << values << "\n";
+ logStream() << "Too many arguments supplied " << values << std::endl;
return frameSoFar;
}
if (isDotVariable(car(variables)))
@@ -90,7 +90,7 @@ const Frame makeBinding(const Frame& frameSoFar, const list<value>& variables, c
if (isNil(values)) {
if (!isNil(variables))
- std::cout << "Too few arguments supplied " << variables << "\n";
+ logStream() << "Too few arguments supplied " << variables << std::endl;
return frameSoFar;
}
@@ -163,7 +163,7 @@ const value lookupEnvScan(const value& var, const list<value>& vars, const list<
const value lookupEnvLoop(const value& var, const Env& env) {
if(env == theEmptyEnvironment()) {
- std::cout << "Unbound variable " << var << "\n";
+ logStream() << "Unbound variable " << var << std::endl;
return value();
}
return lookupEnvScan(var, frameVariables(*firstFrame(env)), frameValues(*firstFrame(env)), env);
diff --git a/sca-cpp/trunk/modules/eval/eval-test.cpp b/sca-cpp/trunk/modules/eval/eval-test.cpp
index 984b17b26d..fb755b9077 100644
--- a/sca-cpp/trunk/modules/eval/eval-test.cpp
+++ b/sca-cpp/trunk/modules/eval/eval-test.cpp
@@ -47,9 +47,9 @@ bool testEnvGC() {
resetListCounters();
resetValueCounters();
testEnv();
- assert(countValues == 0);
- assert(countLambdas == 0);
- assert(countlists == 0);
+ assert(checkValueCounters());
+ assert(checkLambdaCounters());
+ assert(checkListCounters());
//printLambdaCounters();
//printListCounters();
//printValueCounters();
@@ -211,9 +211,9 @@ bool testEvalGC() {
testEval();
testEvalExpr();
testEvalLambda();
- assert(countValues == 0);
- assert(countLambdas == 0);
- assert(countlists == 0);
+ assert(checkValueCounters());
+ assert(checkLambdaCounters());
+ assert(checkListCounters());
//printLambdaCounters();
//printListCounters();
//printValueCounters();
diff --git a/sca-cpp/trunk/modules/eval/eval.hpp b/sca-cpp/trunk/modules/eval/eval.hpp
index 8c9ecfdecc..1b4d94c631 100644
--- a/sca-cpp/trunk/modules/eval/eval.hpp
+++ b/sca-cpp/trunk/modules/eval/eval.hpp
@@ -141,12 +141,12 @@ const value evalSequence(const list<value>& exps, Env& env, const gc_pool& pool)
const value applyProcedure(const value& procedure, list<value>& arguments, const gc_pool& pool) {
if(isPrimitiveProcedure(procedure))
- return applyPrimitiveProcedure(procedure, arguments, pool);
+ return applyPrimitiveProcedure(procedure, arguments);
if(isCompoundProcedure(procedure)) {
Env env = extendEnvironment(procedureParameters(procedure), arguments, procedureEnvironment(procedure), pool);
return evalSequence(procedureBody(procedure), env, pool);
}
- std::cout << "Unknown procedure type " << procedure << "\n";
+ logStream() << "Unknown procedure type " << procedure << std::endl;
return value();
}
@@ -208,7 +208,7 @@ const value expandClauses(const list<value>& clauses) {
if(isCondElseClause(first)) {
if(isNil(rest))
return sequenceToExp(condActions(first));
- std::cout << "else clause isn't last " << clauses << "\n";
+ logStream() << "else clause isn't last " << clauses << std::endl;
return value();
}
return makeIf(condPredicate(first), sequenceToExp(condActions(first)), expandClauses(rest));
@@ -254,7 +254,7 @@ const value evalExpr(const value& exp, Env& env, const gc_pool& pool) {
list<value> operandValues = listOfValues(operands(exp), env, pool);
return applyProcedure(evalExpr(operat(exp), env, pool), operandValues, pool);
}
- std::cout << "Unknown expression type " << exp << "\n";
+ logStream() << "Unknown expression type " << exp << std::endl;
return value();
}
diff --git a/sca-cpp/trunk/modules/eval/io.hpp b/sca-cpp/trunk/modules/eval/io.hpp
index a898a11440..53657ce055 100644
--- a/sca-cpp/trunk/modules/eval/io.hpp
+++ b/sca-cpp/trunk/modules/eval/io.hpp
@@ -77,14 +77,14 @@ const char readChar(std::istream& in) {
if(in.eof()) {
return -1;
}
- char c = in.get();
+ char c = (char)in.get();
return c;
}
const char peekChar(std::istream& in) {
if(in.eof())
return -1;
- char c = in.peek();
+ char c = (char)in.peek();
return c;
}
@@ -95,7 +95,7 @@ const bool isQuote(const value& token) {
const value skipComment(std::istream& in);
const value readQuoted(std::istream& in);
const value readIdentifier(const char chr, std::istream& in);
-const value readString(const char chr, std::istream& in);
+const value readString(std::istream& in);
const value readNumber(const char chr, std::istream& in);
const value readValue(std::istream& in);
@@ -112,14 +112,14 @@ const value readToken(std::istream& in) {
if(firstChar == ')')
return rightParenthesis;
if(firstChar == '"')
- return readString(firstChar, in);
+ return readString(in);
if(isIdentifierStart(firstChar))
return readIdentifier(firstChar, in);
if(isDigit(firstChar))
return readNumber(firstChar, in);
if(firstChar == -1)
return value();
- std::cout << "Illegal lexical syntax '" << firstChar << "'" << "\n";
+ logStream() << "Illegal lexical syntax '" << firstChar << "'" << std::endl;
return readToken(in);
}
@@ -167,7 +167,7 @@ const list<char> readStringHelper(const list<char>& listSoFar, std::istream& in)
return reverse(listSoFar);
}
-const value readString(const char chr, std::istream& in) {
+const value readString(std::istream& in) {
return listToString(readStringHelper(list<char>(), in));
}
@@ -189,11 +189,25 @@ const value readValue(std::istream& in) {
return nextToken;
}
+const value readValue(const std::string s) {
+ std::istringstream in(s);
+ const value nextToken = readToken(in);
+ if(isLeftParenthesis(nextToken))
+ return readList(list<value> (), in);
+ return nextToken;
+}
+
const bool writeValue(const value& val, std::ostream& out) {
out << val;
return true;
}
+const std::string writeValue(const value& val) {
+ std::ostringstream out;
+ out << val;
+ return out.str();
+}
+
const value readScript(std::istream& in) {
const value val = readValue(in);
if (isNil(val))
diff --git a/sca-cpp/trunk/modules/eval/primitive.hpp b/sca-cpp/trunk/modules/eval/primitive.hpp
index bd36c0e226..49bb3e2087 100644
--- a/sca-cpp/trunk/modules/eval/primitive.hpp
+++ b/sca-cpp/trunk/modules/eval/primitive.hpp
@@ -40,13 +40,27 @@ const value primitiveSymbol("primitive");
const value quoteSymbol("'");
const value lambdaSymbol("lambda");
-std::ostream* displayOut = &std::cout;
+std::ostream* displayOutStream = &std::cout;
+std::ostream* logOutStream = &std::cerr;
const bool setupDisplay(std::ostream& out) {
- displayOut = &out;
+ displayOutStream = &out;
return true;
}
+std::ostream& displayStream() {
+ return *displayOutStream;
+}
+
+const bool setupLog(std::ostream& out) {
+ logOutStream = &out;
+ return true;
+}
+
+std::ostream& logStream() {
+ return *logOutStream;
+}
+
const value carProc(const list<value>& args) {
return car((list<value> )car(args));
}
@@ -64,7 +78,12 @@ const value listProc(const list<value>& args) {
}
const value nulProc(const list<value>& args) {
- return (bool)isNil(car(args));
+ const value v(car(args));
+ if (isNil(v))
+ return true;
+ if (isList(v))
+ return isNil(list<value>(v));
+ return false;
}
const value equalProc(const list<value>& args) {
@@ -92,12 +111,24 @@ const value divProc(const list<value>& args) {
}
const value displayProc(const list<value>& args) {
- *displayOut << car(args);
- (*displayOut).flush();
- return true;
+ if (isNil(args)) {
+ displayStream() << std::endl;
+ return true;
+ }
+ displayStream() << car(args);
+ return displayProc(cdr(args));
+}
+
+const value logProc(const list<value>& args) {
+ if (isNil(args)) {
+ logStream() << std::endl;
+ return true;
+ }
+ logStream() << car(args);
+ return logProc(cdr(args));
}
-const value uuidProc(const list<value>& args) {
+const value uuidProc(unused const list<value>& args) {
apr_uuid_t uuid;
apr_uuid_get(&uuid);
char buf[APR_UUID_FORMATTED_LENGTH];
@@ -105,7 +136,7 @@ const value uuidProc(const list<value>& args) {
return std::string(buf, APR_UUID_FORMATTED_LENGTH);
}
-const value applyPrimitiveProcedure(const value& proc, list<value>& args, const gc_pool& pool) {
+const value applyPrimitiveProcedure(const value& proc, list<value>& args) {
const lambda<value(list<value>&)> func(cadr((list<value>)proc));
return func(args);
}
@@ -151,6 +182,7 @@ const list<value> primitiveProcedureNames() {
l = cons<value>("/", l);
l = cons<value>("equal?", l);
l = cons<value>("display", l);
+ l = cons<value>("log", l);
l = cons<value>("uuid", l);
return l;
}
@@ -168,6 +200,7 @@ const list<value> primitiveProcedureObjects() {
l = cons(primitiveProcedure(divProc), l);
l = cons(primitiveProcedure(equalProc), l);
l = cons(primitiveProcedure(displayProc), l);
+ l = cons(primitiveProcedure(logProc), l);
l = cons(primitiveProcedure(uuidProc), l);
return l;
}
diff --git a/sca-cpp/trunk/modules/json/json.hpp b/sca-cpp/trunk/modules/json/json.hpp
index 7b18d237ec..7d9bba564e 100644
--- a/sca-cpp/trunk/modules/json/json.hpp
+++ b/sca-cpp/trunk/modules/json/json.hpp
@@ -40,7 +40,7 @@ namespace json {
/**
* Report JSON errors.
*/
-void reportError(JSContext *cx, const char *message, JSErrorReport *report) {
+void reportError(unused JSContext *cx, const char *message, JSErrorReport *report) {
std::cerr << (const char*)(report->filename? report->filename : "<no filename>") << ":"
<< (unsigned int)report->lineno << ":" << message << std::endl;
}
diff --git a/sca-cpp/trunk/modules/server/mod-wiring.cpp b/sca-cpp/trunk/modules/server/mod-wiring.cpp
index 2d3c8ce045..0d5262d730 100644
--- a/sca-cpp/trunk/modules/server/mod-wiring.cpp
+++ b/sca-cpp/trunk/modules/server/mod-wiring.cpp
@@ -33,6 +33,7 @@
#include "list.hpp"
#include "slist.hpp"
#include "value.hpp"
+#include "debug.hpp"
#include "monad.hpp"
#include "cache.hpp"
#include "../scdl/scdl.hpp"
@@ -51,10 +52,11 @@ namespace modwiring {
*/
class ServerConf {
public:
- ServerConf(server_rec* s) : home("") {
+ ServerConf(server_rec* s) : s(s), home(""), wiringHost("") {
}
- server_rec* s;
+ const server_rec* s;
std::string home;
+ std::string wiringHost;
};
/**
@@ -67,9 +69,9 @@ const bool useModProxy = true;
*/
class DirConf {
public:
- DirConf(char* dirspec) : contributionPath(""), compositeName("") {
+ DirConf(char* dirspec) : dirspec(dirspec), contributionPath(""), compositeName("") {
}
- char* dirspec;
+ const char* dirspec;
std::string contributionPath;
std::string compositeName;
cached<failable<list<value>, std::string> > components;
@@ -106,7 +108,8 @@ const bool isAbsolute(const std::string& uri) {
int translate(request_rec *r) {
if (strncmp(r->uri, "/references/", 12) != 0)
return DECLINED;
- httpd::logRequest(r, "mod_tuscany_wiring::translate");
+ httpdDebugRequest(r, "modwiring::translate::input");
+ debug(r->uri, "modwiring::translate::uri");
// Find the requested component, reference and its target configuration
DirConf& conf = httpd::dirConf<DirConf>(r, &mod_tuscany_wiring);
@@ -165,11 +168,14 @@ const std::string redirect(const std::string& file, const std::string& pi, const
int handler(request_rec *r) {
if(strcmp(r->handler, "mod_tuscany_wiring"))
return DECLINED;
- httpd::logRequest(r, "mod_tuscany_wiring::handler");
+ httpdDebugRequest(r, "modwiring::handler::input");
// Do an internal redirect
if (r->filename == NULL || strncmp(r->filename, "/redirect:", 10) != 0)
return DECLINED;
+ debug(r->uri, "modwiring::handler::uri");
+ debug(r->filename, "modwiring::handler::filename");
+
if (r->args == NULL) {
ap_internal_redirect(apr_pstrdup(r->pool, redirect(r->filename + 10, r->path_info).c_str()), r);
return OK;
@@ -181,18 +187,23 @@ int handler(request_rec *r) {
/**
* Configuration commands.
*/
-const char *confHome(cmd_parms *cmd, void *dummy, const char *arg) {
+const char *confHome(cmd_parms *cmd, unused void *dummy, const char *arg) {
ServerConf *c = (ServerConf*)ap_get_module_config(cmd->server->module_config, &mod_tuscany_wiring);
c->home = arg;
return NULL;
}
-const char *confContribution(cmd_parms *cmd, void *c, const char *arg) {
+const char *confWiringHost(cmd_parms *cmd, unused void *dummy, const char *arg) {
+ ServerConf *c = (ServerConf*)ap_get_module_config(cmd->server->module_config, &mod_tuscany_wiring);
+ c->wiringHost = arg;
+ return NULL;
+}
+const char *confContribution(unused cmd_parms *cmd, void *c, const char *arg) {
DirConf* conf = (DirConf*)c;
conf->contributionPath = arg;
conf->components = components(conf);
return NULL;
}
-const char *confComposite(cmd_parms *cmd, void *c, const char *arg) {
+const char *confComposite(unused cmd_parms *cmd, void *c, const char *arg) {
DirConf* conf = (DirConf*)c;
conf->compositeName = arg;
conf->components = components(conf);
@@ -204,16 +215,17 @@ const char *confComposite(cmd_parms *cmd, void *c, const char *arg) {
*/
const command_rec commands[] = {
AP_INIT_TAKE1("TuscanyHome", (const char*(*)())confHome, NULL, RSRC_CONF, "Tuscany home directory"),
+ AP_INIT_TAKE1("SCAWiringHost", (const char*(*)())confWiringHost, NULL, RSRC_CONF, "SCA wiring host"),
AP_INIT_TAKE1("SCAContribution", (const char*(*)())confContribution, NULL, ACCESS_CONF, "SCA contribution location"),
AP_INIT_TAKE1("SCAComposite", (const char*(*)())confComposite, NULL, ACCESS_CONF, "SCA composite location"),
- {NULL}
+ {NULL, NULL, NULL, 0, NO_ARGS, NULL}
};
-int postConfig(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) {
+int postConfig(unused apr_pool_t *p, unused apr_pool_t *plog, unused apr_pool_t *ptemp, unused server_rec *s) {
return OK;
}
-void childInit(apr_pool_t* p, server_rec* svr_rec) {
+void childInit(unused apr_pool_t* p, server_rec* svr_rec) {
ServerConf *conf = (ServerConf*)ap_get_module_config(svr_rec->module_config, &mod_tuscany_wiring);
if(conf == NULL) {
std::cerr << "[Tuscany] Due to one or more errors mod_tuscany_wiring loading failed. Causing apache to stop loading." << std::endl;
@@ -221,7 +233,7 @@ void childInit(apr_pool_t* p, server_rec* svr_rec) {
}
}
-void registerHooks(apr_pool_t *p) {
+void registerHooks(unused apr_pool_t *p) {
ap_hook_post_config(postConfig, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_child_init(childInit, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_handler(handler, NULL, NULL, APR_HOOK_MIDDLE);
diff --git a/sca-cpp/trunk/test/store-function/currency.hpp b/sca-cpp/trunk/test/store-function/currency.hpp
index 453a5e1e81..ca4376d2c7 100644
--- a/sca-cpp/trunk/test/store-function/currency.hpp
+++ b/sca-cpp/trunk/test/store-function/currency.hpp
@@ -24,13 +24,14 @@
#include <math.h>
#include <string>
+#include "debug.hpp"
#include "service.hpp"
#include "item.hpp"
namespace store
{
-const double currencyConverter_convert(const std::string& fromCurrencyCode, const std::string& toCurrencyCode, const double amount) {
+const double currencyConverter_convert(unused const std::string& fromCurrencyCode, const std::string& toCurrencyCode, const double amount) {
if(toCurrencyCode == "USD")
return amount;
if(toCurrencyCode == "EUR")
diff --git a/sca-cpp/trunk/test/store-object/currency.hpp b/sca-cpp/trunk/test/store-object/currency.hpp
index a8228ea51c..921c0efb3b 100644
--- a/sca-cpp/trunk/test/store-object/currency.hpp
+++ b/sca-cpp/trunk/test/store-object/currency.hpp
@@ -24,6 +24,7 @@
#include <math.h>
#include <string>
+#include "debug.hpp"
namespace store
{
@@ -38,7 +39,7 @@ public:
class CurrencyConverterImpl : public CurrencyConverter {
public:
- virtual const double convert(const std::string& fromCurrencyCode, const std::string& toCurrencyCode, const double amount) const {
+ virtual const double convert(unused const std::string& fromCurrencyCode, const std::string& toCurrencyCode, const double amount) const {
if(toCurrencyCode == "USD")
return amount;
if(toCurrencyCode == "EUR")