Implementation of the Block diagram evaluator. More...
#include "eval.hh"
#include "boxes.hh"
#include "sourcereader.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 "property.hh"
#include "names.hh"
#include <assert.h>
Go to the source code of this file.
Defines | |
#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. | |
static Tree | revEvalList (Tree lexp, Tree visited, Tree localValEnv) |
Eval a list of expression in reverse order. | |
static Tree | applyList (Tree fun, Tree larg) |
Apply a function to a list of arguments. | |
static Tree | iteratePar (Tree id, int num, Tree body, Tree visited, Tree localValEnv) |
Iterate a parallel construction. | |
static Tree | iterateSeq (Tree id, int num, Tree body, Tree visited, Tree localValEnv) |
Iterate a sequential construction. | |
static Tree | iterateSum (Tree id, int num, Tree body, Tree visited, Tree localValEnv) |
Iterate an addition construction. | |
static Tree | iterateProd (Tree id, int num, Tree body, Tree visited, Tree localValEnv) |
Iterate a product construction. | |
static Tree | larg2par (Tree larg) |
Transform a list of expressions in a parallel construction. | |
static int | eval2int (Tree exp, Tree visited, Tree localValEnv) |
Eval a block diagram to an int. | |
static double | eval2double (Tree exp, Tree visited, Tree localValEnv) |
Eval a block diagram to a double. | |
static const char * | evalLabel (const char *l, Tree visited, Tree localValEnv) |
static Tree | pushMultiClosureDefs (Tree ldefs, Tree visited, Tree lenv) |
Push a new layer with multiple definitions creating the appropriate closures. | |
static Tree | evalIdDef (Tree id, Tree visited, Tree lenv) |
Search the environment for the definition of a symbol ID and evaluate it. | |
static Tree | evalCase (Tree rules, Tree env) |
Eval a case expression containing a list of pattern matching rules. | |
static Tree | evalRuleList (Tree rules, Tree env) |
Evaluates each rule of the list. | |
static Tree | evalRule (Tree rule, Tree env) |
Evaluates the list of patterns and closure the rhs. | |
static Tree | evalPatternList (Tree patterns, Tree env) |
Evaluates each pattern of the list. | |
static Tree | evalPattern (Tree pattern, Tree env) |
Evaluates a pattern using a special mode so that free variables are wrapped into a boxPatternVar. | |
static Tree | patternSimplification (Tree pattern) |
static bool | isBoxNumeric (Tree in, Tree &out) |
static Tree | replaceBoxNumeric (Tree exp) |
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. | |
Tree | evalprocess (Tree eqlist) |
Eval "process" from a list of definitions. | |
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 type annotation of sig | |
bool | getEvalProperty (Tree box, Tree env, Tree &value) |
retrieve the value of box in the environment env | |
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. | |
static bool | isDigitChar (char c) |
static bool | isIdentChar (char c) |
static char * | writeIdentValue (char *dst, int format, const char *ident, Tree visited, Tree localValEnv) |
static bool | boxlistOutputs (Tree boxlist, int *outputs) |
Compute the sum of outputs of a list of boxes. | |
static Tree | nwires (int n) |
repeat n times a wire | |
static Tree | pushNewLayer (Tree lenv) |
Push a new (unique) empty layer (where multiple definitions can be stored) on top of an existing environment. | |
static void | addLayerDef (Tree id, Tree def, Tree lenv) |
Add a definition (as a property) to the current top level layer. | |
Tree | pushValueDef (Tree id, Tree def, Tree lenv) |
Push a new layer and add a single definition. | |
bool | searchIdDef (Tree id, Tree &def, Tree lenv) |
Search the environment for the definition of a symbol ID and return it. | |
static void | setPMProperty (Tree t, Tree env, Tree pm) |
static bool | getPMProperty (Tree t, Tree env, Tree &pm) |
Variables | |
SourceReader | gReader |
int | gMaxNameSize |
bool | gPatternEvalMode |
bool | gSimpleNames |
bool | gSimplifyDiagrams |
property< Tree > | gSymbolicBoxProperty |
Transform unused (unapplied) closures into symbolic boxes. | |
static int | gBoxSlotNumber = 0 |
counter for unique slot number | |
static loopDetector | LD (1024, 1) |
Eval a block diagram expression. | |
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. |
Implementation of the Block diagram evaluator.
Interface for names propagation.
A strict lambda-calculus evaluator for block diagram expressions.
Definition in file eval.cpp.
Definition at line 131 of file eval.cpp.
References getDefNameProperty(), real_a2sb(), and setDefNameProperty().
Referenced by evaldocexpr(), evalprocess(), isBoxNumeric(), and real_a2sb().
00132 { 00133 Tree result; 00134 Tree id; 00135 00136 if (gSymbolicBoxProperty.get(exp, result)) { 00137 return result; 00138 } 00139 00140 result = real_a2sb(exp); 00141 if (result != exp && getDefNameProperty(exp, id)) { 00142 setDefNameProperty(result, id); // propagate definition name property when needed 00143 } 00144 gSymbolicBoxProperty.set(exp, result); 00145 return result; 00146 }
Add a definition (as a property) to the current top level layer.
Check and warn for multiple definitions.
id | the symbol id to be defined | |
def | the definition to be binded to the symbol id | |
lenv | the environment where to add this new definition |
Definition at line 1164 of file eval.cpp.
References evalwarning(), gErrorCount, getDefFileProp(), getDefLineProp(), getProperty(), print(), and setProperty().
Referenced by pushMultiClosureDefs(), and pushValueDef().
01165 { 01166 // check for multiple definitions of a symbol in the same layer 01167 Tree olddef; 01168 if (getProperty(lenv, id, olddef)) { 01169 if (def == olddef) { 01170 evalwarning(getDefFileProp(id), getDefLineProp(id), "equivalent re-definitions of", id); 01171 } else { 01172 fprintf(stderr, "%s:%d: ERROR: redefinition of symbols are not allowed : ", getDefFileProp(id), getDefLineProp(id)); 01173 print(id,stderr); 01174 fprintf(stderr, " is already defined in file \"%s\" line %d \n", getDefFileProp(id), getDefLineProp(id)); 01175 gErrorCount++; 01176 } 01177 } 01178 setProperty(lenv, id, def); 01179 }
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
fun | the function to apply | |
larg | the list of arguments |
Definition at line 974 of file eval.cpp.
References apply_pattern_matcher(), boxCase(), boxError(), boxlistOutputs(), boxPatternMatcher(), boxSeq(), concat(), cons(), eval(), evalerror(), evalerrorbox(), getBoxType(), getDefNameProperty(), 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().
00975 { 00976 Tree abstr; 00977 Tree globalDefEnv; 00978 Tree visited; 00979 Tree localValEnv; 00980 Tree envList; 00981 Tree originalRules; 00982 Tree revParamList; 00983 00984 Tree id; 00985 Tree body; 00986 00987 Automaton* automat; 00988 int state; 00989 00990 prim2 p2; 00991 00992 if (isNil(larg)) return fun; 00993 00994 if (isBoxError(fun) || isBoxError(larg)) { 00995 return boxError(); 00996 } 00997 00998 if (isBoxPatternMatcher(fun, automat, state, envList, originalRules, revParamList)) { 00999 Tree result; 01000 int state2; 01001 vector<Tree> envVect; 01002 01003 list2vec(envList, envVect); 01004 state2 = apply_pattern_matcher(automat, state, hd(larg), result, envVect); 01005 if (state2 >= 0 && isNil(result)) { 01006 // we need to continue the pattern matching 01007 return applyList( 01008 boxPatternMatcher(automat, state2, vec2list(envVect), originalRules, cons(hd(larg),revParamList)), 01009 tl(larg) ); 01010 } else if (state2 < 0) { 01011 cerr << "ERROR : pattern matching failed, no rule of " << boxpp(boxCase(originalRules)) 01012 << " matches argument list " << boxpp(reverse(cons(hd(larg), revParamList))) << endl; 01013 exit(1); 01014 } else { 01015 // Pattern Matching was succesful 01016 // the result is a closure that we need to evaluate. 01017 if (isClosure(result, body, globalDefEnv, visited, localValEnv)) { 01018 // why ??? return simplifyPattern(eval(body, nil, localValEnv)); 01019 //return eval(body, nil, localValEnv); 01020 return applyList(eval(body, nil, localValEnv), tl(larg)); 01021 } else { 01022 cerr << "wrong result from pattern matching (not a closure) : " << boxpp(result) << endl; 01023 return boxError(); 01024 } 01025 } 01026 } 01027 if (!isClosure(fun, abstr, globalDefEnv, visited, localValEnv)) { 01028 // principle : f(a,b,c,...) ==> (a,b,c,...):f 01029 int ins, outs; 01030 01031 // check arity of function 01032 if (!getBoxType(fun, &ins, &outs)) { 01033 // we can't determine the input arity of the expression 01034 // hope for the best 01035 return boxSeq(larg2par(larg), fun); 01036 } 01037 01038 // check arity of arg list 01039 if (!boxlistOutputs(larg,&outs)) { 01040 // we don't know yet the output arity of larg. Therefore we can't 01041 // do any arity checking nor add _ to reach the required number of arguments 01042 // cerr << "warning : can't infere the type of : " << boxpp(larg) << endl; 01043 return boxSeq(larg2par(larg), fun); 01044 } 01045 01046 if (outs > ins) { 01047 cerr << "too much arguments : " << outs << ", instead of : " << ins << endl; 01048 cerr << "when applying : " << boxpp(fun) << endl 01049 << " to : " << boxpp(larg) << endl; 01050 assert(false); 01051 } 01052 01053 if ( (outs == 1) && isBoxPrim2(fun, &p2) && (p2 != sigPrefix)) { 01054 // special case : /(3) ==> _,3 : / 01055 Tree larg2 = concat(nwires(ins-outs), larg); 01056 return boxSeq(larg2par(larg2), fun); 01057 } else { 01058 Tree larg2 = concat(larg, nwires(ins-outs)); 01059 return boxSeq(larg2par(larg2), fun); 01060 } 01061 } 01062 01063 if (isBoxEnvironment(abstr)) { 01064 evalerrorbox(yyfilename, -1, "an environment can't be used as a function", fun); 01065 exit(1); 01066 } 01067 01068 if (!isBoxAbstr(abstr, id, body)) { 01069 evalerror(yyfilename, -1, "(internal) not an abstraction inside closure", fun); 01070 exit(1); 01071 } 01072 01073 // try to synthetise a name from the function name and the argument name 01074 { 01075 Tree arg = eval(hd(larg), visited, localValEnv); 01076 Tree narg; if ( isBoxNumeric(arg,narg) ) { arg = narg; } 01077 Tree f = eval(body, visited, pushValueDef(id, arg, localValEnv)); 01078 01079 Tree fname; 01080 if (getDefNameProperty(fun, fname)) { 01081 stringstream s; s << tree2str(fname); if (!gSimpleNames) s << "(" << boxpp(arg) << ")"; 01082 setDefNameProperty(f, s.str()); 01083 } 01084 return applyList(f, tl(larg)); 01085 } 01086 }
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
boxlist | the list of boxes | |
outputs | sum of outputs of the boxes |
Definition at line 920 of file eval.cpp.
References getBoxType(), hd(), isNil(), and tl().
Referenced by applyList().
00921 { 00922 int ins, outs; 00923 00924 *outputs = 0; 00925 while (!isNil(boxlist)) 00926 { 00927 if (getBoxType(hd(boxlist), &ins, &outs)) { 00928 *outputs += outs; 00929 } else { 00930 // arbitrary output arity set to 1 00931 // when can't be determined 00932 *outputs += 1; 00933 } 00934 boxlist = tl(boxlist); 00935 } 00936 return isNil(boxlist); 00937 }
Definition at line 279 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().
00280 { 00281 Tree id; 00282 Tree result; 00283 00284 LD.detect(cons(exp,localValEnv)); 00285 00286 if (!getEvalProperty(exp, localValEnv, result)) { 00287 result = realeval(exp, visited, localValEnv); 00288 setEvalProperty(exp, localValEnv, result); 00289 00290 00291 00292 if (getDefNameProperty(exp, id)) { 00293 setDefNameProperty(result, id); // propagate definition name property 00294 } 00295 } 00296 return result; 00297 }
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.
exp | the expression to evaluate | |
globalDefEnv | the global environment | |
visited | list of visited definition to detect recursive definitions | |
localValEnv | the local environment |
Definition at line 677 of file eval.cpp.
References boxPropagateSig(), eval(), evalerror(), getBoxType(), hd(), makeSigInputList(), nil, simplify(), tree2float(), yyfilename, and yylineno.
Referenced by realeval().
00678 { 00679 Tree diagram = eval(exp, visited, localValEnv); 00680 int numInputs, numOutputs; 00681 getBoxType(diagram, &numInputs, &numOutputs); 00682 if ( (numInputs > 0) || (numOutputs != 1) ) { 00683 evalerror (yyfilename, yylineno, "not a constant expression of type : (0->1)", exp); 00684 return 1; 00685 } else { 00686 Tree lsignals = boxPropagateSig(nil, diagram , makeSigInputList(numInputs) ); 00687 Tree val = simplify(hd(lsignals)); 00688 return tree2float(val); 00689 } 00690 }
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.
exp | the expression to evaluate | |
globalDefEnv | the global environment | |
visited | list of visited definition to detect recursive definitions | |
localValEnv | the local environment |
Definition at line 706 of file eval.cpp.
References boxPropagateSig(), eval(), evalerror(), getBoxType(), hd(), makeSigInputList(), nil, simplify(), tree2int(), yyfilename, and yylineno.
Referenced by realeval(), and writeIdentValue().
00707 { 00708 Tree diagram = eval(exp, visited, localValEnv); 00709 int numInputs, numOutputs; 00710 getBoxType(diagram, &numInputs, &numOutputs); 00711 if ( (numInputs > 0) || (numOutputs != 1) ) { 00712 evalerror (yyfilename, yylineno, "not a constant expression of type : (0->1)", exp); 00713 return 1; 00714 } else { 00715 Tree lsignals = boxPropagateSig(nil, diagram , makeSigInputList(numInputs) ); 00716 Tree val = simplify(hd(lsignals)); 00717 return tree2int(val); 00718 } 00719 }
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.
rules | the list of rules | |
env | the environment uused to evaluate the patterns and closure the rhs |
Definition at line 1321 of file eval.cpp.
References boxPatternMatcher(), evalRuleList(), getPMProperty(), len(), listn(), make_pattern_matcher(), nil, and setPMProperty().
Referenced by realeval().
01322 { 01323 Tree pm; 01324 if (!getPMProperty(rules, env, pm)) { 01325 Automaton* a = make_pattern_matcher(evalRuleList(rules, env)); 01326 pm = boxPatternMatcher(a, 0, listn(len(rules), env), rules, nil); 01327 setPMProperty(rules, env, pm); 01328 } 01329 return pm; 01330 }
Definition at line 110 of file eval.cpp.
References a2sb(), eval(), nil, and pushMultiClosureDefs().
Referenced by mapEvalDocEqn(), and printDocDgm().
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.
id | the symbol ID t-o search | |
visited | set of visited symbols (used for recursive definition detection) | |
lenv | the environment where to search |
Definition at line 1251 of file eval.cpp.
References addElement(), boxPatternVar(), CTree::branch(), cons(), eval(), evalerror(), getDefFileProp(), getDefLineProp(), getDefNameProperty(), getProperty(), gPatternEvalMode, isNil(), name(), and nil.
Referenced by realeval().
01252 { 01253 Tree def, name; 01254 01255 // search the environment env for a definition of symbol id 01256 while (!isNil(lenv) && !getProperty(lenv, id, def)) { 01257 lenv = lenv->branch(0); 01258 } 01259 01260 // check that the definition exists 01261 if (isNil(lenv)) { 01262 if (gPatternEvalMode) return boxPatternVar(id); 01263 cerr << "undefined symbol " << *id << endl; 01264 evalerror(getDefFileProp(id), getDefLineProp(id), "undefined symbol ", id); 01265 exit(1); 01266 // return id; 01267 } 01268 01269 // check that it is not a recursive definition 01270 Tree p = cons(id,lenv); 01271 // set the definition name property 01272 if (!getDefNameProperty(def, name)) { 01273 // if the definition has no name use the identifier 01274 stringstream s; s << boxpp(id); 01275 //XXXXXX setDefNameProperty(def, s.str()); 01276 } 01277 01278 // return the evaluated definition 01279 return eval(def, addElement(p,visited), nil); 01280 }
Definition at line 741 of file eval.cpp.
References isDigitChar(), isIdentChar(), and writeIdentValue().
Referenced by realeval().
00742 { 00743 char res[2000]; 00744 char ident[64]; 00745 00746 const char* src = &label[0]; 00747 char* dst = &res[0]; 00748 char* id = &ident[0]; 00749 00750 bool parametric = false; 00751 int state = 0; int format = 0; 00752 char c; 00753 00754 while ((c=*src++)) { 00755 if (state == 0) { 00756 // outside ident mode 00757 if (c == '%') { 00758 // look ahead for next char 00759 if (*src == '%') { 00760 *dst++ = *src++; // copy escape char and skip one char 00761 } else { 00762 state = 1; // prepare ident mode 00763 format = 0; 00764 parametric = true; 00765 id = &ident[0]; 00766 } 00767 } else { 00768 *dst++ = c; // copy char 00769 } 00770 } else if (state == 1) { 00771 // read the format 00772 if (isDigitChar(c)) { 00773 format = format*10 + (c-'0'); 00774 } else { 00775 state = 2; 00776 --src; // unread !!! 00777 } 00778 00779 } else { 00780 00781 // within ident mode 00782 if (isIdentChar(c)) { 00783 *id++ = c; 00784 } else { 00785 *id = 0; 00786 dst = writeIdentValue(dst, format, ident, visited, localValEnv); 00787 state = 0; 00788 src -= 1; 00789 } 00790 } 00791 } 00792 00793 if (state == 2) { 00794 *id = 0; 00795 dst = writeIdentValue(dst, format, ident, visited, localValEnv); 00796 } 00797 *dst = 0; 00798 return (parametric) ? strdup(res) : label; 00799 }
Evaluates a pattern using a special mode so that free variables are wrapped into a boxPatternVar.
Definition at line 1370 of file eval.cpp.
References eval(), gPatternEvalMode, nil, and patternSimplification().
Referenced by evalPatternList().
01371 { 01372 bool saveMode = gPatternEvalMode; 01373 gPatternEvalMode = true; 01374 Tree p = eval(pattern, nil, env); 01375 gPatternEvalMode = saveMode; 01376 return patternSimplification(p); 01377 }
Evaluates each pattern of the list.
Definition at line 1355 of file eval.cpp.
References cons(), evalPattern(), hd(), isNil(), nil, and tl().
Referenced by evalRule().
01356 { 01357 if (isNil(patterns)) { 01358 return nil; 01359 } else { 01360 return cons( evalPattern(hd(patterns), env), 01361 evalPatternList(tl(patterns), env) ); 01362 } 01363 }
Eval "process" from a list of definitions.
Eval the definition of 'process'.
Strict evaluation of a block diagram expression by applying beta reduction.
eqlist | a list of faust defintions forming the the global environment |
Definition at line 102 of file eval.cpp.
References a2sb(), boxIdent(), eval(), nil, and pushMultiClosureDefs().
Referenced by main().
00103 { 00104 return a2sb(eval(boxIdent("process"), nil, pushMultiClosureDefs(eqlist, nil, nil))); 00105 }
Evaluates the list of patterns and closure the rhs.
Definition at line 1346 of file eval.cpp.
References cons(), evalPatternList(), left(), and right().
Referenced by evalRuleList().
01347 { 01348 return cons(evalPatternList(left(rule), env), right(rule)); 01349 }
Evaluates each rule of the list.
Definition at line 1336 of file eval.cpp.
References cons(), evalRule(), hd(), isNil(), nil, and tl().
Referenced by evalCase().
01337 { 01338 if (isNil(rules)) return nil; 01339 else return cons(evalRule(hd(rules), env), evalRuleList(tl(rules), env)); 01340 }
Definition at line 232 of file eval.cpp.
References autoName().
00233 { 00234 //return getDefNameProperty(t, id) || autoName(t, id) ; 00235 return autoName(t, id) ; 00236 }
retrieve the value of box in the environment env
box | the expression we want to retrieve the value | |
env | the lexical environment | |
value | the returned value if any |
Definition at line 273 of file eval.cpp.
References EVALPROPERTY, getProperty(), and tree().
Referenced by eval().
00274 { 00275 return getProperty(box, tree(EVALPROPERTY,env), value); 00276 }
Definition at line 563 of file eval.cpp.
References getProperty().
Referenced by replaceBoxNumeric(), and simplifyPattern().
00564 { 00565 return getProperty(t, NUMERICPROPERTY, num); 00566 }
Definition at line 1307 of file eval.cpp.
References getProperty(), PMPROPERTYNODE, and tree().
Referenced by evalCase().
01308 { 01309 return getProperty(t, tree(PMPROPERTYNODE, env), pm); 01310 }
Definition at line 618 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().
00619 { 00620 int numInputs, numOutputs; 00621 double x; 00622 int i; 00623 Tree v; 00624 00625 if (isBoxInt(in, &i) || isBoxReal(in, &x)) { 00626 out = in; 00627 return true; 00628 } else { 00629 v = a2sb(in); 00630 if ( getBoxType(v, &numInputs, &numOutputs) && (numInputs == 0) && (numOutputs == 1) ) { 00631 // potential numerical expression 00632 Tree lsignals = boxPropagateSig(nil, v , makeSigInputList(numInputs) ); 00633 Tree res = simplify(hd(lsignals)); 00634 if (isSigReal(res, &x)) { 00635 out = boxReal(x); 00636 return true; 00637 } 00638 if (isSigInt(res, &i)) { 00639 out = boxInt(i); 00640 return true; 00641 } 00642 } 00643 return false; 00644 } 00645 }
Definition at line 540 of file eval.cpp.
References isBoxMerge(), isBoxPar(), isBoxRec(), isBoxSeq(), isBoxSplit(), and CTree::node().
Referenced by patternSimplification().
00541 { 00542 if ( isBoxPar(box, t1, t2) || 00543 isBoxSeq(box, t1, t2) || 00544 isBoxSplit(box, t1, t2) || 00545 isBoxMerge(box, t1, t2) || 00546 isBoxRec(box, t1, t2) ) 00547 { 00548 n = box->node(); 00549 return true; 00550 } else { 00551 return false; 00552 } 00553 }
static bool isDigitChar | ( | char | c | ) | [static] |
Definition at line 721 of file eval.cpp.
Referenced by evalLabel().
static bool isIdentChar | ( | char | c | ) | [static] |
Definition at line 726 of file eval.cpp.
Referenced by evalLabel().
00727 { 00728 return ((c >= 'a') & (c <= 'z')) || ((c >= 'A') & (c <= 'Z')) || ((c >= '0') & (c <= '9')) || (c == '_'); 00729 }
Iterate a parallel construction.
Iterate a parallel construction such that : par(i,10,E) --> E(i<-0),E(i<-1),...,E(i<-9)
id | the formal parameter of the iteration | |
num | the number of iterartions | |
body | the body expression of the iteration | |
globalDefEnv | the global environment | |
visited | list of visited definition to detect recursive definitions | |
localValEnv | the local environment |
Definition at line 816 of file eval.cpp.
References boxPar(), eval(), pushValueDef(), and tree().
Referenced by realeval().
00817 { 00818 assert (num>0); 00819 00820 Tree res = eval(body, visited, pushValueDef(id, tree(0), localValEnv)); 00821 for (int i = 1; i < num; i++) { 00822 res = boxPar(res, eval(body, visited, pushValueDef(id, tree(i), localValEnv))); 00823 } 00824 00825 return res; 00826 }
Iterate a product construction.
Iterate a product construction such that : par(i,10,E) --> E(i<-0)*E(i<-1)*...*E(i<-9)
id | the formal parameter of the iteration | |
num | the number of iterartions | |
body | the body expression of the iteration | |
globalDefEnv | the global environment | |
visited | list of visited definition to detect recursive definitions | |
localValEnv | the local environment |
Definition at line 898 of file eval.cpp.
References boxPar(), boxPrim2(), boxSeq(), eval(), pushValueDef(), sigMul(), and tree().
Referenced by realeval().
00899 { 00900 assert (num>0); 00901 00902 Tree res = eval(body, visited, pushValueDef(id, tree(0), localValEnv)); 00903 00904 for (int i = 1; i < num; i++) { 00905 res = boxSeq(boxPar(res, eval(body, visited, pushValueDef(id, tree(i), localValEnv))),boxPrim2(sigMul)) ; 00906 } 00907 00908 return res; 00909 }
Iterate a sequential construction.
Iterate a sequential construction such that : seq(i,10,E) --> E(i<-0):E(i<-1):...:E(i<-9)
id | the formal parameter of the iteration | |
num | the number of iterartions | |
body | the body expression of the iteration | |
globalDefEnv | the global environment | |
visited | list of visited definition to detect recursive definitions |
Definition at line 842 of file eval.cpp.
References boxSeq(), eval(), pushValueDef(), and tree().
Referenced by realeval().
00843 { 00844 assert (num>0); 00845 00846 Tree res = eval(body, visited, pushValueDef(id, tree(0), localValEnv)); 00847 00848 for (int i = 1; i < num; i++) { 00849 res = boxSeq(res, eval(body, visited, pushValueDef(id, tree(i), localValEnv))); 00850 } 00851 00852 return res; 00853 }
Iterate an addition construction.
Iterate an addition construction such that : par(i,10,E) --> E(i<-0)+E(i<-1)+...+E(i<-9)
id | the formal parameter of the iteration | |
num | the number of iterartions | |
body | the body expression of the iteration | |
globalDefEnv | the global environment | |
visited | list of visited definition to detect recursive definitions | |
localValEnv | the local environment |
Definition at line 870 of file eval.cpp.
References boxPar(), boxPrim2(), boxSeq(), eval(), pushValueDef(), sigAdd(), and tree().
Referenced by realeval().
00871 { 00872 assert (num>0); 00873 00874 Tree res = eval(body, visited, pushValueDef(id, tree(0), localValEnv)); 00875 00876 for (int i = 1; i < num; i++) { 00877 res = boxSeq(boxPar(res, eval(body, visited, pushValueDef(id, tree(i), localValEnv))),boxPrim2(sigAdd)) ; 00878 } 00879 00880 return res; 00881 }
Transform a list of expressions in a parallel construction.
larg | list of expressions |
Definition at line 1119 of file eval.cpp.
References boxPar(), evalerror(), hd(), isNil(), tl(), and yyfilename.
Referenced by applyList().
01120 { 01121 if (isNil(larg)) { 01122 evalerror(yyfilename, -1, "empty list of arguments", larg); 01123 exit(1); 01124 } 01125 if (isNil(tl(larg))) { 01126 return hd(larg); 01127 } 01128 return boxPar(hd(larg), larg2par(tl(larg))); 01129 }
Creates a list of n elements.
n | number of elements | |
e | element to be repeated |
Definition at line 1290 of file eval.cpp.
Referenced by evalCase().
static Tree nwires | ( | int | n | ) | [static] |
Definition at line 647 of file eval.cpp.
References isBoxNumeric(), isBoxPatternOp(), and tree().
Referenced by evalPattern().
00648 { 00649 00650 Node n(0); 00651 Tree v, t1, t2; 00652 00653 if (isBoxNumeric(pattern, v)) { 00654 return v; 00655 } else if (isBoxPatternOp(pattern, n, t1, t2)) { 00656 return tree(n, patternSimplification(t1), patternSimplification(t2)); 00657 } else { 00658 return pattern; 00659 } 00660 }
Push a new layer with multiple definitions creating the appropriate closures.
ldefs | list of pairs (symbol id x definition) to be binded to the symbol id | |
visited | set of visited symbols (used for recursive definition detection) | |
lenv | the environment where to push the layer and add all the definitions |
Definition at line 1204 of file eval.cpp.
References addLayerDef(), closure(), hd(), isBoxCase(), isNil(), nil, pushNewLayer(), setDefNameProperty(), and tl().
Referenced by evaldocexpr(), evalprocess(), and realeval().
01205 { 01206 Tree lenv2 = pushNewLayer(lenv); 01207 while (!isNil(ldefs)) { 01208 Tree def = hd(ldefs); 01209 Tree id = hd(def); 01210 Tree rhs= tl(def); 01211 Tree cl = closure(tl(def),nil,visited,lenv2); 01212 stringstream s; s << boxpp(id); 01213 if (!isBoxCase(rhs)) setDefNameProperty(cl,s.str()); 01214 addLayerDef( id, cl, lenv2 ); 01215 ldefs = tl(ldefs); 01216 } 01217 return lenv2; 01218 }
Push a new (unique) empty layer (where multiple definitions can be stored) on top of an existing environment.
lenv | the old environment |
Definition at line 1151 of file eval.cpp.
References tree(), and unique().
Referenced by pushMultiClosureDefs(), and pushValueDef().
Push a new layer and add a single definition.
id | the symbol id to be defined | |
def | the definition to be binded to the symbol id | |
lenv | the environment where to push the layer and add the definition |
Definition at line 1189 of file eval.cpp.
References addLayerDef(), and pushNewLayer().
Referenced by apply_pattern_matcher(), applyList(), iteratePar(), iterateProd(), iterateSeq(), iterateSum(), and real_a2sb().
01190 { 01191 Tree lenv2 = pushNewLayer(lenv); 01192 addLayerDef(id, def, lenv2); 01193 return lenv2; 01194 }
Definition at line 150 of file eval.cpp.
References a2sb(), applyList(), CTree::arity(), boxSlot(), boxSymbolic(), CTree::branch(), cons(), eval(), evalerror(), gBoxSlotNumber, getDefNameProperty(), gSimplifyDiagrams, isBoxAbstr(), isBoxEnvironment(), isBoxIdent(), isBoxPatternMatcher(), isClosure(), CTree::make(), name(), nil, CTree::node(), pushValueDef(), replaceBoxNumeric(), setDefNameProperty(), and yyfilename.
Referenced by a2sb().
00151 { 00152 Tree abstr, visited, unusedEnv, localValEnv, var, name, body; 00153 00154 if (isClosure(exp, abstr, unusedEnv, visited, localValEnv)) { 00155 00156 if (isBoxIdent(abstr)) { 00157 // special case introduced with access and components 00158 Tree result = a2sb(eval(abstr, visited, localValEnv)); 00159 00160 // propagate definition name property when needed 00161 if (getDefNameProperty(exp, name)) setDefNameProperty(result, name); 00162 return result; 00163 00164 } else if (isBoxAbstr(abstr, var, body)) { 00165 // Here we have remaining abstraction that we will try to 00166 // transform in a symbolic box by applying it to a slot 00167 00168 Tree slot = boxSlot(++gBoxSlotNumber); 00169 stringstream s; s << boxpp(var); 00170 setDefNameProperty(slot, s.str() ); // ajout YO 00171 00172 // Apply the abstraction to the slot 00173 Tree result = boxSymbolic(slot, a2sb(eval(body, visited, pushValueDef(var, slot, localValEnv)))); 00174 00175 // propagate definition name property when needed 00176 if (getDefNameProperty(exp, name)) setDefNameProperty(result, name); 00177 return result; 00178 00179 } else if (isBoxEnvironment(abstr)) { 00180 return abstr; 00181 00182 } else { 00183 evalerror(yyfilename, -1, " a2sb : internal error : not an abstraction inside closure ", exp); 00184 exit(1); 00185 } 00186 00187 } else if (isBoxPatternMatcher(exp)) { 00188 // Here we have remaining PM rules that we will try to 00189 // transform in a symbolic box by applying it to a slot 00190 00191 Tree slot = boxSlot(++gBoxSlotNumber); 00192 stringstream s; s << "PM" << gBoxSlotNumber; 00193 setDefNameProperty(slot, s.str() ); 00194 00195 // apply the PM rules to the slot and transfoms the result in a symbolic box 00196 Tree result = boxSymbolic(slot, a2sb(applyList(exp, cons(slot,nil)))); 00197 00198 // propagate definition name property when needed 00199 if (getDefNameProperty(exp, name)) setDefNameProperty(result, name); 00200 return result; 00201 00202 } else { 00203 // it is a constructor : transform each branches 00204 unsigned int ar = exp->arity(); 00205 tvec B(ar); 00206 bool modified = false; 00207 for (unsigned int i = 0; i < ar; i++) { 00208 Tree b = exp->branch(i); 00209 Tree m = a2sb(b); 00210 B[i] = m; 00211 if (b != m) modified=true; 00212 } 00213 Tree r = (modified) ? CTree::make(exp->node(), B) : exp; 00214 if (gSimplifyDiagrams) { 00215 return replaceBoxNumeric(r); 00216 } else { 00217 return r; 00218 } 00219 /* 00220 if (modified) { 00221 return replaceBoxNumeric(CTree::make(exp->node(), exp->arity(), B));*/ 00222 } 00223 }
Eval a block diagram expression.
Strict evaluation of a block diagram expression by applying beta reduction.
exp | the expression to evaluate | |
visited | list of visited definition to detect recursive definitions | |
localValEnv | the local environment |
Definition at line 309 of file eval.cpp.
References applyList(), boxButton(), boxCheckbox(), boxEnvironment(), boxHBargraph(), boxHGroup(), boxHSlider(), boxIdent(), boxMerge(), boxNumEntry(), boxPar(), boxRec(), boxSeq(), boxSplit(), boxTGroup(), boxVBargraph(), boxVGroup(), boxVSlider(), closure(), eval(), eval2double(), eval2int(), evalCase(), evalerror(), evalIdDef(), evalLabel(), SourceReader::expandlist(), getDefFileProp(), getDefLineProp(), SourceReader::getlist(), getUserData(), isBoxAbstr(), isBoxAccess(), isBoxAppl(), isBoxButton(), isBoxCase(), isBoxCheckbox(), isBoxComponent(), isBoxCut(), isBoxEnvironment(), isBoxFConst(), isBoxFFun(), isBoxFVar(), isBoxHBargraph(), isBoxHGroup(), isBoxHSlider(), isBoxIdent(), isBoxInt(), isBoxIPar(), isBoxIProd(), isBoxISeq(), isBoxISum(), isBoxLibrary(), isBoxMerge(), isBoxNumEntry(), isBoxPar(), isBoxPatternMatcher(), isBoxPatternVar(), isBoxPrim0(), isBoxPrim1(), isBoxPrim2(), isBoxPrim3(), isBoxPrim4(), isBoxPrim5(), isBoxReal(), isBoxRec(), isBoxSeq(), isBoxSlot(), isBoxSplit(), isBoxSymbolic(), isBoxTGroup(), isBoxVBargraph(), isBoxVGroup(), isBoxVSlider(), isBoxWire(), isBoxWithLocalDef(), isClosure(), iteratePar(), iterateProd(), iterateSeq(), iterateSum(), nil, pushMultiClosureDefs(), revEvalList(), setDefNameProperty(), setUnion(), tree(), and tree2str().
Referenced by eval().
00310 { 00311 //Tree def; 00312 Tree fun; 00313 Tree arg; 00314 Tree var, num, body, ldef; 00315 Tree label; 00316 Tree cur, lo, hi, step; 00317 Tree e1, e2, exp2, notused, visited2, lenv2; 00318 Tree rules; 00319 Tree id; 00320 00321 //cerr << "EVAL " << *exp << " (visited : " << *visited << ")" << endl; 00322 //cerr << "REALEVAL of " << boxpp(exp) << endl; 00323 00324 xtended* xt = (xtended*) getUserData(exp); 00325 00326 00327 // constants 00328 //----------- 00329 00330 if ( xt || 00331 isBoxInt(exp) || isBoxReal(exp) || 00332 isBoxWire(exp) || isBoxCut(exp) || 00333 isBoxPrim0(exp) || isBoxPrim1(exp) || 00334 isBoxPrim2(exp) || isBoxPrim3(exp) || 00335 isBoxPrim4(exp) || isBoxPrim5(exp) || 00336 isBoxFFun(exp) || isBoxFConst(exp) || isBoxFVar(exp) ) { 00337 return exp; 00338 00339 // block-diagram constructors 00340 //--------------------------- 00341 00342 } else if ( isBoxSeq(exp, e1, e2) ) { 00343 return boxSeq(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv)); 00344 00345 } else if ( isBoxPar(exp, e1, e2) ) { 00346 return boxPar(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv)); 00347 00348 } else if ( isBoxRec(exp, e1, e2) ) { 00349 return boxRec(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv)); 00350 00351 } else if ( isBoxSplit(exp, e1, e2) ) { 00352 return boxSplit(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv)); 00353 00354 } else if ( isBoxMerge(exp, e1, e2) ) { 00355 return boxMerge(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv)); 00356 00357 // Modules 00358 //-------- 00359 00360 } else if (isBoxAccess(exp, body, var)) { 00361 Tree val = eval(body, visited, localValEnv); 00362 if (isClosure(val, exp2, notused, visited2, lenv2)) { 00363 // it is a closure, we have an environment to access 00364 return eval(closure(var,notused,visited2,lenv2), visited, localValEnv); 00365 } else { 00366 evalerror(getDefFileProp(exp), getDefLineProp(exp), "No environment to access ", exp); 00367 exit(1); 00368 } 00369 00370 } else if (isBoxComponent(exp, label)) { 00371 string fname = tree2str(label); 00372 Tree eqlst = gReader.expandlist(gReader.getlist(fname)); 00373 Tree res = closure(boxIdent("process"), nil, nil, pushMultiClosureDefs(eqlst, nil, nil)); 00374 setDefNameProperty(res, label); 00375 //cerr << "component is " << boxpp(res) << endl; 00376 return res; 00377 00378 } else if (isBoxLibrary(exp, label)) { 00379 string fname = tree2str(label); 00380 Tree eqlst = gReader.expandlist(gReader.getlist(fname)); 00381 Tree res = closure(boxEnvironment(), nil, nil, pushMultiClosureDefs(eqlst, nil, nil)); 00382 setDefNameProperty(res, label); 00383 //cerr << "component is " << boxpp(res) << endl; 00384 return res; 00385 00386 00387 // user interface elements 00388 //------------------------ 00389 00390 } else if (isBoxButton(exp, label)) { 00391 const char* l1 = tree2str(label); 00392 const char* l2= evalLabel(l1, visited, localValEnv); 00393 //cout << "button label : " << l1 << " become " << l2 << endl; 00394 return ((l1 == l2) ? exp : boxButton(tree(l2))); 00395 00396 } else if (isBoxCheckbox(exp, label)) { 00397 const char* l1 = tree2str(label); 00398 const char* l2= evalLabel(l1, visited, localValEnv); 00399 //cout << "check box label : " << l1 << " become " << l2 << endl; 00400 return ((l1 == l2) ? exp : boxCheckbox(tree(l2))); 00401 00402 } else if (isBoxVSlider(exp, label, cur, lo, hi, step)) { 00403 const char* l1 = tree2str(label); 00404 const char* l2= evalLabel(l1, visited, localValEnv); 00405 return ( boxVSlider(tree(l2), 00406 tree(eval2double(cur, visited, localValEnv)), 00407 tree(eval2double(lo, visited, localValEnv)), 00408 tree(eval2double(hi, visited, localValEnv)), 00409 tree(eval2double(step, visited, localValEnv)))); 00410 00411 } else if (isBoxHSlider(exp, label, cur, lo, hi, step)) { 00412 const char* l1 = tree2str(label); 00413 const char* l2= evalLabel(l1, visited, localValEnv); 00414 return ( boxHSlider(tree(l2), 00415 tree(eval2double(cur, visited, localValEnv)), 00416 tree(eval2double(lo, visited, localValEnv)), 00417 tree(eval2double(hi, visited, localValEnv)), 00418 tree(eval2double(step, visited, localValEnv)))); 00419 00420 } else if (isBoxNumEntry(exp, label, cur, lo, hi, step)) { 00421 const char* l1 = tree2str(label); 00422 const char* l2= evalLabel(l1, visited, localValEnv); 00423 return (boxNumEntry(tree(l2), 00424 tree(eval2double(cur, visited, localValEnv)), 00425 tree(eval2double(lo, visited, localValEnv)), 00426 tree(eval2double(hi, visited, localValEnv)), 00427 tree(eval2double(step, visited, localValEnv)))); 00428 00429 } else if (isBoxVGroup(exp, label, arg)) { 00430 const char* l1 = tree2str(label); 00431 const char* l2= evalLabel(l1, visited, localValEnv); 00432 return boxVGroup(tree(l2), eval(arg, visited, localValEnv) ); 00433 00434 } else if (isBoxHGroup(exp, label, arg)) { 00435 const char* l1 = tree2str(label); 00436 const char* l2= evalLabel(l1, visited, localValEnv); 00437 return boxHGroup(tree(l2), eval(arg, visited, localValEnv) ); 00438 00439 } else if (isBoxTGroup(exp, label, arg)) { 00440 const char* l1 = tree2str(label); 00441 const char* l2= evalLabel(l1, visited, localValEnv); 00442 return boxTGroup(tree(l2), eval(arg, visited, localValEnv) ); 00443 00444 } else if (isBoxHBargraph(exp, label, lo, hi)) { 00445 const char* l1 = tree2str(label); 00446 const char* l2= evalLabel(l1, visited, localValEnv); 00447 return boxHBargraph(tree(l2), 00448 tree(eval2double(lo, visited, localValEnv)), 00449 tree(eval2double(hi, visited, localValEnv))); 00450 00451 } else if (isBoxVBargraph(exp, label, lo, hi)) { 00452 const char* l1 = tree2str(label); 00453 const char* l2= evalLabel(l1, visited, localValEnv); 00454 return boxVBargraph(tree(l2), 00455 tree(eval2double(lo, visited, localValEnv)), 00456 tree(eval2double(hi, visited, localValEnv))); 00457 00458 // lambda calculus 00459 //---------------- 00460 00461 } else if (isBoxIdent(exp)) { 00462 return evalIdDef(exp, visited, localValEnv); 00463 00464 } else if (isBoxWithLocalDef(exp, body, ldef)) { 00465 return eval(body, visited, pushMultiClosureDefs(ldef, visited, localValEnv)); 00466 00467 } else if (isBoxAppl(exp, fun, arg)) { 00468 return applyList( eval(fun, visited, localValEnv), 00469 revEvalList(arg, visited, localValEnv) ); 00470 00471 } else if (isBoxAbstr(exp)) { 00472 // it is an abstraction : return a closure 00473 return closure(exp, nil, visited, localValEnv); 00474 00475 } else if (isBoxEnvironment(exp)) { 00476 // environment : return also a closure 00477 return closure(exp, nil, visited, localValEnv); 00478 00479 } else if (isClosure(exp, exp2, notused, visited2, lenv2)) { 00480 00481 if (isBoxAbstr(exp2)) { 00482 // a 'real' closure 00483 return closure(exp2, nil, setUnion(visited,visited2), lenv2); 00484 } else if (isBoxEnvironment(exp2)) { 00485 // a 'real' closure 00486 return closure(exp2, nil, setUnion(visited,visited2), lenv2); 00487 } else { 00488 // it was a suspended evaluation 00489 return eval(exp2, setUnion(visited,visited2), lenv2); 00490 } 00491 00492 // Algorithmic constructions 00493 //-------------------------- 00494 00495 } else if (isBoxIPar(exp, var, num, body)) { 00496 int n = eval2int(num, visited, localValEnv); 00497 return iteratePar(var, n, body, visited, localValEnv); 00498 00499 } else if (isBoxISeq(exp, var, num, body)) { 00500 int n = eval2int(num, visited, localValEnv); 00501 return iterateSeq(var, n, body, visited, localValEnv); 00502 00503 } else if (isBoxISum(exp, var, num, body)) { 00504 int n = eval2int(num, visited, localValEnv); 00505 return iterateSum(var, n, body, visited, localValEnv); 00506 00507 } else if (isBoxIProd(exp, var, num, body)) { 00508 int n = eval2int(num, visited, localValEnv); 00509 return iterateProd(var, n, body, visited, localValEnv); 00510 00511 } else if (isBoxSlot(exp)) { 00512 return exp; 00513 00514 } else if (isBoxSymbolic(exp)) { 00515 00516 return exp; 00517 00518 00519 // Pattern matching extension 00520 //--------------------------- 00521 00522 } else if (isBoxCase(exp, rules)) { 00523 return evalCase(rules, localValEnv); 00524 00525 } else if (isBoxPatternVar(exp, id)) { 00526 return exp; 00527 //return evalIdDef(id, visited, localValEnv); 00528 00529 } else if (isBoxPatternMatcher(exp)) { 00530 return exp; 00531 00532 } else { 00533 cerr << "ERROR : EVAL don't intercept : " << *exp << endl; 00534 assert(false); 00535 } 00536 }
Definition at line 569 of file eval.cpp.
References boxInt(), boxPropagateSig(), boxReal(), getBoxType(), getNumericProperty(), hd(), isBoxInt(), isBoxReal(), isList(), isSigInt(), isSigReal(), makeSigInputList(), nil, setNumericProperty(), and simplify().
Referenced by real_a2sb().
00570 { 00571 int numInputs, numOutputs; 00572 double x; 00573 int i; 00574 Tree out; 00575 00576 if (isBoxInt(exp, &i) || isBoxReal(exp, &x)) { 00577 return exp; 00578 } else if (getNumericProperty(exp, out)) { 00579 return out; 00580 } else { 00581 if ( getBoxType(exp, &numInputs, &numOutputs) && (numInputs == 0) && (numOutputs == 1) ) { 00582 // potential numerical expression 00583 Tree lsignals = boxPropagateSig(nil, exp , makeSigInputList(numInputs) ); 00584 assert(isList(lsignals)); 00585 Tree res = simplify(hd(lsignals)); 00586 if (isSigReal(res, &x)) out = boxReal(x); 00587 else if (isSigInt(res, &i)) out = boxInt(i); 00588 else out = exp; 00589 } else { 00590 out = exp; 00591 } 00592 setNumericProperty(exp,out); 00593 return out; 00594 } 00595 }
Eval a list of expression in reverse order.
Eval a list of expressions returning the list of results in reverse order.
lexp | list of expressions to evaluate | |
globalDefEnv | the global environment | |
visited | list of visited definition to detect recursive definitions | |
localValEnv | the local environment |
Definition at line 1101 of file eval.cpp.
References cons(), eval(), hd(), isNil(), nil, and tl().
Referenced by realeval().
01102 { 01103 Tree result = nil; 01104 while (!isNil(lexp)) { 01105 result = cons(eval(hd(lexp), visited, localValEnv), result); 01106 lexp = tl(lexp); 01107 } 01108 return result; 01109 }
Search the environment for the definition of a symbol ID and return it.
id | the symbol ID to search | |
def | where to store the definition if any | |
lenv | the environment |
Definition at line 1229 of file eval.cpp.
References CTree::branch(), getProperty(), and isNil().
Referenced by apply_pattern_matcher().
01230 { 01231 // search the environment until a definition is found 01232 // or nil (the empty environment) is reached 01233 while (!isNil(lenv) && !getProperty(lenv, id, def)) { 01234 lenv = lenv->branch(0); 01235 } 01236 return !isNil(lenv); 01237 }
set the type annotation of sig
sig | the signal we want to type | |
t | the type of the signal |
Definition at line 259 of file eval.cpp.
References EVALPROPERTY, setProperty(), and tree().
Referenced by eval().
00260 { 00261 //cerr << "setSigType(" << *sig << ", " << t << ")" << endl; 00262 setProperty(box, tree(EVALPROPERTY,env), value); 00263 }
Definition at line 558 of file eval.cpp.
References setProperty().
Referenced by replaceBoxNumeric(), and simplifyPattern().
00559 { 00560 setProperty(t, NUMERICPROPERTY, num); 00561 }
Definition at line 1302 of file eval.cpp.
References PMPROPERTYNODE, setProperty(), and tree().
Referenced by evalCase().
01303 { 01304 setProperty(t, tree(PMPROPERTYNODE, env), pm); 01305 }
Simplify a block-diagram pattern by computing its numerical sub-expressions.
pattern | an evaluated block-diagram |
Definition at line 605 of file eval.cpp.
References getNumericProperty(), isBoxNumeric(), and setNumericProperty().
Referenced by apply_pattern_matcher_internal().
00606 { 00607 Tree num; 00608 if (!getNumericProperty(value,num)) { 00609 if (!isBoxNumeric(value,num)) { 00610 num = value; 00611 } 00612 setNumericProperty(value,num); 00613 } 00614 return num; 00615 }
static char* writeIdentValue | ( | char * | dst, | |
int | format, | |||
const char * | ident, | |||
Tree | visited, | |||
Tree | localValEnv | |||
) | [static] |
Definition at line 733 of file eval.cpp.
References boxIdent(), eval2int(), max(), and min().
Referenced by evalLabel().
00734 { 00735 int n = eval2int(boxIdent(ident), visited, localValEnv); 00736 int i = min(4,max(format,0)); 00737 00738 return dst + sprintf(dst, Formats[i], n); 00739 }
Node EVALPROPERTY(symbol("EvalProperty")) [static] |
Referenced by getEvalProperty(), and setEvalProperty().
int gBoxSlotNumber = 0 [static] |
int gMaxNameSize |
Definition at line 120 of file main.cpp.
Referenced by process_cmdline(), and setDefNameProperty().
bool gPatternEvalMode |
Definition at line 129 of file main.cpp.
Referenced by evalIdDef(), and evalPattern().
bool gSimpleNames |
Definition at line 121 of file main.cpp.
Referenced by applyList(), and process_cmdline().
bool gSimplifyDiagrams |
Definition at line 122 of file main.cpp.
Referenced by process_cmdline(), and real_a2sb().
loopDetector LD(1024, 1) [static] |
Eval a block diagram expression.
Wrap the realeval function in order to propagate the name property
exp | the expression to evaluate | |
visited | list of visited definition to detect recursive definitions | |
localValEnv | the local environment |
Referenced by eval().
Tree NUMERICPROPERTY = tree(symbol("NUMERICPROPERTY")) |
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().