Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
//------------------------------------------------------
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;
}
Ejemplo n.º 3
0
take_tree (expr x)
{
	if (!atom(x) && cons_free(x & 0x7FFF))
	{
		take_cons (x & 0x7FFF);
		take_tree (car(x));
		take_tree (cdr(x));
	}
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
//------------------------------------------------------
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);
		}
	}
}
Ejemplo n.º 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;
}
Ejemplo n.º 7
0
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);
	}

}