00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00044 #include <stdio.h>
00045 #include <string.h>
00046 #include "boxes.hh"
00047 #include "ppbox.hh"
00048 #include "prim2.hh"
00049
00050
00051
00052
00053
00054 Sym BOXIDENT = symbol ("BoxIdent");
00055
00056 Tree boxIdent(const char* name) { return tree(BOXIDENT, tree(symbol(name)) ); }
00057 bool isBoxIdent(Tree t) { return t->node() == Node(BOXIDENT); }
00058 bool isBoxIdent(Tree t0, const char** str)
00059 {
00060 Tree t1; Sym s;
00061 if ( isTree(t0, BOXIDENT, t1) && isSym(t1->node(), &s) ) {
00062 *str = name(s);
00063 return true;
00064 } else {
00065 return false;
00066 }
00067 }
00068
00069
00070
00071
00072
00073
00074 Tree boxInt(int n) { return tree(n); }
00075 Tree boxReal(double n) { return tree(n); }
00076
00077 bool isBoxInt(Tree t) { return isInt(t->node()); }
00078 bool isBoxReal(Tree t) { return isDouble(t->node()); }
00079
00080 bool isBoxInt(Tree t, int* i) { return isInt(t->node(), i); }
00081 bool isBoxReal(Tree t, double* r) { return isDouble(t->node(), r); }
00082
00083
00084
00085
00086
00087
00088 Sym BOXCUT = symbol ("BoxCut");
00089 Tree boxCut() { return tree(BOXCUT); }
00090 bool isBoxCut(Tree t) { return isTree(t, BOXCUT); }
00091
00092 Sym BOXWIRE = symbol ("BoxWire");
00093 Tree boxWire() { return tree(BOXWIRE); }
00094 bool isBoxWire(Tree t) { return isTree(t, BOXWIRE); }
00095
00096
00097
00098
00099
00100
00101 Sym BOXSLOT = symbol ("BoxSlot");
00102
00103 Tree boxSlot(int id) { return tree(BOXSLOT,tree(id)); }
00104 bool isBoxSlot(Tree t) { Tree w; return isTree(t, BOXSLOT,w); }
00105 bool isBoxSlot(Tree t, int* id) { Tree w; return isTree(t, BOXSLOT,w) && isInt(w->node(),id); }
00106
00107
00108 Sym BOXSYMBOLIC = symbol ("BoxSymbolic");
00109
00110 Tree boxSymbolic(Tree slot, Tree body) { return tree(BOXSYMBOLIC,slot, body); }
00111 bool isBoxSymbolic(Tree t) { Tree slot, body; return isTree(t, BOXSYMBOLIC, slot, body); }
00112 bool isBoxSymbolic(Tree t, Tree& slot, Tree& body) { return isTree(t, BOXSYMBOLIC, slot, body); }
00113
00114
00115
00116
00117
00118
00119 Sym BOXSEQ = symbol ("BoxSeq");
00120 Tree boxSeq(Tree x, Tree y) { return tree(BOXSEQ, x, y); }
00121 bool isBoxSeq(Tree t, Tree& x, Tree& y) { return isTree(t, BOXSEQ, x, y); }
00122
00123 Sym BOXPAR = symbol ("BoxPar");
00124 Tree boxPar(Tree x, Tree y) { return tree(BOXPAR, x, y); }
00125 bool isBoxPar(Tree t, Tree& x, Tree& y) { return isTree(t, BOXPAR, x, y); }
00126
00127 Sym BOXREC = symbol ("BoxRec");
00128 Tree boxRec(Tree x, Tree y) { return tree(BOXREC, x, y); }
00129 bool isBoxRec(Tree t, Tree& x, Tree& y) { return isTree(t, BOXREC, x, y); }
00130
00131 Sym BOXSPLIT = symbol ("BoxSplit");
00132 Tree boxSplit(Tree x, Tree y) { return tree(BOXSPLIT, x, y); }
00133 bool isBoxSplit(Tree t, Tree& x, Tree& y) { return isTree(t, BOXSPLIT, x, y); }
00134
00135 Sym BOXMERGE = symbol ("BoxMerge");
00136 Tree boxMerge(Tree x, Tree y) { return tree(BOXMERGE, x, y); }
00137 bool isBoxMerge(Tree t, Tree& x, Tree& y) { return isTree(t, BOXMERGE, x, y); }
00138
00139
00140
00141
00142
00143
00144 Sym BOXIPAR = symbol ("BoxIPar");
00145 Sym BOXISEQ = symbol ("BoxISeq");
00146 Sym BOXISUM = symbol ("BoxISum");
00147 Sym BOXIPROD = symbol ("BoxIProd");
00148
00149 Tree boxIPar(Tree x, Tree y, Tree z) { return tree(BOXIPAR, x, y, z); }
00150 Tree boxISeq(Tree x, Tree y, Tree z) { return tree(BOXISEQ, x, y, z); }
00151 Tree boxISum(Tree x, Tree y, Tree z) { return tree(BOXISUM, x, y, z); }
00152 Tree boxIProd(Tree x, Tree y, Tree z) { return tree(BOXIPROD, x, y, z); }
00153
00154 bool isBoxIPar(Tree t, Tree& x, Tree& y, Tree& z) { return isTree(t, BOXIPAR, x, y, z); }
00155 bool isBoxISeq(Tree t, Tree& x, Tree& y, Tree& z) { return isTree(t, BOXISEQ, x, y, z); }
00156 bool isBoxISum(Tree t, Tree& x, Tree& y, Tree& z) { return isTree(t, BOXISUM, x, y, z); }
00157 bool isBoxIProd(Tree t, Tree& x, Tree& y, Tree& z) { return isTree(t, BOXIPROD, x, y, z); }
00158
00159
00160
00161
00162
00163
00164 Sym BOXABSTR = symbol ("BoxAbstr");
00165 Sym BOXAPPL = symbol ("BoxAppl");
00166 Sym CLOSURE = symbol ("Closure");
00167 Sym BOXERROR = symbol ("BoxError");
00168 Sym BOXACCESS = symbol ("BoxAccess");
00169
00170 Tree boxAbstr (Tree x, Tree y) { return tree(BOXABSTR, x, y); }
00171 Tree boxAppl (Tree x, Tree y) { return tree(BOXAPPL, x, y); }
00172
00173 bool isBoxAbstr (Tree t) { return t->node() == Node(BOXABSTR); }
00174 bool isBoxAppl (Tree t) { return t->node() == Node(BOXAPPL); }
00175
00176 bool isBoxAbstr (Tree t, Tree& x, Tree& y) { return isTree(t, BOXABSTR, x, y); }
00177 bool isBoxAppl (Tree t, Tree& x, Tree& y) { return isTree(t, BOXAPPL, x, y); }
00178
00179 Tree buildBoxAbstr (Tree largs, Tree body)
00180 {
00181 if (isNil(largs)) {
00182 return body;
00183 } else {
00184 return buildBoxAbstr(tl(largs), boxAbstr(hd(largs), body));
00185 }
00186 }
00187 #if 0
00188 Tree buildBoxAppl (Tree fun, Tree revarglist)
00189 {
00190 if (isNil(revarglist)) {
00191 return fun;
00192 } else {
00193 return boxAppl(buildBoxAppl(fun, tl(revarglist)), hd(revarglist));
00194 }
00195 }
00196 #else
00197 Tree buildBoxAppl (Tree fun, Tree revarglist)
00198 {
00199 if (isNil (revarglist)) exit(1);
00200 return boxAppl(fun, revarglist);
00201 }
00202 #endif
00203
00204 Tree closure (Tree abstr, Tree genv, Tree vis, Tree lenv)
00205 {
00206 return tree(CLOSURE, abstr, genv, vis, lenv);
00207 }
00208
00209 bool isClosure (Tree t, Tree& abstr, Tree& genv, Tree& vis, Tree& lenv)
00210 {
00211 return isTree(t, CLOSURE, abstr, genv, vis, lenv);
00212 }
00213
00214 Tree boxError()
00215 {
00216 return tree(BOXERROR);
00217 }
00218
00219 bool isBoxError(Tree t)
00220 {
00221 return isTree(t, BOXERROR);
00222 }
00223
00224
00225 Tree boxAccess (Tree exp, Tree id) { return tree(BOXACCESS, exp, id); }
00226 bool isBoxAccess(Tree t, Tree& exp, Tree& id) { return isTree(t, BOXACCESS, exp, id); }
00227
00228
00229
00230
00231
00232 Sym BOXWITHLOCALDEF = symbol ("BoxWithLocalDef");
00233
00234 Tree boxWithLocalDef (Tree body, Tree ldef) { return tree(BOXWITHLOCALDEF, body, ldef); }
00235 bool isBoxWithLocalDef (Tree t, Tree& body, Tree& ldef) { return isTree(t, BOXWITHLOCALDEF, body, ldef); }
00236
00237
00238
00239
00240
00241
00242 Sym BOXENVIRONMENT = symbol ("BoxEnvironment");
00243
00244 Tree boxEnvironment () { return tree(BOXENVIRONMENT); }
00245 bool isBoxEnvironment (Tree s) { return isTree(s, BOXENVIRONMENT); }
00246
00247 Sym BOXCOMPONENT = symbol ("BoxComponent");
00248
00249 Tree boxComponent (Tree filename) { return tree(BOXCOMPONENT, filename); }
00250 bool isBoxComponent (Tree s, Tree& filename) { return isTree(s, BOXCOMPONENT, filename); }
00251
00252 Sym BOXLIBRARY = symbol ("BoxLibrary");
00253
00254 Tree boxLibrary (Tree filename) { return tree(BOXLIBRARY, filename); }
00255 bool isBoxLibrary (Tree s, Tree& filename) { return isTree(s, BOXLIBRARY, filename); }
00256
00257
00258 Sym IMPORTFILE = symbol ("ImportFile");
00259
00260 Tree importFile(Tree filename) { return tree(IMPORTFILE, filename); }
00261 bool isImportFile(Tree s, Tree& filename) { return isTree(s, IMPORTFILE, filename); }
00262
00263
00264
00265
00266
00267
00268 Sym BOXPRIM0 = symbol ("BoxPrim0");
00269 Tree boxPrim0(prim0 foo) { return tree(BOXPRIM0, tree((void*)foo)); }
00270 bool isBoxPrim0 (Tree s) { Tree t; return isTree(s, BOXPRIM0, t); }
00271 bool isBoxPrim0 (Tree s, prim0* p) { Tree t; return isTree(s, BOXPRIM0, t) && isPointer(t->node(),(void**)p); }
00272
00273 Sym BOXPRIM1 = symbol ("BoxPrim1");
00274 Tree boxPrim1(prim1 foo) { return tree(BOXPRIM1, tree((void*)foo)); }
00275 bool isBoxPrim1 (Tree s) { Tree t; return isTree(s, BOXPRIM1, t); }
00276 bool isBoxPrim1 (Tree s, prim1* p) { Tree t; return isTree(s, BOXPRIM1, t) && isPointer(t->node(),(void**)p); }
00277
00278 Sym BOXPRIM2 = symbol ("BoxPrim2");
00279 Tree boxPrim2(prim2 foo) { return tree(BOXPRIM2, tree((void*)foo)); }
00280 bool isBoxPrim2 (Tree s) { Tree t; return isTree(s, BOXPRIM2, t); }
00281 bool isBoxPrim2 (Tree s, prim2* p) { Tree t; return isTree(s, BOXPRIM2, t) && isPointer(t->node(),(void**)p); }
00282
00283 Sym BOXPRIM3 = symbol ("BoxPrim3");
00284 Tree boxPrim3(prim3 foo) { return tree(BOXPRIM3, tree((void*)foo)); }
00285 bool isBoxPrim3 (Tree s) { Tree t; return isTree(s, BOXPRIM3, t); }
00286 bool isBoxPrim3 (Tree s, prim3* p) { Tree t; return isTree(s, BOXPRIM3, t) && isPointer(t->node(),(void**)p); }
00287
00288 Sym BOXPRIM4 = symbol ("BoxPrim4");
00289 Tree boxPrim4(prim4 foo) { return tree(BOXPRIM4, tree((void*)foo)); }
00290 bool isBoxPrim4 (Tree s) { Tree t; return isTree(s, BOXPRIM4, t); }
00291 bool isBoxPrim4 (Tree s, prim4* p) { Tree t; return isTree(s, BOXPRIM4, t) && isPointer(t->node(),(void**)p); }
00292
00293 Sym BOXPRIM5 = symbol ("BoxPrim5");
00294 Tree boxPrim5(prim5 foo) { return tree(BOXPRIM5, tree((void*)foo)); }
00295 bool isBoxPrim5 (Tree s) { Tree t; return isTree(s, BOXPRIM5, t); }
00296 bool isBoxPrim5 (Tree s, prim5* p) { Tree t; return isTree(s, BOXPRIM5, t) && isPointer(t->node(),(void**)p); }
00297
00298
00299
00300
00301
00302 Sym BOXFFUN = symbol ("BoxFFun");
00303 Tree boxFFun (Tree ff) { return tree(BOXFFUN, ff); }
00304 bool isBoxFFun (Tree s) { Tree ff; return isTree(s, BOXFFUN, ff); }
00305 bool isBoxFFun (Tree s, Tree& ff) { return isTree(s, BOXFFUN, ff); }
00306
00307
00308 Sym BOXFCONST = symbol ("BoxFConst");
00309 Tree boxFConst (Tree type, Tree name, Tree file) { return tree(BOXFCONST, type, name, file); }
00310 bool isBoxFConst (Tree s) { Tree t,n,f; return isTree(s, BOXFCONST, t, n, f); }
00311 bool isBoxFConst (Tree s, Tree& type, Tree& name, Tree& file) { return isTree(s, BOXFCONST,type, name, file); }
00312
00313
00314 Sym BOXFVAR = symbol ("BoxFVar");
00315 Tree boxFVar (Tree type, Tree name, Tree file) { return tree(BOXFVAR, type, name, file); }
00316 bool isBoxFVar (Tree s) { Tree t,n,f; return isTree(s, BOXFVAR, t, n, f); }
00317 bool isBoxFVar (Tree s, Tree& type, Tree& name, Tree& file) { return isTree(s, BOXFVAR,type, name, file); }
00318
00319
00320
00321
00322
00323
00324 Sym BOXBUTTON = symbol ("BoxButton");
00325 Tree boxButton (Tree lbl) { return tree(BOXBUTTON, lbl); }
00326 bool isBoxButton (Tree s) { Tree lbl; return isTree(s, BOXBUTTON, lbl); }
00327 bool isBoxButton (Tree s, Tree& lbl) { return isTree(s, BOXBUTTON, lbl); }
00328
00329
00330 Sym BOXCHECKBOX = symbol ("BoxCheckbox");
00331 Tree boxCheckbox (Tree lbl) { return tree(BOXCHECKBOX, lbl); }
00332 bool isBoxCheckbox (Tree s) { Tree lbl; return isTree(s, BOXCHECKBOX, lbl); }
00333 bool isBoxCheckbox (Tree s, Tree& lbl) { return isTree(s, BOXCHECKBOX, lbl); }
00334
00335
00336 Sym BOXHSLIDER = symbol ("BoxHSlider");
00337 Tree boxHSlider (Tree lbl, Tree cur, Tree min, Tree max, Tree step)
00338 { return tree(BOXHSLIDER, lbl, list4(cur,min,max,step)); }
00339 bool isBoxHSlider (Tree s) { Tree lbl, params; return isTree(s, BOXHSLIDER, lbl, params); }
00340
00341 bool isBoxHSlider (Tree s, Tree& lbl, Tree& cur, Tree& min, Tree& max, Tree& step)
00342 {
00343 Tree params;
00344 if (isTree(s, BOXHSLIDER, lbl, params)) {
00345 cur = nth(params, 0);
00346 min = nth(params, 1);
00347 max = nth(params, 2);
00348 step= nth(params, 3);
00349 return true;
00350 } else {
00351 return false;
00352 }
00353 }
00354
00355
00356 Sym BOXVSLIDER = symbol ("BoxVSlider");
00357 Tree boxVSlider (Tree lbl, Tree cur, Tree min, Tree max, Tree step)
00358 { return tree(BOXVSLIDER, lbl, list4(cur,min,max,step)); }
00359 bool isBoxVSlider (Tree s) { Tree lbl, params; return isTree(s, BOXVSLIDER, lbl, params); }
00360
00361 bool isBoxVSlider (Tree s, Tree& lbl, Tree& cur, Tree& min, Tree& max, Tree& step)
00362 {
00363 Tree params;
00364 if (isTree(s, BOXVSLIDER, lbl, params)) {
00365 cur = nth(params, 0);
00366 min = nth(params, 1);
00367 max = nth(params, 2);
00368 step= nth(params, 3);
00369 return true;
00370 } else {
00371 return false;
00372 }
00373 }
00374
00375
00376
00377 Sym BOXNUMENTRY = symbol ("BoxNumEntry");
00378 Tree boxNumEntry (Tree lbl, Tree cur, Tree min, Tree max, Tree step)
00379 { return tree(BOXNUMENTRY, lbl, list4(cur,min,max,step)); }
00380 bool isBoxNumEntry (Tree s) { Tree lbl, params; return isTree(s, BOXNUMENTRY, lbl, params); }
00381
00382 bool isBoxNumEntry (Tree s, Tree& lbl, Tree& cur, Tree& min, Tree& max, Tree& step)
00383 {
00384 Tree params;
00385 if (isTree(s, BOXNUMENTRY, lbl, params)) {
00386 cur = nth(params, 0);
00387 min = nth(params, 1);
00388 max = nth(params, 2);
00389 step= nth(params, 3);
00390 return true;
00391 } else {
00392 return false;
00393 }
00394 }
00395
00396
00397 Sym BOXHGROUP = symbol ("BoxHGroup");
00398 Tree boxHGroup (Tree lbl, Tree x) { return tree(BOXHGROUP, lbl, x); }
00399 bool isBoxHGroup (Tree s) { Tree lbl, x; return isTree(s, BOXHGROUP, lbl, x); }
00400 bool isBoxHGroup (Tree s, Tree& lbl, Tree& x) { return isTree(s, BOXHGROUP, lbl, x); }
00401
00402
00403 Sym BOXVGROUP = symbol ("BoxVGroup");
00404 Tree boxVGroup (Tree lbl, Tree x) { return tree(BOXVGROUP, lbl, x); }
00405 bool isBoxVGroup (Tree s) { Tree lbl, x; return isTree(s, BOXVGROUP, lbl, x); }
00406 bool isBoxVGroup (Tree s, Tree& lbl, Tree& x) { return isTree(s, BOXVGROUP, lbl, x); }
00407
00408
00409 Sym BOXTGROUP = symbol ("BoxTGroup");
00410 Tree boxTGroup (Tree lbl, Tree x) { return tree(BOXTGROUP, lbl, x); }
00411 bool isBoxTGroup (Tree s) { Tree lbl, x; return isTree(s, BOXTGROUP, lbl, x); }
00412 bool isBoxTGroup (Tree s, Tree& lbl, Tree& x) { return isTree(s, BOXTGROUP, lbl, x); }
00413
00414
00415 Sym BOXHBARGRAPH = symbol ("BoxHBargraph");
00416 Tree boxHBargraph(Tree lbl, Tree min, Tree max) { return tree(BOXHBARGRAPH, lbl, min, max); }
00417 bool isBoxHBargraph (Tree s) { Tree lbl, min, max; return isTree(s, BOXHBARGRAPH, lbl, min, max); }
00418 bool isBoxHBargraph (Tree s, Tree& lbl, Tree& min, Tree& max) { return isTree(s, BOXHBARGRAPH, lbl, min, max); }
00419
00420
00421 Sym BOXVBARGRAPH = symbol ("BoxVBargraph");
00422 Tree boxVBargraph(Tree lbl, Tree min, Tree max) { return tree(BOXVBARGRAPH, lbl, min, max); }
00423 bool isBoxVBargraph (Tree s) { Tree lbl, min, max; return isTree(s, BOXVBARGRAPH, lbl, min, max); }
00424 bool isBoxVBargraph (Tree s, Tree& lbl, Tree& min, Tree& max) { return isTree(s, BOXVBARGRAPH, lbl, min, max); }
00425
00426
00427
00428
00429
00430
00431 Sym BOXCASE = symbol ("BoxCase");
00432 Sym BOXPATMATCHER = symbol ("BoxPatMatcher");
00433 Sym BOXPATVAR = symbol ("BoxPatVar");
00434
00435 Tree boxCase (Tree rules) { return tree(BOXCASE, rules); }
00436 bool isBoxCase (Tree s) { Tree rules; return isTree(s, BOXCASE, rules); }
00437 bool isBoxCase (Tree s, Tree& rules) { return isTree(s, BOXCASE, rules); }
00438
00439 Tree boxPatternVar (Tree id) { return tree(BOXPATVAR, id); }
00440 bool isBoxPatternVar(Tree s, Tree& id) { return isTree(s, BOXPATVAR, id); }
00441
00442
00443 Tree boxPatternMatcher (Automaton* a, int state, Tree env, Tree origRules, Tree revParamList)
00444 {
00445 return tree(BOXPATMATCHER, tree((void*)a), tree(state), env, origRules, revParamList);
00446 }
00447
00448 bool isBoxPatternMatcher (Tree s)
00449 {
00450 Tree ta, ts, env, orig, rpl;
00451 return isTree(s, BOXPATMATCHER, ta, ts, env, orig, rpl);
00452 }
00453
00454 bool isBoxPatternMatcher (Tree s, Automaton*& a, int& state, Tree& env, Tree& origRules, Tree& revParamList)
00455 {
00456 Tree ta, ts;
00457 if (isTree(s, BOXPATMATCHER, ta, ts, env, origRules, revParamList)) {
00458 a = (Automaton*)tree2ptr(ta);
00459 state = tree2int(ts);
00460 return true;
00461 } else {
00462 return false;
00463 }
00464 }
00465
00466