~ubuntu-branches/ubuntu/saucy/faust/saucy

« back to all changes in this revision

Viewing changes to compiler/boxes/boxes.cpp

  • Committer: Package Import Robot
  • Author(s): Mario Lang
  • Date: 2012-04-04 13:52:01 UTC
  • mfrom: (1.1.6) (3.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120404135201-hpsrk87x3hga94tc
Tags: 0.9.46-2
* Fix "ftbfs with GCC-4.7":
  - debian/patches/unistd: Include <unistd.h> where necessary.
    (Closes: #667163)

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
#include "boxes.hh"
47
47
#include "ppbox.hh"
48
48
#include "prim2.hh"
 
49
#include "xtended.hh"
49
50
 
50
51
 
51
52
/*****************************************************************************
382
383
        }
383
384
}
384
385
 
385
 
 
386
 
 
387
386
Sym BOXNUMENTRY = symbol ("BoxNumEntry");
388
387
Tree boxNumEntry   (Tree lbl, Tree cur, Tree min, Tree max, Tree step)
389
388
                                                                                        { return tree(BOXNUMENTRY, lbl, list4(cur,min,max,step));               }
442
441
Sym BOXPATMATCHER       = symbol ("BoxPatMatcher");
443
442
Sym BOXPATVAR           = symbol ("BoxPatVar");
444
443
 
445
 
Tree boxCase     (Tree rules)                           { return tree(BOXCASE, rules);                                  }
 
444
/**
 
445
 * Prepare a "pattern" by replacing variables x by special
 
446
 * pattern variables ?x.
 
447
 *
 
448
 * P[x]     -> ?x
 
449
 * P[x(e)]  -> x(P[e])
 
450
 * P[e(f)]  -> P[e](P[f])
 
451
 * P[e:f]   -> P[e]:P[f]
 
452
 * etc.
 
453
 */
 
454
static Tree preparePattern(Tree box)
 
455
{
 
456
//    cerr << "preparePattern(" << boxpp(box) << ")" << endl;
 
457
 
 
458
        int             id;
 
459
        double  r;
 
460
        prim0   p0;
 
461
        prim1   p1;
 
462
        prim2   p2;
 
463
        prim3   p3;
 
464
        prim4   p4;
 
465
        prim5   p5;
 
466
 
 
467
        Tree    t1, t2, t3, ff, label, cur, min, max, step, type, name, file, arg,
 
468
                body, fun, args, ldef, slot,
 
469
                ident, rules;
 
470
 
 
471
        xtended* xt = (xtended*) getUserData(box);
 
472
 
 
473
 
 
474
        // primitive elements
 
475
             if (xt)                                            return box;
 
476
        else if (isBoxIdent(box))           return boxPatternVar(box);
 
477
        else if (isBoxAppl(box, fun, args))     {
 
478
                if (isBoxIdent(fun))        return boxAppl( fun, lmap(preparePattern,args));
 
479
                else                        return boxAppl( preparePattern(fun), lmap(preparePattern,args));
 
480
            }
 
481
        else if (isBoxAbstr(box,arg,body))      return box;
 
482
        else if (isBoxInt(box))             return box;
 
483
        else if (isBoxReal(box, &r))            return box;
 
484
        else if (isBoxCut(box))                         return box;
 
485
        else if (isBoxWire(box))                        return box;
 
486
        else if (isBoxPrim0(box, &p0))          return box;
 
487
        else if (isBoxPrim1(box, &p1))          return box;
 
488
        else if (isBoxPrim2(box, &p2))          return box;
 
489
        else if (isBoxPrim3(box, &p3))          return box;
 
490
        else if (isBoxPrim4(box, &p4))          return box;
 
491
        else if (isBoxPrim5(box, &p5))          return box;
 
492
 
 
493
        else if (isBoxWithLocalDef(box, body, ldef))    return boxWithLocalDef(preparePattern(body), ldef);
 
494
 
 
495
 
 
496
        // foreign elements
 
497
        else if (isBoxFFun(box, ff))            return box;
 
498
        else if (isBoxFConst(box, type, name, file))
 
499
                                            return box;
 
500
        else if (isBoxFVar(box, type, name, file))
 
501
                                            return box;
 
502
 
 
503
        // block diagram binary operator
 
504
        else if (isBoxSeq(box, t1, t2))         return boxSeq( preparePattern(t1), preparePattern(t2) );
 
505
        else if (isBoxSplit(box, t1, t2))       return boxSplit( preparePattern(t1), preparePattern(t2) );
 
506
        else if (isBoxMerge(box, t1, t2))       return boxMerge( preparePattern(t1), preparePattern(t2) );
 
507
        else if (isBoxPar(box, t1, t2))         return boxPar( preparePattern(t1), preparePattern(t2) );
 
508
        else if (isBoxRec(box, t1, t2))         return boxRec( preparePattern(t1), preparePattern(t2) );
 
509
 
 
510
        // iterative block diagram construction
 
511
        else if (isBoxIPar(box, t1, t2, t3))    return boxIPar ( t1, t2, preparePattern(t3) );
 
512
        else if (isBoxISeq(box, t1, t2, t3))    return boxISeq ( t1, t2, preparePattern(t3) );
 
513
        else if (isBoxISum(box, t1, t2, t3))    return boxISum ( t1, t2, preparePattern(t3) );
 
514
        else if (isBoxIProd(box, t1, t2, t3))   return boxIProd( t1, t2, preparePattern(t3) );
 
515
 
 
516
        // user interface
 
517
        else if (isBoxButton(box, label))       return box;
 
518
        else if (isBoxCheckbox(box, label))     return box;
 
519
 
 
520
        else if (isBoxVSlider(box, label, cur, min, max, step))         return box;
 
521
        else if (isBoxHSlider(box, label, cur, min, max, step))         return box;
 
522
 
 
523
        else if (isBoxVGroup(box, label, t1))   return boxVGroup(label, preparePattern(t1));
 
524
        else if (isBoxHGroup(box, label, t1))   return boxHGroup(label, preparePattern(t1));
 
525
        else if (isBoxTGroup(box, label, t1))   return boxTGroup(label, preparePattern(t1));
 
526
 
 
527
        else if (isBoxHBargraph(box, label, min, max))              return box;
 
528
        else if (isBoxVBargraph(box, label, min, max))              return box;
 
529
        else if (isBoxNumEntry(box, label, cur, min, max, step))    return box;
 
530
 
 
531
        else if (isNil(box))                    return box;
 
532
        else if (isList(box))                   return lmap(preparePattern, box);
 
533
        else if (isBoxEnvironment(box))         return box;
 
534
        /* not expected
 
535
        else if (isClosure(box, abstr, genv, vis, lenv)) {
 
536
            fout << "closure[" << boxpp(abstr)
 
537
                << ", genv = " << envpp(genv)
 
538
                << ", lenv = " << envpp(lenv)
 
539
                << "]";
 
540
        }
 
541
        */
 
542
        else if (isBoxComponent(box, label))        return box;
 
543
        else if (isBoxAccess(box, t1, t2))          return box;
 
544
 
 
545
        /* not expected
 
546
        else if (isImportFile(box, label)) {
 
547
            fout << "import("
 
548
                << tree2str(label) << ')';
 
549
        }
 
550
        */
 
551
 
 
552
 
 
553
        else if (isBoxSlot(box, &id))               return box;
 
554
        else if (isBoxSymbolic(box, slot, body))    return box;
 
555
 
 
556
        // Pattern Matching Extensions
 
557
        else if (isBoxCase(box, rules))             return box;
 
558
        else if (isBoxPatternVar(box, ident))       return box;
 
559
 
 
560
 
 
561
        // None of the previous tests succeded, then it is not a valid box
 
562
        else {
 
563
            cerr << "Error in preparePattern() : " << *box << " is not a valid box" << endl;
 
564
            exit(1);
 
565
        }
 
566
 
 
567
 
 
568
   return box;
 
569
}
 
570
 
 
571
static Tree prepareRule(Tree rule)
 
572
{
 
573
    return cons (lmap(preparePattern,hd(rule)), tl(rule));
 
574
}
 
575
 
 
576
static Tree prepareRules(Tree rules) {
 
577
    return lmap(prepareRule, rules);
 
578
}
 
579
 
 
580
Tree boxCaseInternal     (Tree rules)       { return tree(BOXCASE, rules);                                      }
 
581
Tree boxCase    (Tree rules)                            { return boxCaseInternal(prepareRules(rules));  }
 
582
 
446
583
bool isBoxCase (Tree s)                                         { Tree rules; return isTree(s, BOXCASE, rules); }
447
584
bool isBoxCase (Tree s, Tree& rules)            { return isTree(s, BOXCASE, rules);                             }
448
585
 
 
586
 
449
587
Tree boxPatternVar      (Tree id)                               { return tree(BOXPATVAR, id);                                   }
450
588
bool isBoxPatternVar(Tree s, Tree& id)          { return isTree(s, BOXPATVAR, id);                              }
451
589