140 if (gSymbolicBoxProperty.
get(exp, result)) {
148 gSymbolicBoxProperty.
set(exp, result);
156 Tree abstr, visited, unusedEnv, localValEnv, var,
name, body;
158 if (
isClosure(exp, abstr, unusedEnv, visited, localValEnv)) {
173 stringstream s; s <<
boxpp(var);
187 evalerror(
yyfilename, -1,
" a2sb : internal error : not an abstraction inside closure ", exp);
212 unsigned int ar = exp->
arity();
214 bool modified =
false;
215 for (
unsigned int i = 0; i < ar; i++) {
219 if (b != m) modified=
true;
228 stringstream s; s <<
boxpp(exp);
229 id =
tree(s.str().c_str());
288 result =
realeval(exp, visited, localValEnv);
315 Tree cur, lo, hi, step;
316 Tree e1, e2, exp2, notused, visited2, lenv2;
342 }
else if (
isBoxSeq(exp, e1, e2) ) {
343 return boxSeq(
eval(e1, visited, localValEnv),
eval(e2, visited, localValEnv));
345 }
else if (
isBoxPar(exp, e1, e2) ) {
346 return boxPar(
eval(e1, visited, localValEnv),
eval(e2, visited, localValEnv));
348 }
else if (
isBoxRec(exp, e1, e2) ) {
349 return boxRec(
eval(e1, visited, localValEnv),
eval(e2, visited, localValEnv));
352 return boxSplit(
eval(e1, visited, localValEnv),
eval(e2, visited, localValEnv));
355 return boxMerge(
eval(e1, visited, localValEnv),
eval(e2, visited, localValEnv));
361 Tree val =
eval(body, visited, localValEnv);
362 if (
isClosure(val, exp2, notused, visited2, lenv2)) {
364 return eval(
closure(var,notused,visited2,lenv2), visited, localValEnv);
373 Tree val =
eval(body, visited, localValEnv);
374 if (
isClosure(val, exp2, notused, visited2, lenv2)) {
378 return eval(
closure(exp2,notused,visited2,lenv3), visited, localValEnv);
410 const char* l2=
evalLabel(l1, visited, localValEnv);
416 const char* l2=
evalLabel(l1, visited, localValEnv);
420 }
else if (
isBoxVSlider(exp, label, cur, lo, hi, step)) {
422 const char* l2=
evalLabel(l1, visited, localValEnv);
429 }
else if (
isBoxHSlider(exp, label, cur, lo, hi, step)) {
431 const char* l2=
evalLabel(l1, visited, localValEnv);
440 const char* l2=
evalLabel(l1, visited, localValEnv);
449 const char* l2=
evalLabel(l1, visited, localValEnv);
454 const char* l2=
evalLabel(l1, visited, localValEnv);
459 const char* l2=
evalLabel(l1, visited, localValEnv);
464 const char* l2=
evalLabel(l1, visited, localValEnv);
471 const char* l2=
evalLabel(l1, visited, localValEnv);
480 return evalIdDef(exp, visited, localValEnv);
491 return closure(exp,
nil, visited, localValEnv);
495 return closure(exp,
nil, visited, localValEnv);
497 }
else if (
isClosure(exp, exp2, notused, visited2, lenv2)) {
513 }
else if (
isBoxIPar(exp, var, num, body)) {
514 int n =
eval2int(num, visited, localValEnv);
515 return iteratePar(var, n, body, visited, localValEnv);
517 }
else if (
isBoxISeq(exp, var, num, body)) {
518 int n =
eval2int(num, visited, localValEnv);
519 return iterateSeq(var, n, body, visited, localValEnv);
521 }
else if (
isBoxISum(exp, var, num, body)) {
522 int n =
eval2int(num, visited, localValEnv);
523 return iterateSum(var, n, body, visited, localValEnv);
526 int n =
eval2int(num, visited, localValEnv);
527 return iterateProd(var, n, body, visited, localValEnv);
536 cerr <<
"ERROR : can't evaluate ' : " << *exp << endl;
546 cerr <<
"ERROR : can't evaluate ' : " << *exp << endl;
563 return evalCase(rules, localValEnv);
573 cerr <<
"ERROR : EVAL don't intercept : " << *exp << endl;
632 int numInputs, numOutputs;
642 if (
getBoxType(v, &numInputs, &numOutputs) && (numInputs == 0) && (numOutputs == 1) ) {
692 int numInputs, numOutputs;
694 if ( (numInputs > 0) || (numOutputs != 1) ) {
721 int numInputs, numOutputs;
723 if ( (numInputs > 0) || (numOutputs != 1) ) {
735 return (c >=
'0') & (c <=
'9');
740 return ((c >=
'a') & (c <=
'z')) || ((c >=
'A') & (c <=
'Z')) || ((c >=
'0') & (c <=
'9')) || (c ==
'_');
743 const char*
Formats [] = {
"%d",
"%1d",
"%2d",
"%3d",
"%4d"};
745 static void writeIdentValue(std::string& dst,
const std::string& format,
const std::string& ident,
Tree visited,
Tree localValEnv)
747 int f = atoi(format.c_str());
752 snprintf(val, 250, Formats[i], n);
769 while (state != -1) {
777 }
else if (c ==
'%') {
786 }
else if (state == 1) {
807 }
else if (state == 2) {
820 std::cerr <<
"internal error in evallabel : undefined state " << state << std::endl;
825 const char* val = strdup(dst.c_str());
850 for (
int i = num-2; i >= 0; i--) {
876 for (
int i = num-2; i >= 0; i--) {
904 for (
int i = 1; i < num; i++) {
932 for (
int i = 1; i < num; i++) {
953 while (!
isNil(boxlist))
963 boxlist =
tl(boxlist);
965 return isNil(boxlist);
975 boxlist =
tl(boxlist);
977 return isNil(boxlist);
1023 if (
isNil(larg))
return fun;
1032 vector<Tree> envVect;
1038 if (state2 >= 0 &&
isNil(result)) {
1043 }
else if (state2 < 0) {
1044 cerr <<
"ERROR : pattern matching failed, no rule of " <<
boxpp(
boxCase(originalRules))
1045 <<
" matches argument list " <<
boxpp(
reverse(
cons(
hd(larg), revParamList))) << endl;
1050 if (
isClosure(result, body, globalDefEnv, visited, localValEnv)) {
1055 cerr <<
"wrong result from pattern matching (not a closure) : " <<
boxpp(result) << endl;
1060 if (!
isClosure(fun, abstr, globalDefEnv, visited, localValEnv)) {
1082 cerr <<
"too much arguments : " << outs <<
", instead of : " << ins << endl;
1083 cerr <<
"when applying : " <<
boxpp(fun) << endl
1084 <<
" to : " <<
boxpp(larg) << endl;
1115 Tree arg =
eval(
hd(larg), visited, localValEnv);
1146 while (!
isNil(lexp)) {
1147 result =
cons(
eval(
hd(lexp), visited, localValEnv), result);
1199 cerr <<
"undefined symbol " << *
id << endl;
1210 stringstream s; s <<
boxpp(
id);
1295 if (
isNil(patterns)) {
1327 int n = (int)v.size();
1328 while (n--) { l =
cons(v[n],l); }
1351 if (SimplifiedBoxProperty.
get(box,simplified)) {
1363 SimplifiedBoxProperty.
set(box,simplified);
1380 cout <<
"ERROR in file " << __FILE__ <<
':' << __LINE__ <<
", Can't compute the box type of : " << *box << endl;
1384 if (ins==0 && outs==1) {
1424 Tree t1, t2, ff, label, cur,
min,
max, step, type,
name, file, slot, body;
1448 else if (
isBoxFVar(box, type, name, file)) {
1502 else if (
isBoxVSlider(box, label, cur, min, max, step)) {
1506 else if (
isBoxHSlider(box, label, cur, min, max, step)) {
1579 cout <<
"ERROR in file " << __FILE__ <<
':' << __LINE__ <<
", unrecognised box expression : " << *box << endl;
static Tree evalRule(Tree rule, Tree env)
Evaluates the list of patterns and closure the rhs.
bool getDefNameProperty(Tree t, Tree &id)
Indicates the identifier (if any) the expression was a definition of.
Tree(* prim2)(Tree x, Tree y)
bool isBoxIPar(Tree t, Tree &x, Tree &y, Tree &z)
static bool isBoxNumeric(Tree in, Tree &out)
Tree boxSymbolic(Tree slot, Tree body)
Tree addElement(Tree e, Tree l)
bool isBoxSeq(Tree t, Tree &x, Tree &y)
bool isBoxWithLocalDef(Tree t, Tree &body, Tree &ldef)
Class Node = (type x (int + double + Sym + void*))
static Tree evalPattern(Tree pattern, Tree env)
Evaluates a pattern and simplify it to numerical value if possible.
static Tree boxSimplification(Tree box)
boxSimplification(box) : simplify a block-diagram by replacing expressions denoting a constant number...
void evalerrorbox(const char *filename, int linenum, const char *msg, Tree exp)
Tree boxCheckbox(Tree lbl)
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Tree boxHBargraph(Tree lbl, Tree min, Tree max)
bool isBoxOutputs(Tree t, Tree &x)
Tree cons(Tree a, Tree b)
bool isBoxIProd(Tree t, Tree &x, Tree &y, Tree &z)
Tree pushValueDef(Tree id, Tree def, Tree lenv)
Push a new layer and add a single definition.
bool isBoxPatternMatcher(Tree s)
int tree2int(Tree t)
if t has a node of type int, return it otherwise error
Tree boxRec(Tree x, Tree y)
Tree copyEnvReplaceDefs(Tree anEnv, Tree ldefs, Tree visited, Tree curEnv)
Create a new environment by copying an existing one and replacing some definitions.
static Tree vec2list(const vector< Tree > &v)
static Tree nwires(int n)
repeat n times a wire
bool getArgName(Tree t, Tree &id)
Tree evaldocexpr(Tree docexpr, Tree eqlist)
bool isBoxSplit(Tree t, Tree &x, Tree &y)
static Tree iterateSeq(Tree id, int num, Tree body, Tree visited, Tree localValEnv)
Iterate a sequential construction.
Tree boxNumEntry(Tree lbl, Tree cur, Tree min, Tree max, Tree step)
void setNumericProperty(Tree t, Tree num)
bool isBoxComponent(Tree s, Tree &filename)
Tree(* prim4)(Tree w, Tree x, Tree y, Tree z)
static Node PMPROPERTYNODE(symbol("PMPROPERTY"))
A property to store the pattern matcher corresponding to a set of rules in a specific environement...
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
static loopDetector LD(1024, 512)
Eval a block diagram expression.
static void list2vec(Tree l, vector< Tree > &v)
Tree boxVSlider(Tree lbl, Tree cur, Tree min, Tree max, Tree step)
Tree boxIdent(const char *name)
Tree sigPrefix(Tree t0, Tree t1)
bool isBoxAccess(Tree t, Tree &exp, Tree &id)
const Node & node() const
return the content of the tree
bool isBoxHBargraph(Tree s)
Tree boxHSlider(Tree lbl, Tree cur, Tree min, Tree max, Tree step)
static bool isIdentChar(char c)
static Tree make(const Node &n, int ar, Tree br[])
return a new tree or an existing equivalent one
static Tree listn(int n, Tree e)
Creates a list of n elements.
static void writeIdentValue(std::string &dst, const std::string &format, const std::string &ident, Tree visited, Tree localValEnv)
void setDefNameProperty(Tree t, Tree id)
bool getEvalProperty(Tree box, Tree env, Tree &value)
retrieve the value of box in the environment env
Tree pushEnvBarrier(Tree lenv)
bool isBoxRec(Tree t, Tree &x, Tree &y)
static void setPMProperty(Tree t, Tree env, Tree pm)
Interface of the block diagram evaluator.
static Tree real_a2sb(Tree exp)
double max(double x, double y)
static Node EVALPROPERTY(symbol("EvalProperty"))
static Tree a2sb(Tree exp)
Tree(* prim3)(Tree x, Tree y, Tree z)
static Tree evalPatternList(Tree patterns, Tree env)
Evaluates each pattern of the list.
static Tree evalCase(Tree rules, Tree env)
Eval a case expression containing a list of pattern matching rules.
bool get(Tree t, Tree &data)
Tree(* prim5)(Tree v, Tree w, Tree x, Tree y, Tree z)
Tree boxVBargraph(Tree lbl, Tree min, Tree max)
bool isSigReal(Tree t, double *r)
Tree simplifyPattern(Tree value)
Simplify a block-diagram pattern by computing its numerical sub-expressions.
static const char * evalLabel(const char *l, Tree visited, Tree localValEnv)
evallabel replace "...%2i..." occurences in label with value of i
Tree boxPatternMatcher(Automaton *a, int state, Tree env, Tree origRules, Tree revParamList)
static Tree revEvalList(Tree lexp, Tree visited, Tree localValEnv)
Eval a list of expression in reverse order.
bool isBoxModifLocalDef(Tree t, Tree &body, Tree &ldef)
static double eval2double(Tree exp, Tree visited, Tree localValEnv)
Eval a block diagram to a double.
bool isBoxSymbolic(Tree t)
bool isBoxISum(Tree t, Tree &x, Tree &y, Tree &z)
bool isBoxEnvironment(Tree s)
Tree boxPropagateSig(Tree path, Tree box, const siglist &lsig)
Top level propagate a list of signals into a block diagram.
Tree pushMultiClosureDefs(Tree ldefs, Tree visited, Tree lenv)
Push a new layer with multiple definitions creating the appropriate closures.
Tree evalprocess(Tree eqlist)
Eval "process" from a list of definitions.
static property< Tree > SimplifiedBoxProperty
bool getNumericProperty(Tree t, Tree &num)
Tree setUnion(Tree A, Tree B)
int getDefLineProp(Tree sym)
bool isBoxPar(Tree t, Tree &x, Tree &y)
bool isBoxHSlider(Tree s)
static int gBoxSlotNumber
counter for unique slot number
Tree boxMerge(Tree x, Tree y)
bool isBoxVBargraph(Tree s)
bool isBoxWaveform(Tree s)
static Tree numericBoxSimplification(Tree box)
Try to do a numeric simplification of a block-diagram.
bool isClosure(Tree t, Tree &abstr, Tree &genv, Tree &vis, Tree &lenv)
static bool boxlistOutputs(Tree boxlist, int *outputs)
Compute the sum of outputs of a list of boxes.
Tree expandlist(Tree ldef)
Return the list of definitions where all imports have been expanded.
Tree sigAdd(Tree x, Tree y)
bool isBoxCheckbox(Tree s)
static bool autoName(Tree exp, Tree &id)
Tree concat(Tree l, Tree q)
static bool getPMProperty(Tree t, Tree env, Tree &pm)
static Tree patternSimplification(Tree pattern)
static bool isDigitChar(char c)
static Tree applyList(Tree fun, Tree larg)
Apply a function to a list of arguments.
int arity() const
return the number of branches (subtrees) of a tree
void set(Tree t, Tree data)
siglist makeSigInputList(int n)
Fabrique une liste de n entrées.
Tree boxSeq(Tree x, Tree y)
void evalerror(const char *filename, int linenum, const char *msg, Tree exp)
const char * name(Symbol *sym)
Returns the name of a symbol.
Tree closure(Tree abstr, Tree genv, Tree vis, Tree lenv)
bool isSigInt(Tree t, int *i)
bool isBoxVSlider(Tree s)
Tree boxHGroup(Tree lbl, Tree x)
static Tree evalRuleList(Tree rules, Tree env)
Evaluates each rule of the list.
static bool isBoxPatternOp(Tree box, Node &n, Tree &t1, Tree &t2)
bool isBoxNumEntry(Tree s)
Tree boxTGroup(Tree lbl, Tree x)
void setProperty(Tree t, Tree key, Tree val)
static int eval2int(Tree exp, Tree visited, Tree localValEnv)
Eval a block diagram to an int.
Tree boxPar(Tree x, Tree y)
static Tree iteratePar(Tree var, int num, Tree body, Tree visited, Tree localValEnv)
Iterate a parallel construction.
bool isBoxInputs(Tree t, Tree &x)
void * getUserData(Symbol *sym)
Returns user data.
bool isBoxISeq(Tree t, Tree &x, Tree &y, Tree &z)
bool isBoxPatternVar(Tree s, Tree &id)
Tree sigMul(Tree x, Tree y)
Tree getlist(string fname)
Return the list of definitions file contains.
Symbol * symbol(const char *str)
Returns (and creates if new) the symbol of name str.
bool isBoxLibrary(Tree s, Tree &filename)
static Tree iterateSum(Tree id, int num, Tree body, Tree visited, Tree localValEnv)
Iterate an addition construction.
static Tree insideBoxSimplification(Tree box)
Simplify inside a block-diagram : S[A*B] => S[A]*S[B].
Interface for names management.
static Tree larg2par(Tree larg)
Transform a list of expressions in a parallel construction.
bool isBoxMerge(Tree t, Tree &x, Tree &y)
double min(double x, double y)
int apply_pattern_matcher(Automaton *A, int s, Tree X, Tree &C, vector< Tree > &E)
double tree2float(Tree t)
if t has a node of type float, return it otherwise error
Tree boxSplit(Tree x, Tree y)
Automaton * make_pattern_matcher(Tree R)
void setEvalProperty(Tree box, Tree env, Tree value)
set the value of box in the environment env
property< Tree > gSymbolicBoxProperty
Transform unused (unapplied) closures into symbolic boxes.
static Tree evalIdDef(Tree id, Tree visited, Tree env)
Search the environment for the definition of a symbol ID and evaluate it.
const char * tree2str(Tree t)
if t has a node of type symbol, return its name otherwise error
Tree boxVGroup(Tree lbl, Tree x)
Tree branch(int i) const
return the ith branch (subtree) of a tree
const char * getDefFileProp(Tree sym)
bool getProperty(Tree t, Tree key, Tree &val)
static Tree iterateProd(Tree id, int num, Tree body, Tree visited, Tree localValEnv)
Iterate a product construction.
bool getBoxType(Tree box, int *inum, int *onum)
Return the type (number of inputs and outputs) of a box or false if undefined.
static Tree realeval(Tree exp, Tree visited, Tree localValEnv)
Eval a block diagram expression.