示例#1
0
文件: expr.c 项目: jbailhache/log
expr cons (expr a, expr d)
{
expr c;
#ifdef TRACE
	printf ("\n\t\tcons (car=");
	print_expr (a);
	printf (", cdr=");
	print_expr (d);
	printf (")...");
#endif
	while (!cons_free(ptr_cons) && ptr_cons < N_CONS-1)
		ptr_cons++;
	if (!cons_free(ptr_cons))
		gc ();
	take_cons (ptr_cons);
	tab_cons [ptr_cons] [0] = a;
	tab_cons [ptr_cons] [1] = d;
	c = (ptr_cons | 0x8000) ;
#ifdef TRACE
	printf ("\n\t\tcons (car=");
	print_expr (a);
	printf (", cdr=");
	print_expr (d);
	printf (") = ");
	print_expr (c);
#endif
	return c;
}
示例#2
0
文件: lisp.cpp 项目: wakama2/lisp2
//------------------------------------------------------
void cons_free(Cons *cons) {
	if(cons->type == CONS_CAR && cons->car != NULL) {
		cons_free(cons->car);
	} else if(cons->type == CONS_STR) {
		delete [] cons->str;
	}
	if(cons->cdr != NULL) {
		cons_free(cons->cdr);
	}
	delete cons;
}
示例#3
0
文件: expr.c 项目: jbailhache/log
take_tree (expr x)
{
	if (!atom(x) && cons_free(x & 0x7FFF))
	{
		take_cons (x & 0x7FFF);
		take_tree (car(x));
		take_tree (cdr(x));
	}
}
示例#4
0
文件: hash_table.c 项目: Columpio/hw
void del_hash_table(hash_table* ht)
{
    int i, n = ht->hash_div;
    cons** table = ht->table;

    for (i = 0; i < n; i++) {
        cons_free(&table[i]);
    }

    free(table);
    free(ht);
}
示例#5
0
文件: lisp.cpp 项目: wakama2/lisp2
//------------------------------------------------------
static void compileAndRun(Context *ctx, Reader *r) {
	Tokenizer tk(r);
	Cons *res;
	while(parseCons(&tk, &res)) {
		if(res != NULL) {
			res->cdr = NULL;
			//cons_println(res);
			runCons(ctx, res);
			cons_free(res);
		}
	}
}
示例#6
0
int main() {
  
  // CONSTRUCTOR
  void* car = malloc(sizeof(int));;
  int cdr = 2;
  cons_t* c = cons(car, &cdr);
  assert(c->car == car);
  assert(c->cdr == &cdr);
  cons_free(c, free, NULL);

  return 0;
}
示例#7
0
文件: expr.c 项目: jbailhache/log
gc ()
{
int i, pr, n;
	for (i=0; i<N_CONS; i++)
		free_cons(i);
	pr = ptr_recup - 1;
	n = n_decl;
	while (n != -1 && pr > 0)
	{
		for (i=0; i<n; i++)
			take_tree (*(tab_recup[pr-i].adr));
		pr -= n;
		n = tab_recup[pr--].n;
	}
	ptr_cons = 0;
	while (!cons_free(ptr_cons) && ptr_cons < N_CONS-1)
		ptr_cons++;
	if (!cons_free(ptr_cons))
	{
		fprintf (stderr, "Memory overflow\n");
		exit (-1);
	}

}