Beispiel #1
0
 void PrintArray(){
	Lemon le1(1.4), le2(4.3), le3(2.1);
	Orange or1(.9), or2(0.2), or3(0.6);
	CitrusFruit *cfarr[] = {&or1, &le1,
							 &or2, &le2,
							 &or3, &le3};
	for(int i = 0; i < 6; i++)
		PrintTheFruits(*(cfarr[i]));
 }
Beispiel #2
0
int sc_main(int argc, char *argv[])
{

	sc_signal<bool> or_1,or_2,and_3,and_4,and_5,and_6,nor_7,CO,SUM,A,B,CI;

	OR2  or1("or1");
	OR2  or8("or8");
 	OR3  or2("or2");
 	AND2 and3("and3");
 	AND2 and4("and4");
 	AND2 and5("and5");
 	AND3 and6("and6");
 	NOR2 nor7("nor7");
 	INV inv9("inv9");

 	or1.a(A); or1.b(B); or1.o(or_1);
  	or2.a(A); or2.b(B); or2.c(CI); or2.o(or_2);
  	and3.a(or_1); and3.b(CI); and3.o(and_3);
  	and4.a(A); and4.b(B); and4.o(and_4);
  	and5.a(nor_7); and5.b(or_2); and5.o(and_5);
  	and6.a(A); and6.b(B); and6.c(CI); and6.o(and_6);
  	nor7.a(and_3); nor7.b(and_4); nor7.o(nor_7);
  	or8.a(and_5); or8.b(and_6); or8.o(SUM);
  	inv9.a(nor_7); inv9.o(CO);

	//sc_initialize();   // initialize the simulation engine
	  // create the file to store simulation results
	sc_trace_file *tf = sc_create_vcd_trace_file("trace");
	  // 4: specify the signals we’d like to record in the trace file
	sc_trace(tf, A, "A"); sc_trace(tf, B, "B");
	sc_trace(tf, CI, "CI");
	sc_trace(tf, SUM, "SUM"); sc_trace(tf, CO, "CO");
	  // 5: put values on the input signals
	A=0; B=0; CI=0;                 // initialize the input values
	sc_start(10, SC_PS);
	for( int i = 0 ; i < 8 ; i++ )  // generate all input combinations
	  {
	      A  = ((i & 0x1) != 0);    // value of A is the bit0 of i
	      B  = ((i & 0x2) != 0);    // value of B is the bit1 of i
	      CI = ((i & 0x4) != 0);    // value of CI is the bit2 of i
	      sc_start(10, SC_PS);           // evaluate
	   }
	 
	sc_close_vcd_trace_file(tf);    // close file and we’re done
	return 0;
}
Beispiel #3
0
//prints the clauses corresponding to the  "greater than or equal to" operation between two array of literals, p1 an p2 - all arrays with 'bits' literals representing integer numbers in the binary system.
void ClauseGen::geq(long* p1, long* p2, int bits){
	long conj, disj, greater, equal;
	int i;
	conj = topAtom++;
	eq_equiv2(conj, p1[0],p2[0]);
	for(i=0;i<bits-1;i++){
		greater = topAtom++;
		eq_and2(greater, p1[i],-p2[i]);
		disj = topAtom++;
		eq_or2(disj, greater, conj);
		equal = topAtom++;
		eq_equiv2(equal, p1[i+1],p2[i+1]);
		conj = topAtom++;
		eq_and2(conj, equal, disj);
	}
	greater = topAtom++;
	eq_and2(greater, p1[bits-1],-p2[bits-1]);
	or2(greater, conj);
}
Beispiel #4
0
val ftw_wrap(val dirpath, val fn, val flags_in, val nopenfd_in)
{
  if (s_callback) {
    uw_throwf(error_s, lit("ftw: cannot be re-entered from "
                           "ftw callback"), nao);
  } else if (dirpath == nil) {
    return t;
  } else if (consp(dirpath)) {
    uses_or2;
    val ret = nil;
    for (; dirpath; dirpath = cdr(dirpath)) {
      val res = ftw_wrap(car(dirpath), fn, flags_in, nopenfd_in);
      if (res != t && res != nil)
        return res;
      ret = or2(ret, res);
    }
    return ret;
  } else {
    int nopenfd = c_num(default_arg(nopenfd_in, num_fast(20)));
    int flags = c_num(default_arg(flags_in, zero));
    char *dirpath_u8 = utf8_dup_to(c_str(dirpath));
    int res = (s_callback = fn,
               nftw(dirpath_u8, ftw_callback, nopenfd, flags));
    s_callback = nil;
    free(dirpath_u8);

    if (s_exit_point) {
      uw_frame_t *ep = s_exit_point;
      s_exit_point = 0;
      uw_continue(ep);
    }

    switch (res) {
    case 0:
      return t;
    case -1:
      return nil;
    default:
      return num(res);
    }
  }
}
Beispiel #5
0
int old_main( int args, char **argv ){
  /*
    Useful cull test cases:
    one literal T,F,BTerm
    one AND
    SOR in DNF
    SOR not in DNF
    SAND not in DNF
   */
  //To quiet compiler
  args = 1;
  char ** argv2 = argv;
  argv2 = argv2;

  //Test SymTree

  SymTree * st1 = new SymTree(1);
  st1 = and2(st1,new SymTree(2));
  st1 = or2(st1,3);
  st1 = or2(st1,4);

  SymTree * st2 = new SymTree(10);
  st2 = or2(st2,11);
  st2 = or2(st2,12);
  
  
  st1 = or2(st1,new SymTree(st2));
  cout << "AND and OR tests" << endl;
  st1->printTree();
  
  SymTree *st3;
  st3 = new SymTree(20);
  st3 = and2(st3,21);
  st3 = and2(st3,22);
  st3 = and2(st3,23);

  st3->printTree();
  delete st3;
 
  st1 = and2(st1,st2);

  st2 = 0;

  st1->printTree();
  //Should have been 20^21^22^(1\/2\/3\/4\/10\/11\/12)
  SymTree *tmp;
  cout << "TEST and2\n";
  tmp = and2(1,2);
  tmp->printTree();
  delete tmp;
  tmp = 0;

  cout << "TEST copy";
  SymTree *st1c = new SymTree(st1);
  st1 = or2(st1, and2(30,31) );
  st1c->printTree();
  
  delete st1c;
  st1c = 0;

  st1->printTree();
  
  delete st1;
  st1 = 0;

  cout << "TEST remove duplicate terms from SymNode"<<endl;

  SymNode * root = new SymNode(SAND, -1);
  root->addChild(new SymNode(BTERM, 1));
  noDuplicateNodes(root->children);
  cout <<"when only 1 node is present" <<endl;
  root->printTree(0);

  cout <<"when only 2 nodes are present, same." <<endl;
  root->addChild(new SymNode(BTERM, 1));
  noDuplicateNodes(root->children);
  root->printTree(0);

  cout <<"when 3 nodes are present, same." <<endl;
  root->addChild(new SymNode(BTERM, 1));
  root->addChild(new SymNode(BTERM, 1));
  root->addChild(new SymNode(BTERM, 1));
  noDuplicateNodes(root->children);
  root->printTree(0);
  

  cout <<"when 4 nodes are present, 3 same." <<endl;
  root->addChild(new SymNode(BTERM, 1));
  root->addChild(new SymNode(BTERM, 2));  
  root->addChild(new SymNode(BTERM, 1));
  root->addChild(new SymNode(BTERM, 1));
  noDuplicateNodes(root->children);
  root->printTree(0);

  root->destroyTree();
  root = 0;

  cout << "TEST toDNF "<< endl;

  SymTree *dnfTest = new SymTree(1);
  cout << "simple singleton\nbefore:"<< endl;
  dnfTest->printTree();
  dnfTest->toDNF();
  cout <<"after"<<endl;
  dnfTest->printTree();
  
  testIterator(dnfTest);

  cout << "simple 2-and\nbefore:"<< endl;
  dnfTest = and2( dnfTest,2);
  dnfTest->printTree();
  dnfTest->toDNF();
  cout <<"after"<<endl;
  dnfTest->printTree();
  
  testIterator(dnfTest);

  cout << "simple 3-and\nbefore:"<< endl;
  dnfTest = and2(dnfTest,3);
  dnfTest->printTree();
  dnfTest->toDNF();
  cout <<"after"<<endl;
  dnfTest->printTree();

  cout << "simple 4-and\nbefore:"<< endl;
  dnfTest = and2(dnfTest,4);
  dnfTest->printTree();
  dnfTest->toDNF();
  cout <<"after"<<endl;
  dnfTest->printTree();

  cout << "(5 or (and 1 2 3 4))\nbefore:"<< endl;  
  dnfTest = or2(dnfTest,5);
  dnfTest->printTree();
  dnfTest->toDNF();
  dnfTest->printTree();


  cout << "(or 5 6 (and 1 2 3 4))\nbefore:"<< endl;  
  dnfTest = or2(dnfTest,6);
  dnfTest->printTree();
  dnfTest->toDNF();
  dnfTest->printTree();
  
  cout << "(or 5 6 7 (and 1 2 3 4))\nbefore:"<< endl;  
  dnfTest = or2(dnfTest,7);
  dnfTest->printTree();
  dnfTest->toDNF();
  dnfTest->printTree();
  
  testIterator(dnfTest);

  cout << "(and 8 (or 5 6 ))\nbefore:"<< endl;  
  SymTree *dnfTestPrime = and2( new SymTree(8),or2(5,6));
  dnfTestPrime->printTree();
  dnfTestPrime->toDNF();
  dnfTestPrime->printTree();

  testIterator(dnfTestPrime);

  delete dnfTestPrime;
  dnfTestPrime = 0;

  cout << "(and 8 (or 5 6 7(and 1 2 3 4)))\nbefore:"<< endl;  
  dnfTest = and2(dnfTest,8);
  dnfTest->printTree();
  dnfTest->toDNF();
  dnfTest->printTree();
  

  cout << "(and 8 9 (or 5 6 7(and 1 2 3 4)))\nbefore:"<< endl;  
  //This below is a massive memory leak
  // BK comment: only leak in main (8/7/2007)
  SymTree *dnfTestSecond = and2(1,2)->sand(and2( 3,4))->sor(7)->sor(or2(5,6))->sand(and2(8,9));
  dnfTestSecond->printTree();
  cout << "after" <<endl;
  dnfTestSecond->toDNF();
  dnfTestSecond->printTree();


  cout << "(and 8 8 9 (or 5 6 7(and 1 2 3 4)))\nbefore:"<< endl;  
  dnfTestSecond = and2(dnfTestSecond,8);
  dnfTestSecond->printTree();
  cout << "after" <<endl;
  dnfTestSecond->toDNF();
  dnfTestSecond->printTree();
  
  cout << "\nCULLING Test:\nbefore" << endl;
  dnfTestSecond = or2(dnfTestSecond , and2( and2(13,12),and2(13,12)) );
  dnfTestSecond->printTree();
  dnfTestSecond->cull();
  cout << "after" << endl;
  dnfTestSecond->printTree();

  testIterator(dnfTest);

  delete dnfTest;
  dnfTest = NULL;

  delete dnfTestSecond;
  dnfTestSecond = 0;

  cout << "END TEST"<< endl;;


  // Success Case
  cout << "Success CASE" << endl;
  SymTree * tree = new SymTree();
  SymTree* children = new SymTree(4);
  SymTree* children2 = children->sand(5);
  delete children;
  children = children2;
  SymTree* tree2 = tree->sor(children);
  delete children;
  delete tree;
  tree=tree2;
  //delete children2;
  children = NULL;
  children = new SymTree(6);
  children2 = children->sand(7);
  delete children;
  children = children2;
  tree2 = tree->sor(children);
  delete children;
  delete tree;
  tree = tree2;
  children = new SymTree(6);
  children2 = children->sor(7);
  delete children;
  children = children2;
  tree2 = tree->sand(children);
  delete children;
  delete tree;
  tree = tree2;

  tree->printTree();
  cout << "toDNF" << endl;
  tree->toDNF();
  tree->printTree();
  cout << "cull" << endl;
  tree->cull();
  tree->printTree();
  cout << "END Success CASE" << endl << endl << endl;
  delete tree;



  SymTree *myTree = and2( and2(or2((BTerm)0,1),1),and2((BTerm)0,1));
  myTree->printTree();
		
  myTree->toDNF();
  myTree->printTree();
  myTree->cull();
  myTree->printTree();
  delete myTree;



  // Fail Case
  cout << "FAIL CASE:" << endl;
  SymTree* testCase = new SymTree();
  
  // Valid options (i.e. solutions)
  SymTree* myAnd = new SymTree();
  myAnd = and2((BTerm)0,5);
  testCase = or2(testCase, myAnd);
  myAnd = and2((BTerm)0,15);
  testCase = or2(testCase, myAnd);
  myAnd = and2((BTerm)0,7);
  testCase = or2(testCase, myAnd);
  myAnd = and2((BTerm)0,13);
  testCase = or2(testCase, myAnd);
  myAnd = and2(5,20);
  testCase = or2(testCase, myAnd);
  myAnd = and2(15,20);
  testCase = or2(testCase, myAnd);
  myAnd = and2(7,20);
  testCase = or2(testCase, myAnd);
  myAnd = and2(13,20);
  testCase = or2(testCase, myAnd);
  myAnd = and2(4,5);
  testCase = or2(testCase, myAnd);
  myAnd = and2(4,15);
  testCase = or2(testCase, myAnd);
  myAnd = and2(4,7);
  testCase = or2(testCase, myAnd);
  myAnd = and2(4,13);
  testCase = or2(testCase, myAnd);
  myAnd = and2(5,16);
  testCase = or2(testCase, myAnd);
  myAnd = and2(15,16);
  testCase = or2(testCase, myAnd);
  myAnd = and2(7,16);
  testCase = or2(testCase, myAnd);
  myAnd = and2(13,16);
  testCase = or2(testCase, myAnd);

  // All possible haplotype assignments for Father
//   SymTree* myAnd = new SymTree();
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)7);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)6);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)1);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)0);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)3);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)2);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)6,(BTerm)1);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)7,(BTerm)0);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)13);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)12);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)15);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)14);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)6,(BTerm)13);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)7,(BTerm)12);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)9);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)8);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)11);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)10);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)6,(BTerm)9);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)7,(BTerm)8);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)0,(BTerm)13);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)1,(BTerm)12);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)0,(BTerm)15);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)1,(BTerm)14);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)2,(BTerm)13);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)3,(BTerm)12);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)21);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)20);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)23);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)22);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)6,(BTerm)21);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)7,(BTerm)20);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)17);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)16);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)19);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)18);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)6,(BTerm)17);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)7,(BTerm)16);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)0,(BTerm)21);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)1,(BTerm)20);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)0,(BTerm)23);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)1,(BTerm)22);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)2,(BTerm)21);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)3,(BTerm)20);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)29);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)28);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)31);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)30);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)6,(BTerm)29);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)7,(BTerm)28);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)25);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)24);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)4,(BTerm)27);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)5,(BTerm)26);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)6,(BTerm)25);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)7,(BTerm)24);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)0,(BTerm)29);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)1,(BTerm)28);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)0,(BTerm)31);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)1,(BTerm)30);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)2,(BTerm)29);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)3,(BTerm)28);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)12,(BTerm)21);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)13,(BTerm)20);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)12,(BTerm)23);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)13,(BTerm)22);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)14,(BTerm)21);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)15,(BTerm)20);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)12,(BTerm)17);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)13,(BTerm)16);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)12,(BTerm)19);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)13,(BTerm)18);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)14,(BTerm)17);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)15,(BTerm)16);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)8,(BTerm)21);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)9,(BTerm)20);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)8,(BTerm)23);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)9,(BTerm)22);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)10,(BTerm)21);
//   testCase = or2(testCase, myAnd);
//   myAnd = and2((BTerm)11,(BTerm)20);
//   testCase = or2(testCase, myAnd);

  SymTree* testCase2 = new SymTree();
  SymTree* myOr = new SymTree();
  myOr = or2(or2(or2(5,15), 7), 13);
  testCase2 = and2(testCase2, myOr);
  myOr = or2(or2(or2(5,15), 7), 13);
  testCase2 = and2(testCase2, myOr);
  myOr = or2(or2(or2((BTerm) 0,20), 4), 16);
  testCase2 = and2(testCase2, myOr);
  myOr = or2(or2(or2(or2(or2(or2(or2((BTerm) 0, 21), 1), 20), 4), 17), 5), 16);
  testCase2 = and2(testCase2, myOr);
  myOr = or2(or2(or2(or2(or2(or2(or2(4, 15), 5), 14), 6), 13), 7), 12);
  testCase2 = and2(testCase2, myOr);
  myOr = or2(or2(or2(or2(or2(or2(or2(4, 15), 5), 14), 6), 13), 7), 12);
  testCase2 = and2(testCase2, myOr);
  cout << "  first step toDNF and cull" << endl;
  testCase2->toDNF();
  testCase2->cull();

  testCase = and2(testCase, testCase2);

  testCase->printTree();
  printf("BIG ToDNF\n");
  testCase->toDNF();
  printf("BIG Cull\n");
  testCase->cull();
  testCase->printTree();
  cout << "END FAIL CASE" << endl << endl << endl;

  delete testCase;


  return 0;
}
Beispiel #6
0
val debug(val ctx, val bindings, val data, val line, val pos, val base)
{
  uses_or2;
  val form = ctx_form(ctx);
  val rl = source_loc(form);
  cons_bind (lineno, file, rl);

  if (consp(data))
    data = car(data);
  else if (data == t)
    data = nil;

  if (!step_mode && !memqual(rl, breakpoints)
      && (debug_depth > next_depth))
  {
    return nil;
  } else {
    val print_form = t;
    val print_data = t;

    for (;;) {
      val input, command;

      if (print_form) {
        format(std_debug, lit("stopped at line ~d of ~a\n"),
               lineno, file, nao);
        format(std_debug, lit("form: ~s\n"), form, nao);
        format(std_debug, lit("depth: ~s\n"), num(debug_depth), nao);
        print_form = nil;
      }

      if (print_data) {
        int lim = cols * 8;

        if (data && pos) {
          val half = num((lim - 8) / 2);
          val full = num((lim - 8));
          val prefix, suffix;

          if (lt(pos, half)) {
            prefix = sub_str(data, zero, pos);
            suffix = sub_str(data, pos, full);
          } else {
            prefix = sub_str(data, minus(pos, half), pos);
            suffix = sub_str(data, pos, plus(pos, half));
          }

          format(std_debug, lit("data (~d:~d):\n~s . ~s\n"),
                 line, plus(pos, base), prefix, suffix, nao);
        } else if (data && length_str_ge(data, num(lim - 2))) {
          format(std_debug, lit("data (~d):\n~s...~s\n"), line,
                 sub_str(data, zero, num(lim/2 - 4)),
                 sub_str(data, num(-(lim/2 - 3)), t), nao);
        } else {
          format(std_debug, lit("data (~d):\n~s\n"), line, data, nao);
        }
        print_data = nil;
      }

      format(std_debug, lit("txr> "), nao);
      flush_stream(std_debug);

      input = split_str_set(or2(get_line(std_input), lit("q")), lit("\t "));
      command = if3(equal(first(input), null_string),
                    or2(last_command, lit("")), first(input));
      last_command = command;

      if (equal(command, lit("?")) || equal(command, lit("h"))) {
        help(std_debug);
        continue;
      } else if (equal(command, null_string)) {
        continue;
      } else if (equal(command, lit("c"))) {
        step_mode = 0;
        next_depth = -1;
        return nil;
      } else if (equal(command, lit("s"))) {
        step_mode = 1;
        return nil;
      } else if (equal(command, lit("n"))) {
        step_mode = 0;
        next_depth = debug_depth;
        return nil;
      } else if (equal(command, lit("f"))) {
        step_mode = 0;
        next_depth = debug_depth - 1;
        return nil;
      } else if (equal(command, lit("v"))) {
        show_bindings(bindings, std_debug);
      } else if (equal(command, lit("o"))) {
        print_form = t;
      } else if (equal(command, lit("i"))) {
        print_data = t;
      } else if (equal(command, lit("b")) || equal(command, lit("d")) ||
                 equal(command, lit("g")))
      {
        if (!rest(input)) {
          format(std_debug, lit("~s needs arguments\n"), command, nao);
          continue;
        } else {
          val n = int_str(second(input), num(10));
          val l = cons(n, or2(third(input), file));

          if (!n) {
            format(std_debug, lit("~s needs <line> [ <file> ]\n"),
                   command, nao);
            continue;
          }

          if (equal(command, lit("b"))) {
            breakpoints = remqual(l, breakpoints, nil);
            push(l, &breakpoints);
          } else if (equal(command, lit("d"))) {
            val breakpoints_old = breakpoints;
            breakpoints = remqual(l, breakpoints, nil);
            if (breakpoints == breakpoints_old)
              format(std_debug, lit("no such breakpoint\n"), nao);
          } else {
            opt_loglevel = c_num(n);
          }
        }
      } else if (equal(command, lit("l"))) {
        format(std_debug, lit("breakpoints: ~s\n"), breakpoints, nao);
      } else if (equal(command, lit("w"))) {
        format(std_debug, lit("backtrace:\n"), nao);
        {
          uw_frame_t *iter;

          for (iter = uw_current_frame(); iter != 0; iter = iter->uw.up) {
            if (iter->uw.type == UW_DBG) {
              if (iter->db.ub_p_a_pairs)
                format(std_debug, lit("(~s ~s ~s)\n"), iter->db.func,
                       args_copy_to_list(iter->db.args),
                       iter->db.ub_p_a_pairs, nao);
              else
                format(std_debug, lit("(~s ~s)\n"), iter->db.func,
                       args_copy_to_list(iter->db.args), nao);
            }
          }
        }
      } else if (equal(command, lit("q"))) {
        uw_throwf(debug_quit_s, lit("terminated via debugger"), nao);
      } else {
        format(std_debug, lit("unrecognized command: ~a\n"), command, nao);
      }
    }

    return nil;
  }
}