Logo Search packages:      
Sourcecode: faust version File versions  Download package

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:
exp the expression to evaluate
visited list of visited definition to detect recursive definitions
localValEnv the local environment
Returns:
a block diagram in normal form

Definition at line 309 of file eval.cpp.

References applyList(), eval2double(), eval2int(), evalCase(), evalIdDef(), getUserData(), iteratePar(), iterateProd(), iterateSeq(), iterateSum(), and revEvalList().

{
      //Tree      def;
      Tree  fun;
      Tree  arg;
      Tree  var, num, body, ldef;
      Tree  label;
      Tree  cur, lo, hi, step;
      Tree  e1, e2, exp2, notused, visited2, lenv2;
      Tree  rules;
      Tree  id;

      //cerr << "EVAL " << *exp << " (visited : " << *visited << ")" << endl;
      //cerr << "REALEVAL of " << boxpp(exp) << endl;
      
      xtended* xt = (xtended*) getUserData(exp);


      // constants
      //-----------
      
      if (  xt || 
                  isBoxInt(exp) || isBoxReal(exp) || 
                  isBoxWire(exp) || isBoxCut(exp) ||
                  isBoxPrim0(exp) || isBoxPrim1(exp) || 
                  isBoxPrim2(exp) || isBoxPrim3(exp) || 
                  isBoxPrim4(exp) || isBoxPrim5(exp) ||
                  isBoxFFun(exp) || isBoxFConst(exp) || isBoxFVar(exp) ) {
            return exp;

      // block-diagram constructors
      //---------------------------
      
      } else if ( isBoxSeq(exp, e1, e2) ) {
            return boxSeq(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));

      } else if ( isBoxPar(exp, e1, e2) ) {
            return boxPar(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));

      } else if ( isBoxRec(exp, e1, e2) ) {
            return boxRec(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));

      } else if ( isBoxSplit(exp, e1, e2) ) {
            return boxSplit(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));

      } else if ( isBoxMerge(exp, e1, e2) ) {
            return boxMerge(eval(e1, visited, localValEnv), eval(e2, visited, localValEnv));
            
      // Modules
      //--------

    } else if (isBoxAccess(exp, body, var)) {
        Tree val = eval(body, visited, localValEnv);
        if (isClosure(val, exp2, notused, visited2, lenv2)) {
            // it is a closure, we have an environment to access
            return eval(closure(var,notused,visited2,lenv2), visited, localValEnv);
        } else {
            evalerror(getDefFileProp(exp), getDefLineProp(exp), "No environment to access ", exp);
            exit(1);
        }

//////////////////////en chantier////////////////////////////

    } else if (isBoxModifLocalDef(exp, body, ldef)) {
        Tree val = eval(body, visited, localValEnv);
        if (isClosure(val, exp2, notused, visited2, lenv2)) {
            // we rebuild the closure using a copy of the original environment
            // modified with some new definitions
            Tree lenv3 = copyEnvReplaceDefs(lenv2, ldef, visited2, localValEnv);
            return eval(closure(exp2,notused,visited2,lenv3), visited, localValEnv);
        } else {

            evalerror(getDefFileProp(exp), getDefLineProp(exp), "not a closure ", val);
            evalerror(getDefFileProp(exp), getDefLineProp(exp), "No environment to access ", exp);
            exit(1);
        }

///////////////////////////////////////////////////////////////////

    } else if (isBoxComponent(exp, label)) {
        string  fname   = tree2str(label);
        Tree    eqlst   = gReader.expandlist(gReader.getlist(fname));
        Tree    res     = closure(boxIdent("process"), nil, nil, pushMultiClosureDefs(eqlst, nil, nil));
        setDefNameProperty(res, label);
        //cerr << "component is " << boxpp(res) << endl;
        return res;

    } else if (isBoxLibrary(exp, label)) {
        string  fname   = tree2str(label);
        Tree    eqlst   = gReader.expandlist(gReader.getlist(fname));
        Tree    res     = closure(boxEnvironment(), nil, nil, pushMultiClosureDefs(eqlst, nil, nil));
        setDefNameProperty(res, label);
        //cerr << "component is " << boxpp(res) << endl;
        return res;


      // user interface elements
      //------------------------
      
      } else if (isBoxButton(exp, label)) {
            const char* l1 = tree2str(label);
            const char* l2= evalLabel(l1, visited, localValEnv);
            //cout << "button label : " << l1 << " become " << l2 << endl;
            return ((l1 == l2) ? exp : boxButton(tree(l2)));

      } else if (isBoxCheckbox(exp, label)) {
            const char* l1 = tree2str(label);
            const char* l2= evalLabel(l1, visited, localValEnv);
            //cout << "check box label : " << l1 << " become " << l2 << endl;
            return ((l1 == l2) ? exp : boxCheckbox(tree(l2)));

      } else if (isBoxVSlider(exp, label, cur, lo, hi, step)) {
            const char* l1 = tree2str(label);
            const char* l2= evalLabel(l1, visited, localValEnv);
            return ( boxVSlider(tree(l2),
                              tree(eval2double(cur, visited, localValEnv)),
                              tree(eval2double(lo, visited, localValEnv)),
                              tree(eval2double(hi, visited, localValEnv)),
                              tree(eval2double(step, visited, localValEnv))));

      } else if (isBoxHSlider(exp, label, cur, lo, hi, step)) {
            const char* l1 = tree2str(label);
            const char* l2= evalLabel(l1, visited, localValEnv);
            return ( boxHSlider(tree(l2),
                              tree(eval2double(cur, visited, localValEnv)),
                              tree(eval2double(lo, visited, localValEnv)),
                              tree(eval2double(hi, visited, localValEnv)),
                              tree(eval2double(step, visited, localValEnv))));

      } else if (isBoxNumEntry(exp, label, cur, lo, hi, step)) {
            const char* l1 = tree2str(label);
            const char* l2= evalLabel(l1, visited, localValEnv);
            return (boxNumEntry(tree(l2),
                              tree(eval2double(cur, visited, localValEnv)),
                              tree(eval2double(lo, visited, localValEnv)),
                              tree(eval2double(hi, visited, localValEnv)),
                              tree(eval2double(step, visited, localValEnv))));

      } else if (isBoxVGroup(exp, label, arg)) {
            const char* l1 = tree2str(label);
            const char* l2= evalLabel(l1, visited, localValEnv);
            return boxVGroup(tree(l2),    eval(arg, visited, localValEnv) );

      } else if (isBoxHGroup(exp, label, arg)) {
            const char* l1 = tree2str(label);
            const char* l2= evalLabel(l1, visited, localValEnv);
            return boxHGroup(tree(l2),    eval(arg, visited, localValEnv) );

      } else if (isBoxTGroup(exp, label, arg)) {
            const char* l1 = tree2str(label);
            const char* l2= evalLabel(l1, visited, localValEnv);
            return boxTGroup(tree(l2),    eval(arg, visited, localValEnv) );

      } else if (isBoxHBargraph(exp, label, lo, hi)) {
            const char* l1 = tree2str(label);
            const char* l2= evalLabel(l1, visited, localValEnv);
            return boxHBargraph(tree(l2),
                              tree(eval2double(lo, visited, localValEnv)),
                              tree(eval2double(hi, visited, localValEnv)));

      } else if (isBoxVBargraph(exp, label, lo, hi)) {
            const char* l1 = tree2str(label);
            const char* l2= evalLabel(l1, visited, localValEnv);
            return boxVBargraph(tree(l2),
                              tree(eval2double(lo, visited, localValEnv)),
                              tree(eval2double(hi, visited, localValEnv)));

      // lambda calculus
      //----------------
            
      } else if (isBoxIdent(exp)) {
            return evalIdDef(exp, visited, localValEnv);

      } else if (isBoxWithLocalDef(exp, body, ldef)) {
            return eval(body, visited, pushMultiClosureDefs(ldef, visited, localValEnv));
      
      } else if (isBoxAppl(exp, fun, arg)) {
            return applyList( eval(fun, visited, localValEnv),
                                          revEvalList(arg, visited, localValEnv) );

    } else if (isBoxAbstr(exp)) {
        // it is an abstraction : return a closure
        return closure(exp, nil, visited, localValEnv);

    } else if (isBoxEnvironment(exp)) {
        // environment : return also a closure
        return closure(exp, nil, visited, localValEnv);

      } else if (isClosure(exp, exp2, notused, visited2, lenv2)) {

        if (isBoxAbstr(exp2)) {
            // a 'real' closure
            return closure(exp2, nil, setUnion(visited,visited2), lenv2);
        } else if (isBoxEnvironment(exp2)) {
            // a 'real' closure
            return closure(exp2, nil, setUnion(visited,visited2), lenv2);
        } else {
                  // it was a suspended evaluation
                  return eval(exp2, setUnion(visited,visited2), lenv2);
            }

      // Algorithmic constructions
      //--------------------------
      
      } else if (isBoxIPar(exp, var, num, body)) {
            int n = eval2int(num, visited, localValEnv);
            return iteratePar(var, n, body, visited, localValEnv);

      } else if (isBoxISeq(exp, var, num, body)) {
            int n = eval2int(num, visited, localValEnv);
            return iterateSeq(var, n, body, visited, localValEnv);

      } else if (isBoxISum(exp, var, num, body)) {
            int n = eval2int(num, visited, localValEnv);
            return iterateSum(var, n, body, visited, localValEnv);

      } else if (isBoxIProd(exp, var, num, body)) {
            int n = eval2int(num, visited, localValEnv);
            return iterateProd(var, n, body, visited, localValEnv);
            
      } else if (isBoxSlot(exp))          { 
            return exp; 
      
      } else if (isBoxSymbolic(exp))      {
       
            return exp;
      

      // Pattern matching extension
      //---------------------------
      
      } else if (isBoxCase(exp, rules)) {
            return evalCase(rules, localValEnv);

      } else if (isBoxPatternVar(exp, id)) {
            return exp;
            //return evalIdDef(id, visited, localValEnv);

      } else if (isBoxPatternMatcher(exp)) {
            return exp;

      } else {
            cerr << "ERROR : EVAL don't intercept : " << *exp << endl;
            assert(false);
      }
}


Generated by  Doxygen 1.6.0   Back to index