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