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 Sym BOXMODIFLOCALDEF = symbol ("BoxModifLocalDef");
00242
00243
00244 Tree boxModifLocalDef (Tree body, Tree ldef) { return tree(BOXMODIFLOCALDEF, body, ldef); }
00245 bool isBoxModifLocalDef (Tree t, Tree& body, Tree& ldef) { return isTree(t, BOXMODIFLOCALDEF, body, ldef); }
00246
00247
00248
00249
00250
00251
00252 Sym BOXENVIRONMENT = symbol ("BoxEnvironment");
00253
00254 Tree boxEnvironment () { return tree(BOXENVIRONMENT); }
00255 bool isBoxEnvironment (Tree s) { return isTree(s, BOXENVIRONMENT); }
00256
00257 Sym BOXCOMPONENT = symbol ("BoxComponent");
00258
00259 Tree boxComponent (Tree filename) { return tree(BOXCOMPONENT, filename); }
00260 bool isBoxComponent (Tree s, Tree& filename) { return isTree(s, BOXCOMPONENT, filename); }
00261
00262 Sym BOXLIBRARY = symbol ("BoxLibrary");
00263
00264 Tree boxLibrary (Tree filename) { return tree(BOXLIBRARY, filename); }
00265 bool isBoxLibrary (Tree s, Tree& filename) { return isTree(s, BOXLIBRARY, filename); }
00266
00267
00268 Sym IMPORTFILE = symbol ("ImportFile");
00269
00270 Tree importFile(Tree filename) { return tree(IMPORTFILE, filename); }
00271 bool isImportFile(Tree s, Tree& filename) { return isTree(s, IMPORTFILE, filename); }
00272
00273
00274
00275
00276
00277
00278 Sym BOXPRIM0 = symbol ("BoxPrim0");
00279 Tree boxPrim0(prim0 foo) { return tree(BOXPRIM0, tree((void*)foo)); }
00280 bool isBoxPrim0 (Tree s) { Tree t; return isTree(s, BOXPRIM0, t); }
00281 bool isBoxPrim0 (Tree s, prim0* p) { Tree t; return isTree(s, BOXPRIM0, t) && isPointer(t->node(),(void**)p); }
00282
00283 Sym BOXPRIM1 = symbol ("BoxPrim1");
00284 Tree boxPrim1(prim1 foo) { return tree(BOXPRIM1, tree((void*)foo)); }
00285 bool isBoxPrim1 (Tree s) { Tree t; return isTree(s, BOXPRIM1, t); }
00286 bool isBoxPrim1 (Tree s, prim1* p) { Tree t; return isTree(s, BOXPRIM1, t) && isPointer(t->node(),(void**)p); }
00287
00288 Sym BOXPRIM2 = symbol ("BoxPrim2");
00289 Tree boxPrim2(prim2 foo) { return tree(BOXPRIM2, tree((void*)foo)); }
00290 bool isBoxPrim2 (Tree s) { Tree t; return isTree(s, BOXPRIM2, t); }
00291 bool isBoxPrim2 (Tree s, prim2* p) { Tree t; return isTree(s, BOXPRIM2, t) && isPointer(t->node(),(void**)p); }
00292
00293 Sym BOXPRIM3 = symbol ("BoxPrim3");
00294 Tree boxPrim3(prim3 foo) { return tree(BOXPRIM3, tree((void*)foo)); }
00295 bool isBoxPrim3 (Tree s) { Tree t; return isTree(s, BOXPRIM3, t); }
00296 bool isBoxPrim3 (Tree s, prim3* p) { Tree t; return isTree(s, BOXPRIM3, t) && isPointer(t->node(),(void**)p); }
00297
00298 Sym BOXPRIM4 = symbol ("BoxPrim4");
00299 Tree boxPrim4(prim4 foo) { return tree(BOXPRIM4, tree((void*)foo)); }
00300 bool isBoxPrim4 (Tree s) { Tree t; return isTree(s, BOXPRIM4, t); }
00301 bool isBoxPrim4 (Tree s, prim4* p) { Tree t; return isTree(s, BOXPRIM4, t) && isPointer(t->node(),(void**)p); }
00302
00303 Sym BOXPRIM5 = symbol ("BoxPrim5");
00304 Tree boxPrim5(prim5 foo) { return tree(BOXPRIM5, tree((void*)foo)); }
00305 bool isBoxPrim5 (Tree s) { Tree t; return isTree(s, BOXPRIM5, t); }
00306 bool isBoxPrim5 (Tree s, prim5* p) { Tree t; return isTree(s, BOXPRIM5, t) && isPointer(t->node(),(void**)p); }
00307
00308
00309
00310
00311
00312 Sym BOXFFUN = symbol ("BoxFFun");
00313 Tree boxFFun (Tree ff) { return tree(BOXFFUN, ff); }
00314 bool isBoxFFun (Tree s) { Tree ff; return isTree(s, BOXFFUN, ff); }
00315 bool isBoxFFun (Tree s, Tree& ff) { return isTree(s, BOXFFUN, ff); }
00316
00317
00318 Sym BOXFCONST = symbol ("BoxFConst");
00319 Tree boxFConst (Tree type, Tree name, Tree file) { return tree(BOXFCONST, type, name, file); }
00320 bool isBoxFConst (Tree s) { Tree t,n,f; return isTree(s, BOXFCONST, t, n, f); }
00321 bool isBoxFConst (Tree s, Tree& type, Tree& name, Tree& file) { return isTree(s, BOXFCONST,type, name, file); }
00322
00323
00324 Sym BOXFVAR = symbol ("BoxFVar");
00325 Tree boxFVar (Tree type, Tree name, Tree file) { return tree(BOXFVAR, type, name, file); }
00326 bool isBoxFVar (Tree s) { Tree t,n,f; return isTree(s, BOXFVAR, t, n, f); }
00327 bool isBoxFVar (Tree s, Tree& type, Tree& name, Tree& file) { return isTree(s, BOXFVAR,type, name, file); }
00328
00329
00330
00331
00332
00333
00334 Sym BOXBUTTON = symbol ("BoxButton");
00335 Tree boxButton (Tree lbl) { return tree(BOXBUTTON, lbl); }
00336 bool isBoxButton (Tree s) { Tree lbl; return isTree(s, BOXBUTTON, lbl); }
00337 bool isBoxButton (Tree s, Tree& lbl) { return isTree(s, BOXBUTTON, lbl); }
00338
00339
00340 Sym BOXCHECKBOX = symbol ("BoxCheckbox");
00341 Tree boxCheckbox (Tree lbl) { return tree(BOXCHECKBOX, lbl); }
00342 bool isBoxCheckbox (Tree s) { Tree lbl; return isTree(s, BOXCHECKBOX, lbl); }
00343 bool isBoxCheckbox (Tree s, Tree& lbl) { return isTree(s, BOXCHECKBOX, lbl); }
00344
00345
00346 Sym BOXHSLIDER = symbol ("BoxHSlider");
00347 Tree boxHSlider (Tree lbl, Tree cur, Tree min, Tree max, Tree step)
00348 { return tree(BOXHSLIDER, lbl, list4(cur,min,max,step)); }
00349 bool isBoxHSlider (Tree s) { Tree lbl, params; return isTree(s, BOXHSLIDER, lbl, params); }
00350
00351 bool isBoxHSlider (Tree s, Tree& lbl, Tree& cur, Tree& min, Tree& max, Tree& step)
00352 {
00353 Tree params;
00354 if (isTree(s, BOXHSLIDER, lbl, params)) {
00355 cur = nth(params, 0);
00356 min = nth(params, 1);
00357 max = nth(params, 2);
00358 step= nth(params, 3);
00359 return true;
00360 } else {
00361 return false;
00362 }
00363 }
00364
00365
00366 Sym BOXVSLIDER = symbol ("BoxVSlider");
00367 Tree boxVSlider (Tree lbl, Tree cur, Tree min, Tree max, Tree step)
00368 { return tree(BOXVSLIDER, lbl, list4(cur,min,max,step)); }
00369 bool isBoxVSlider (Tree s) { Tree lbl, params; return isTree(s, BOXVSLIDER, lbl, params); }
00370
00371 bool isBoxVSlider (Tree s, Tree& lbl, Tree& cur, Tree& min, Tree& max, Tree& step)
00372 {
00373 Tree params;
00374 if (isTree(s, BOXVSLIDER, lbl, params)) {
00375 cur = nth(params, 0);
00376 min = nth(params, 1);
00377 max = nth(params, 2);
00378 step= nth(params, 3);
00379 return true;
00380 } else {
00381 return false;
00382 }
00383 }
00384
00385
00386
00387 Sym BOXNUMENTRY = symbol ("BoxNumEntry");
00388 Tree boxNumEntry (Tree lbl, Tree cur, Tree min, Tree max, Tree step)
00389 { return tree(BOXNUMENTRY, lbl, list4(cur,min,max,step)); }
00390 bool isBoxNumEntry (Tree s) { Tree lbl, params; return isTree(s, BOXNUMENTRY, lbl, params); }
00391
00392 bool isBoxNumEntry (Tree s, Tree& lbl, Tree& cur, Tree& min, Tree& max, Tree& step)
00393 {
00394 Tree params;
00395 if (isTree(s, BOXNUMENTRY, lbl, params)) {
00396 cur = nth(params, 0);
00397 min = nth(params, 1);
00398 max = nth(params, 2);
00399 step= nth(params, 3);
00400 return true;
00401 } else {
00402 return false;
00403 }
00404 }
00405
00406
00407 Sym BOXHGROUP = symbol ("BoxHGroup");
00408 Tree boxHGroup (Tree lbl, Tree x) { return tree(BOXHGROUP, lbl, x); }
00409 bool isBoxHGroup (Tree s) { Tree lbl, x; return isTree(s, BOXHGROUP, lbl, x); }
00410 bool isBoxHGroup (Tree s, Tree& lbl, Tree& x) { return isTree(s, BOXHGROUP, lbl, x); }
00411
00412
00413 Sym BOXVGROUP = symbol ("BoxVGroup");
00414 Tree boxVGroup (Tree lbl, Tree x) { return tree(BOXVGROUP, lbl, x); }
00415 bool isBoxVGroup (Tree s) { Tree lbl, x; return isTree(s, BOXVGROUP, lbl, x); }
00416 bool isBoxVGroup (Tree s, Tree& lbl, Tree& x) { return isTree(s, BOXVGROUP, lbl, x); }
00417
00418
00419 Sym BOXTGROUP = symbol ("BoxTGroup");
00420 Tree boxTGroup (Tree lbl, Tree x) { return tree(BOXTGROUP, lbl, x); }
00421 bool isBoxTGroup (Tree s) { Tree lbl, x; return isTree(s, BOXTGROUP, lbl, x); }
00422 bool isBoxTGroup (Tree s, Tree& lbl, Tree& x) { return isTree(s, BOXTGROUP, lbl, x); }
00423
00424
00425 Sym BOXHBARGRAPH = symbol ("BoxHBargraph");
00426 Tree boxHBargraph(Tree lbl, Tree min, Tree max) { return tree(BOXHBARGRAPH, lbl, min, max); }
00427 bool isBoxHBargraph (Tree s) { Tree lbl, min, max; return isTree(s, BOXHBARGRAPH, lbl, min, max); }
00428 bool isBoxHBargraph (Tree s, Tree& lbl, Tree& min, Tree& max) { return isTree(s, BOXHBARGRAPH, lbl, min, max); }
00429
00430
00431 Sym BOXVBARGRAPH = symbol ("BoxVBargraph");
00432 Tree boxVBargraph(Tree lbl, Tree min, Tree max) { return tree(BOXVBARGRAPH, lbl, min, max); }
00433 bool isBoxVBargraph (Tree s) { Tree lbl, min, max; return isTree(s, BOXVBARGRAPH, lbl, min, max); }
00434 bool isBoxVBargraph (Tree s, Tree& lbl, Tree& min, Tree& max) { return isTree(s, BOXVBARGRAPH, lbl, min, max); }
00435
00436
00437
00438
00439
00440
00441 Sym BOXCASE = symbol ("BoxCase");
00442 Sym BOXPATMATCHER = symbol ("BoxPatMatcher");
00443 Sym BOXPATVAR = symbol ("BoxPatVar");
00444
00445 Tree boxCase (Tree rules) { return tree(BOXCASE, rules); }
00446 bool isBoxCase (Tree s) { Tree rules; return isTree(s, BOXCASE, rules); }
00447 bool isBoxCase (Tree s, Tree& rules) { return isTree(s, BOXCASE, rules); }
00448
00449 Tree boxPatternVar (Tree id) { return tree(BOXPATVAR, id); }
00450 bool isBoxPatternVar(Tree s, Tree& id) { return isTree(s, BOXPATVAR, id); }
00451
00452
00453 Tree boxPatternMatcher (Automaton* a, int state, Tree env, Tree origRules, Tree revParamList)
00454 {
00455 return tree(BOXPATMATCHER, tree((void*)a), tree(state), env, origRules, revParamList);
00456 }
00457
00458 bool isBoxPatternMatcher (Tree s)
00459 {
00460 Tree ta, ts, env, orig, rpl;
00461 return isTree(s, BOXPATMATCHER, ta, ts, env, orig, rpl);
00462 }
00463
00464 bool isBoxPatternMatcher (Tree s, Automaton*& a, int& state, Tree& env, Tree& origRules, Tree& revParamList)
00465 {
00466 Tree ta, ts;
00467 if (isTree(s, BOXPATMATCHER, ta, ts, env, origRules, revParamList)) {
00468 a = (Automaton*)tree2ptr(ta);
00469 state = tree2int(ts);
00470 return true;
00471 } else {
00472 return false;
00473 }
00474 }
00475
00476