diff options
-rw-r--r-- | cpp/sca/Makefile.am | 6 | ||||
-rw-r--r-- | cpp/sca/configure.ac | 14 | ||||
-rw-r--r-- | cpp/sca/etc/git-exclude | 6 | ||||
-rw-r--r-- | cpp/sca/kernel/kernel-test.cpp | 30 | ||||
-rw-r--r-- | cpp/sca/kernel/list.hpp | 4 | ||||
-rw-r--r-- | cpp/sca/modules/eval/Makefile.am | 5 | ||||
-rw-r--r-- | cpp/sca/modules/eval/driver.hpp | 8 | ||||
-rw-r--r-- | cpp/sca/modules/eval/environment.hpp | 45 | ||||
-rwxr-xr-x | cpp/sca/modules/eval/eval-test | bin | 436085 -> 335904 bytes | |||
-rw-r--r-- | cpp/sca/modules/eval/eval-test.cpp | 14 | ||||
-rw-r--r-- | cpp/sca/modules/eval/eval.hpp | 261 | ||||
-rw-r--r-- | cpp/sca/modules/eval/primitive.hpp | 12 | ||||
-rw-r--r-- | cpp/sca/modules/eval/read.hpp | 2 | ||||
-rw-r--r-- | cpp/sca/samples/Makefile.am | 4 | ||||
-rw-r--r-- | cpp/sca/samples/configure.ac | 2 | ||||
-rw-r--r-- | cpp/sca/test/Makefile.am (renamed from cpp/sca/samples/store/Makefile.am) | 10 | ||||
-rw-r--r-- | cpp/sca/test/store-function/Makefile.am | 28 | ||||
-rw-r--r-- | cpp/sca/test/store-function/cart.hpp (renamed from cpp/sca/samples/store2/cart.hpp) | 16 | ||||
-rw-r--r-- | cpp/sca/test/store-function/catalog.hpp (renamed from cpp/sca/samples/store2/catalog.hpp) | 4 | ||||
-rw-r--r-- | cpp/sca/test/store-function/catalogs.composite (renamed from cpp/sca/samples/store/catalogs.composite) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-function/currency-composite.hpp (renamed from cpp/sca/samples/store2/currency-composite.hpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-function/currency.composite (renamed from cpp/sca/samples/store/currency.composite) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-function/currency.hpp (renamed from cpp/sca/samples/store2/currency.hpp) | 8 | ||||
-rw-r--r-- | cpp/sca/test/store-function/item.hpp (renamed from cpp/sca/samples/store2/item.hpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-function/service.hpp (renamed from cpp/sca/samples/store2/service.hpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-function/store-composite.hpp (renamed from cpp/sca/samples/store2/store-composite.hpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-function/store-function-test.cpp (renamed from cpp/sca/samples/store2/store2-test.cpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-function/store-solution.hpp (renamed from cpp/sca/samples/store2/store-solution.hpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-function/store-ui.hpp (renamed from cpp/sca/samples/store2/store-ui.hpp) | 16 | ||||
-rw-r--r-- | cpp/sca/test/store-function/store.composite (renamed from cpp/sca/samples/store/store.composite) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-object/Makefile.am (renamed from cpp/sca/samples/store2/Makefile.am) | 13 | ||||
-rw-r--r-- | cpp/sca/test/store-object/cart.hpp (renamed from cpp/sca/samples/store/cart.hpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-object/catalog.hpp (renamed from cpp/sca/samples/store/catalog.hpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-object/catalogs.composite (renamed from cpp/sca/samples/store2/catalogs.composite) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-object/currency-composite.hpp (renamed from cpp/sca/samples/store/currency-composite.hpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-object/currency.composite (renamed from cpp/sca/samples/store2/currency.composite) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-object/currency.hpp (renamed from cpp/sca/samples/store/currency.hpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-object/item.hpp (renamed from cpp/sca/samples/store/item.hpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-object/store-composite.hpp (renamed from cpp/sca/samples/store/store-composite.hpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-object/store-object-test.cpp (renamed from cpp/sca/samples/store/store-test.cpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-object/store-solution.hpp (renamed from cpp/sca/samples/store/store-solution.hpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-object/store-ui.hpp (renamed from cpp/sca/samples/store/store-ui.hpp) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-object/store.composite (renamed from cpp/sca/samples/store2/store.composite) | 0 | ||||
-rw-r--r-- | cpp/sca/test/store-script/Makefile.am | 28 | ||||
-rw-r--r-- | cpp/sca/test/store-script/catalogs.composite | 43 | ||||
-rw-r--r-- | cpp/sca/test/store-script/currency.composite | 32 | ||||
-rw-r--r-- | cpp/sca/test/store-script/store-script-test.cpp | 58 | ||||
-rw-r--r-- | cpp/sca/test/store-script/store-script.scm | 99 | ||||
-rw-r--r-- | cpp/sca/test/store-script/store.composite | 64 |
49 files changed, 551 insertions, 281 deletions
diff --git a/cpp/sca/Makefile.am b/cpp/sca/Makefile.am index 106fa5e25b..caa00d389a 100644 --- a/cpp/sca/Makefile.am +++ b/cpp/sca/Makefile.am @@ -15,8 +15,8 @@ # specific language governing permissions and limitations # under the License. -SUBDIRS = runtime kernel modules doc -DIST_SUBDIRS = runtime doc samples +SUBDIRS = kernel modules test doc runtime +DIST_SUBDIRS = doc runtime samples datadir=$(prefix) data_DATA = INSTALL README LICENSE COPYING NOTICE GettingStarted.html nobase_data_DATA = xsd/*.* @@ -47,7 +47,7 @@ bindist: dist mv ${PACKAGE}-${PACKAGE_VERSION} ${PACKAGE}-${PACKAGE_VERSION}-src tar -cf - ${PACKAGE}-${PACKAGE_VERSION}-src | gzip -c > ${PACKAGE}-${PACKAGE_VERSION}-src.tar.gz cd ${PACKAGE}-${PACKAGE_VERSION}-src \ - && sh ../makebindist.sh + && sh ../makebindist.sh mkdir ${PACKAGE}-${PACKAGE_VERSION}-bin cp -r ${PACKAGE}-${PACKAGE_VERSION}-src/deploy/* ${PACKAGE}-${PACKAGE_VERSION}-bin tar -cf - ${PACKAGE}-${PACKAGE_VERSION}-bin | gzip -c > ${PACKAGE}-${PACKAGE_VERSION}-bin.tar.gz diff --git a/cpp/sca/configure.ac b/cpp/sca/configure.ac index 0bac946b68..457c53d09d 100644 --- a/cpp/sca/configure.ac +++ b/cpp/sca/configure.ac @@ -255,6 +255,15 @@ fi AM_CONDITIONAL([WANT_DOXYGEN], [test x$want_doxygen = xtrue]) AC_CONFIG_FILES([Makefile + kernel/Makefile + modules/Makefile + modules/eval/Makefile + test/Makefile + test/store-object/Makefile + test/store-function/Makefile + test/store-script/Makefile + doc/Makefile + doc/Doxyfile runtime/Makefile runtime/core/Makefile runtime/core/src/Makefile @@ -290,11 +299,6 @@ AC_CONFIG_FILES([Makefile runtime/extensions/ruby/Makefile runtime/extensions/ruby/src/Makefile runtime/extensions/ruby/extension/Makefile - kernel/Makefile - modules/Makefile - modules/eval/Makefile - doc/Makefile - doc/Doxyfile ]) AC_OUTPUT diff --git a/cpp/sca/etc/git-exclude b/cpp/sca/etc/git-exclude index a6e5b24dd4..0350dd230f 100644 --- a/cpp/sca/etc/git-exclude +++ b/cpp/sca/etc/git-exclude @@ -59,8 +59,10 @@ gmon.out sca/runtime/extensions/cpp/tools/scagen/docs/ account_client calculator_client -store-test -store2-test kernel-test xml-test +eval-test +store-function-test +store-object-test +store-script-test diff --git a/cpp/sca/kernel/kernel-test.cpp b/cpp/sca/kernel/kernel-test.cpp index 3e2793f070..02bb63c928 100644 --- a/cpp/sca/kernel/kernel-test.cpp +++ b/cpp/sca/kernel/kernel-test.cpp @@ -105,9 +105,9 @@ bool testCons() { return true; } -bool testlistGC() { +bool testListGC() { resetLambdaCounters(); - resetlistCounters(); + resetListCounters(); countElements = 0; testCons(); assert(countLambdas == 0); @@ -227,13 +227,13 @@ double testSeqReduce(double v, double accum) { } bool testSeq() { - //resetLambdaCounters(); - //resetlistCounters(); + resetLambdaCounters(); + resetListCounters(); list<double> s = seq(0.0, 1000.0); assert(1001 == length(s)); - //printLambdaCounters(); - //printlistCounters(); + printLambdaCounters(); + printListCounters(); assert(1001 == length(map(lambda<double(double)>(testSeqMap), s))); @@ -241,8 +241,8 @@ bool testSeq() { assert(201 == length(member(200.0, reverse(s)))); assert(1001 == reduce(lambda<double(double, double)>(testSeqReduce), 0.0, s)); - //printLambdaCounters(); - //printlistCounters(); + printLambdaCounters(); + printListCounters(); return true; } @@ -262,9 +262,9 @@ bool testValue() { } bool testValueGC() { - resetValueCounters(); resetLambdaCounters(); - resetlistCounters(); + resetListCounters(); + resetValueCounters(); testValue(); assert(countValues == 0); assert(countLambdas == 0); @@ -292,7 +292,7 @@ bool testCppPerf() { assert(1000 == length(r)); gettimeofday(&end, NULL); - long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); + //long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); //std::cout << "Fib cpp perf test " << t << " ms" << std::endl; return true; } @@ -305,7 +305,7 @@ bool testAtomicPerf() { for(int i = 0; i < 10000000;) i = i + 1; gettimeofday(&end, NULL); - long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); + //long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); //std::cout << "Loop test " << t << " ms" << std::endl; } { @@ -313,7 +313,7 @@ bool testAtomicPerf() { for(int i = 0; i < 10000000;) __sync_add_and_fetch(&i, 1); gettimeofday(&end, NULL); - long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); + //long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); //std::cout << "Loop atomic test " << t << " ms" << std::endl; } { @@ -327,7 +327,7 @@ bool testAtomicPerf() { } gettimeofday(&end, NULL); pthread_mutex_destroy(&mutex); - long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); + //long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); //std::cout << "Loop mutex test " << t << " ms" << std::endl; } return true; @@ -418,7 +418,7 @@ int main() { tuscany::testFunction(); tuscany::testFunctionGC(); tuscany::testCons(); - tuscany::testlistGC(); + tuscany::testListGC(); tuscany::testOut(); tuscany::testEquals(); tuscany::testLength(); diff --git a/cpp/sca/kernel/list.hpp b/cpp/sca/kernel/list.hpp index ef493b19ca..5ee527e10c 100644 --- a/cpp/sca/kernel/list.hpp +++ b/cpp/sca/kernel/list.hpp @@ -36,12 +36,12 @@ long countIlists = 0; long countClists = 0; long countElists = 0; -bool resetlistCounters() { +bool resetListCounters() { countlists = countIlists = countClists = countElists = 0; return true; } -bool printlistCounters() { +bool printListCounters() { std::cout << "countlists " << countlists << std::endl; std::cout << "countElists " << countElists << std::endl; std::cout << "countIlists " << countIlists << std::endl; diff --git a/cpp/sca/modules/eval/Makefile.am b/cpp/sca/modules/eval/Makefile.am index 9b09d912d9..e1add383f4 100644 --- a/cpp/sca/modules/eval/Makefile.am +++ b/cpp/sca/modules/eval/Makefile.am @@ -22,11 +22,6 @@ nobase_data_DATA = *.xsd INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -#libdir=$(prefix)/modules/eval/lib -#lib_LTLIBRARIES = libtuscany_eval.la -#libtuscany_eval_la_SOURCES = eval.cpp -#libtuscany_eval_la_LIBADD = -L${TUSCANY_SCACPP}/lib -ltuscany_sca -lpthread - eval_test_SOURCES = eval-test.cpp eval_test_LDADD = -lpthread -L${LIBXML2_LIB} -lxml2 diff --git a/cpp/sca/modules/eval/driver.hpp b/cpp/sca/modules/eval/driver.hpp index c1b2e1e96f..582f4f1b08 100644 --- a/cpp/sca/modules/eval/driver.hpp +++ b/cpp/sca/modules/eval/driver.hpp @@ -33,16 +33,16 @@ namespace tuscany { -const std::string evalOutputPrompt(";;; Eval value: "); -const std::string evalInputPrompt(";;; Eval input: "); +const std::string evalOutputPrompt("; "); +const std::string evalInputPrompt("=> "); const bool promptForInput(std::ostream& out, const std::string str) { - out << "\n\n" << str << "\n"; + out << "\n\n" << str; return true; } const bool announceOutput(std::ostream& out, const std::string str) { - out << "\n" << str << "\n"; + out << "\n" << str; return true; } diff --git a/cpp/sca/modules/eval/environment.hpp b/cpp/sca/modules/eval/environment.hpp index 4ee27df552..46c1716cd8 100644 --- a/cpp/sca/modules/eval/environment.hpp +++ b/cpp/sca/modules/eval/environment.hpp @@ -29,6 +29,7 @@ #include <string> #include "list.hpp" #include "value.hpp" +#include "primitive.hpp" namespace tuscany { @@ -40,6 +41,7 @@ const value trueSymbol = value("true"); const value falseSymbol = value("false"); const value defineSymbol = value("define"); const value setSymbol = value("set!"); +const value dotSymbol = value("."); const Env theEmptyEnvironment() { return list<value>(); @@ -73,8 +75,35 @@ list<value> frameValues(const Frame& frame) { return cdr((list<value> )frame); } +const bool isDotVariable(const value& var) { + return var == dotSymbol; +} + +const Frame makeBinding(const Frame& frameSoFar, const list<value>& variables, const list<value> values) { + if (variables == list<value>()) { + if (values != list<value>()) + std::cout << "Too many arguments supplied " << values << "\n"; + return frameSoFar; + } + if (isDotVariable(car(variables))) + return makeBinding(frameSoFar, cdr(variables), makeList(value(values))); + + if (values == list<value>()) { + if (variables != list<value>()) + std::cout << "Too few arguments supplied " << variables << "\n"; + return frameSoFar; + } + + const list<value> vars = cons(car(variables), frameVariables(frameSoFar)); + const list<value> vals = cons(car(values), frameValues(frameSoFar)); + const Frame newFrame = value(cons(value(vars), vals)); + + return makeBinding(newFrame, cdr(variables), cdr(values)); +} + const Frame makeFrame(const list<value>& variables, const list<value> values) { - return value(cons((value)variables, values)); + const Frame emptyFrame = value(cons((value)list<value>(), list<value>())); + return makeBinding(emptyFrame, variables, values); } const value definitionVariable(const value& exp) { @@ -110,13 +139,13 @@ const Env defineVariable(const value& var, const value& val, Env& env) { } const Env extendEnvironment(const list<value>& vars, const list<value>& vals, const Env& baseEnv) { - if(length(vars) == length(vals)) - return cons(makeFrame(vars, vals), baseEnv); - else if(length(vars) < length(vals)) - std::cout << "Too many arguments supplied " << vars << " " << vals << "\n"; - else - std::cout << "Too few arguments supplied " << vars << " " << vals << "\n"; - return baseEnv; +// if(length(vars) == length(vals)) +// else if(length(vars) < length(vals)) +// std::cout << "Too many arguments supplied " << vars << " " << vals << "\n"; +// else +// std::cout << "Too few arguments supplied " << vars << " " << vals << "\n"; +// return baseEnv; + return cons(makeFrame(vars, vals), baseEnv); } const Env setupEnvironment() { diff --git a/cpp/sca/modules/eval/eval-test b/cpp/sca/modules/eval/eval-test Binary files differindex 9e9b36ddbb..ff394153d1 100755 --- a/cpp/sca/modules/eval/eval-test +++ b/cpp/sca/modules/eval/eval-test diff --git a/cpp/sca/modules/eval/eval-test.cpp b/cpp/sca/modules/eval/eval-test.cpp index e75485a2d5..c8c86a1666 100644 --- a/cpp/sca/modules/eval/eval-test.cpp +++ b/cpp/sca/modules/eval/eval-test.cpp @@ -41,13 +41,16 @@ bool testEnv() { } bool testEnvGC() { - resetValueCounters(); resetLambdaCounters(); - resetlistCounters(); + resetListCounters(); + resetValueCounters(); testEnv(); assert(countValues == 0); assert(countLambdas == 0); assert(countlists == 0); + printLambdaCounters(); + printListCounters(); + printValueCounters(); return true; } @@ -138,13 +141,16 @@ bool testEvalExpr() { } bool testEvalGC() { - resetValueCounters(); resetLambdaCounters(); - resetlistCounters(); + resetListCounters(); + resetValueCounters(); testEval(); assert(countValues == 0); assert(countLambdas == 0); assert(countlists == 0); + printLambdaCounters(); + printListCounters(); + printValueCounters(); return true; } diff --git a/cpp/sca/modules/eval/eval.hpp b/cpp/sca/modules/eval/eval.hpp index 23e9554aa8..28e1d01ffc 100644 --- a/cpp/sca/modules/eval/eval.hpp +++ b/cpp/sca/modules/eval/eval.hpp @@ -23,10 +23,10 @@ #define tuscany_eval_eval_hpp /** - * Script evaluator core evaluation logic. + * Core script evaluation logic. */ -#include <string> +#include <string.h> #include "list.hpp" #include "value.hpp" #include "primitive.hpp" @@ -36,8 +36,11 @@ namespace tuscany { +const value eval(const value& exp, Env& env); + const value compoundProcedureSymbol("compound-procedure"); const value procedureSymbol("procedure"); +const value applySymbol("apply"); const value beginSymbol("begin"); const value condSymbol("cond"); const value elseSymbol("else"); @@ -67,6 +70,10 @@ const value makeProcedure(const list<value>& parameters, const value& body, cons return value(makeList(procedureSymbol, value(parameters), body, value(env))); } +const bool isApply(const value& exp) { + return isTaggedList(exp, applySymbol); +} + const bool isApplication(const value& exp) { return isList(exp); } @@ -79,6 +86,20 @@ const list<value> operands(const value& exp) { return cdr((list<value> )exp); } +const list<value> listOfValues(const list<value> exps, Env& env) { + if(exps == list<value> ()) + return list<value> (); + return cons(eval(car(exps), env), listOfValues(cdr(exps), env)); +} + +const value applyOperat(const value& exp) { + return cadr((list<value> )exp); +} + +const value applyOperand(const value& exp) { + return caddr((list<value> )exp); +} + const bool isCompoundProcedure(const value& procedure) { return isTaggedList(procedure, procedureSymbol); } @@ -103,10 +124,32 @@ const value firstExp(const list<value>& seq) { return car(seq); } +const list<value> restExp(const list<value>& seq) { + return cdr(seq); +} + const value makeBegin(const list<value> seq) { return value(cons(beginSymbol, seq)); } +const value evalSequence(const list<value>& exps, Env& env) { + if(isLastExp(exps)) + return eval(firstExp(exps), env); + eval(firstExp(exps), env); + return evalSequence(restExp(exps), env); +} + +const value applyProcedure(const value& procedure, list<value>& arguments) { + if(isPrimitiveProcedure(procedure)) + return applyPrimitiveProcedure(procedure, arguments); + if(isCompoundProcedure(procedure)) { + Env env = extendEnvironment(procedureParameters(procedure), arguments, procedureEnvironment(procedure)); + return evalSequence(procedureBody(procedure), env); + } + std::cout << "Unknown procedure type " << procedure << "\n"; + return value(); +} + const value sequenceToExp(const list<value> exps) { if(exps == list<value> ()) return value(list<value>()); @@ -175,208 +218,44 @@ value condToIf(const value& exp) { return expandClauses(condClauses(exp)); } -const lambda<value(Env&)> analyze(const value exp); - -struct evalUndefinedLambda { - evalUndefinedLambda() { - } - - const value operator()(Env& env) const { - return value(); - } -}; - -struct evalSelfEvaluatingLambda { - const value exp; - evalSelfEvaluatingLambda(const value& exp) : exp(exp) { - } - const value operator()(Env& env) const { - return exp; - } -}; - -const lambda<value(Env&)> analyzeSelfEvaluating(value exp) { - return lambda<value(Env&)>(evalSelfEvaluatingLambda(exp)); -} - -struct evalQuotedLambda { - const value qval; - evalQuotedLambda(const value& qval) : qval(qval) { - } - const value operator()(Env& env) const { - return qval; - } -}; - -const lambda<value(Env&)> analyzeQuoted(const value& exp) { - return lambda<value(Env&)>(evalQuotedLambda(textOfQuotation(exp))); -} - -struct evalVariableLambda { - const value var; - evalVariableLambda(const value& var) : var(var) { - } - const value operator()(Env& env) const { - return lookupVariableValue(var, env); - } -}; - -const lambda<value(Env&)> analyzeVariable(const value& exp) { - return lambda<value(Env&)>(evalVariableLambda(exp)); -} - -struct evalDefinitionLambda { - const value var; - const lambda<value(Env&)> vproc; - evalDefinitionLambda(const value& var, const lambda<value(Env&)>& vproc) : var(var), vproc(vproc) { - } - const value operator()(Env& env) const { - env = defineVariable(var, vproc(env), env); - return var; - } -}; - -const lambda<value(Env&)> analyzeDefinition(const value& exp) { - return lambda<value(Env&)>(evalDefinitionLambda(definitionVariable(exp), analyze(definitionValue(exp)))); +value evalIf(const value& exp, Env& env) { + if(isTrue(eval(ifPredicate(exp), env))) + return eval(ifConsequent(exp), env); + return eval(ifAlternative(exp), env); } -struct evalIfLambda { - const lambda<value(Env&)> pproc; - const lambda<value(Env&)> cproc; - const lambda<value(Env&)> aproc; - evalIfLambda(const lambda<value(Env&)> pproc, const lambda<value(Env&)>& cproc, const lambda<value(Env&)>& aproc) : - pproc(pproc), cproc(cproc), aproc(aproc) { - } - const value operator()(Env& env) const { - if(pproc(env)) - return cproc(env); - return aproc(env); - } -}; - -const lambda<value(Env&)> analyzeIf(const value& exp) { - const lambda<value(Env&)> pproc = analyze(ifPredicate(exp)); - const lambda<value(Env&)> cproc = analyze(ifConsequent(exp)); - const lambda<value(Env&)> aproc = analyze(ifAlternative(exp)); - return lambda<value(Env&)>(evalIfLambda(pproc, cproc, aproc)); -} - -struct evalSequenceLambda { - const lambda<value(Env&)> proc1; - const lambda<value(Env&)> proc2; - evalSequenceLambda(const lambda<value(Env&)>& proc1, const lambda<value(Env&)>& proc2) : - proc1(proc1), proc2(proc2) { - } - const value operator()(Env& env) const { - proc1(env); - return proc2(env); - } -}; - -const lambda<value(Env&)> analyzeSequenceSequentially(const lambda<value(Env&)>& proc1, const lambda<value(Env&)>& proc2) { - return lambda<value(Env&)>(evalSequenceLambda(proc1, proc2)); +const value evalDefinition(const value& exp, Env& env) { + env = defineVariable(definitionVariable(exp), eval(definitionValue(exp), env), env); + return definitionVariable(exp); } -const lambda<value(Env&)> analyzeSequenceLoop(const lambda<value(Env&)>& firstProc, const list<lambda<value(Env&)> >& restProcs) { - if(restProcs == list<lambda<value(Env&)> >()) - return firstProc; - return analyzeSequenceLoop(analyzeSequenceSequentially(firstProc, car(restProcs)), cdr(restProcs)); -} - -const lambda<value(Env&)> analyzeSequence(const list<value>& exps) { - lambda<lambda<value(Env&)>(value exp)> a(analyze); - const list<lambda<value(Env&)> > procs = map(a, exps); - if(procs == list<lambda<value(Env&)> >()) { - std::cout << "Empty sequence" << "\n"; - return lambda<value(Env&)>(evalUndefinedLambda()); - } - return analyzeSequenceLoop(car(procs), cdr(procs)); -} - -struct lambdaLambda { - const list<value> vars; - const lambda<value(Env&)> bproc; - lambdaLambda(const list<value> vars, const lambda<value(Env&)>& bproc) - : vars(vars), bproc(bproc) { - } - - const value operator()(Env& env) const { - return makeProcedure(vars, value(bproc), env); - } -}; - -const lambda<value(Env&)> analyzeLambda(const value& exp) { - const list<value> vars = lambdaParameters(exp); - const lambda<value(Env&)> bproc = analyzeSequence(lambdaBody(exp)); - return lambda<value(Env&)>(lambdaLambda(vars, bproc)); -} - -const value executeApplication(const value& proc, const list<value>& args) { - if(isPrimitiveProcedure(proc)) { - list<value> ncargs = args; - return applyPrimitiveProcedure(proc, ncargs); - } - if(isCompoundProcedure(proc)) { - lambda<value(Env&) > bproc(procedureBody(proc)); - Env env = extendEnvironment(procedureParameters(proc), args, procedureEnvironment(proc)); - return bproc(env); - } - std::cout << "Unknown procedure type " << proc << "\n"; - return value(); -} - -struct evalApplicationArgLambda { - Env& env; - evalApplicationArgLambda(Env& env) : env(env) { - } - const value operator()(const lambda<value(Env&)>& aproc) const { - return aproc(env); - } -}; - -struct evalApplicationLambda { - const lambda<value(Env&)> fproc; - const list<lambda<value(Env&)> > aprocs; - evalApplicationLambda(const lambda<value(Env&)>& fproc, const list<lambda<value(Env&)> >& aprocs) : - fproc(fproc), aprocs(aprocs) { - } - const value operator()(Env& env) const { - return executeApplication(fproc(env), map(lambda<value(lambda<value(Env&)>)>(evalApplicationArgLambda(env)), aprocs)); - } -}; - -const lambda<value(Env&)> analyzeApplication(const value& exp) { - const lambda<value(Env&)> fproc = analyze(operat(exp)); - lambda<lambda<value(Env&)>(value exp)> a(analyze); - const list<lambda<value(Env&)> > aprocs = map(a, operands(exp)); - return lambda<value(Env&)>(evalApplicationLambda(fproc, aprocs)); -} - -const lambda<value(Env&)> analyze(const value exp) { +const value eval(const value& exp, Env& env) { if(isSelfEvaluating(exp)) - return analyzeSelfEvaluating(exp); + return exp; if(isQuoted(exp)) - return analyzeQuoted(exp); + return textOfQuotation(exp); if(isDefinition(exp)) - return analyzeDefinition(exp); + return evalDefinition(exp, env); if(isIf(exp)) - return analyzeIf(exp); + return evalIf(exp, env); if(isBegin(exp)) - return analyzeSequence(beginActions(exp)); + return evalSequence(beginActions(exp), env); if(isCond(exp)) - return analyze(condToIf(exp)); + return eval(condToIf(exp), env); if(isLambda(exp)) - return analyzeLambda(exp); + return makeProcedure(lambdaParameters(exp), value(lambdaBody(exp)), env); if(isVariable(exp)) - return analyzeVariable(exp); - if(isApplication(exp)) - return analyzeApplication(exp); + return lookupVariableValue(exp, env); + if(isApply(exp)) { + list<value> applyOperandValues = eval(applyOperand(exp), env); + return applyProcedure(eval(applyOperat(exp), env), applyOperandValues); + } + if(isApplication(exp)) { + list<value> operandValues = listOfValues(operands(exp), env); + return applyProcedure(eval(operat(exp), env), operandValues); + } std::cout << "Unknown expression type " << exp << "\n"; - return lambda<value(Env&)>(evalUndefinedLambda()); -} - - const value eval(const value& exp, Env& env) { - return analyze(exp)(env); + return value(); } } diff --git a/cpp/sca/modules/eval/primitive.hpp b/cpp/sca/modules/eval/primitive.hpp index 881f669317..04e26178f4 100644 --- a/cpp/sca/modules/eval/primitive.hpp +++ b/cpp/sca/modules/eval/primitive.hpp @@ -57,6 +57,10 @@ const value valueCons(list<value>& args) { return value(cons(car(args), (list<value> )cadr(args))); } +const value valueList(list<value>& args) { + return value(args); +} + const value valueNul(list<value>& args) { return value((bool)isNil(car(args))); } @@ -66,10 +70,14 @@ const value valueEqual(list<value>& args) { } const value valueAdd(list<value>& args) { + if (cdr(args) == list<value>()) + return value((double)car(args)); return value((double)car(args) + (double)cadr(args)); } const value valueSub(list<value>& args) { + if (cdr(args) == list<value>()) + return value(0 - (double)car(args)); return value((double)car(args) - (double)cadr(args)); } @@ -126,12 +134,14 @@ const list<value> primitiveProcedureNames() { list<value> l = makeList(value("car")); l = cons(value("cdr"), l); l = cons(value("cons"), l); + l = cons(value("list"), l); l = cons(value("nul"), l); l = cons(value("="), l); l = cons(value("+"), l); l = cons(value("-"), l); l = cons(value("*"), l); l = cons(value("/"), l); + l = cons(value("equal?"), l); l = cons(value("display"), l); return l; } @@ -140,12 +150,14 @@ const list<value> primitiveProcedureObjects() { list<value> l = makeList(primitiveProcedure(valueCar)); l = cons(primitiveProcedure(valueCdr), l); l = cons(primitiveProcedure(valueCons), l); + l = cons(primitiveProcedure(valueList), l); l = cons(primitiveProcedure(valueNul), l); l = cons(primitiveProcedure(valueEqual), l); l = cons(primitiveProcedure(valueAdd), l); l = cons(primitiveProcedure(valueSub), l); l = cons(primitiveProcedure(valueMul), l); l = cons(primitiveProcedure(valueDiv), l); + l = cons(primitiveProcedure(valueEqual), l); l = cons(primitiveProcedure(valueDisplay), l); return l; } diff --git a/cpp/sca/modules/eval/read.hpp b/cpp/sca/modules/eval/read.hpp index 8ede2189a6..cd9068c017 100644 --- a/cpp/sca/modules/eval/read.hpp +++ b/cpp/sca/modules/eval/read.hpp @@ -61,7 +61,7 @@ const bool isIdentifierPart(const char ch) { } const bool isDigit(const char ch) { - return isdigit(ch); + return isdigit(ch) || ch == '.'; } const bool isLeftParenthesis(const value& token) { diff --git a/cpp/sca/samples/Makefile.am b/cpp/sca/samples/Makefile.am index 9ccf905d72..0fdf524cc1 100644 --- a/cpp/sca/samples/Makefile.am +++ b/cpp/sca/samples/Makefile.am @@ -16,13 +16,13 @@ # under the License. if WANT_ALL_SAMPLES - CPP_SAMPLES = CppCalculator CppBigBank store store2 + CPP_SAMPLES = CppCalculator CppBigBank PYTHON_SAMPLES = PythonCalculator PythonWeatherForecast RestCustomer AlertAggregator RUBY_SAMPLES = RubyCalculator RubyBigBank HttpdBigBank RestCalculator PYTHON_RUBY_SAMPLES = RestYahoo else if WANT_CPP_SAMPLES - CPP_SAMPLES = CppCalculator CppBigBank store + CPP_SAMPLES = CppCalculator CppBigBank endif if WANT_PYTHON_SAMPLES PYTHON_SAMPLES = PythonCalculator PythonWeatherForecast RestCustomer AlertAggregator diff --git a/cpp/sca/samples/configure.ac b/cpp/sca/samples/configure.ac index c4021401fe..41cd6f4dbe 100644 --- a/cpp/sca/samples/configure.ac +++ b/cpp/sca/samples/configure.ac @@ -162,8 +162,6 @@ AC_ARG_ENABLE(ruby, [AS_HELP_STRING([--enable-ruby],[build Ruby samples [default AM_CONDITIONAL([WANT_RUBY_SAMPLES], [test x$want_ruby_samples = xtrue]) AC_CONFIG_FILES([Makefile - store/Makefile - store2/Makefile AlertAggregator/Makefile AlertAggregator/sample.alerter/Makefile AlertAggregator/sample.display/Makefile diff --git a/cpp/sca/samples/store/Makefile.am b/cpp/sca/test/Makefile.am index 05a0e4482a..4a20e27139 100644 --- a/cpp/sca/samples/store/Makefile.am +++ b/cpp/sca/test/Makefile.am @@ -15,13 +15,5 @@ # specific language governing permissions and limitations # under the License. -store_PROGRAMS = store-test -storedir=$(prefix)/store/deploy +SUBDIRS = store-object store-function store-script -store_test_SOURCES = store-test.cpp - -INCLUDES = -I. -I${TUSCANY_SCACPP}/include -store_test_LDADD = -L${TUSCANY_SCACPP}/lib -ltuscany_sca -L${LIBXML2_LIB} -lxml2 - -EXTRA_DIST = *.composite -store_DATA = *.composite diff --git a/cpp/sca/test/store-function/Makefile.am b/cpp/sca/test/store-function/Makefile.am new file mode 100644 index 0000000000..b63381c0cf --- /dev/null +++ b/cpp/sca/test/store-function/Makefile.am @@ -0,0 +1,28 @@ +# 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. + +store_function_PROGRAMS = store-function-test +store_functiondir=$(prefix)/test/store-function/deploy + +INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} + +store_function_test_SOURCES = store-function-test.cpp +store_function_test_LDADD = -L${LIBXML2_LIB} -lxml2 -lpthread + +EXTRA_DIST = *.composite +store_function_DATA = *.composite + diff --git a/cpp/sca/samples/store2/cart.hpp b/cpp/sca/test/store-function/cart.hpp index f3b0f6195e..c21e509487 100644 --- a/cpp/sca/samples/store2/cart.hpp +++ b/cpp/sca/test/store-function/cart.hpp @@ -55,14 +55,14 @@ const double shoppingCart_getTotal() { } const tuscany::value shoppingCart_service(const tuscany::list<tuscany::value>& args) { - if (car(args) == "getAll") - return shoppingCart_getAll(); - if (car(args) == "post") - return shoppingCart_post(cadr(args)); - if (car(args) == "deleteAll") - return shoppingCart_deleteAll(); - if (car(args) == "getTotal") - return shoppingCart_getTotal(); + if (car(args) == tuscany::value("getAll")) + return tuscany::value(shoppingCart_getAll()); + if (car(args) == tuscany::value("post")) + return tuscany::value(shoppingCart_post(cadr(args))); + if (car(args) == tuscany::value("deleteAll")) + return tuscany::value(shoppingCart_deleteAll()); + if (car(args) == tuscany::value("getTotal")) + return tuscany::value(shoppingCart_getTotal()); return tuscany::value(); } diff --git a/cpp/sca/samples/store2/catalog.hpp b/cpp/sca/test/store-function/catalog.hpp index 82a2a458a9..82a69e2bbd 100644 --- a/cpp/sca/samples/store2/catalog.hpp +++ b/cpp/sca/test/store-function/catalog.hpp @@ -45,8 +45,8 @@ const tuscany::list<ItemType> catalog_get(const service& currencyConverter) { } const tuscany::value catalog_service(const service& currencyConverter, const tuscany::list<tuscany::value>& args) { - if (car(args) == "get") - return catalog_get(currencyConverter); + if (car(args) == tuscany::value("get")) + return tuscany::value(catalog_get(currencyConverter)); return tuscany::value(); } diff --git a/cpp/sca/samples/store/catalogs.composite b/cpp/sca/test/store-function/catalogs.composite index 1638ed0a05..1638ed0a05 100644 --- a/cpp/sca/samples/store/catalogs.composite +++ b/cpp/sca/test/store-function/catalogs.composite diff --git a/cpp/sca/samples/store2/currency-composite.hpp b/cpp/sca/test/store-function/currency-composite.hpp index ae28471538..ae28471538 100644 --- a/cpp/sca/samples/store2/currency-composite.hpp +++ b/cpp/sca/test/store-function/currency-composite.hpp diff --git a/cpp/sca/samples/store/currency.composite b/cpp/sca/test/store-function/currency.composite index aefd474f1f..aefd474f1f 100644 --- a/cpp/sca/samples/store/currency.composite +++ b/cpp/sca/test/store-function/currency.composite diff --git a/cpp/sca/samples/store2/currency.hpp b/cpp/sca/test/store-function/currency.hpp index 453a5e1e81..ce7e4f464b 100644 --- a/cpp/sca/samples/store2/currency.hpp +++ b/cpp/sca/test/store-function/currency.hpp @@ -47,10 +47,10 @@ const std::string currencyConverter_getSymbol(const std::string& currencyCode) { } const tuscany::value currencyConverter_service(const tuscany::list<tuscany::value>& args) { - if (car(args) == "convert") - return currencyConverter_convert(cadr(args), car(cdr(cdr(args))), car(cdr(cdr(cdr(args))))); - if (car(args) == "getSymbol") - return currencyConverter_getSymbol(cadr(args)); + if (car(args) == tuscany::value("convert")) + return tuscany::value(currencyConverter_convert(cadr(args), car(cdr(cdr(args))), car(cdr(cdr(cdr(args)))))); + if (car(args) == tuscany::value("getSymbol")) + return tuscany::value(currencyConverter_getSymbol(cadr(args))); return tuscany::value(); } diff --git a/cpp/sca/samples/store2/item.hpp b/cpp/sca/test/store-function/item.hpp index 8a121124a3..8a121124a3 100644 --- a/cpp/sca/samples/store2/item.hpp +++ b/cpp/sca/test/store-function/item.hpp diff --git a/cpp/sca/samples/store2/service.hpp b/cpp/sca/test/store-function/service.hpp index b764e87d1a..b764e87d1a 100644 --- a/cpp/sca/samples/store2/service.hpp +++ b/cpp/sca/test/store-function/service.hpp diff --git a/cpp/sca/samples/store2/store-composite.hpp b/cpp/sca/test/store-function/store-composite.hpp index 351c905eae..351c905eae 100644 --- a/cpp/sca/samples/store2/store-composite.hpp +++ b/cpp/sca/test/store-function/store-composite.hpp diff --git a/cpp/sca/samples/store2/store2-test.cpp b/cpp/sca/test/store-function/store-function-test.cpp index e71ecfd633..e71ecfd633 100644 --- a/cpp/sca/samples/store2/store2-test.cpp +++ b/cpp/sca/test/store-function/store-function-test.cpp diff --git a/cpp/sca/samples/store2/store-solution.hpp b/cpp/sca/test/store-function/store-solution.hpp index e0addcba12..e0addcba12 100644 --- a/cpp/sca/samples/store2/store-solution.hpp +++ b/cpp/sca/test/store-function/store-solution.hpp diff --git a/cpp/sca/samples/store2/store-ui.hpp b/cpp/sca/test/store-function/store-ui.hpp index 3be7480339..9b100a6793 100644 --- a/cpp/sca/samples/store2/store-ui.hpp +++ b/cpp/sca/test/store-function/store-ui.hpp @@ -49,14 +49,14 @@ const bool storeUI_post(const service& cart, const ItemType& item) { } const tuscany::value storeUI_service(const service& catalog, const service& cart, const tuscany::list<tuscany::value>& args) { - if (car(args) == "getCatalog") - return storeUI_getCatalog(catalog); - if (car(args) == "getCart") - return storeUI_getCart(cart); - if (car(args) == "getTotal") - return storeUI_getTotal(cart); - if (car(args) == "post") - return storeUI_post(cart, cadr(args)); + if (car(args) == tuscany::value("getCatalog")) + return tuscany::value(storeUI_getCatalog(catalog)); + if (car(args) == tuscany::value("getCart")) + return tuscany::value(storeUI_getCart(cart)); + if (car(args) == tuscany::value("getTotal")) + return tuscany::value(storeUI_getTotal(cart)); + if (car(args) == tuscany::value("post")) + return tuscany::value(storeUI_post(cart, cadr(args))); return tuscany::value(); } diff --git a/cpp/sca/samples/store/store.composite b/cpp/sca/test/store-function/store.composite index 124adff853..124adff853 100644 --- a/cpp/sca/samples/store/store.composite +++ b/cpp/sca/test/store-function/store.composite diff --git a/cpp/sca/samples/store2/Makefile.am b/cpp/sca/test/store-object/Makefile.am index f7af244044..c79bf6ebde 100644 --- a/cpp/sca/samples/store2/Makefile.am +++ b/cpp/sca/test/store-object/Makefile.am @@ -15,13 +15,14 @@ # specific language governing permissions and limitations # under the License. -store2_PROGRAMS = store2-test -store2dir=$(prefix)/store2/deploy +store_object_PROGRAMS = store-object-test +store_objectdir=$(prefix)/test/store-object/deploy -store2_test_SOURCES = store2-test.cpp +INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -INCLUDES = -I. -I${TUSCANY_SCACPP}/include -store2_test_LDADD = -L${TUSCANY_SCACPP}/lib -ltuscany_sca -L${LIBXML2_LIB} -lxml2 +store_object_test_SOURCES = store-object-test.cpp +store_object_test_LDADD = -L${LIBXML2_LIB} -lxml2 -lpthread EXTRA_DIST = *.composite -store2_DATA = *.composite +store_object_DATA = *.composite + diff --git a/cpp/sca/samples/store/cart.hpp b/cpp/sca/test/store-object/cart.hpp index fc6155aa25..fc6155aa25 100644 --- a/cpp/sca/samples/store/cart.hpp +++ b/cpp/sca/test/store-object/cart.hpp diff --git a/cpp/sca/samples/store/catalog.hpp b/cpp/sca/test/store-object/catalog.hpp index 6909911c07..6909911c07 100644 --- a/cpp/sca/samples/store/catalog.hpp +++ b/cpp/sca/test/store-object/catalog.hpp diff --git a/cpp/sca/samples/store2/catalogs.composite b/cpp/sca/test/store-object/catalogs.composite index 1638ed0a05..1638ed0a05 100644 --- a/cpp/sca/samples/store2/catalogs.composite +++ b/cpp/sca/test/store-object/catalogs.composite diff --git a/cpp/sca/samples/store/currency-composite.hpp b/cpp/sca/test/store-object/currency-composite.hpp index 94b52b461e..94b52b461e 100644 --- a/cpp/sca/samples/store/currency-composite.hpp +++ b/cpp/sca/test/store-object/currency-composite.hpp diff --git a/cpp/sca/samples/store2/currency.composite b/cpp/sca/test/store-object/currency.composite index aefd474f1f..aefd474f1f 100644 --- a/cpp/sca/samples/store2/currency.composite +++ b/cpp/sca/test/store-object/currency.composite diff --git a/cpp/sca/samples/store/currency.hpp b/cpp/sca/test/store-object/currency.hpp index a8228ea51c..a8228ea51c 100644 --- a/cpp/sca/samples/store/currency.hpp +++ b/cpp/sca/test/store-object/currency.hpp diff --git a/cpp/sca/samples/store/item.hpp b/cpp/sca/test/store-object/item.hpp index ab8e52769b..ab8e52769b 100644 --- a/cpp/sca/samples/store/item.hpp +++ b/cpp/sca/test/store-object/item.hpp diff --git a/cpp/sca/samples/store/store-composite.hpp b/cpp/sca/test/store-object/store-composite.hpp index 8cee5a943f..8cee5a943f 100644 --- a/cpp/sca/samples/store/store-composite.hpp +++ b/cpp/sca/test/store-object/store-composite.hpp diff --git a/cpp/sca/samples/store/store-test.cpp b/cpp/sca/test/store-object/store-object-test.cpp index bfbf5459ac..bfbf5459ac 100644 --- a/cpp/sca/samples/store/store-test.cpp +++ b/cpp/sca/test/store-object/store-object-test.cpp diff --git a/cpp/sca/samples/store/store-solution.hpp b/cpp/sca/test/store-object/store-solution.hpp index ecabb18f1c..ecabb18f1c 100644 --- a/cpp/sca/samples/store/store-solution.hpp +++ b/cpp/sca/test/store-object/store-solution.hpp diff --git a/cpp/sca/samples/store/store-ui.hpp b/cpp/sca/test/store-object/store-ui.hpp index c9d0f4330b..c9d0f4330b 100644 --- a/cpp/sca/samples/store/store-ui.hpp +++ b/cpp/sca/test/store-object/store-ui.hpp diff --git a/cpp/sca/samples/store2/store.composite b/cpp/sca/test/store-object/store.composite index 124adff853..124adff853 100644 --- a/cpp/sca/samples/store2/store.composite +++ b/cpp/sca/test/store-object/store.composite diff --git a/cpp/sca/test/store-script/Makefile.am b/cpp/sca/test/store-script/Makefile.am new file mode 100644 index 0000000000..aded08f6b3 --- /dev/null +++ b/cpp/sca/test/store-script/Makefile.am @@ -0,0 +1,28 @@ +# 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. + +store_script_PROGRAMS = store-script-test +store_scriptdir=$(prefix)/test/store-script/deploy + +INCLUDES = -I. -I$(top_builddir)/kernel -I$(top_builddir)/modules/eval -I${LIBXML2_INCLUDE} + +store_script_test_SOURCES = store-script-test.cpp +store_script_test_LDADD = -L${LIBXML2_LIB} -lxml2 -lpthread + +EXTRA_DIST = *.composite +store_script_DATA = *.composite + diff --git a/cpp/sca/test/store-script/catalogs.composite b/cpp/sca/test/store-script/catalogs.composite new file mode 100644 index 0000000000..1638ed0a05 --- /dev/null +++ b/cpp/sca/test/store-script/catalogs.composite @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" + xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1" + targetNamespace="http://services" + name="catalogs"> + + <component name="FruitsCatalogWebService"> + <implementation.java class="services.FruitsCatalogImpl"/> + <service name="Catalog"> + <binding.ws/> + </service> + <property name="currencyCode">USD</property> + <reference name="currencyConverter" target="CurrencyConverterWebService"> + <binding.ws/> + </reference> + </component> + + <component name="VegetablesCatalogWebService"> + <implementation.java class="services.VegetablesCatalogImpl"/> + <service name="Catalog"> + <binding.ws/> + </service> + </component> + +</composite> diff --git a/cpp/sca/test/store-script/currency.composite b/cpp/sca/test/store-script/currency.composite new file mode 100644 index 0000000000..aefd474f1f --- /dev/null +++ b/cpp/sca/test/store-script/currency.composite @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" + xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1" + targetNamespace="http://services" + name="currency"> + + <component name="CurrencyConverterWebService"> + <implementation.java class="services.CurrencyConverterImpl"/> + <service name="CurrencyConverter"> + <binding.ws/> + </service> + </component> + +</composite> diff --git a/cpp/sca/test/store-script/store-script-test.cpp b/cpp/sca/test/store-script/store-script-test.cpp new file mode 100644 index 0000000000..dff802b714 --- /dev/null +++ b/cpp/sca/test/store-script/store-script-test.cpp @@ -0,0 +1,58 @@ +/* + * 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$ */ + +/** + * Store Test case. + */ + +#include <assert.h> +#include <iostream> +#include <fstream> +#include <string> +#include "driver.hpp" + +namespace store +{ + +bool contains(const std::string& str, const std::string& pattern) { + return str.find(pattern) != str.npos; +} + +bool testScript() { + std::ifstream is("store-script.scm", std::ios_base::in); + std::ostringstream os; + tuscany::evalDriverRun(is, os); + assert(contains(os.str(), "List::(List::(String::'apple', (String::'USD', (String::'$', (Number::2.99, ())))), ())")); + return true; +} + +} + +int main() { + + std::cout << "Testing..." << std::endl; + + store::testScript(); + + std::cout << "OK" << std::endl; + + return 0; +} diff --git a/cpp/sca/test/store-script/store-script.scm b/cpp/sca/test/store-script/store-script.scm new file mode 100644 index 0000000000..8af88b45f0 --- /dev/null +++ b/cpp/sca/test/store-script/store-script.scm @@ -0,0 +1,99 @@ + +(display "Currency implementation") + +(define (currency_convert from to amount) + (if (equal? to "EUR") (* amount 0.70) amount) +) + +(define (currency_symbol currency) + (if (equal? currency "EUR") "E" "$") +) + +(define (currency_impl op args) + (cond + ((equal? op "convert") (apply currency_convert args)) + ((equal? op "symbol") (apply currency_symbol args)) + ) +) + +(display "Currency composite") + +(define (currency_service op . args) (currency_impl op args)) + +(display "Catalog implementation") + +(define (catalog_get converter) + (define (convert price) (converter "convert" "USD" "USD" price)) + + (define code "USD") + (define symbol (converter "symbol" code)) + + (list (list "apple" code symbol (convert 2.99)) + (list "orange" code symbol (convert 3.55)) + (list "pear" code symbol (convert 1.55)) + ) +) + +(define (catalog_impl converter op args) + (cond + ((equal? op "get") (apply catalog_get (cons converter args))) + ) +) + +(display "Catalog composite") + +(define (catalog_service op . args) (catalog_impl currency_service op args)) + +(display "Cart implementation") + +(define (cart_post content item) + (cons item content) +) + +(define (cart_getall content) + content +) + +(define (cart_impl op args) + (cond + ((equal? op "post") (apply cart_post args)) + ((equal? op "getall") (apply cart_getall args)) + ) +) + +(display "Store UI implementation") + +(define (storeui_post cart content item) + (cart "post" content item) +) + +(define (storeui_getcart cart content) + (cart "getall" content) +) + +(define (storeui_getcatalog catalog) + (catalog "get") +) + +(define (storeui_impl cart catalog op args) + (cond + ((equal? op "post") (apply storeui_post (cons cart args))) + ((equal? op "getall") (apply storeui_getcart (cons cart args))) + ((equal? op "getcatalog") (apply storeui_getcatalog (cons catalog args))) + ) +) + +(display "Store UI composite") + +(define (cart_service op . args) (cart_impl op args)) + +(define (storeui_service op . args) (storeui_impl cart_service catalog_service op args)) + +(display "Store UI test case") + +(define catalog (storeui_service "getcatalog")) +(define empty (list)) +(define apple (car catalog)) +(define full (storeui_service "post" empty apple)) +(display (storeui_service "getall" full)) + diff --git a/cpp/sca/test/store-script/store.composite b/cpp/sca/test/store-script/store.composite new file mode 100644 index 0000000000..124adff853 --- /dev/null +++ b/cpp/sca/test/store-script/store.composite @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" + xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1" + targetNamespace="http://store" + name="store"> + + <component name="Store"> + <t:implementation.widget location="uiservices/store.html"/> + <service name="Widget"> + <t:binding.http uri="/ui"/> + </service> + <reference name="catalog" target="StoreCatalog"> + <t:binding.jsonrpc/> + </reference> + <reference name="shoppingCart" target="StoreShoppingCart/Cart"> + <t:binding.atom/> + </reference> + <reference name="shoppingTotal" target="StoreShoppingCart/Total"> + <t:binding.jsonrpc/> + </reference> + </component> + + <component name="StoreCatalog"> + <implementation.java class="services.FruitsCatalogImpl"/> + <property name="currencyCode">USD</property> + <service name="Catalog"> + <t:binding.jsonrpc/> + </service> + <reference name="currencyConverter" target="StoreCurrencyConverter"/> + </component> + + <component name="StoreShoppingCart"> + <implementation.java class="services.ShoppingCartImpl"/> + <service name="Cart"> + <t:binding.atom uri="/ShoppingCart/Cart"/> + </service> + <service name="Total"> + <t:binding.jsonrpc/> + </service> + </component> + + <component name="StoreCurrencyConverter"> + <implementation.java class="services.CurrencyConverterImpl"/> + </component> + +</composite> |