summaryrefslogtreecommitdiff
path: root/src/piraha/Call.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/piraha/Call.cc')
-rw-r--r--src/piraha/Call.cc87
1 files changed, 63 insertions, 24 deletions
diff --git a/src/piraha/Call.cc b/src/piraha/Call.cc
index 3f507b93..5c3b5757 100644
--- a/src/piraha/Call.cc
+++ b/src/piraha/Call.cc
@@ -10,6 +10,7 @@
#include <math.h>
#include <algorithm>
#include <limits>
+#include <fstream>
namespace piraha {
@@ -208,7 +209,6 @@ std::ostream& operator<<(std::ostream& o,const smart_ptr<Value>& val) {
return o;
}
-std::map<std::string,std::map<std::string,smart_ptr<Value> > > values;
typedef std::map<std::string,std::map<std::string,smart_ptr<Value> > >::iterator th_iter;
typedef std::map<std::string,smart_ptr<Value> >::iterator nm_iter;
@@ -216,21 +216,47 @@ smart_ptr<Value> eval_expr(std::string inp);
// If the value was already defined in this parameter file, look
// it up in the map. Otherwise, get it from Cactus.
-smart_ptr<Value> find_val(std::string thorn,std::string name) {
- smart_ptr<Value> ret;
- th_iter th = values.find(thorn);
- if(th != values.end()) {
- nm_iter nm = th->second.find(name);
- if(nm != th->second.end()) {
- ret = nm->second;
- return ret;
- }
- }
- const cParamData *data = CCTK_ParameterData(name.c_str(),thorn.c_str());
- if(data != NULL) {
- std::string expr = data->defval;
- ret = eval_expr(expr);
- }
+smart_ptr<Value> find_val(smart_ptr<Group> gr,std::string thorn,std::string name) {
+ smart_ptr<Value> ret = new Value(gr);
+ int type;
+ const void *result;
+ result = CCTK_ParameterGet(name.c_str(),thorn.c_str(),&type);
+ if(result == NULL) {
+ std::ostringstream msg;
+ msg << "Undefined or inaccessible variable: " << thorn << "::" << name << std::endl;
+ std::string par = get_parfile();
+ CCTK_Error(gr->line(),par.c_str(),current_thorn.c_str(),msg.str().c_str());
+ }
+
+ switch(type) {
+ case PARAMETER_REAL:
+ ret->type = PIR_REAL;
+ ret->ddata = *(const CCTK_REAL*)result;
+ break;
+ case PARAMETER_INT:
+ ret->type = PIR_INT;
+ ret->idata = *(const CCTK_INT*)result;
+ break;
+ case PARAMETER_BOOLEAN:
+ ret->type = PIR_BOOL;
+ ret->idata = *(const CCTK_INT*)result;
+ break;
+ case PARAMETER_STRING:
+ case PARAMETER_SENTENCE:
+ case PARAMETER_KEYWORD:
+ {
+ ret->type = PIR_STRING;
+ const char *s = *(const char **)result;
+ ret->sdata += s;
+ }
+ break;
+ default:
+ std::ostringstream msg;
+ msg << "Unexpected type result from ParameterGet=" << type << std::endl;
+ std::string par = get_parfile();
+ CCTK_Error(gr->line(),par.c_str(),current_thorn.c_str(),msg.str().c_str());
+ }
+ //std::cout << "Piraha: GET: " << thorn << "::" << name << "=" << ret << std::endl;
return ret;
}
@@ -425,11 +451,11 @@ smart_ptr<Value> meval(smart_ptr<Group> gr) {
o << name << "[" << index->idata << "]";
o << std::flush;
std::string keyi = o.str();
- ret = find_val(thorn,keyi);
+ ret = find_val(gr,thorn,keyi);
return ret;
}
} else {
- ret = find_val(thorn,name);
+ ret = find_val(gr,thorn,name);
return ret;
}
std::ostringstream msg;
@@ -573,9 +599,11 @@ smart_ptr<Value> meval(smart_ptr<Group> gr) {
ret->sdata = v1->sdata + v2->sdata;
} else {
std::ostringstream msg;
+ ret->sdata = v1->sdata + addop + v2->sdata;
msg << "Unknown add operator: " << addop << std::endl;
+ msg << "Interpreting as literal string with value '" << ret->sdata << "'" << std::endl;
std::string par = get_parfile();
- CCTK_Error(gr->line(),par.c_str(),current_thorn.c_str(),msg.str().c_str());
+ CCTK_Warn(1,gr->line(),par.c_str(),current_thorn.c_str(),msg.str().c_str());
}
} else if(v1->intOrDouble() && v2->intOrDouble()) {
ret->type = PIR_REAL;
@@ -643,6 +671,14 @@ smart_ptr<Value> meval(smart_ptr<Group> gr) {
std::string par = get_parfile();
CCTK_Error(gr->line(),par.c_str(),current_thorn.c_str(),msg.str().c_str());
}
+ } else if(v1->type == PIR_STRING && v2->type == PIR_STRING) {
+ std::ostringstream msg;
+ ret->type = PIR_STRING;
+ ret->sdata = v1->sdata + mulop + v2->sdata;
+ msg << "Unknown operation: " << v1->type << " " << mulop << v2->type << std::endl;
+ msg << "Interpreting as literal string with value '" << ret->sdata << "'" << std::endl;
+ std::string par = get_parfile();
+ CCTK_Warn(1,gr->line(),par.c_str(),current_thorn.c_str(),msg.str().c_str());
} else {
std::ostringstream msg;
msg << "Unknown operation: " << v1->type << " " << mulop << v2->type << std::endl;
@@ -722,7 +758,7 @@ extern "C" int cctk_PirahaParser(const char *buffer,unsigned long buffersize,int
"# Note that / occurs in some par files. It is my\n"
"# feeling that this should require quote marks.\n"
- "name = [@a-zA-Z_][@/a-zA-Z0-9_-]*\n"
+ "name = [a-zA-Z][a-zA-Z0-9_]*\n"
"dname = [0-9][a-zA-Z_]{2,}\n"
"inquot = ({var}|\\\\.|[^\\\\\"])*\n"
"fname = \\.?/[-\\./0-9a-zA-Z_]+\n"
@@ -757,7 +793,11 @@ extern "C" int cctk_PirahaParser(const char *buffer,unsigned long buffersize,int
"parindex = \\[ {expr} \\]\n"
"active = (?i:ActiveThorns)\n"
"set = ({active} = ({quot}|{name})|{par}( {index}|) = ({array}|\\+?{expr})){-skipeol}\n"
- "file = ^( !DESC {quot}|)( ({set}|{active}) )*$";
+ "desc = !DESC {quot}\n"
+ "file = ^( ({desc}|{set}|{active}) )*$";
+ //std::ofstream peg("/tmp/par.peg");
+ //peg << par_file_src;
+ //peg.close();
compileFile(par_file_grammar,par_file_src,strlen(par_file_src));
@@ -813,7 +853,6 @@ extern "C" int cctk_PirahaParser(const char *buffer,unsigned long buffersize,int
smart_ptr<Value> smv = meval(aexpr);
val = smv->copy();
assert(smv.valid());
- values[thorn][key] = smv;
smv->integerize();
if(data != NULL) {
if(data->type == PARAMETER_REAL)
@@ -834,7 +873,6 @@ extern "C" int cctk_PirahaParser(const char *buffer,unsigned long buffersize,int
keyi << key << '[' << i << ']';
smart_ptr<Value> smv = meval(aexpr);
val = smv->copy();
- values[thorn][keyi.str()] = smv;
if(data != NULL) {
if(data->type == PARAMETER_REAL)
smv->integerize();
@@ -851,9 +889,10 @@ extern "C" int cctk_PirahaParser(const char *buffer,unsigned long buffersize,int
}
}
} else {
+ // TODO: Fix this
std::cout << "ERROR IN PARAMETER FILE:" << std::endl;
m2->showError();
- return 1;
+ return 1;
}
return 0;
}