FAUST compiler  0.9.9.6b8
Macros | Functions | Variables
eval.cpp File Reference

Implementation of the Block diagram evaluator. More...

#include "eval.hh"
#include <stdio.h>
#include "errormsg.hh"
#include "ppbox.hh"
#include "simplify.hh"
#include "propagate.hh"
#include "patternmatcher.hh"
#include "signals.hh"
#include "xtended.hh"
#include "loopDetector.hh"
#include "property.hh"
#include "names.hh"
#include "compatibility.hh"
#include <assert.h>
Include dependency graph for eval.cpp:

Go to the source code of this file.

Macros

#define TRACE
 

Functions

static Tree a2sb (Tree exp)
 
static Tree eval (Tree exp, Tree visited, Tree localValEnv)
 
static Tree realeval (Tree exp, Tree visited, Tree localValEnv)
 Eval a block diagram expression. More...
 
static Tree revEvalList (Tree lexp, Tree visited, Tree localValEnv)
 Eval a list of expression in reverse order. More...
 
static Tree applyList (Tree fun, Tree larg)
 Apply a function to a list of arguments. More...
 
static Tree iteratePar (Tree id, int num, Tree body, Tree visited, Tree localValEnv)
 Iterate a parallel construction. More...
 
static Tree iterateSeq (Tree id, int num, Tree body, Tree visited, Tree localValEnv)
 Iterate a sequential construction. More...
 
static Tree iterateSum (Tree id, int num, Tree body, Tree visited, Tree localValEnv)
 Iterate an addition construction. More...
 
static Tree iterateProd (Tree id, int num, Tree body, Tree visited, Tree localValEnv)
 Iterate a product construction. More...
 
static Tree larg2par (Tree larg)
 Transform a list of expressions in a parallel construction. More...
 
static int eval2int (Tree exp, Tree visited, Tree localValEnv)
 Eval a block diagram to an int. More...
 
static double eval2double (Tree exp, Tree visited, Tree localValEnv)
 Eval a block diagram to a double. More...
 
static const char * evalLabel (const char *src, Tree visited, Tree localValEnv)
 evallabel replace "...%2i..." occurences in label with value of i More...
 
static Tree evalIdDef (Tree id, Tree visited, Tree lenv)
 Search the environment for the definition of a symbol ID and evaluate it. More...
 
static Tree evalCase (Tree rules, Tree env)
 Eval a case expression containing a list of pattern matching rules. More...
 
static Tree evalRuleList (Tree rules, Tree env)
 Evaluates each rule of the list. More...
 
static Tree evalRule (Tree rule, Tree env)
 Evaluates the list of patterns and closure the rhs. More...
 
static Tree evalPatternList (Tree patterns, Tree env)
 Evaluates each pattern of the list. More...
 
static Tree evalPattern (Tree pattern, Tree env)
 Evaluates a pattern and simplify it to numerical value if possible. More...
 
static Tree patternSimplification (Tree pattern)
 
static bool isBoxNumeric (Tree in, Tree &out)
 
static Tree vec2list (const vector< Tree > &v)
 
static void list2vec (Tree l, vector< Tree > &v)
 
static Tree listn (int n, Tree e)
 Creates a list of n elements. More...
 
static Tree boxSimplification (Tree box)
 boxSimplification(box) : simplify a block-diagram by replacing expressions denoting a constant number by this number. More...
 
Tree evalprocess (Tree eqlist)
 Eval "process" from a list of definitions. More...
 
Tree evaldocexpr (Tree docexpr, Tree eqlist)
 
static Tree real_a2sb (Tree exp)
 
static bool autoName (Tree exp, Tree &id)
 
bool getArgName (Tree t, Tree &id)
 
void setEvalProperty (Tree box, Tree env, Tree value)
 set the value of box in the environment env More...
 
bool getEvalProperty (Tree box, Tree env, Tree &value)
 retrieve the value of box in the environment env More...
 
static bool isBoxPatternOp (Tree box, Node &n, Tree &t1, Tree &t2)
 
void setNumericProperty (Tree t, Tree num)
 
bool getNumericProperty (Tree t, Tree &num)
 
Tree simplifyPattern (Tree value)
 Simplify a block-diagram pattern by computing its numerical sub-expressions. More...
 
static bool isDigitChar (char c)
 
static bool isIdentChar (char c)
 
static void writeIdentValue (std::string &dst, const std::string &format, const std::string &ident, Tree visited, Tree localValEnv)
 
static bool boxlistOutputs (Tree boxlist, int *outputs)
 Compute the sum of outputs of a list of boxes. More...
 
static Tree nwires (int n)
 repeat n times a wire More...
 
static void setPMProperty (Tree t, Tree env, Tree pm)
 
static bool getPMProperty (Tree t, Tree env, Tree &pm)
 
static Tree numericBoxSimplification (Tree box)
 Try to do a numeric simplification of a block-diagram. More...
 
static Tree insideBoxSimplification (Tree box)
 Simplify inside a block-diagram : S[A*B] => S[A]*S[B]. More...
 

Variables

SourceReader gReader
 
int gMaxNameSize
 
bool gSimpleNames
 
bool gSimplifyDiagrams
 
property< TreegSymbolicBoxProperty
 Transform unused (unapplied) closures into symbolic boxes. More...
 
static int gBoxSlotNumber = 0
 counter for unique slot number More...
 
static loopDetector LD (1024, 512)
 Eval a block diagram expression. More...
 
static Node EVALPROPERTY (symbol("EvalProperty"))
 
Tree NUMERICPROPERTY = tree(symbol("NUMERICPROPERTY"))
 
const char * Formats [] = {"%d", "%1d", "%2d", "%3d", "%4d"}
 
static Node PMPROPERTYNODE (symbol("PMPROPERTY"))
 A property to store the pattern matcher corresponding to a set of rules in a specific environement. More...
 
static property< TreeSimplifiedBoxProperty
 

Detailed Description

Implementation of the Block diagram evaluator.

Interface for names propagation.

A strict lambda-calculus evaluator for block diagram expressions.

Definition in file eval.cpp.

Macro Definition Documentation

#define TRACE

Definition at line 21 of file eval.cpp.

Function Documentation

static Tree a2sb ( Tree  exp)
static

Definition at line 135 of file eval.cpp.

References property< Tree >::get(), getDefNameProperty(), real_a2sb(), property< Tree >::set(), and setDefNameProperty().

Referenced by applyList(), boxlistOutputs(), eval2double(), eval2int(), evaldocexpr(), evalprocess(), isBoxNumeric(), real_a2sb(), and realeval().

136 {
137  Tree result;
138  Tree id;
139 
140  if (gSymbolicBoxProperty.get(exp, result)) {
141  return result;
142  }
143 
144  result = real_a2sb(exp);
145  if (result != exp && getDefNameProperty(exp, id)) {
146  setDefNameProperty(result, id); // propagate definition name property when needed
147  }
148  gSymbolicBoxProperty.set(exp, result);
149  return result;
150 }
bool getDefNameProperty(Tree t, Tree &id)
Indicates the identifier (if any) the expression was a definition of.
Definition: names.cpp:85
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
void setDefNameProperty(Tree t, Tree id)
Definition: names.cpp:54
static Tree real_a2sb(Tree exp)
Definition: eval.cpp:154
bool get(Tree t, Tree &data)
Definition: property.hh:67
void set(Tree t, Tree data)
Definition: property.hh:62
property< Tree > gSymbolicBoxProperty
Transform unused (unapplied) closures into symbolic boxes.
Definition: eval.cpp:131

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree applyList ( Tree  fun,
Tree  larg 
)
static

Apply a function to a list of arguments.

Apply a function F to a list of arguments (a,b,c,...). F can be either a closure over an abstraction, or a pattern matcher. If it is not the case then we have : F(a,b,c,...) ==> (a,b,c,...):F

Parameters
funthe function to apply
largthe list of arguments
Returns
the resulting expression in normal form

Definition at line 1003 of file eval.cpp.

References a2sb(), apply_pattern_matcher(), boxCase(), boxError(), boxlistOutputs(), boxPatternMatcher(), boxSeq(), concat(), cons(), eval(), evalerror(), evalerrorbox(), getBoxType(), getDefNameProperty(), getUserData(), gSimpleNames, hd(), isBoxAbstr(), isBoxEnvironment(), isBoxError(), isBoxNumeric(), isBoxPatternMatcher(), isBoxPrim2(), isClosure(), isNil(), larg2par(), list2vec(), nil, nwires(), pushValueDef(), reverse(), setDefNameProperty(), sigPrefix(), tl(), tree2str(), vec2list(), and yyfilename.

Referenced by real_a2sb(), and realeval().

1004 {
1005  Tree abstr;
1006  Tree globalDefEnv;
1007  Tree visited;
1008  Tree localValEnv;
1009  Tree envList;
1010  Tree originalRules;
1011  Tree revParamList;
1012 
1013  Tree id;
1014  Tree body;
1015 
1016  Automaton* automat;
1017  int state;
1018 
1019  prim2 p2;
1020 
1021  //cerr << "applyList (" << *fun << ", " << *larg << ")" << endl;
1022 
1023  if (isNil(larg)) return fun;
1024 
1025  if (isBoxError(fun) || isBoxError(larg)) {
1026  return boxError();
1027  }
1028 
1029  if (isBoxPatternMatcher(fun, automat, state, envList, originalRules, revParamList)) {
1030  Tree result;
1031  int state2;
1032  vector<Tree> envVect;
1033 
1034  list2vec(envList, envVect);
1035  //cerr << "applyList/apply_pattern_matcher(" << automat << "," << state << "," << *hd(larg) << ")" << endl;
1036  state2 = apply_pattern_matcher(automat, state, hd(larg), result, envVect);
1037  //cerr << "state2 = " << state2 << "; result = " << *result << endl;
1038  if (state2 >= 0 && isNil(result)) {
1039  // we need to continue the pattern matching
1040  return applyList(
1041  boxPatternMatcher(automat, state2, vec2list(envVect), originalRules, cons(hd(larg),revParamList)),
1042  tl(larg) );
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;
1046  exit(1);
1047  } else {
1048  // Pattern Matching was succesful
1049  // the result is a closure that we need to evaluate.
1050  if (isClosure(result, body, globalDefEnv, visited, localValEnv)) {
1051  // why ??? return simplifyPattern(eval(body, nil, localValEnv));
1052  //return eval(body, nil, localValEnv);
1053  return applyList(eval(body, nil, localValEnv), tl(larg));
1054  } else {
1055  cerr << "wrong result from pattern matching (not a closure) : " << boxpp(result) << endl;
1056  return boxError();
1057  }
1058  }
1059  }
1060  if (!isClosure(fun, abstr, globalDefEnv, visited, localValEnv)) {
1061  // principle : f(a,b,c,...) ==> (a,b,c,...):f
1062  int ins, outs;
1063 
1064  // check arity of function
1065  Tree efun = a2sb(fun);
1066  //cerr << "TRACEPOINT 1 : " << boxpp(efun) << endl;
1067  if (!getBoxType(efun, &ins, &outs)) { // on laisse comme ca pour le moment
1068  // we can't determine the input arity of the expression
1069  // hope for the best
1070  return boxSeq(larg2par(larg), fun);
1071  }
1072 
1073  // check arity of arg list
1074  if (!boxlistOutputs(larg,&outs)) {
1075  // we don't know yet the output arity of larg. Therefore we can't
1076  // do any arity checking nor add _ to reach the required number of arguments
1077  // cerr << "warning : can't infere the type of : " << boxpp(larg) << endl;
1078  return boxSeq(larg2par(larg), fun);
1079  }
1080 
1081  if (outs > ins) {
1082  cerr << "too much arguments : " << outs << ", instead of : " << ins << endl;
1083  cerr << "when applying : " << boxpp(fun) << endl
1084  << " to : " << boxpp(larg) << endl;
1085  assert(false);
1086  }
1087 
1088  if ( (outs == 1)
1089  &&
1090  ( ( isBoxPrim2(fun, &p2) && (p2 != sigPrefix) )
1091  || ( getUserData(fun) && ((xtended*)getUserData(fun))->isSpecialInfix() ) ) ) {
1092  // special case : /(3) ==> _,3 : /
1093  Tree larg2 = concat(nwires(ins-outs), larg);
1094  return boxSeq(larg2par(larg2), fun);
1095 
1096  } else {
1097 
1098  Tree larg2 = concat(larg, nwires(ins-outs));
1099  return boxSeq(larg2par(larg2), fun);
1100  }
1101  }
1102 
1103  if (isBoxEnvironment(abstr)) {
1104  evalerrorbox(yyfilename, -1, "an environment can't be used as a function", fun);
1105  exit(1);
1106  }
1107 
1108  if (!isBoxAbstr(abstr, id, body)) {
1109  evalerror(yyfilename, -1, "(internal) not an abstraction inside closure", fun);
1110  exit(1);
1111  }
1112 
1113  // try to synthetise a name from the function name and the argument name
1114  {
1115  Tree arg = eval(hd(larg), visited, localValEnv);
1116  Tree narg; if ( isBoxNumeric(arg,narg) ) { arg = narg; }
1117  Tree f = eval(body, visited, pushValueDef(id, arg, localValEnv));
1118 
1119  Tree fname;
1120  if (getDefNameProperty(fun, fname)) {
1121  stringstream s; s << tree2str(fname); if (!gSimpleNames) s << "(" << boxpp(arg) << ")";
1122  setDefNameProperty(f, s.str());
1123  }
1124  return applyList(f, tl(larg));
1125  }
1126 }
bool getDefNameProperty(Tree t, Tree &id)
Indicates the identifier (if any) the expression was a definition of.
Definition: names.cpp:85
Tree(* prim2)(Tree x, Tree y)
Definition: boxes.hh:210
static bool isBoxNumeric(Tree in, Tree &out)
Definition: eval.cpp:630
Tree reverse(Tree l)
Definition: list.cpp:240
void evalerrorbox(const char *filename, int linenum, const char *msg, Tree exp)
Definition: errormsg.cpp:47
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Definition: eval.cpp:280
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree pushValueDef(Tree id, Tree def, Tree lenv)
Push a new layer and add a single definition.
Definition: environment.cpp:94
bool isBoxPatternMatcher(Tree s)
Definition: boxes.cpp:630
static Tree vec2list(const vector< Tree > &v)
Definition: eval.cpp:1324
static Tree nwires(int n)
repeat n times a wire
Definition: eval.cpp:984
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
static void list2vec(Tree l, vector< Tree > &v)
Definition: eval.cpp:1315
Tree sigPrefix(Tree t0, Tree t1)
Definition: signals.cpp:65
Tree hd(Tree l)
Definition: list.hh:133
bool gSimpleNames
Definition: main.cpp:128
void setDefNameProperty(Tree t, Tree id)
Definition: names.cpp:54
static Tree a2sb(Tree exp)
Definition: eval.cpp:135
bool isBoxAbstr(Tree t)
Definition: boxes.cpp:202
bool isNil(Tree l)
Definition: list.hh:137
Tree boxPatternMatcher(Automaton *a, int state, Tree env, Tree origRules, Tree revParamList)
Definition: boxes.cpp:625
bool isBoxEnvironment(Tree s)
Definition: boxes.cpp:285
bool isClosure(Tree t, Tree &abstr, Tree &genv, Tree &vis, Tree &lenv)
Definition: boxes.cpp:239
static bool boxlistOutputs(Tree boxlist, int *outputs)
Compute the sum of outputs of a list of boxes.
Definition: eval.cpp:948
Tree boxError()
Definition: boxes.cpp:244
Tree concat(Tree l, Tree q)
Definition: list.cpp:216
static Tree applyList(Tree fun, Tree larg)
Apply a function to a list of arguments.
Definition: eval.cpp:1003
Tree boxSeq(Tree x, Tree y)
Definition: boxes.cpp:135
void evalerror(const char *filename, int linenum, const char *msg, Tree exp)
Definition: errormsg.cpp:40
const char * yyfilename
Definition: errormsg.cpp:30
Definition: ppbox.hh:58
void * getUserData(Symbol *sym)
Returns user data.
Definition: symbol.hh:100
Tree nil
Definition: list.cpp:116
static Tree larg2par(Tree larg)
Transform a list of expressions in a parallel construction.
Definition: eval.cpp:1163
bool isBoxError(Tree t)
Definition: boxes.cpp:249
bool isBoxPrim2(Tree s)
Definition: boxes.cpp:320
int apply_pattern_matcher(Automaton *A, int s, Tree X, Tree &C, vector< Tree > &E)
Tree boxCase(Tree rules)
Definition: boxes.cpp:615
Tree tl(Tree l)
Definition: list.hh:134
const char * tree2str(Tree t)
if t has a node of type symbol, return its name otherwise error
Definition: tree.cpp:278
bool getBoxType(Tree box, int *inum, int *onum)
Return the type (number of inputs and outputs) of a box or false if undefined.
Definition: boxtype.cpp:63

Here is the call graph for this function:

Here is the caller graph for this function:

static bool autoName ( Tree  exp,
Tree id 
)
static

Definition at line 226 of file eval.cpp.

References tree().

Referenced by getArgName().

227 {
228  stringstream s; s << boxpp(exp);
229  id = tree(s.str().c_str());
230  return true;
231 }
Tree tree(const Node &n)
Definition: tree.hh:186
Definition: ppbox.hh:58

Here is the call graph for this function:

Here is the caller graph for this function:

static bool boxlistOutputs ( Tree  boxlist,
int *  outputs 
)
static

Compute the sum of outputs of a list of boxes.

The sum is valid if all the boxes have a valid boxType

Parameters
boxlistthe list of boxes
outputssum of outputs of the boxes
Returns
true if outputs is valid, false otherwise

Definition at line 948 of file eval.cpp.

References a2sb(), getBoxType(), hd(), isNil(), and tl().

Referenced by applyList().

949 {
950  int ins, outs;
951 
952  *outputs = 0;
953  while (!isNil(boxlist))
954  {
955  Tree b = a2sb(hd(boxlist)); // for getBoxType, suppose list of evaluated boxes
956  if (getBoxType(b, &ins, &outs)) {
957  *outputs += outs;
958  } else {
959  // arbitrary output arity set to 1
960  // when can't be determined
961  *outputs += 1;
962  }
963  boxlist = tl(boxlist);
964  }
965  return isNil(boxlist);
966 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree hd(Tree l)
Definition: list.hh:133
static Tree a2sb(Tree exp)
Definition: eval.cpp:135
bool isNil(Tree l)
Definition: list.hh:137
Tree tl(Tree l)
Definition: list.hh:134
bool getBoxType(Tree box, int *inum, int *onum)
Return the type (number of inputs and outputs) of a box or false if undefined.
Definition: boxtype.cpp:63

Here is the call graph for this function:

Here is the caller graph for this function:

Tree boxSimplification ( Tree  box)
static

boxSimplification(box) : simplify a block-diagram by replacing expressions denoting a constant number by this number.

Definition at line 1347 of file eval.cpp.

References property< Tree >::get(), getDefNameProperty(), name(), numericBoxSimplification(), property< Tree >::set(), and setDefNameProperty().

Referenced by evalprocess(), and insideBoxSimplification().

1348 {
1349  Tree simplified;
1350 
1351  if (SimplifiedBoxProperty.get(box,simplified)) {
1352 
1353  return simplified;
1354 
1355  } else {
1356 
1357  simplified = numericBoxSimplification(box);
1358 
1359  // transferts name property if any
1360  Tree name; if (getDefNameProperty(box, name)) setDefNameProperty(simplified, name);
1361 
1362  // attach simplified expression as a property of original box
1363  SimplifiedBoxProperty.set(box,simplified);
1364 
1365  return simplified;
1366  }
1367 }
bool getDefNameProperty(Tree t, Tree &id)
Indicates the identifier (if any) the expression was a definition of.
Definition: names.cpp:85
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
void setDefNameProperty(Tree t, Tree id)
Definition: names.cpp:54
bool get(Tree t, Tree &data)
Definition: property.hh:67
static property< Tree > SimplifiedBoxProperty
Definition: eval.cpp:1339
static Tree numericBoxSimplification(Tree box)
Try to do a numeric simplification of a block-diagram.
Definition: eval.cpp:1372
void set(Tree t, Tree data)
Definition: property.hh:62
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree eval ( Tree  exp,
Tree  visited,
Tree  localValEnv 
)
static

Definition at line 280 of file eval.cpp.

References cons(), loopDetector::detect(), getDefNameProperty(), getEvalProperty(), LD, realeval(), setDefNameProperty(), and setEvalProperty().

Referenced by applyList(), eval2double(), eval2int(), evaldocexpr(), evalIdDef(), evalPattern(), evalprocess(), iteratePar(), iterateProd(), iterateSeq(), iterateSum(), real_a2sb(), realeval(), and revEvalList().

281 {
282  Tree id;
283  Tree result;
284 
285  if (!getEvalProperty(exp, localValEnv, result)) {
286  LD.detect(cons(exp,localValEnv));
287  //cerr << "ENTER eval("<< *exp << ") with env " << *localValEnv << endl;
288  result = realeval(exp, visited, localValEnv);
289  setEvalProperty(exp, localValEnv, result);
290  //cerr << "EXIT eval(" << *exp << ") IS " << *result << " with env " << *localValEnv << endl;
291  if (getDefNameProperty(exp, id)) {
292  setDefNameProperty(result, id); // propagate definition name property
293  }
294  }
295  return result;
296 }
bool getDefNameProperty(Tree t, Tree &id)
Indicates the identifier (if any) the expression was a definition of.
Definition: names.cpp:85
Tree cons(Tree a, Tree b)
Definition: list.hh:124
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
static loopDetector LD(1024, 512)
Eval a block diagram expression.
void setDefNameProperty(Tree t, Tree id)
Definition: names.cpp:54
bool getEvalProperty(Tree box, Tree env, Tree &value)
retrieve the value of box in the environment env
Definition: eval.cpp:274
bool detect(Tree t)
Definition: loopDetector.cpp:4
void setEvalProperty(Tree box, Tree env, Tree value)
set the value of box in the environment env
Definition: eval.cpp:261
static Tree realeval(Tree exp, Tree visited, Tree localValEnv)
Eval a block diagram expression.
Definition: eval.cpp:308

Here is the call graph for this function:

Here is the caller graph for this function:

static double eval2double ( Tree  exp,
Tree  visited,
Tree  localValEnv 
)
static

Eval a block diagram to a double.

Eval a block diagram that represent a double constant. This function first eval a block diagram to its normal form, then check it represent a numerical value (a block diagram of type : 0->1) then do a symbolic propagation and try to convert the resulting signal to a double.

Parameters
expthe expression to evaluate
globalDefEnvthe global environment
visitedlist of visited definition to detect recursive definitions
localValEnvthe local environment
Returns
a block diagram in normal form

Definition at line 689 of file eval.cpp.

References a2sb(), boxPropagateSig(), eval(), evalerror(), getBoxType(), hd(), makeSigInputList(), nil, simplify(), tree2float(), yyfilename, and yylineno.

Referenced by realeval().

690 {
691  Tree diagram = a2sb(eval(exp, visited, localValEnv)); // pour getBoxType
692  int numInputs, numOutputs;
693  getBoxType(diagram, &numInputs, &numOutputs);
694  if ( (numInputs > 0) || (numOutputs != 1) ) {
695  evalerror (yyfilename, yylineno, "not a constant expression of type : (0->1)", exp);
696  return 1;
697  } else {
698  Tree lsignals = boxPropagateSig(nil, diagram , makeSigInputList(numInputs) );
699  Tree val = simplify(hd(lsignals));
700  return tree2float(val);
701  }
702 }
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Definition: eval.cpp:280
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree simplify(Tree sig)
Definition: simplify.cpp:76
Tree hd(Tree l)
Definition: list.hh:133
static Tree a2sb(Tree exp)
Definition: eval.cpp:135
Tree boxPropagateSig(Tree path, Tree box, const siglist &lsig)
Top level propagate a list of signals into a block diagram.
Definition: propagate.cpp:501
siglist makeSigInputList(int n)
Fabrique une liste de n entrées.
Definition: propagate.cpp:96
void evalerror(const char *filename, int linenum, const char *msg, Tree exp)
Definition: errormsg.cpp:40
const char * yyfilename
Definition: errormsg.cpp:30
Tree nil
Definition: list.cpp:116
double tree2float(Tree t)
if t has a node of type float, return it otherwise error
Definition: tree.cpp:246
int yylineno
Definition: faustlexer.cpp:357
bool getBoxType(Tree box, int *inum, int *onum)
Return the type (number of inputs and outputs) of a box or false if undefined.
Definition: boxtype.cpp:63

Here is the call graph for this function:

Here is the caller graph for this function:

static int eval2int ( Tree  exp,
Tree  visited,
Tree  localValEnv 
)
static

Eval a block diagram to an int.

Eval a block diagram that represent an integer constant. This function first eval a block diagram to its normal form, then check it represent a numerical value (a block diagram of type : 0->1) then do a symbolic propagation and try to convert the resulting signal to an int.

Parameters
expthe expression to evaluate
globalDefEnvthe global environment
visitedlist of visited definition to detect recursive definitions
localValEnvthe local environment
Returns
a block diagram in normal form

Definition at line 718 of file eval.cpp.

References a2sb(), boxPropagateSig(), eval(), evalerror(), getBoxType(), hd(), makeSigInputList(), nil, simplify(), tree2int(), yyfilename, and yylineno.

Referenced by realeval(), and writeIdentValue().

719 {
720  Tree diagram = a2sb(eval(exp, visited, localValEnv)); // pour getBoxType()
721  int numInputs, numOutputs;
722  getBoxType(diagram, &numInputs, &numOutputs);
723  if ( (numInputs > 0) || (numOutputs != 1) ) {
724  evalerror (yyfilename, yylineno, "not a constant expression of type : (0->1)", exp);
725  return 1;
726  } else {
727  Tree lsignals = boxPropagateSig(nil, diagram , makeSigInputList(numInputs) );
728  Tree val = simplify(hd(lsignals));
729  return tree2int(val);
730  }
731 }
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Definition: eval.cpp:280
int tree2int(Tree t)
if t has a node of type int, return it otherwise error
Definition: tree.cpp:230
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree simplify(Tree sig)
Definition: simplify.cpp:76
Tree hd(Tree l)
Definition: list.hh:133
static Tree a2sb(Tree exp)
Definition: eval.cpp:135
Tree boxPropagateSig(Tree path, Tree box, const siglist &lsig)
Top level propagate a list of signals into a block diagram.
Definition: propagate.cpp:501
siglist makeSigInputList(int n)
Fabrique une liste de n entrées.
Definition: propagate.cpp:96
void evalerror(const char *filename, int linenum, const char *msg, Tree exp)
Definition: errormsg.cpp:40
const char * yyfilename
Definition: errormsg.cpp:30
Tree nil
Definition: list.cpp:116
int yylineno
Definition: faustlexer.cpp:357
bool getBoxType(Tree box, int *inum, int *onum)
Return the type (number of inputs and outputs) of a box or false if undefined.
Definition: boxtype.cpp:63

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree evalCase ( Tree  rules,
Tree  env 
)
static

Eval a case expression containing a list of pattern matching rules.

Creates a boxPatternMatcher containing a pm autamaton a state and a list of environments.

Parameters
rulesthe list of rules
envthe environment uused to evaluate the patterns and closure the rhs
Returns
a boxPatternMatcher ready to be applied

Definition at line 1257 of file eval.cpp.

References boxPatternMatcher(), evalRuleList(), getPMProperty(), len(), listn(), make_pattern_matcher(), nil, pushEnvBarrier(), and setPMProperty().

Referenced by realeval().

1258 {
1259  Tree pm;
1260  if (!getPMProperty(rules, env, pm)) {
1261  Automaton* a = make_pattern_matcher(evalRuleList(rules, env));
1262  pm = boxPatternMatcher(a, 0, listn(len(rules), pushEnvBarrier(env)), rules, nil);
1263  setPMProperty(rules, env, pm);
1264  }
1265  return pm;
1266 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
static Tree listn(int n, Tree e)
Creates a list of n elements.
Definition: eval.cpp:1226
Tree pushEnvBarrier(Tree lenv)
Definition: environment.cpp:43
static void setPMProperty(Tree t, Tree env, Tree pm)
Definition: eval.cpp:1238
Tree boxPatternMatcher(Automaton *a, int state, Tree env, Tree origRules, Tree revParamList)
Definition: boxes.cpp:625
static bool getPMProperty(Tree t, Tree env, Tree &pm)
Definition: eval.cpp:1243
static Tree evalRuleList(Tree rules, Tree env)
Evaluates each rule of the list.
Definition: eval.cpp:1272
Tree nil
Definition: list.cpp:116
int len(Tree l)
Definition: list.cpp:198
Automaton * make_pattern_matcher(Tree R)

Here is the call graph for this function:

Here is the caller graph for this function:

Tree evaldocexpr ( Tree  docexpr,
Tree  eqlist 
)

Definition at line 114 of file eval.cpp.

References a2sb(), eval(), nil, and pushMultiClosureDefs().

Referenced by mapEvalDocEqn(), and printDocDgm().

115 {
116  return a2sb(eval(docexpr, nil, pushMultiClosureDefs(eqlist, nil, nil)));
117 }
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Definition: eval.cpp:280
static Tree a2sb(Tree exp)
Definition: eval.cpp:135
Tree pushMultiClosureDefs(Tree ldefs, Tree visited, Tree lenv)
Push a new layer with multiple definitions creating the appropriate closures.
Tree nil
Definition: list.cpp:116

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree evalIdDef ( Tree  id,
Tree  visited,
Tree  lenv 
)
static

Search the environment for the definition of a symbol ID and evaluate it.

Detects recursive definitions using a set of visited IDxENV. Associates the symbol as a definition name property of the definition.

Parameters
idthe symbol ID t-o search
visitedset of visited symbols (used for recursive definition detection)
lenvthe environment where to search
Returns
the evaluated definition of ID

Definition at line 1188 of file eval.cpp.

References addElement(), CTree::branch(), cons(), eval(), evalerror(), getDefFileProp(), getDefLineProp(), getDefNameProperty(), getProperty(), isNil(), name(), and nil.

Referenced by realeval().

1189 {
1190  Tree def, name;
1191 
1192  // search the environment env for a definition of symbol id
1193  while (!isNil(lenv) && !getProperty(lenv, id, def)) {
1194  lenv = lenv->branch(0);
1195  }
1196 
1197  // check that the definition exists
1198  if (isNil(lenv)) {
1199  cerr << "undefined symbol " << *id << endl;
1200  evalerror(getDefFileProp(id), getDefLineProp(id), "undefined symbol ", id);
1201  exit(1);
1202  }
1203 
1204  //cerr << "Id definition is " << *def << endl;
1205  // check that it is not a recursive definition
1206  Tree p = cons(id,lenv);
1207  // set the definition name property
1208  if (!getDefNameProperty(def, name)) {
1209  // if the definition has no name use the identifier
1210  stringstream s; s << boxpp(id);
1211  //XXXXXX setDefNameProperty(def, s.str());
1212  }
1213 
1214  // return the evaluated definition
1215  return eval(def, addElement(p,visited), nil);
1216 }
bool getDefNameProperty(Tree t, Tree &id)
Indicates the identifier (if any) the expression was a definition of.
Definition: names.cpp:85
Tree addElement(Tree e, Tree l)
Definition: list.cpp:272
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Definition: eval.cpp:280
Tree cons(Tree a, Tree b)
Definition: list.hh:124
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool isNil(Tree l)
Definition: list.hh:137
int getDefLineProp(Tree sym)
Definition: errormsg.cpp:82
void evalerror(const char *filename, int linenum, const char *msg, Tree exp)
Definition: errormsg.cpp:40
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
Definition: ppbox.hh:58
Tree nil
Definition: list.cpp:116
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145
const char * getDefFileProp(Tree sym)
Definition: errormsg.cpp:72
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423

Here is the call graph for this function:

Here is the caller graph for this function:

static const char * evalLabel ( const char *  l,
Tree  visited,
Tree  localValEnv 
)
static

evallabel replace "...%2i..." occurences in label with value of i

Definition at line 760 of file eval.cpp.

References isDigitChar(), isIdentChar(), and writeIdentValue().

Referenced by realeval().

761 {
762  //std::cerr << "Eval Label : " << src;
763 
764  int state = 0; // current state
765  std::string dst; // label once evaluated
766  std::string ident; // current identifier
767  std::string format; // current format
768 
769  while (state != -1) {
770 
771  char c = *src++;
772 
773  if (state == 0) {
774 
775  if (c == 0) {
776  state = -1;
777  } else if (c == '%') {
778  ident = "";
779  format = "";
780  state = 1;
781  } else {
782  dst+=c;
783  state = 0;
784  }
785 
786  } else if (state == 1) {
787 
788  if (c == 0) {
789  // fin et pas d'indentifiant, abandon
790  dst += '%';
791  dst += format;
792  state = -1;
793  } else if (isDigitChar(c)) {
794  format += c;
795  state = 1;
796  } else if (isIdentChar(c)) {
797  ident += c;
798  state = 2;
799  } else {
800  // caractere de ponctuation et pas d'indentifiant, abandon
801  dst += '%';
802  dst += format;
803  src--;
804  state = 0;
805  }
806 
807  } else if (state == 2) {
808 
809  if (isIdentChar(c)) {
810  ident += c;
811  state = 2;
812  } else {
813  writeIdentValue(dst, format, ident, visited, localValEnv);
814  src--;
815  state = 0;
816  }
817 
818  } else {
819 
820  std::cerr << "internal error in evallabel : undefined state " << state << std::endl;
821  exit(1);
822  }
823  }
824 
825  const char* val = strdup(dst.c_str());
826  //std::cerr << " ===> " << val << std::endl;
827  return val;
828 }
static bool isIdentChar(char c)
Definition: eval.cpp:738
static void writeIdentValue(std::string &dst, const std::string &format, const std::string &ident, Tree visited, Tree localValEnv)
Definition: eval.cpp:745
static bool isDigitChar(char c)
Definition: eval.cpp:733

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree evalPattern ( Tree  pattern,
Tree  env 
)
static

Evaluates a pattern and simplify it to numerical value if possible.

Definition at line 1308 of file eval.cpp.

References eval(), nil, and patternSimplification().

Referenced by evalPatternList().

1309 {
1310  Tree p = eval(pattern, nil, env);
1311  return patternSimplification(p);
1312 }
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Definition: eval.cpp:280
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
static Tree patternSimplification(Tree pattern)
Definition: eval.cpp:659
Tree nil
Definition: list.cpp:116

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree evalPatternList ( Tree  patterns,
Tree  env 
)
static

Evaluates each pattern of the list.

Definition at line 1293 of file eval.cpp.

References cons(), evalPattern(), hd(), isNil(), nil, and tl().

Referenced by evalRule().

1294 {
1295  if (isNil(patterns)) {
1296  return nil;
1297  } else {
1298  return cons( evalPattern(hd(patterns), env),
1299  evalPatternList(tl(patterns), env) );
1300  }
1301 }
static Tree evalPattern(Tree pattern, Tree env)
Evaluates a pattern and simplify it to numerical value if possible.
Definition: eval.cpp:1308
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree hd(Tree l)
Definition: list.hh:133
static Tree evalPatternList(Tree patterns, Tree env)
Evaluates each pattern of the list.
Definition: eval.cpp:1293
bool isNil(Tree l)
Definition: list.hh:137
Tree nil
Definition: list.cpp:116
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

Tree evalprocess ( Tree  eqlist)

Eval "process" from a list of definitions.

Eval the definition of 'process'.

Strict evaluation of a block diagram expression by applying beta reduction.

Parameters
eqlista list of faust defintions forming the the global environment
Returns
the process block diagram in normal form

Definition at line 100 of file eval.cpp.

References a2sb(), boxIdent(), boxSimplification(), eval(), gSimplifyDiagrams, nil, and pushMultiClosureDefs().

Referenced by main().

101 {
102  Tree b = a2sb(eval(boxIdent("process"), nil, pushMultiClosureDefs(eqlist, nil, nil)));
103 
104  if (gSimplifyDiagrams) {
105  b = boxSimplification(b);
106  }
107 
108  return b;
109 }
static Tree boxSimplification(Tree box)
boxSimplification(box) : simplify a block-diagram by replacing expressions denoting a constant number...
Definition: eval.cpp:1347
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Definition: eval.cpp:280
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree boxIdent(const char *name)
Definition: boxes.cpp:57
static Tree a2sb(Tree exp)
Definition: eval.cpp:135
Tree pushMultiClosureDefs(Tree ldefs, Tree visited, Tree lenv)
Push a new layer with multiple definitions creating the appropriate closures.
bool gSimplifyDiagrams
Definition: main.cpp:129
Tree nil
Definition: list.cpp:116

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree evalRule ( Tree  rule,
Tree  env 
)
static

Evaluates the list of patterns and closure the rhs.

Definition at line 1283 of file eval.cpp.

References cons(), evalPatternList(), left(), and right().

Referenced by evalRuleList().

1284 {
1285  //cerr << "evalRule "<< *rule << " in " << *env << endl;
1286  return cons(evalPatternList(left(rule), env), right(rule));
1287 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree left(Tree t)
Definition: list.hh:170
Tree right(Tree t)
Definition: list.hh:171
static Tree evalPatternList(Tree patterns, Tree env)
Evaluates each pattern of the list.
Definition: eval.cpp:1293

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree evalRuleList ( Tree  rules,
Tree  env 
)
static

Evaluates each rule of the list.

Definition at line 1272 of file eval.cpp.

References cons(), evalRule(), hd(), isNil(), nil, and tl().

Referenced by evalCase().

1273 {
1274  //cerr << "evalRuleList "<< *rules << " in " << *env << endl;
1275  if (isNil(rules)) return nil;
1276  else return cons(evalRule(hd(rules), env), evalRuleList(tl(rules), env));
1277 }
static Tree evalRule(Tree rule, Tree env)
Evaluates the list of patterns and closure the rhs.
Definition: eval.cpp:1283
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree hd(Tree l)
Definition: list.hh:133
bool isNil(Tree l)
Definition: list.hh:137
static Tree evalRuleList(Tree rules, Tree env)
Evaluates each rule of the list.
Definition: eval.cpp:1272
Tree nil
Definition: list.cpp:116
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

bool getArgName ( Tree  t,
Tree id 
)

Definition at line 233 of file eval.cpp.

References autoName().

234 {
235  //return getDefNameProperty(t, id) || autoName(t, id) ;
236  return autoName(t, id) ;
237 }
static bool autoName(Tree exp, Tree &id)
Definition: eval.cpp:226

Here is the call graph for this function:

bool getEvalProperty ( Tree  box,
Tree  env,
Tree value 
)

retrieve the value of box in the environment env

Parameters
boxthe expression we want to retrieve the value
envthe lexical environment
valuethe returned value if any
Returns
true if a value already exist

Definition at line 274 of file eval.cpp.

References EVALPROPERTY, getProperty(), and tree().

Referenced by eval().

275 {
276  return getProperty(box, tree(EVALPROPERTY,env), value);
277 }
static Node EVALPROPERTY(symbol("EvalProperty"))
Tree tree(const Node &n)
Definition: tree.hh:186
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423

Here is the call graph for this function:

Here is the caller graph for this function:

bool getNumericProperty ( Tree  t,
Tree num 
)

Definition at line 604 of file eval.cpp.

References getProperty().

Referenced by simplifyPattern().

605 {
606  return getProperty(t, NUMERICPROPERTY, num);
607 }
Tree NUMERICPROPERTY
Definition: eval.cpp:597
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423

Here is the call graph for this function:

Here is the caller graph for this function:

static bool getPMProperty ( Tree  t,
Tree  env,
Tree pm 
)
static

Definition at line 1243 of file eval.cpp.

References getProperty(), PMPROPERTYNODE, and tree().

Referenced by evalCase().

1244 {
1245  return getProperty(t, tree(PMPROPERTYNODE, env), pm);
1246 }
static Node PMPROPERTYNODE(symbol("PMPROPERTY"))
A property to store the pattern matcher corresponding to a set of rules in a specific environement...
Tree tree(const Node &n)
Definition: tree.hh:186
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423

Here is the call graph for this function:

Here is the caller graph for this function:

Tree insideBoxSimplification ( Tree  box)
static

Simplify inside a block-diagram : S[A*B] => S[A]*S[B].

Definition at line 1413 of file eval.cpp.

References boxHGroup(), boxMerge(), boxPar(), boxRec(), boxSeq(), boxSimplification(), boxSplit(), boxSymbolic(), boxTGroup(), boxVGroup(), getUserData(), isBoxButton(), isBoxCheckbox(), isBoxCut(), isBoxFConst(), isBoxFFun(), isBoxFVar(), isBoxHBargraph(), isBoxHGroup(), isBoxHSlider(), isBoxInt(), isBoxMerge(), isBoxNumEntry(), isBoxPar(), isBoxPrim0(), isBoxPrim1(), isBoxPrim2(), isBoxPrim3(), isBoxPrim4(), isBoxPrim5(), isBoxReal(), isBoxRec(), isBoxSeq(), isBoxSlot(), isBoxSplit(), isBoxSymbolic(), isBoxTGroup(), isBoxVBargraph(), isBoxVGroup(), isBoxVSlider(), isBoxWire(), max(), min(), and name().

Referenced by numericBoxSimplification().

1414 {
1415  int i;
1416  double r;
1417  prim0 p0;
1418  prim1 p1;
1419  prim2 p2;
1420  prim3 p3;
1421  prim4 p4;
1422  prim5 p5;
1423 
1424  Tree t1, t2, ff, label, cur, min, max, step, type, name, file, slot, body;
1425 
1426 
1427  xtended* xt = (xtended*)getUserData(box);
1428 
1429  // Extended Primitives
1430 
1431  if (xt) {
1432  return box;
1433  }
1434 
1435  // Numbers and Constants
1436 
1437  else if (isBoxInt(box, &i)) {
1438  return box;
1439  }
1440  else if (isBoxReal(box, &r)) {
1441  return box;
1442  }
1443 
1444  else if (isBoxFConst(box, type, name, file)) {
1445  return box;
1446  }
1447 
1448  else if (isBoxFVar(box, type, name, file)) {
1449  return box;
1450  }
1451 
1452  // Wire and Cut
1453 
1454  else if (isBoxCut(box)) {
1455  return box;
1456  }
1457 
1458  else if (isBoxWire(box)) {
1459  return box;
1460  }
1461 
1462  // Primitives
1463 
1464  else if (isBoxPrim0(box, &p0)) {
1465  return box;
1466  }
1467 
1468  else if (isBoxPrim1(box, &p1)) {
1469  return box;
1470  }
1471 
1472  else if (isBoxPrim2(box, &p2)) {
1473  return box;
1474  }
1475 
1476  else if (isBoxPrim3(box, &p3)) {
1477  return box;
1478  }
1479 
1480  else if (isBoxPrim4(box, &p4)) {
1481  return box;
1482  }
1483 
1484  else if (isBoxPrim5(box, &p5)) {
1485  return box;
1486  }
1487 
1488  else if (isBoxFFun(box, ff)) {
1489  return box;
1490  }
1491 
1492  // User Interface Widgets
1493 
1494  else if (isBoxButton(box, label)) {
1495  return box;
1496  }
1497 
1498  else if (isBoxCheckbox(box, label)) {
1499  return box;
1500  }
1501 
1502  else if (isBoxVSlider(box, label, cur, min, max, step)) {
1503  return box;
1504  }
1505 
1506  else if (isBoxHSlider(box, label, cur, min, max, step)) {
1507  return box;
1508  }
1509 
1510  else if (isBoxNumEntry(box, label, cur, min, max, step)) {
1511  return box;
1512  }
1513 
1514  else if (isBoxVBargraph(box, label, min, max)) {
1515  return box;
1516  }
1517 
1518  else if (isBoxHBargraph(box, label, min, max)) {
1519  return box;
1520  }
1521 
1522  // User Interface Groups
1523 
1524  else if (isBoxVGroup(box, label, t1)) {
1525  return boxVGroup(label, boxSimplification(t1));
1526  }
1527 
1528  else if (isBoxHGroup(box, label, t1)) {
1529  return boxHGroup(label, boxSimplification(t1));
1530  }
1531 
1532  else if (isBoxTGroup(box, label, t1)) {
1533  return boxTGroup(label, boxSimplification(t1));
1534  }
1535 
1536  // Slots and Symbolic Boxes
1537 
1538  else if (isBoxSlot(box)) {
1539  return box;;
1540  }
1541 
1542  else if (isBoxSymbolic(box, slot, body)){
1543 
1544  Tree b = boxSimplification(body);
1545  return boxSymbolic(slot,b);
1546  }
1547 
1548  // Block Diagram Composition Algebra
1549 
1550  else if (isBoxSeq(box, t1, t2)) {
1551  Tree s1 = boxSimplification(t1);
1552  Tree s2 = boxSimplification(t2);
1553  return boxSeq(s1,s2);
1554  }
1555 
1556  else if (isBoxPar(box, t1, t2)) {
1557  Tree s1 = boxSimplification(t1);
1558  Tree s2 = boxSimplification(t2);
1559  return boxPar(s1,s2);
1560  }
1561 
1562  else if (isBoxSplit(box, t1, t2)) {
1563  Tree s1 = boxSimplification(t1);
1564  Tree s2 = boxSimplification(t2);
1565  return boxSplit(s1,s2);
1566  }
1567 
1568  else if (isBoxMerge(box, t1, t2)) {
1569  Tree s1 = boxSimplification(t1);
1570  Tree s2 = boxSimplification(t2);
1571  return boxMerge(s1,s2);
1572  }
1573  else if (isBoxRec(box, t1, t2)) {
1574  Tree s1 = boxSimplification(t1);
1575  Tree s2 = boxSimplification(t2);
1576  return boxRec(s1,s2);
1577  }
1578 
1579  cout << "ERROR in file " << __FILE__ << ':' << __LINE__ << ", unrecognised box expression : " << *box << endl;
1580  exit(1);
1581  return 0;
1582 }
bool isBoxPrim1(Tree s)
Definition: boxes.cpp:315
bool isBoxPrim5(Tree s)
Definition: boxes.cpp:335
Tree(* prim2)(Tree x, Tree y)
Definition: boxes.hh:210
bool isBoxWire(Tree t)
Definition: boxes.cpp:109
Tree boxSymbolic(Tree slot, Tree body)
Definition: boxes.cpp:125
bool isBoxSeq(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:136
bool isBoxInt(Tree t)
Definition: boxes.cpp:78
static Tree boxSimplification(Tree box)
boxSimplification(box) : simplify a block-diagram by replacing expressions denoting a constant number...
Definition: eval.cpp:1347
Tree boxRec(Tree x, Tree y)
Definition: boxes.cpp:143
bool isBoxSplit(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:148
Tree(* prim4)(Tree w, Tree x, Tree y, Tree z)
Definition: boxes.hh:212
bool isBoxFFun(Tree s)
Definition: boxes.cpp:344
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool isBoxCut(Tree t)
Definition: boxes.cpp:105
bool isBoxPrim0(Tree s)
Definition: boxes.cpp:310
bool isBoxPrim4(Tree s)
Definition: boxes.cpp:330
bool isBoxHGroup(Tree s)
Definition: boxes.cpp:437
bool isBoxHBargraph(Tree s)
Definition: boxes.cpp:455
bool isBoxRec(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:144
double max(double x, double y)
Definition: interval.hh:60
Tree(* prim3)(Tree x, Tree y, Tree z)
Definition: boxes.hh:211
Tree(* prim5)(Tree v, Tree w, Tree x, Tree y, Tree z)
Definition: boxes.hh:213
bool isBoxSymbolic(Tree t)
Definition: boxes.cpp:126
bool isBoxTGroup(Tree s)
Definition: boxes.cpp:449
bool isBoxButton(Tree s)
Definition: boxes.cpp:366
bool isBoxReal(Tree t)
Definition: boxes.cpp:79
Tree(* prim1)(Tree x)
Definition: boxes.hh:209
bool isBoxPar(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:140
bool isBoxHSlider(Tree s)
Definition: boxes.cpp:379
Tree boxMerge(Tree x, Tree y)
Definition: boxes.cpp:151
bool isBoxVBargraph(Tree s)
Definition: boxes.cpp:461
bool isBoxCheckbox(Tree s)
Definition: boxes.cpp:372
bool isBoxVGroup(Tree s)
Definition: boxes.cpp:443
Tree boxSeq(Tree x, Tree y)
Definition: boxes.cpp:135
bool isBoxFVar(Tree s)
Definition: boxes.cpp:356
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
bool isBoxVSlider(Tree s)
Definition: boxes.cpp:399
Tree boxHGroup(Tree lbl, Tree x)
Definition: boxes.cpp:436
bool isBoxNumEntry(Tree s)
Definition: boxes.cpp:418
Tree boxTGroup(Tree lbl, Tree x)
Definition: boxes.cpp:448
bool isBoxSlot(Tree t)
Definition: boxes.cpp:119
Tree boxPar(Tree x, Tree y)
Definition: boxes.cpp:139
void * getUserData(Symbol *sym)
Returns user data.
Definition: symbol.hh:100
bool isBoxPrim3(Tree s)
Definition: boxes.cpp:325
bool isBoxMerge(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:152
bool isBoxFConst(Tree s)
Definition: boxes.cpp:350
double min(double x, double y)
Definition: interval.hh:59
bool isBoxPrim2(Tree s)
Definition: boxes.cpp:320
Tree boxSplit(Tree x, Tree y)
Definition: boxes.cpp:147
Tree boxVGroup(Tree lbl, Tree x)
Definition: boxes.cpp:442
Tree(* prim0)()
Definition: boxes.hh:208

Here is the call graph for this function:

Here is the caller graph for this function:

static bool isBoxNumeric ( Tree  in,
Tree out 
)
static

Definition at line 630 of file eval.cpp.

References a2sb(), boxInt(), boxPropagateSig(), boxReal(), getBoxType(), hd(), isBoxInt(), isBoxReal(), isSigInt(), isSigReal(), makeSigInputList(), nil, and simplify().

Referenced by applyList(), patternSimplification(), and simplifyPattern().

631 {
632  int numInputs, numOutputs;
633  double x;
634  int i;
635  Tree v;
636 
637  if (isBoxInt(in, &i) || isBoxReal(in, &x)) {
638  out = in;
639  return true;
640  } else {
641  v = a2sb(in);
642  if ( getBoxType(v, &numInputs, &numOutputs) && (numInputs == 0) && (numOutputs == 1) ) {
643  // potential numerical expression
644  Tree lsignals = boxPropagateSig(nil, v , makeSigInputList(numInputs) );
645  Tree res = simplify(hd(lsignals));
646  if (isSigReal(res, &x)) {
647  out = boxReal(x);
648  return true;
649  }
650  if (isSigInt(res, &i)) {
651  out = boxInt(i);
652  return true;
653  }
654  }
655  return false;
656  }
657 }
bool isBoxInt(Tree t)
Definition: boxes.cpp:78
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree simplify(Tree sig)
Definition: simplify.cpp:76
Tree hd(Tree l)
Definition: list.hh:133
Tree boxInt(int n)
Definition: boxes.cpp:75
static Tree a2sb(Tree exp)
Definition: eval.cpp:135
bool isSigReal(Tree t, double *r)
Definition: signals.cpp:44
Tree boxPropagateSig(Tree path, Tree box, const siglist &lsig)
Top level propagate a list of signals into a block diagram.
Definition: propagate.cpp:501
bool isBoxReal(Tree t)
Definition: boxes.cpp:79
Tree boxReal(double n)
Definition: boxes.cpp:76
siglist makeSigInputList(int n)
Fabrique une liste de n entrées.
Definition: propagate.cpp:96
bool isSigInt(Tree t, int *i)
Definition: signals.cpp:41
Tree nil
Definition: list.cpp:116
bool getBoxType(Tree box, int *inum, int *onum)
Return the type (number of inputs and outputs) of a box or false if undefined.
Definition: boxtype.cpp:63

Here is the call graph for this function:

Here is the caller graph for this function:

static bool isBoxPatternOp ( Tree  box,
Node n,
Tree t1,
Tree t2 
)
inlinestatic

Definition at line 581 of file eval.cpp.

References isBoxMerge(), isBoxPar(), isBoxRec(), isBoxSeq(), isBoxSplit(), and CTree::node().

Referenced by patternSimplification().

582 {
583  if ( isBoxPar(box, t1, t2) ||
584  isBoxSeq(box, t1, t2) ||
585  isBoxSplit(box, t1, t2) ||
586  isBoxMerge(box, t1, t2) ||
587  isBoxRec(box, t1, t2) )
588  {
589  n = box->node();
590  return true;
591  } else {
592  return false;
593  }
594 }
bool isBoxSeq(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:136
bool isBoxSplit(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:148
const Node & node() const
return the content of the tree
Definition: tree.hh:143
bool isBoxRec(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:144
bool isBoxPar(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:140
bool isBoxMerge(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:152

Here is the call graph for this function:

Here is the caller graph for this function:

static bool isDigitChar ( char  c)
static

Definition at line 733 of file eval.cpp.

Referenced by evalLabel().

734 {
735  return (c >= '0') & (c <= '9');
736 }

Here is the caller graph for this function:

static bool isIdentChar ( char  c)
static

Definition at line 738 of file eval.cpp.

Referenced by evalLabel().

739 {
740  return ((c >= 'a') & (c <= 'z')) || ((c >= 'A') & (c <= 'Z')) || ((c >= '0') & (c <= '9')) || (c == '_');
741 }

Here is the caller graph for this function:

static Tree iteratePar ( Tree  id,
int  num,
Tree  body,
Tree  visited,
Tree  localValEnv 
)
static

Iterate a parallel construction.

Iterate a parallel construction such that : par(i,10,E) –> E(i<-0),(E(i<-1),...,E(i<-9))

Parameters
idthe formal parameter of the iteration
numthe number of iterartions
bodythe body expression of the iteration
globalDefEnvthe global environment
visitedlist of visited definition to detect recursive definitions
localValEnvthe local environment
Returns
a block diagram in normal form

Definition at line 845 of file eval.cpp.

References boxPar(), eval(), pushValueDef(), and tree().

Referenced by realeval().

846 {
847  assert (num>0);
848 
849  Tree res = eval(body, visited, pushValueDef(id, tree(num-1), localValEnv));
850  for (int i = num-2; i >= 0; i--) {
851  res = boxPar(eval(body, visited, pushValueDef(id, tree(i), localValEnv)), res);
852  }
853 
854  return res;
855 }
Definition: num.hh:58
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Definition: eval.cpp:280
Tree pushValueDef(Tree id, Tree def, Tree lenv)
Push a new layer and add a single definition.
Definition: environment.cpp:94
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree tree(const Node &n)
Definition: tree.hh:186
Tree boxPar(Tree x, Tree y)
Definition: boxes.cpp:139

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree iterateProd ( Tree  id,
int  num,
Tree  body,
Tree  visited,
Tree  localValEnv 
)
static

Iterate a product construction.

Iterate a product construction such that : par(i,10,E) –> E(i<-0)*E(i<-1)*...*E(i<-9)

Parameters
idthe formal parameter of the iteration
numthe number of iterartions
bodythe body expression of the iteration
globalDefEnvthe global environment
visitedlist of visited definition to detect recursive definitions
localValEnvthe local environment
Returns
a block diagram in normal form

Definition at line 926 of file eval.cpp.

References boxPar(), boxPrim2(), boxSeq(), eval(), pushValueDef(), sigMul(), and tree().

Referenced by realeval().

927 {
928  assert (num>0);
929 
930  Tree res = eval(body, visited, pushValueDef(id, tree(0), localValEnv));
931 
932  for (int i = 1; i < num; i++) {
933  res = boxSeq(boxPar(res, eval(body, visited, pushValueDef(id, tree(i), localValEnv))),boxPrim2(sigMul)) ;
934  }
935 
936  return res;
937 }
Definition: num.hh:58
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Definition: eval.cpp:280
Tree pushValueDef(Tree id, Tree def, Tree lenv)
Push a new layer and add a single definition.
Definition: environment.cpp:94
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree boxPrim2(prim2 foo)
Definition: boxes.cpp:319
Tree boxSeq(Tree x, Tree y)
Definition: boxes.cpp:135
Tree tree(const Node &n)
Definition: tree.hh:186
Tree boxPar(Tree x, Tree y)
Definition: boxes.cpp:139
Tree sigMul(Tree x, Tree y)
Definition: signals.hh:154

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree iterateSeq ( Tree  id,
int  num,
Tree  body,
Tree  visited,
Tree  localValEnv 
)
static

Iterate a sequential construction.

Iterate a sequential construction such that : seq(i,10,E) –> E(i<-0):(E(i<-1):...:E(i<-9))

Parameters
idthe formal parameter of the iteration
numthe number of iterartions
bodythe body expression of the iteration
globalDefEnvthe global environment
visitedlist of visited definition to detect recursive definitions
Returns
a block diagram in normal form

Definition at line 871 of file eval.cpp.

References boxSeq(), eval(), pushValueDef(), and tree().

Referenced by realeval().

872 {
873  assert (num>0);
874 
875  Tree res = eval(body, visited, pushValueDef(id, tree(num-1), localValEnv));
876  for (int i = num-2; i >= 0; i--) {
877  res = boxSeq(eval(body, visited, pushValueDef(id, tree(i), localValEnv)), res);
878  }
879 
880  return res;
881 }
Definition: num.hh:58
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Definition: eval.cpp:280
Tree pushValueDef(Tree id, Tree def, Tree lenv)
Push a new layer and add a single definition.
Definition: environment.cpp:94
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree boxSeq(Tree x, Tree y)
Definition: boxes.cpp:135
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree iterateSum ( Tree  id,
int  num,
Tree  body,
Tree  visited,
Tree  localValEnv 
)
static

Iterate an addition construction.

Iterate an addition construction such that : par(i,10,E) –> E(i<-0)+E(i<-1)+...+E(i<-9)

Parameters
idthe formal parameter of the iteration
numthe number of iterartions
bodythe body expression of the iteration
globalDefEnvthe global environment
visitedlist of visited definition to detect recursive definitions
localValEnvthe local environment
Returns
a block diagram in normal form

Definition at line 898 of file eval.cpp.

References boxPar(), boxPrim2(), boxSeq(), eval(), pushValueDef(), sigAdd(), and tree().

Referenced by realeval().

899 {
900  assert (num>0);
901 
902  Tree res = eval(body, visited, pushValueDef(id, tree(0), localValEnv));
903 
904  for (int i = 1; i < num; i++) {
905  res = boxSeq(boxPar(res, eval(body, visited, pushValueDef(id, tree(i), localValEnv))),boxPrim2(sigAdd)) ;
906  }
907 
908  return res;
909 }
Definition: num.hh:58
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Definition: eval.cpp:280
Tree pushValueDef(Tree id, Tree def, Tree lenv)
Push a new layer and add a single definition.
Definition: environment.cpp:94
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree sigAdd(Tree x, Tree y)
Definition: signals.hh:152
Tree boxPrim2(prim2 foo)
Definition: boxes.cpp:319
Tree boxSeq(Tree x, Tree y)
Definition: boxes.cpp:135
Tree tree(const Node &n)
Definition: tree.hh:186
Tree boxPar(Tree x, Tree y)
Definition: boxes.cpp:139

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree larg2par ( Tree  larg)
static

Transform a list of expressions in a parallel construction.

Parameters
larglist of expressions
Returns
parallel construction

Definition at line 1163 of file eval.cpp.

References boxPar(), evalerror(), hd(), isNil(), tl(), and yyfilename.

Referenced by applyList().

1164 {
1165  if (isNil(larg)) {
1166  evalerror(yyfilename, -1, "empty list of arguments", larg);
1167  exit(1);
1168  }
1169  if (isNil(tl(larg))) {
1170  return hd(larg);
1171  }
1172  return boxPar(hd(larg), larg2par(tl(larg)));
1173 }
Tree hd(Tree l)
Definition: list.hh:133
bool isNil(Tree l)
Definition: list.hh:137
void evalerror(const char *filename, int linenum, const char *msg, Tree exp)
Definition: errormsg.cpp:40
const char * yyfilename
Definition: errormsg.cpp:30
Tree boxPar(Tree x, Tree y)
Definition: boxes.cpp:139
static Tree larg2par(Tree larg)
Transform a list of expressions in a parallel construction.
Definition: eval.cpp:1163
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

static void list2vec ( Tree  l,
vector< Tree > &  v 
)
static

Definition at line 1315 of file eval.cpp.

References hd(), isNil(), and tl().

Referenced by applyList().

1316 {
1317  while (!isNil(l)) {
1318  v.push_back(hd(l));
1319  l = tl(l);
1320  }
1321 }
Tree hd(Tree l)
Definition: list.hh:133
bool isNil(Tree l)
Definition: list.hh:137
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree listn ( int  n,
Tree  e 
)
static

Creates a list of n elements.

Parameters
nnumber of elements
eelement to be repeated
Returns
[e e e ...] n times

Definition at line 1226 of file eval.cpp.

References cons(), and nil.

Referenced by evalCase().

1227 {
1228  return (n<= 0) ? nil : cons(e, listn(n-1,e));
1229 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
static Tree listn(int n, Tree e)
Creates a list of n elements.
Definition: eval.cpp:1226
Tree nil
Definition: list.cpp:116

Here is the call graph for this function:

Here is the caller graph for this function:

Tree numericBoxSimplification ( Tree  box)
static

Try to do a numeric simplification of a block-diagram.

Definition at line 1372 of file eval.cpp.

References boxInt(), boxPropagateSig(), boxReal(), getBoxType(), hd(), insideBoxSimplification(), isBoxInt(), isBoxReal(), isSigInt(), isSigReal(), makeSigInputList(), nil, and simplify().

Referenced by boxSimplification().

1373 {
1374  int ins, outs;
1375  Tree result;
1376  int i;
1377  double x;
1378 
1379  if ( ! getBoxType(box, &ins, &outs)) {
1380  cout << "ERROR in file " << __FILE__ << ':' << __LINE__ << ", Can't compute the box type of : " << *box << endl;
1381  exit(1);
1382  }
1383 
1384  if (ins==0 && outs==1) {
1385  // this box can potentially denote a number
1386  if (isBoxInt(box, &i) || isBoxReal(box, &x)) {
1387  result = box;
1388  } else {
1389  // propagate signals to discover if it simplifies to a number
1390  int i;
1391  double x;
1392  Tree lsignals = boxPropagateSig(nil, box , makeSigInputList(0));
1393  Tree s = simplify(hd(lsignals));
1394 
1395  if (isSigReal(s, &x)) {
1396  result = boxReal(x);
1397  } else if (isSigInt(s, &i)) {
1398  result = boxInt(i);
1399  } else {
1400  result = insideBoxSimplification(box);
1401  }
1402  }
1403  } else {
1404  // this box can't denote a number
1405  result = insideBoxSimplification(box);
1406  }
1407  return result;
1408 }
bool isBoxInt(Tree t)
Definition: boxes.cpp:78
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree simplify(Tree sig)
Definition: simplify.cpp:76
Tree hd(Tree l)
Definition: list.hh:133
Tree boxInt(int n)
Definition: boxes.cpp:75
bool isSigReal(Tree t, double *r)
Definition: signals.cpp:44
Tree boxPropagateSig(Tree path, Tree box, const siglist &lsig)
Top level propagate a list of signals into a block diagram.
Definition: propagate.cpp:501
bool isBoxReal(Tree t)
Definition: boxes.cpp:79
Tree boxReal(double n)
Definition: boxes.cpp:76
siglist makeSigInputList(int n)
Fabrique une liste de n entrées.
Definition: propagate.cpp:96
bool isSigInt(Tree t, int *i)
Definition: signals.cpp:41
Tree nil
Definition: list.cpp:116
static Tree insideBoxSimplification(Tree box)
Simplify inside a block-diagram : S[A*B] => S[A]*S[B].
Definition: eval.cpp:1413
bool getBoxType(Tree box, int *inum, int *onum)
Return the type (number of inputs and outputs) of a box or false if undefined.
Definition: boxtype.cpp:63

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree nwires ( int  n)
static

repeat n times a wire

Definition at line 984 of file eval.cpp.

References boxWire(), cons(), and nil.

Referenced by applyList().

985 {
986  Tree l = nil;
987  while (n--) { l = cons(boxWire(), l); }
988  return l;
989 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree boxWire()
Definition: boxes.cpp:108
Tree nil
Definition: list.cpp:116

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree patternSimplification ( Tree  pattern)
static

Definition at line 659 of file eval.cpp.

References isBoxNumeric(), isBoxPatternOp(), and tree().

Referenced by evalPattern().

660 {
661 
662  Node n(0);
663  Tree v, t1, t2;
664 
665  if (isBoxNumeric(pattern, v)) {
666  return v;
667  } else if (isBoxPatternOp(pattern, n, t1, t2)) {
669  } else {
670  return pattern;
671  }
672 }
static bool isBoxNumeric(Tree in, Tree &out)
Definition: eval.cpp:630
Class Node = (type x (int + double + Sym + void*))
Definition: node.hh:75
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
static Tree patternSimplification(Tree pattern)
Definition: eval.cpp:659
Tree tree(const Node &n)
Definition: tree.hh:186
static bool isBoxPatternOp(Tree box, Node &n, Tree &t1, Tree &t2)
Definition: eval.cpp:581

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree real_a2sb ( Tree  exp)
static

Definition at line 154 of file eval.cpp.

References a2sb(), applyList(), CTree::arity(), boxSlot(), boxSymbolic(), CTree::branch(), cons(), eval(), evalerror(), gBoxSlotNumber, getDefNameProperty(), isBoxAbstr(), isBoxEnvironment(), isBoxIdent(), isBoxPatternMatcher(), isBoxWaveform(), isClosure(), CTree::make(), name(), nil, CTree::node(), pushValueDef(), setDefNameProperty(), and yyfilename.

Referenced by a2sb().

155 {
156  Tree abstr, visited, unusedEnv, localValEnv, var, name, body;
157 
158  if (isClosure(exp, abstr, unusedEnv, visited, localValEnv)) {
159 
160  if (isBoxIdent(abstr)) {
161  // special case introduced with access and components
162  Tree result = a2sb(eval(abstr, visited, localValEnv));
163 
164  // propagate definition name property when needed
165  if (getDefNameProperty(exp, name)) setDefNameProperty(result, name);
166  return result;
167 
168  } else if (isBoxAbstr(abstr, var, body)) {
169  // Here we have remaining abstraction that we will try to
170  // transform in a symbolic box by applying it to a slot
171 
172  Tree slot = boxSlot(++gBoxSlotNumber);
173  stringstream s; s << boxpp(var);
174  setDefNameProperty(slot, s.str() ); // ajout YO
175 
176  // Apply the abstraction to the slot
177  Tree result = boxSymbolic(slot, a2sb(eval(body, visited, pushValueDef(var, slot, localValEnv))));
178 
179  // propagate definition name property when needed
180  if (getDefNameProperty(exp, name)) setDefNameProperty(result, name);
181  return result;
182 
183  } else if (isBoxEnvironment(abstr)) {
184  return abstr;
185 
186  } else {
187  evalerror(yyfilename, -1, " a2sb : internal error : not an abstraction inside closure ", exp);
188  exit(1);
189  }
190 
191  } else if (isBoxPatternMatcher(exp)) {
192  // Here we have remaining PM rules that we will try to
193  // transform in a symbolic box by applying it to a slot
194 
195  Tree slot = boxSlot(++gBoxSlotNumber);
196  stringstream s; s << "PM" << gBoxSlotNumber;
197  setDefNameProperty(slot, s.str() );
198 
199  // apply the PM rules to the slot and transfoms the result in a symbolic box
200  Tree result = boxSymbolic(slot, a2sb(applyList(exp, cons(slot,nil))));
201 
202  // propagate definition name property when needed
203  if (getDefNameProperty(exp, name)) setDefNameProperty(result, name);
204  return result;
205 
206  } else if (isBoxWaveform(exp)) {
207  // A waveform is always in Normal Form, nothing to evaluate
208  return exp;
209 
210  } else {
211  // it is a constructor : transform each branches
212  unsigned int ar = exp->arity();
213  tvec B(ar);
214  bool modified = false;
215  for (unsigned int i = 0; i < ar; i++) {
216  Tree b = exp->branch(i);
217  Tree m = a2sb(b);
218  B[i] = m;
219  if (b != m) modified=true;
220  }
221  Tree r = (modified) ? CTree::make(exp->node(), B) : exp;
222  return r;
223  }
224 }
bool getDefNameProperty(Tree t, Tree &id)
Indicates the identifier (if any) the expression was a definition of.
Definition: names.cpp:85
Tree boxSymbolic(Tree slot, Tree body)
Definition: boxes.cpp:125
bool isBoxIdent(Tree t)
Definition: boxes.cpp:58
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Definition: eval.cpp:280
Tree boxSlot(int id)
Definition: boxes.cpp:118
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree pushValueDef(Tree id, Tree def, Tree lenv)
Push a new layer and add a single definition.
Definition: environment.cpp:94
bool isBoxPatternMatcher(Tree s)
Definition: boxes.cpp:630
vector< Tree > tvec
Definition: tree.hh:90
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const Node & node() const
return the content of the tree
Definition: tree.hh:143
static Tree make(const Node &n, int ar, Tree br[])
return a new tree or an existing equivalent one
void setDefNameProperty(Tree t, Tree id)
Definition: names.cpp:54
static Tree a2sb(Tree exp)
Definition: eval.cpp:135
bool isBoxAbstr(Tree t)
Definition: boxes.cpp:202
bool isBoxEnvironment(Tree s)
Definition: boxes.cpp:285
static int gBoxSlotNumber
counter for unique slot number
Definition: eval.cpp:152
bool isBoxWaveform(Tree s)
Definition: boxes.cpp:97
bool isClosure(Tree t, Tree &abstr, Tree &genv, Tree &vis, Tree &lenv)
Definition: boxes.cpp:239
static Tree applyList(Tree fun, Tree larg)
Apply a function to a list of arguments.
Definition: eval.cpp:1003
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
void evalerror(const char *filename, int linenum, const char *msg, Tree exp)
Definition: errormsg.cpp:40
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
const char * yyfilename
Definition: errormsg.cpp:30
Definition: ppbox.hh:58
Tree nil
Definition: list.cpp:116
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree realeval ( Tree  exp,
Tree  visited,
Tree  localValEnv 
)
static

Eval a block diagram expression.

Strict evaluation of a block diagram expression by applying beta reduction.

Parameters
expthe expression to evaluate
visitedlist of visited definition to detect recursive definitions
localValEnvthe local environment
Returns
a block diagram in normal form

Definition at line 308 of file eval.cpp.

References a2sb(), applyList(), boxButton(), boxCheckbox(), boxEnvironment(), boxHBargraph(), boxHGroup(), boxHSlider(), boxIdent(), boxInt(), boxMerge(), boxNumEntry(), boxPar(), boxRec(), boxSeq(), boxSplit(), boxTGroup(), boxVBargraph(), boxVGroup(), boxVSlider(), closure(), copyEnvReplaceDefs(), eval(), eval2double(), eval2int(), evalCase(), evalerror(), evalIdDef(), evalLabel(), SourceReader::expandlist(), getBoxType(), getDefFileProp(), getDefLineProp(), SourceReader::getlist(), getUserData(), isBoxAbstr(), isBoxAccess(), isBoxAppl(), isBoxButton(), isBoxCase(), isBoxCheckbox(), isBoxComponent(), isBoxCut(), isBoxEnvironment(), isBoxFConst(), isBoxFFun(), isBoxFVar(), isBoxHBargraph(), isBoxHGroup(), isBoxHSlider(), isBoxIdent(), isBoxInputs(), isBoxInt(), isBoxIPar(), isBoxIProd(), isBoxISeq(), isBoxISum(), isBoxLibrary(), isBoxMerge(), isBoxModifLocalDef(), isBoxNumEntry(), isBoxOutputs(), isBoxPar(), isBoxPatternMatcher(), isBoxPatternVar(), isBoxPrim0(), isBoxPrim1(), isBoxPrim2(), isBoxPrim3(), isBoxPrim4(), isBoxPrim5(), isBoxReal(), isBoxRec(), isBoxSeq(), isBoxSlot(), isBoxSplit(), isBoxSymbolic(), isBoxTGroup(), isBoxVBargraph(), isBoxVGroup(), isBoxVSlider(), isBoxWaveform(), isBoxWire(), isBoxWithLocalDef(), isClosure(), iteratePar(), iterateProd(), iterateSeq(), iterateSum(), nil, pushMultiClosureDefs(), revEvalList(), setDefNameProperty(), setUnion(), tree(), and tree2str().

Referenced by eval().

309 {
310  //Tree def;
311  Tree fun;
312  Tree arg;
313  Tree var, num, body, ldef;
314  Tree label;
315  Tree cur, lo, hi, step;
316  Tree e1, e2, exp2, notused, visited2, lenv2;
317  Tree rules;
318  Tree id;
319 
320  //cerr << "EVAL " << *exp << " (visited : " << *visited << ")" << endl;
321  //cerr << "REALEVAL of " << *exp << endl;
322 
323  xtended* xt = (xtended*) getUserData(exp);
324 
325 
326  // constants
327  //-----------
328 
329  if ( xt ||
330  isBoxInt(exp) || isBoxReal(exp) ||
331  isBoxWire(exp) || isBoxCut(exp) ||
332  isBoxPrim0(exp) || isBoxPrim1(exp) ||
333  isBoxPrim2(exp) || isBoxPrim3(exp) ||
334  isBoxPrim4(exp) || isBoxPrim5(exp) ||
335  isBoxFFun(exp) || isBoxFConst(exp) || isBoxFVar(exp) ||
336  isBoxWaveform(exp)) {
337  return exp;
338 
339  // block-diagram constructors
340  //---------------------------
341 
342  } else if ( isBoxSeq(exp, e1, e2) ) {
343  return boxSeq(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));
344 
345  } else if ( isBoxPar(exp, e1, e2) ) {
346  return boxPar(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));
347 
348  } else if ( isBoxRec(exp, e1, e2) ) {
349  return boxRec(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));
350 
351  } else if ( isBoxSplit(exp, e1, e2) ) {
352  return boxSplit(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));
353 
354  } else if ( isBoxMerge(exp, e1, e2) ) {
355  return boxMerge(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));
356 
357  // Modules
358  //--------
359 
360  } else if (isBoxAccess(exp, body, var)) {
361  Tree val = eval(body, visited, localValEnv);
362  if (isClosure(val, exp2, notused, visited2, lenv2)) {
363  // it is a closure, we have an environment to access
364  return eval(closure(var,notused,visited2,lenv2), visited, localValEnv);
365  } else {
366  evalerror(getDefFileProp(exp), getDefLineProp(exp), "No environment to access ", exp);
367  exit(1);
368  }
369 
371 
372  } else if (isBoxModifLocalDef(exp, body, ldef)) {
373  Tree val = eval(body, visited, localValEnv);
374  if (isClosure(val, exp2, notused, visited2, lenv2)) {
375  // we rebuild the closure using a copy of the original environment
376  // modified with some new definitions
377  Tree lenv3 = copyEnvReplaceDefs(lenv2, ldef, visited2, localValEnv);
378  return eval(closure(exp2,notused,visited2,lenv3), visited, localValEnv);
379  } else {
380 
381  evalerror(getDefFileProp(exp), getDefLineProp(exp), "not a closure ", val);
382  evalerror(getDefFileProp(exp), getDefLineProp(exp), "No environment to access ", exp);
383  exit(1);
384  }
385 
387 
388  } else if (isBoxComponent(exp, label)) {
389  string fname = tree2str(label);
390  Tree eqlst = gReader.expandlist(gReader.getlist(fname));
391  Tree res = closure(boxIdent("process"), nil, nil, pushMultiClosureDefs(eqlst, nil, nil));
392  setDefNameProperty(res, label);
393  //cerr << "component is " << boxpp(res) << endl;
394  return res;
395 
396  } else if (isBoxLibrary(exp, label)) {
397  string fname = tree2str(label);
398  Tree eqlst = gReader.expandlist(gReader.getlist(fname));
400  setDefNameProperty(res, label);
401  //cerr << "component is " << boxpp(res) << endl;
402  return res;
403 
404 
405  // user interface elements
406  //------------------------
407 
408  } else if (isBoxButton(exp, label)) {
409  const char* l1 = tree2str(label);
410  const char* l2= evalLabel(l1, visited, localValEnv);
411  //cout << "button label : " << l1 << " become " << l2 << endl;
412  return ((l1 == l2) ? exp : boxButton(tree(l2)));
413 
414  } else if (isBoxCheckbox(exp, label)) {
415  const char* l1 = tree2str(label);
416  const char* l2= evalLabel(l1, visited, localValEnv);
417  //cout << "check box label : " << l1 << " become " << l2 << endl;
418  return ((l1 == l2) ? exp : boxCheckbox(tree(l2)));
419 
420  } else if (isBoxVSlider(exp, label, cur, lo, hi, step)) {
421  const char* l1 = tree2str(label);
422  const char* l2= evalLabel(l1, visited, localValEnv);
423  return ( boxVSlider(tree(l2),
424  tree(eval2double(cur, visited, localValEnv)),
425  tree(eval2double(lo, visited, localValEnv)),
426  tree(eval2double(hi, visited, localValEnv)),
427  tree(eval2double(step, visited, localValEnv))));
428 
429  } else if (isBoxHSlider(exp, label, cur, lo, hi, step)) {
430  const char* l1 = tree2str(label);
431  const char* l2= evalLabel(l1, visited, localValEnv);
432  return ( boxHSlider(tree(l2),
433  tree(eval2double(cur, visited, localValEnv)),
434  tree(eval2double(lo, visited, localValEnv)),
435  tree(eval2double(hi, visited, localValEnv)),
436  tree(eval2double(step, visited, localValEnv))));
437 
438  } else if (isBoxNumEntry(exp, label, cur, lo, hi, step)) {
439  const char* l1 = tree2str(label);
440  const char* l2= evalLabel(l1, visited, localValEnv);
441  return (boxNumEntry(tree(l2),
442  tree(eval2double(cur, visited, localValEnv)),
443  tree(eval2double(lo, visited, localValEnv)),
444  tree(eval2double(hi, visited, localValEnv)),
445  tree(eval2double(step, visited, localValEnv))));
446 
447  } else if (isBoxVGroup(exp, label, arg)) {
448  const char* l1 = tree2str(label);
449  const char* l2= evalLabel(l1, visited, localValEnv);
450  return boxVGroup(tree(l2), eval(arg, visited, localValEnv) );
451 
452  } else if (isBoxHGroup(exp, label, arg)) {
453  const char* l1 = tree2str(label);
454  const char* l2= evalLabel(l1, visited, localValEnv);
455  return boxHGroup(tree(l2), eval(arg, visited, localValEnv) );
456 
457  } else if (isBoxTGroup(exp, label, arg)) {
458  const char* l1 = tree2str(label);
459  const char* l2= evalLabel(l1, visited, localValEnv);
460  return boxTGroup(tree(l2), eval(arg, visited, localValEnv) );
461 
462  } else if (isBoxHBargraph(exp, label, lo, hi)) {
463  const char* l1 = tree2str(label);
464  const char* l2= evalLabel(l1, visited, localValEnv);
465  return boxHBargraph(tree(l2),
466  tree(eval2double(lo, visited, localValEnv)),
467  tree(eval2double(hi, visited, localValEnv)));
468 
469  } else if (isBoxVBargraph(exp, label, lo, hi)) {
470  const char* l1 = tree2str(label);
471  const char* l2= evalLabel(l1, visited, localValEnv);
472  return boxVBargraph(tree(l2),
473  tree(eval2double(lo, visited, localValEnv)),
474  tree(eval2double(hi, visited, localValEnv)));
475 
476  // lambda calculus
477  //----------------
478 
479  } else if (isBoxIdent(exp)) {
480  return evalIdDef(exp, visited, localValEnv);
481 
482  } else if (isBoxWithLocalDef(exp, body, ldef)) {
483  return eval(body, visited, pushMultiClosureDefs(ldef, visited, localValEnv));
484 
485  } else if (isBoxAppl(exp, fun, arg)) {
486  return applyList( eval(fun, visited, localValEnv),
487  revEvalList(arg, visited, localValEnv) );
488 
489  } else if (isBoxAbstr(exp)) {
490  // it is an abstraction : return a closure
491  return closure(exp, nil, visited, localValEnv);
492 
493  } else if (isBoxEnvironment(exp)) {
494  // environment : return also a closure
495  return closure(exp, nil, visited, localValEnv);
496 
497  } else if (isClosure(exp, exp2, notused, visited2, lenv2)) {
498 
499  if (isBoxAbstr(exp2)) {
500  // a 'real' closure
501  return closure(exp2, nil, setUnion(visited,visited2), lenv2);
502  } else if (isBoxEnvironment(exp2)) {
503  // a 'real' closure
504  return closure(exp2, nil, setUnion(visited,visited2), lenv2);
505  } else {
506  // it was a suspended evaluation
507  return eval(exp2, setUnion(visited,visited2), lenv2);
508  }
509 
510  // Algorithmic constructions
511  //--------------------------
512 
513  } else if (isBoxIPar(exp, var, num, body)) {
514  int n = eval2int(num, visited, localValEnv);
515  return iteratePar(var, n, body, visited, localValEnv);
516 
517  } else if (isBoxISeq(exp, var, num, body)) {
518  int n = eval2int(num, visited, localValEnv);
519  return iterateSeq(var, n, body, visited, localValEnv);
520 
521  } else if (isBoxISum(exp, var, num, body)) {
522  int n = eval2int(num, visited, localValEnv);
523  return iterateSum(var, n, body, visited, localValEnv);
524 
525  } else if (isBoxIProd(exp, var, num, body)) {
526  int n = eval2int(num, visited, localValEnv);
527  return iterateProd(var, n, body, visited, localValEnv);
528 
529  // static
530  } else if (isBoxInputs(exp, body)) {
531  int ins, outs;
532  Tree b = a2sb(eval(body, visited, localValEnv));
533  if (getBoxType (b, &ins, &outs)) {
534  return boxInt(ins);
535  } else {
536  cerr << "ERROR : can't evaluate ' : " << *exp << endl;
537  assert(false);
538  }
539 
540  } else if (isBoxOutputs(exp, body)) {
541  int ins, outs;
542  Tree b = a2sb(eval(body, visited, localValEnv));
543  if (getBoxType (b, &ins, &outs)) {
544  return boxInt(outs);
545  } else {
546  cerr << "ERROR : can't evaluate ' : " << *exp << endl;
547  assert(false);
548  }
549 
550 
551  } else if (isBoxSlot(exp)) {
552  return exp;
553 
554  } else if (isBoxSymbolic(exp)) {
555 
556  return exp;
557 
558 
559  // Pattern matching extension
560  //---------------------------
561 
562  } else if (isBoxCase(exp, rules)) {
563  return evalCase(rules, localValEnv);
564 
565  } else if (isBoxPatternVar(exp, id)) {
566  return exp;
567  //return evalIdDef(id, visited, localValEnv);
568 
569  } else if (isBoxPatternMatcher(exp)) {
570  return exp;
571 
572  } else {
573  cerr << "ERROR : EVAL don't intercept : " << *exp << endl;
574  assert(false);
575  }
576  return NULL;
577 }
bool isBoxPrim1(Tree s)
Definition: boxes.cpp:315
bool isBoxPrim5(Tree s)
Definition: boxes.cpp:335
bool isBoxIPar(Tree t, Tree &x, Tree &y, Tree &z)
Definition: boxes.cpp:169
bool isBoxWire(Tree t)
Definition: boxes.cpp:109
Definition: num.hh:58
bool isBoxSeq(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:136
bool isBoxWithLocalDef(Tree t, Tree &body, Tree &ldef)
Definition: boxes.cpp:265
bool isBoxInt(Tree t)
Definition: boxes.cpp:78
bool isBoxIdent(Tree t)
Definition: boxes.cpp:58
Tree boxCheckbox(Tree lbl)
Definition: boxes.cpp:371
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Definition: eval.cpp:280
Tree boxHBargraph(Tree lbl, Tree min, Tree max)
Definition: boxes.cpp:454
bool isBoxOutputs(Tree t, Tree &x)
Definition: boxes.cpp:186
bool isBoxIProd(Tree t, Tree &x, Tree &y, Tree &z)
Definition: boxes.cpp:172
bool isBoxPatternMatcher(Tree s)
Definition: boxes.cpp:630
Tree boxRec(Tree x, Tree y)
Definition: boxes.cpp:143
Tree copyEnvReplaceDefs(Tree anEnv, Tree ldefs, Tree visited, Tree curEnv)
Create a new environment by copying an existing one and replacing some definitions.
bool isBoxSplit(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:148
static Tree iterateSeq(Tree id, int num, Tree body, Tree visited, Tree localValEnv)
Iterate a sequential construction.
Definition: eval.cpp:871
Tree boxNumEntry(Tree lbl, Tree cur, Tree min, Tree max, Tree step)
Definition: boxes.cpp:416
Tree boxEnvironment()
Definition: boxes.cpp:284
bool isBoxComponent(Tree s, Tree &filename)
Definition: boxes.cpp:290
bool isBoxFFun(Tree s)
Definition: boxes.cpp:344
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool isBoxCut(Tree t)
Definition: boxes.cpp:105
bool isBoxAppl(Tree t)
Definition: boxes.cpp:203
Tree boxVSlider(Tree lbl, Tree cur, Tree min, Tree max, Tree step)
Definition: boxes.cpp:397
Tree boxIdent(const char *name)
Definition: boxes.cpp:57
bool isBoxAccess(Tree t, Tree &exp, Tree &id)
Definition: boxes.cpp:256
bool isBoxPrim0(Tree s)
Definition: boxes.cpp:310
bool isBoxPrim4(Tree s)
Definition: boxes.cpp:330
bool isBoxHGroup(Tree s)
Definition: boxes.cpp:437
bool isBoxHBargraph(Tree s)
Definition: boxes.cpp:455
Tree boxHSlider(Tree lbl, Tree cur, Tree min, Tree max, Tree step)
Definition: boxes.cpp:377
void setDefNameProperty(Tree t, Tree id)
Definition: names.cpp:54
bool isBoxRec(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:144
Tree boxInt(int n)
Definition: boxes.cpp:75
static Tree a2sb(Tree exp)
Definition: eval.cpp:135
bool isBoxAbstr(Tree t)
Definition: boxes.cpp:202
static Tree evalCase(Tree rules, Tree env)
Eval a case expression containing a list of pattern matching rules.
Definition: eval.cpp:1257
Tree boxVBargraph(Tree lbl, Tree min, Tree max)
Definition: boxes.cpp:460
static const char * evalLabel(const char *l, Tree visited, Tree localValEnv)
evallabel replace "...%2i..." occurences in label with value of i
Definition: eval.cpp:760
static Tree revEvalList(Tree lexp, Tree visited, Tree localValEnv)
Eval a list of expression in reverse order.
Definition: eval.cpp:1141
bool isBoxModifLocalDef(Tree t, Tree &body, Tree &ldef)
Definition: boxes.cpp:275
static double eval2double(Tree exp, Tree visited, Tree localValEnv)
Eval a block diagram to a double.
Definition: eval.cpp:689
bool isBoxSymbolic(Tree t)
Definition: boxes.cpp:126
bool isBoxTGroup(Tree s)
Definition: boxes.cpp:449
Tree boxButton(Tree lbl)
Definition: boxes.cpp:365
bool isBoxISum(Tree t, Tree &x, Tree &y, Tree &z)
Definition: boxes.cpp:171
bool isBoxEnvironment(Tree s)
Definition: boxes.cpp:285
Tree pushMultiClosureDefs(Tree ldefs, Tree visited, Tree lenv)
Push a new layer with multiple definitions creating the appropriate closures.
bool isBoxButton(Tree s)
Definition: boxes.cpp:366
bool isBoxReal(Tree t)
Definition: boxes.cpp:79
bool isBoxCase(Tree s)
Definition: boxes.cpp:617
Tree setUnion(Tree A, Tree B)
Definition: list.cpp:317
int getDefLineProp(Tree sym)
Definition: errormsg.cpp:82
bool isBoxPar(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:140
bool isBoxHSlider(Tree s)
Definition: boxes.cpp:379
Tree boxMerge(Tree x, Tree y)
Definition: boxes.cpp:151
bool isBoxVBargraph(Tree s)
Definition: boxes.cpp:461
bool isBoxWaveform(Tree s)
Definition: boxes.cpp:97
bool isClosure(Tree t, Tree &abstr, Tree &genv, Tree &vis, Tree &lenv)
Definition: boxes.cpp:239
Tree expandlist(Tree ldef)
Return the list of definitions where all imports have been expanded.
bool isBoxCheckbox(Tree s)
Definition: boxes.cpp:372
static Tree applyList(Tree fun, Tree larg)
Apply a function to a list of arguments.
Definition: eval.cpp:1003
bool isBoxVGroup(Tree s)
Definition: boxes.cpp:443
Tree boxSeq(Tree x, Tree y)
Definition: boxes.cpp:135
void evalerror(const char *filename, int linenum, const char *msg, Tree exp)
Definition: errormsg.cpp:40
bool isBoxFVar(Tree s)
Definition: boxes.cpp:356
Tree closure(Tree abstr, Tree genv, Tree vis, Tree lenv)
Definition: boxes.cpp:234
Tree tree(const Node &n)
Definition: tree.hh:186
bool isBoxVSlider(Tree s)
Definition: boxes.cpp:399
Tree boxHGroup(Tree lbl, Tree x)
Definition: boxes.cpp:436
SourceReader gReader
Definition: main.cpp:89
bool isBoxNumEntry(Tree s)
Definition: boxes.cpp:418
Tree boxTGroup(Tree lbl, Tree x)
Definition: boxes.cpp:448
bool isBoxSlot(Tree t)
Definition: boxes.cpp:119
static int eval2int(Tree exp, Tree visited, Tree localValEnv)
Eval a block diagram to an int.
Definition: eval.cpp:718
Tree boxPar(Tree x, Tree y)
Definition: boxes.cpp:139
static Tree iteratePar(Tree var, int num, Tree body, Tree visited, Tree localValEnv)
Iterate a parallel construction.
Definition: eval.cpp:845
bool isBoxInputs(Tree t, Tree &x)
Definition: boxes.cpp:185
void * getUserData(Symbol *sym)
Returns user data.
Definition: symbol.hh:100
bool isBoxPrim3(Tree s)
Definition: boxes.cpp:325
bool isBoxISeq(Tree t, Tree &x, Tree &y, Tree &z)
Definition: boxes.cpp:170
Tree nil
Definition: list.cpp:116
bool isBoxPatternVar(Tree s, Tree &id)
Definition: boxes.cpp:622
Tree getlist(string fname)
Return the list of definitions file contains.
bool isBoxLibrary(Tree s, Tree &filename)
Definition: boxes.cpp:295
static Tree iterateSum(Tree id, int num, Tree body, Tree visited, Tree localValEnv)
Iterate an addition construction.
Definition: eval.cpp:898
bool isBoxMerge(Tree t, Tree &x, Tree &y)
Definition: boxes.cpp:152
bool isBoxFConst(Tree s)
Definition: boxes.cpp:350
bool isBoxPrim2(Tree s)
Definition: boxes.cpp:320
Tree boxSplit(Tree x, Tree y)
Definition: boxes.cpp:147
static Tree evalIdDef(Tree id, Tree visited, Tree env)
Search the environment for the definition of a symbol ID and evaluate it.
Definition: eval.cpp:1188
const char * tree2str(Tree t)
if t has a node of type symbol, return its name otherwise error
Definition: tree.cpp:278
Tree boxVGroup(Tree lbl, Tree x)
Definition: boxes.cpp:442
const char * getDefFileProp(Tree sym)
Definition: errormsg.cpp:72
static Tree iterateProd(Tree id, int num, Tree body, Tree visited, Tree localValEnv)
Iterate a product construction.
Definition: eval.cpp:926
bool getBoxType(Tree box, int *inum, int *onum)
Return the type (number of inputs and outputs) of a box or false if undefined.
Definition: boxtype.cpp:63

Here is the caller graph for this function:

static Tree revEvalList ( Tree  lexp,
Tree  visited,
Tree  localValEnv 
)
static

Eval a list of expression in reverse order.

Eval a list of expressions returning the list of results in reverse order.

Parameters
lexplist of expressions to evaluate
globalDefEnvthe global environment
visitedlist of visited definition to detect recursive definitions
localValEnvthe local environment
Returns
list of evaluated expressions in reverse order

Definition at line 1141 of file eval.cpp.

References cons(), eval(), hd(), isNil(), nil, and tl().

Referenced by realeval().

1142 {
1143  Tree result = nil;
1144  //Tree lexp_orig = lexp;
1145  //cerr << "ENTER revEvalList(" << *lexp_orig << ", env:" << *localValEnv << ")" << endl;
1146  while (!isNil(lexp)) {
1147  result = cons(eval(hd(lexp), visited, localValEnv), result);
1148  lexp = tl(lexp);
1149  }
1150 
1151  //cerr << "EXIT revEvalList(" << *lexp_orig << ", env:" << *localValEnv << ") -> " << *result << endl;
1152  return result;
1153 }
static Tree eval(Tree exp, Tree visited, Tree localValEnv)
Definition: eval.cpp:280
Tree cons(Tree a, Tree b)
Definition: list.hh:124
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree hd(Tree l)
Definition: list.hh:133
bool isNil(Tree l)
Definition: list.hh:137
Tree nil
Definition: list.cpp:116
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

void setEvalProperty ( Tree  box,
Tree  env,
Tree  value 
)

set the value of box in the environment env

Parameters
boxthe block diagram we have evaluated
envthe evaluation environment
valuethe evaluated block diagram

Definition at line 261 of file eval.cpp.

References EVALPROPERTY, setProperty(), and tree().

Referenced by eval().

262 {
263  setProperty(box, tree(EVALPROPERTY,env), value);
264 }
static Node EVALPROPERTY(symbol("EvalProperty"))
Tree tree(const Node &n)
Definition: tree.hh:186
void setProperty(Tree t, Tree key, Tree val)
Definition: list.cpp:418

Here is the call graph for this function:

Here is the caller graph for this function:

void setNumericProperty ( Tree  t,
Tree  num 
)

Definition at line 599 of file eval.cpp.

References setProperty().

Referenced by simplifyPattern().

600 {
601  setProperty(t, NUMERICPROPERTY, num);
602 }
void setProperty(Tree t, Tree key, Tree val)
Definition: list.cpp:418
Tree NUMERICPROPERTY
Definition: eval.cpp:597

Here is the call graph for this function:

Here is the caller graph for this function:

static void setPMProperty ( Tree  t,
Tree  env,
Tree  pm 
)
static

Definition at line 1238 of file eval.cpp.

References PMPROPERTYNODE, setProperty(), and tree().

Referenced by evalCase().

1239 {
1240  setProperty(t, tree(PMPROPERTYNODE, env), pm);
1241 }
static Node PMPROPERTYNODE(symbol("PMPROPERTY"))
A property to store the pattern matcher corresponding to a set of rules in a specific environement...
Tree tree(const Node &n)
Definition: tree.hh:186
void setProperty(Tree t, Tree key, Tree val)
Definition: list.cpp:418

Here is the call graph for this function:

Here is the caller graph for this function:

Tree simplifyPattern ( Tree  value)

Simplify a block-diagram pattern by computing its numerical sub-expressions.

Parameters
patternan evaluated block-diagram
Returns
a simplified pattern

Definition at line 617 of file eval.cpp.

References getNumericProperty(), isBoxNumeric(), and setNumericProperty().

Referenced by apply_pattern_matcher_internal().

618 {
619  Tree num;
620  if (!getNumericProperty(value,num)) {
621  if (!isBoxNumeric(value,num)) {
622  num = value;
623  }
624  setNumericProperty(value,num);
625  }
626  return num;
627 }
static bool isBoxNumeric(Tree in, Tree &out)
Definition: eval.cpp:630
Definition: num.hh:58
void setNumericProperty(Tree t, Tree num)
Definition: eval.cpp:599
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool getNumericProperty(Tree t, Tree &num)
Definition: eval.cpp:604

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree vec2list ( const vector< Tree > &  v)
static

Definition at line 1324 of file eval.cpp.

References cons(), and nil.

Referenced by applyList().

1325 {
1326  Tree l = nil;
1327  int n = (int)v.size();
1328  while (n--) { l = cons(v[n],l); }
1329  return l;
1330 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree nil
Definition: list.cpp:116

Here is the call graph for this function:

Here is the caller graph for this function:

static void writeIdentValue ( std::string &  dst,
const std::string &  format,
const std::string &  ident,
Tree  visited,
Tree  localValEnv 
)
static

Definition at line 745 of file eval.cpp.

References boxIdent(), eval2int(), max(), and min().

Referenced by evalLabel().

746 {
747  int f = atoi(format.c_str());
748  int n = eval2int(boxIdent(ident.c_str()), visited, localValEnv);
749  int i = min(4,max(f,0));
750  char val[256];
751 
752  snprintf(val, 250, Formats[i], n);
753  dst += val;
754 }
Tree boxIdent(const char *name)
Definition: boxes.cpp:57
double max(double x, double y)
Definition: interval.hh:60
const char * Formats[]
Definition: eval.cpp:743
static int eval2int(Tree exp, Tree visited, Tree localValEnv)
Eval a block diagram to an int.
Definition: eval.cpp:718
double min(double x, double y)
Definition: interval.hh:59

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

Node EVALPROPERTY(symbol("EvalProperty"))
static

Referenced by getEvalProperty(), and setEvalProperty().

const char* Formats[] = {"%d", "%1d", "%2d", "%3d", "%4d"}

Definition at line 743 of file eval.cpp.

int gBoxSlotNumber = 0
static

counter for unique slot number

Definition at line 152 of file eval.cpp.

Referenced by real_a2sb().

int gMaxNameSize

Definition at line 127 of file main.cpp.

SourceReader gReader

Definition at line 89 of file main.cpp.

Referenced by main().

bool gSimpleNames

Definition at line 128 of file main.cpp.

Referenced by applyList(), and process_cmdline().

bool gSimplifyDiagrams

Definition at line 129 of file main.cpp.

Referenced by evalprocess(), and process_cmdline().

property<Tree> gSymbolicBoxProperty

Transform unused (unapplied) closures into symbolic boxes.

Parameters
expthe expression to transform
Returns
an expression where abstractions have been replaced by symbolic boxes

Definition at line 131 of file eval.cpp.

loopDetector LD(1024, 512)
static

Eval a block diagram expression.

Wrap the realeval function in order to propagate the name property

Parameters
expthe expression to evaluate
visitedlist of visited definition to detect recursive definitions
localValEnvthe local environment
Returns
a block diagram in normal form

Referenced by eval().

Tree NUMERICPROPERTY = tree(symbol("NUMERICPROPERTY"))

Definition at line 597 of file eval.cpp.

Node PMPROPERTYNODE(symbol("PMPROPERTY"))
static

A property to store the pattern matcher corresponding to a set of rules in a specific environement.

Referenced by getPMProperty(), and setPMProperty().

property<Tree> SimplifiedBoxProperty
static

Definition at line 1339 of file eval.cpp.