Пример #1
0
reg_closure_t *create_reg_primop_closure(OBJECT_PTR    operator,
                                         OBJECT_PTR    operands,
                                         unsigned int  nof_vals,
                                         OBJECT_PTR    *vals,
                                         reg_closure_t *cls)
{  
  reg_closure_t *primop_closure = (reg_closure_t *)GC_MALLOC(sizeof(reg_closure_t));

  if(cons_length(operands) == 0) //last binding
    primop_closure->fn = primop_cont_fn_non_recur;
  else
    primop_closure->fn = primop_cont_fn_recur;

  primop_closure->nof_closed_vals = nof_vals + 2;
  primop_closure->closed_vals     = (OBJECT_PTR *)GC_MALLOC(primop_closure->nof_closed_vals * sizeof(OBJECT_PTR));

  primop_closure->closed_vals[0]  = operator;
  primop_closure->closed_vals[1]  = operands;

  int i;
  for(i=2; i<primop_closure->nof_closed_vals; i++)
    primop_closure->closed_vals[i] = vals[i-2];

  primop_closure->data = cls;
  
  return primop_closure;
}
Пример #2
0
reg_closure_t *create_reg_app_closure(OBJECT_PTR    exp,
                                      unsigned int  nof_vals,
                                      OBJECT_PTR    *vals,
                                      reg_closure_t *cls)
{  
  reg_closure_t *app_closure = (reg_closure_t *)GC_MALLOC(sizeof(reg_closure_t));

  if(cons_length(exp) == 0) //last binding
    app_closure->fn = app_cont_fn_non_recur;
  else
    app_closure->fn = app_cont_fn_recur;

  app_closure->nof_closed_vals = nof_vals + 1;
  app_closure->closed_vals     = (OBJECT_PTR *)GC_MALLOC(app_closure->nof_closed_vals * sizeof(OBJECT_PTR));

  app_closure->closed_vals[0]  = exp;

  int i;
  for(i=1; i<app_closure->nof_closed_vals; i++)
    app_closure->closed_vals[i] = vals[i-1];

  app_closure->data = cls;
  
  return app_closure;
}
Пример #3
0
reg_closure_t *create_reg_let_closure(OBJECT_PTR    bindings,
                                      OBJECT_PTR    full_bindings,
                                      OBJECT_PTR    body,
                                      unsigned int  nof_vals,
                                      OBJECT_PTR    *vals,
                                      reg_closure_t *cls)
{  
  reg_closure_t *let_closure = (reg_closure_t *)GC_MALLOC(sizeof(reg_closure_t));

  if(cons_length(bindings) == 0) //last binding
    let_closure->fn = let_cont_fn_non_recur;
  else
    let_closure->fn = let_cont_fn_recur;

  let_closure->nof_closed_vals = nof_vals + 3;
  let_closure->closed_vals     = (OBJECT_PTR *)GC_MALLOC(let_closure->nof_closed_vals * sizeof(OBJECT_PTR));

  let_closure->closed_vals[0]  = bindings;
  let_closure->closed_vals[1]  = full_bindings;
  let_closure->closed_vals[2]  = body;

  int i;
  for(i=3; i<let_closure->nof_closed_vals; i++)
    let_closure->closed_vals[i] = vals[i-3];

  let_closure->data = cls;
  
  return let_closure;
}
Пример #4
0
void print_statistics(hash_table* ht)
{
    int min_length = 0, max_length = 0;
    int curLength, NnonzeroConses = 0, SummarConsLength = 0;
    int i, n = ht->hash_div;
    cons** table = ht->table;

    for (i = 0; i < n; i++) {
        if (table[i] != NULL) {
            ++NnonzeroConses;
            curLength = cons_length(&table[i]);
            SummarConsLength += curLength;
            if (curLength < min_length || !min_length) {
                min_length = curLength;
            }
            if (curLength > max_length) {
                max_length = curLength;
            }
        }
    }

    pprint_stat(NnonzeroConses, SummarConsLength, min_length, max_length);
}